Merge commit '1d5c59a175fa4bcc9d525f1feda2cd4b9415143e'

This commit is contained in:
Scott R Charlton 2018-07-31 18:45:29 -06:00
commit 526e02330d
150 changed files with 130516 additions and 0 deletions

View File

@ -0,0 +1,227 @@
// 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.h"
#include <iostream>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ChartHandler::ChartHandler(PHRQ_io *io)
:
PHRQ_base(io)
//
// default constructor for ChartHandler
//
{
current_chart = NULL;
current_chart_n_user = -1000;
u_g_defined = false;
timer = true;
active_charts = 0;
}
ChartHandler::~ChartHandler()
{
std::map<int, ChartObject *>::iterator it;
for (it = this->chart_map.begin(); it != chart_map.end(); it++)
{
delete it->second;
}
}
void
ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr)
{
std::map<int, ChartObject *>::iterator it = this->chart_map.begin();
for ( ; it != chart_map.end(); it++)
{
if (it->second->Get_active())
{
#if defined(__cplusplus_cli)
while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 4, 0))
{
System::Threading::Thread::Sleep(5);
}
#endif
try
{
this->current_chart = it->second;
phreeqc_ptr-> punch_user_graph();
}
catch (...)
{
#if defined(__cplusplus_cli)
int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0);
assert(n == 4);
#endif
throw;
}
#if defined(__cplusplus_cli)
System::Threading::Interlocked::Exchange(it->second->usingResource, 0);
#endif
}
}
}
bool
ChartHandler::Read(Phreeqc * phreeqc_ptr, 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<int, ChartObject *>::iterator it = this->chart_map.find(n_user);
if (it == this->chart_map.end())
{
chart_map[n_user] = new ChartObject(this->Get_io());
it = this->chart_map.find(n_user);
it->second->Set_phreeqc(phreeqc_ptr);
}
// Read/update ChartObject
#if defined(__cplusplus_cli)
while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 5, 0))
{
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;
}
// 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(...)
{
#if defined(__cplusplus_cli)
// Release lock
int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0);
assert(n == 5);
throw;
#endif
}
#if defined(__cplusplus_cli)
// Release lock
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
if (it->second->Get_detach())
{
while (it->second->Get_form_started() && it->second->Get_done() != true)
{
#if defined(__cplusplus_cli)
System::Threading::Thread::Sleep(5);
#endif
}
delete it->second;
this->chart_map.erase(it);
}
return true;
}
bool
ChartHandler::End_timer()
{
size_t max_tries = 6000; // 1 h, but not used
std::map<int, ChartObject *>::iterator it = this->chart_map.begin();
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++)
{
i = 0;
it->second->Rate_free();
if (it->second->Get_form_started())
{
#if defined(__cplusplus_cli)
while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 6, 0))
{
//if (i > max_tries) break;
i++;
System::Threading::Thread::Sleep(60);
}
#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);
#endif
i2 = 0;
while (it->second->Get_done() != true)
{
//if (i2 > max_tries) break;
i2++;
#if defined(__cplusplus_cli)
System::Threading::Thread::Sleep(60);
#endif
}
//if (i >= max_tries || i2 >= max_tries)
//{
// error_msg("\nChart did not respond.", CONTINUE);
//}
}
}
if (chart_map.size() > 0)
{
screen_msg("\rCharts detached. \n");
if (io != NULL)
{
io->error_flush();
}
}
this->timer = false;
return true;
}
bool
ChartHandler::dump(std::ostream & oss, unsigned int indent)
{
std::map<int, ChartObject *>::iterator it = this->chart_map.begin();
for ( ; it != chart_map.end(); it++)
{
size_t i = 0;
it->second->dump(oss, indent);
}
return true;
}
#endif

View File

@ -0,0 +1,59 @@
#if !defined(CHARTHANDLER_H_INCLUDED)
#define CHARTHANDLER_H_INCLUDED
#if defined MULTICHART
#include <vector>
#include <map>
#include <string>
#include "Parser.h"
#include "ChartObject.h"
#include "PHRQ_base.h"
class ChartHandler: public PHRQ_base
{
public:
ChartHandler(PHRQ_io *io = NULL);
virtual ~ChartHandler();
size_t Get_chart_count()const
{
return this->chart_map.size();
}
ChartObject * Get_current_chart()
{
return this->current_chart;
}
const ChartObject * Get_current_chart()const
{
return this->current_chart;
}
bool Get_timer()
{
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();
bool dump(std::ostream & oss, unsigned int indent);
protected:
std::map<int, ChartObject *> chart_map;
int current_chart_n_user;
ChartObject * current_chart;
bool u_g_defined;
bool timer;
int active_charts;
public:
};
#endif // MULTICHART
#endif // !defined(CHARTHANDLER_H_INCLUDED)

File diff suppressed because it is too large Load Diff

444
src/phreeqcpp/ChartObject.h Normal file
View File

@ -0,0 +1,444 @@
#if !defined(CHARTOBJECT_H_INCLUDED)
#define CHARTOBJECT_H_INCLUDED
#if defined MULTICHART
#include <vector>
#include <list>
#include <string>
#include <sstream>
#include "CurveObject.h"
#include "NumKeyword.h"
#include <float.h>
class Phreeqc;
class ChartObject:public cxxNumKeyword
{
public:
ChartObject(PHRQ_io *io=NULL);
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()const
{
return this->new_ug;
}
void Set_new_ug(bool b)
{
this->new_ug = b;
}
void Set_FirstCallToUSER_GRAPH(bool b)
{
this->FirstCallToUSER_GRAPH = b;
}
bool Get_FirstCallToUSER_GRAPH()const
{
return this->FirstCallToUSER_GRAPH;
}
int Get_update_time_chart()const
{
return (this->update_time_chart);
}
int Get_PanelHeight()const
{
return (this->PanelHeight);
}
int Get_PanelWidth()const
{
return (this->PanelWidth);
}
std::string &Get_chart_title()
{
return this->chart_title;
}
const std::string &Get_chart_title()const
{
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<std::string> &Get_axis_titles()
{
return this->axis_titles;
}
const std::vector<std::string> &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;
}
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()const
{
return this->graph_initial_solutions;
}
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()const
{
return (this->colnr);
}
void Set_ColumnOffset(int i)
{
this->ColumnOffset = i;
}
int Get_ColumnOffset()const
{
return (this->ColumnOffset);
}
void Set_AddSeries(bool b)
{
this->AddSeries = b;
}
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()const
{
return (this->prev_advection_step);
}
void Set_prev_transport_step(int i)
{
this->prev_transport_step = i;
}
int Get_prev_transport_step()const
{
return (this->prev_transport_step);
}
void Set_prev_sim_no(int i)
{
this->prev_sim_no = i;
}
int Get_prev_sim_no(void)const
{
return this->prev_sim_no;
}
void Set_end_timer(bool b)
{
this->end_timer = b;
}
bool Get_end_timer()const
{
return this->end_timer;
}
void Set_done(bool b)
{
this->done = b;
}
bool Get_done()const
{
return this->done;
}
std::vector<CurveObject *> &Get_CurvesCSV()
{
return this->CurvesCSV;
}
const std::vector<CurveObject *> &Get_CurvesCSV()const
{
return this->CurvesCSV;
}
std::vector<CurveObject *> &Get_Curves()
{
return this->Curves;
}
const std::vector<CurveObject *> &Get_Curves()const
{
return this->Curves;
}
void Set_curve_added(bool tf)
{
this->curve_added = tf;
}
bool Get_curve_added()const
{
return this->curve_added;
}
void Set_point_added(bool tf)
{
this->point_added = tf;
}
bool Get_point_added()const
{
return this->point_added;
}
struct rate *Get_user_graph()
{
return this->user_graph;
}
const struct rate *Get_user_graph()const
{
return this->user_graph;
}
std::list<std::string> &Get_rate_command_list()
{
return this->rate_command_list;
}
const std::list<std::string> &Get_rate_command_list()const
{
return this->rate_command_list;
}
void Set_rate_new_def(bool tf);
bool Get_rate_new_def()const
{
return this->rate_new_def;
}
void Set_graph_x(LDBLE d)
{
this->graph_x = d;
}
LDBLE Get_graph_x()const
{
return this->graph_x;
}
std::map<int, LDBLE> &Get_graph_y()
{
return this->graph_y;
}
const std::map<int, LDBLE> &Get_graph_y()const
{
return this->graph_y;
}
std::map<int, bool> &Get_secondary_y()
{
return this->secondary_y;
}
const std::map<int, bool> &Get_secondary_y()const
{
return this->secondary_y;
}
std::vector<CurveObject> &Get_new_plotxy_curves()
{
return this->new_plotxy_curves;
}
const std::vector<CurveObject> &Get_new_plotxy_curves()const
{
return this->new_plotxy_curves;
}
std::vector<std::string> &Get_new_headings()
{
return this->new_headings;
}
const std::vector<std::string> &Get_new_headings()const
{
return this->new_headings;
}
void Set_active(bool tf)
{
this->active = tf;
}
bool Get_active()const
{
return this->active;
}
void Set_detach(bool tf)
{
this->detach = tf;
}
bool Get_detach()const
{
return this->detach;
}
bool Get_form_started()const
{
return this->form_started;
}
void Set_phreeqc(Phreeqc * ptr)
{
this->phreeqc_ptr = ptr;
}
Phreeqc * Get_phreeqc()
{
return this->phreeqc_ptr;
}
const Phreeqc * Get_phreeqc()const
{
return this->phreeqc_ptr;
}
const std::list<std::string>& Get_rate_command_list_original()const
{
return this->rate_command_list_original;
}
bool Set_axis_scale(std::vector<std::string>, std::vector<int> types, std::ostringstream &);
bool Set_axis_scale(CParser & parser);
bool Read(CParser & parser);
bool OpenCSVFile(std::string fn);
static CurveObject 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 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(bool plotxy, std::string id = "",
LDBLE line_width = 1.0,
std::string symbol = "",
LDBLE symbol_size = 6.0,
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;}
bool Get_batch_grid(void) {return this->batch_grid;}
void Set_batch_grid(bool tf) {this->batch_grid = tf;}
protected:
bool new_ug;
bool FirstCallToUSER_GRAPH;
int update_time_chart; /* milliseconds, maybe read */
int PanelHeight;
int PanelWidth;
std::map<std::string, int> Symbol_map;
std::vector<std::string> Color_vector;
std::string chart_title;
std::vector<std::string> axis_titles;
LDBLE axis_scale_x[5];
LDBLE axis_scale_y[5];
LDBLE axis_scale_y2[5];
int chart_type;
bool graph_initial_solutions;
bool connect_simulations;
int shifts_as_points;
int colnr;
int ColumnOffset;
bool AddSeries;
int prev_advection_step;
int prev_transport_step;
int prev_sim_no;
bool end_timer;
bool done;
std::vector<std::string> csv_file_names;
std::vector<CurveObject *> CurvesCSV;
std::vector<CurveObject *> Curves;
bool curve_added;
bool point_added;
struct rate *user_graph;
// C++ for rate struct
std::string rate_name;
std::list<std::string> rate_command_list;
std::list<std::string> rate_command_list_original;
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.
LDBLE graph_x;
std::map<int, LDBLE> graph_y;
std::map<int, bool> 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<CurveObject> new_plotxy_curves;
// temporary headings until stored during basic_run
std::vector<std::string> new_headings;
std::vector<std::string> headings_original;
bool active;
bool detach;
bool form_started;
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;
public:
int usingResource;
};
#endif // MULTICHART
#endif // !defined(CHARTOBJECT_H_INCLUDED)

View File

@ -0,0 +1,35 @@
// CurveObject.cpp: implementation of the CurveObject class.
//
//////////////////////////////////////////////////////////////////////
#ifdef MULTICHART
#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->id = "";
this->symbol = "";
this->color = "";
this->y_axis = 1;
this->line_w = 1.0;
this->symbol_size = 6.0;
}
CurveObject::~CurveObject()
{
}
#endif // MULTICHART

View File

@ -0,0 +1,79 @@
#if !defined(CURVEOBJECT_H_INCLUDED)
#define CURVEOBJECT_H_INCLUDED
#include <vector>
#include <string>
#include "phrqtype.h"
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(LDBLE f)
{
this->symbol_size = f;
}
LDBLE Get_symbol_size(void)
{
return this->symbol_size;
}
void Set_line_w(LDBLE f)
{
this->line_w = f;
}
LDBLE Get_line_w(void)
{
return this->line_w;
}
void Set_y_axis(int f)
{
this->y_axis = f;
}
std::vector<LDBLE> & Get_x()
{
return this->x;
}
std::vector<LDBLE> & Get_y()
{
return this->y;
}
int Get_y_axis()
{
return this->y_axis;
}
protected:
std::vector<LDBLE> x, y;
std::string id, color, symbol;
int y_axis;
LDBLE line_w, symbol_size;
public:
};
#endif // !defined(CURVEOBJECT_H_INCLUDED)

View File

@ -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<std::string, int>::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;
}

View File

@ -0,0 +1,28 @@
#if !defined(DICTIONARY_H_INCLUDED)
#define DICTIONARY_H_INCLUDED
#include <iostream>
#include <map>
#include <vector>
#include <sstream>
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<std::string> &GetWords() {return this->words;}
protected:
std::map<std::string, int> dictionary_map;
std::vector<std::string> words;
std::ostringstream dictionary_oss;
};
#endif // !defined(DICTIONARY_H_INCLUDED)

450
src/phreeqcpp/ExchComp.cxx Normal file
View File

@ -0,0 +1,450 @@
// ExchComp.cxx: implementation of the cxxExchComp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <iostream> // std::cout std::cerr
#include <cassert> // assert
#include <algorithm> // std::sort
#include <float.h>
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "ExchComp.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxExchComp::cxxExchComp(PHRQ_io *io)
//
// default constructor for cxxExchComp
//
: PHRQ_base(io)
{
totals.type = cxxNameDouble::ND_ELT_MOLES;
la = 0.0;
charge_balance = 0.0;
phase_proportion = 0.0;
formula_z = 0.0;
}
#ifdef SKIP
cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector,
std::vector < LDBLE >&f_vector)
//
// constructor for cxxExchComp from mixing
//
{
if (ec_vector.size() <= 0)
return;
//
// check consistency
//
std::vector < LDBLE >::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;
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
LDBLE 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();)
{
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;
this->phase_proportion += it_ec->phase_proportion * intensive;
this->totals.add_extensive(it_ec->totals, extensive);
it_ec++;
it_f++;
}
}
#endif
cxxExchComp::~cxxExchComp()
{
}
void
cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const
{
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 << "\"" << "\n";
s_oss << indent0 << "formula_z=\"" << this->
formula_z << "\"" << "\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 << 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 << "phase_proportion=\"" << this->
phase_proportion << "\"" << "\n";
// totals
s_oss << indent0;
s_oss << "<totals " << "\n";
this->totals.dump_xml(s_oss, indent + 1);
}
void
cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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 << indent1 << "# critical values" << "\n";
// totals
s_oss << indent0 << "# EXCHANGE_MODIFY candidate identifiers #\n";
s_oss << indent0;
s_oss << "-totals" << "\n";
this->totals.dump_raw(s_oss, indent + 1);
s_oss << indent0 << "-charge_balance " << this->charge_balance << "\n";
//s_oss << indent1 << "# Noncritical values" << "\n";
s_oss << indent0 << "-la " << this->la << "\n";
if (this->phase_name.size() != 0)
{
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 << "-phase_proportion " << this->phase_proportion << "\n";
s_oss << indent0 << "-formula_z " << this->formula_z << "\n";
}
void
cxxExchComp::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_ERROR;
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
break;
case 0: // formula
warning_msg("-formula ignored. Defined with -component.");
break;
case 1: // moles
parser.warning_msg("-moles is an obsolete identifier");
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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
charge_balance_defined = true;
break;
case 4: // 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;
}
break;
case 5: // rate_name
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;
}
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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
opt_save = 8;
break;
case 9: // formula_totals
parser.warning_msg("-formula_totals is an obsolete identifier");
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
if (check)
{
// members that must be defined
if (la_defined == false)
{
parser.incr_input_error();
parser.error_msg("La not defined for ExchComp input.",
PHRQ_io::OT_CONTINUE);
}
if (charge_balance_defined == false)
{
parser.incr_input_error();
parser.error_msg("Charge_balance not defined for ExchComp input.",
PHRQ_io::OT_CONTINUE);
}
if (formula_z_defined == false)
{
parser.incr_input_error();
parser.error_msg("Formula_z not defined for ExchComp input.",
PHRQ_io::OT_CONTINUE);
}
}
}
void
cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive)
{
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;
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.size() == 0 && addee.formula.size() != 0)
{
this->formula = addee.formula;
}
this->totals.add_extensive(addee.totals, extensive);
this->la = f1 * this->la + f2 * addee.la;
this->charge_balance += addee.charge_balance * extensive;
if (this->phase_name != addee.phase_name)
{
std::ostringstream oss;
oss <<
"Cannot mix two exchange components with same formula and different related phases, "
<< this->formula;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
else if (this->phase_name.size() != 0)
{
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
}
if (this->rate_name != addee.rate_name)
{
std::ostringstream oss;
oss <<
"Cannot mix two exchange components with same formula and different related kinetics, "
<< this->formula;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
else if (this->rate_name.size() != 0)
{
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
}
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 <<
"Cannot mix exchange components related to phase with exchange components related to kinetics, "
<< this->formula;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
}
void
cxxExchComp::multiply(LDBLE extensive)
{
this->totals.multiply(extensive);
this->charge_balance *= 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
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]);

125
src/phreeqcpp/ExchComp.h Normal file
View File

@ -0,0 +1,125 @@
#if !defined(EXCHCOMP_H_INCLUDED)
#define EXCHCOMP_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.h"
class cxxExchComp: public PHRQ_base
{
public:
cxxExchComp(PHRQ_io *io=NULL);
virtual ~cxxExchComp();
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_formula() const
{
return this->formula;
}
void Set_formula(const char *cstring)
{
if (cstring != NULL)
this->formula = std::string(cstring);
else
this->formula.clear();
}
LDBLE Get_la() const
{
return this->la;
}
void Set_la(LDBLE d)
{
this->la = d;
}
LDBLE Get_charge_balance() const
{
return this->charge_balance;
}
void Set_charge_balance(LDBLE d)
{
this->charge_balance = d;
}
const std::string &Get_phase_name() const
{
return this->phase_name;
}
void Set_phase_name(const char *cstring)
{
if (cstring != NULL)
this->phase_name = std::string(cstring);
else
this->phase_name.clear();
}
LDBLE Get_phase_proportion() const
{
return this->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 *cstring)
{
if (cstring != NULL)
this->rate_name = std::string(cstring);
else
this->rate_name.clear();
}
LDBLE Get_formula_z() const
{
return this->formula_z;
}
void Set_formula_z(LDBLE 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;
}
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);
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;
// EXCHANGE_MODIFY candidates
cxxNameDouble totals;
LDBLE la;
LDBLE charge_balance;
std::string phase_name;
LDBLE phase_proportion;
std::string rate_name;
LDBLE formula_z; // charge on formula
const static std::vector < std::string > vopts;
public:
};
#endif // !defined(EXCHCOMP_H_INCLUDED)

492
src/phreeqcpp/Exchange.cxx Normal file
View File

@ -0,0 +1,492 @@
// Exchange.cxx: implementation of the cxxExchange class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <iostream> // std::cout std::cerr
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "cxxMix.h"
#include "Exchange.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxExchange::cxxExchange(PHRQ_io *io)
//
// default constructor for cxxExchange
//
: cxxNumKeyword(io)
{
new_def = false;
solution_equilibria = false;
n_solution = -999;
pitzer_exchange_gammas = true;
}
cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities,
cxxMix & mix, int l_n_user, PHRQ_io *io):
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
//
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())
{
const cxxExchange *entity_ptr =
&(entities.find(it->first)->second);
this->add(*entity_ptr, it->second);
this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas;
}
}
}
cxxExchange::~cxxExchange()
{
}
bool
cxxExchange::Get_related_phases() const
{
for (size_t i = 0; i < this->exchange_comps.size(); i++)
{
if (this->exchange_comps[i].Get_phase_name().size() > 0)
{
return (true);
}
}
return (false);
}
bool
cxxExchange::Get_related_rate() const
{
for (size_t i = 0; i < this->exchange_comps.size(); i++)
{
if (this->exchange_comps[i].Get_rate_name().size() > 0)
{
return (true);
}
}
return (false);
}
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("");
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 " << "\n";
s_oss << indent1;
s_oss << "pitzer_exchange_gammas=\"" << this->
pitzer_exchange_gammas << "\"" << "\n";
// components
s_oss << indent1;
s_oss << "<component " << "\n";
for (size_t j = 0; j < this->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("");
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 " << "\n";
s_oss << indent1;
s_oss << "pitzer_exchange_gammas=\"" << this->
pitzer_exchange_gammas << "\"" << "\n";
// components
s_oss << indent1;
s_oss << "<component " << "\n";
for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin();
it != exchComps.end(); ++it)
{
(*it).second.dump_xml(s_oss, indent + 2);
}
return;
}
#endif
void
cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const
{
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;
int n_user_local = (n_out != NULL) ? *n_out : this->n_user;
s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << "\n";
s_oss << indent1 << "# EXCHANGE_MODIFY candidate identifiers #\n";
s_oss << indent1;
s_oss << "-exchange_gammas " << (this->pitzer_exchange_gammas ? 1 : 0) << "\n";
// exchComps
for (size_t i = 0; i < this->exchange_comps.size(); i++)
{
s_oss << indent1;
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 " << 0 << "\n";
s_oss << indent1;
s_oss << "-solution_equilibria " << 0 << "\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)
{
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
bool useLastLine(false);
// Read exchange number and description
this->read_number_description(parser);
this->Set_new_def(false);
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, true);
}
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 EXCH_COMP_RAW keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
break;
case 0: // pitzer_exchange_gammas
case 2: // 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.",
PHRQ_io::OT_CONTINUE);
}
pitzer_exchange_gammas_defined = true;
break;
case 1: // 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
{
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;
}
}
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.",
PHRQ_io::OT_CONTINUE);
}
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.",
PHRQ_io::OT_CONTINUE);
}
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.",
PHRQ_io::OT_CONTINUE);
}
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);
}
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
// members that must be defined
if (check)
{
if (pitzer_exchange_gammas_defined == false)
{
parser.incr_input_error();
parser.
error_msg
("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
}
this->Sort_comps();
}
void
cxxExchange::add(const cxxExchange & addee, LDBLE extensive)
//
// Add existing exchange to "this" exchange
//
{
// exchComps
if (extensive == 0.0)
return;
for (size_t i = 0; i < addee.exchange_comps.size(); i++)
{
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())
{
this->exchange_comps[j].add(addee.exchange_comps[i], extensive);
break;
}
if (j == this->exchange_comps.size())
{
cxxExchComp exc = addee.exchange_comps[i];
exc.multiply(extensive);
this->exchange_comps.push_back(exc);
}
}
this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas;
}
void
cxxExchange::totalize()
{
this->totals.clear();
// component structures
for (size_t i = 0; i < this->exchange_comps.size(); i++)
{
this->totals.add_extensive(this->exchange_comps[i].Get_totals(), 1.0);
this->totals.add("Charge", this->exchange_comps[i].Get_charge_balance());
}
return;
}
bool
cxxExchange::Get_pitzer_exchange_gammas() const
{
return this->pitzer_exchange_gammas;
}
void
cxxExchange::Set_pitzer_exchange_gammas(bool b)
{
this->pitzer_exchange_gammas = b;
}
const cxxNameDouble &
cxxExchange::Get_totals() const
{
return totals;
}
cxxExchComp *cxxExchange::Find_comp(std::string s)
{
for (size_t i = 0; i < this->exchange_comps.size(); i++)
{
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 (&(this->exchange_comps[i]));
}
}
}
return NULL;
}
void cxxExchange::
Sort_comps(void)
{
// sort comps
{
std::map<std::string, cxxExchComp> 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<std::string, cxxExchComp>::iterator it;
for (it = comp_map.begin(); it != comp_map.end(); it++)
{
this->exchange_comps.push_back(it->second);
}
}
}
/* ---------------------------------------------------------------------- */
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
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]);

74
src/phreeqcpp/Exchange.h Normal file
View File

@ -0,0 +1,74 @@
#if !defined(EXCHANGE_H_INCLUDED)
#define EXCHANGE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include "NumKeyword.h"
#include "ExchComp.h"
#include "NameDouble.h"
#include "PHRQ_base.h"
class cxxMix;
class cxxExchange:public cxxNumKeyword
{
public:
cxxExchange(PHRQ_io *io=NULL);
cxxExchange(const std::map < int, cxxExchange > &exchange_map,
cxxMix & mx, int n_user, PHRQ_io *io=NULL);
~cxxExchange();
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;
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;}
cxxExchComp *Find_comp(std::string s);
std::vector<cxxExchComp> & Get_exchange_comps(void) {return this->exchange_comps;}
const std::vector<cxxExchComp> & Get_exchange_comps(void)const {return this->exchange_comps;}
void Set_exchange_comps(std::vector<cxxExchComp> &c) {this->exchange_comps = c;}
void Sort_comps(void);
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);
// not written
void dump_xml(std::ostream & os, unsigned int indent = 0) const;
protected:
// EXCHANGE_MODIFY candidates
std::vector<cxxExchComp> exchange_comps;
bool pitzer_exchange_gammas;
// EXCHANGE_MODIFY candidates with new_def=true
bool new_def;
bool solution_equilibria;
int n_solution;
// exchange workspace variables
cxxNameDouble totals;
const static std::vector < std::string > vopts;
public:
};
#endif // !defined(EXCHANGE_H_INCLUDED)

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!-- In Managed Resources,
set Resource File Name:
$(IntDir)\zdg_ui2.$(InputName).resources
-->
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAP8AMzOaAGgymgA0Mc0AmWVoAGdlmwBjZssAy5kvAP+ZNQDLmmMAzpmVAP/MLQDLzWUA/8xjAP3/
mAAAAAAAiIiIiIiIiIiIgAAIhIiIhHAAAAB3KXcXcAeQAAeTk5fQDd0ADdoK3b27uwALugm7u7u7AAtz
k9vbuwAAu2u7Xbu7AAva29u5zMzAAMzMzMzu7u4ADu7szOAO7gAO7u7u4ADuAA7u7u7uAAAA7u7u7u7g
AA7u7u7u7u7u7u7u7u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA
</value>
</data>
</root>

1151
src/phreeqcpp/Form1.h Normal file

File diff suppressed because it is too large Load Diff

36
src/phreeqcpp/Form1.resX Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!-- In Managed Resources,
set Resource File Name:
$(IntDir)\zdg_ui2.$(InputName).resources
in VS2012: compile with resgen.exe:
click Start, All Programs, Visual Studio 20**, Visual Studio Tools, Visual Studio Command Prompt
resgen path**.Form1.resX
-->
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAP8AMzOaAGgymgA0Mc0AmWVoAGdlmwBjZssAy5kvAP+ZNQDLmmMAzpmVAP/MLQDLzWUA/8xjAP3/
mAAAAAAAiIiIiIiIiIiIgAAIhIiIhHAAAAB3KXcXcAeQAAeTk5fQDd0ADdoK3b27uwALugm7u7u7AAtz
k9vbuwAAu2u7Xbu7AAva29u5zMzAAMzMzMzu7u4ADu7szOAO7gAO7u7u4ADuAA7u7u7uAAAA7u7u7u7g
AA7u7u7u7u7u7u7u7u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA
</value>
</data>
</root>

208
src/phreeqcpp/GasComp.cxx Normal file
View File

@ -0,0 +1,208 @@
// GasComp.cxx: implementation of the cxxGasComp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <iostream> // std::cout std::cerr
#include <cassert> // assert
#include <algorithm> // std::sort
#include <float.h>
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "GasComp.h"
#include "phqalloc.h"
#include "Dictionary.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
{
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 << "# GAS_PHASE_MODIFY candidate identifiers #\n";
s_oss << indent0 << "-moles " << this->moles << "\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
cxxGasComp::read_raw(CParser & parser, bool check)
{
std::string str;
int errors = parser.get_input_error();
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
bool moles_defined(false);
int opt;
for (;;)
{
opt = parser.get_option(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_KEYWORD;
// Allow return to Exchange for more processing
break;
case 0: // phase_name
output_msg("-phase_name is obsolete. Define with -component\n");
break;
case 1: // name
output_msg("-name is obsolete. Define with -component\n");
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 (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;
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);
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;
}
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
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]);

50
src/phreeqcpp/GasComp.h Normal file
View File

@ -0,0 +1,50 @@
#if !defined(GASCOMP_H_INCLUDED)
#define GASCOMP_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.h"
class cxxGasComp: public PHRQ_base
{
public:
cxxGasComp(PHRQ_io *io=NULL);
virtual ~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 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 phase_name;
// GAS_PHASE_MODIFY candidates
LDBLE moles;
// GAS_PHASE_MODIFY candidates with new_def=true
LDBLE p_read;
// internal workspace
LDBLE initial_moles;
const static std::vector < std::string > vopts;
};
#endif // !defined(GASCOMP_H_INCLUDED)

729
src/phreeqcpp/GasPhase.cxx Normal file
View File

@ -0,0 +1,729 @@
// GasPhase.cxx: implementation of the cxxGasPhase class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include <float.h>
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "GasPhase.h"
#include "cxxMix.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxGasPhase::cxxGasPhase(PHRQ_io * io)
//
// default constructor for cxxGasPhase
//
: cxxNumKeyword(io)
{
new_def = false;
solution_equilibria = false;
n_solution = -999;
type = cxxGasPhase::GP_PRESSURE;
total_p = 1.0;
total_moles = 0.0;
volume = 1.0;
v_m = 0;
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)
{
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<std::string, cxxGasComp> comp_map;
std::map<std::string, cxxGasComp>::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++)
{
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<cxxGasComp> 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<cxxGasComp> gc;
for (comp_it = comp_map.begin(); comp_it != comp_map.end(); comp_it++)
{
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<std::string, cxxGasComp> comp_map;
std::map<std::string, cxxGasComp>::iterator comp_it;
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())
{
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_moles = entity_ptr->total_moles * it->second;
this->volume = entity_ptr->volume * it->second;
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
{
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<cxxGasComp> 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<cxxGasComp> 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):
cxxNumKeyword(io)
{
this->n_user = this->n_user_end = l_n_user;
gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF;
total_p = 0;
volume = 0;
v_m = 0;
pr_in = false;
bool first = true;
//
// Mix
//
//cxxNameDouble gasPhaseComps;
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())
{
const cxxGasPhase *entity_ptr =
&(entities.find(it->first)->second);
this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps,
it->second);
//GP_TYPE type;
//LDBLE total_p;
//LDBLE volume;
if (first)
{
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;
this->pr_in = entity_ptr->pr_in;
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);
//input_error++;
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;
}
}
}
}
#endif
cxxGasPhase::~cxxGasPhase()
{
}
#ifdef SKIP
void
cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 " << "\n";
s_oss << indent1;
s_oss << "pitzer_gas_phase_gammas=\"" << this->
pitzer_gas_phase_gammas << "\"" << "\n";
// components
s_oss << indent1;
s_oss << "<component " << "\n";
for (std::list < cxxGasPhaseComp >::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, int *n_out) const
{
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;
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 << indent1 << "# GAS_PHASE_MODIFY candidate identifiers #\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 << "-volume " << this->volume << "\n";
// gasPhaseComps
for (size_t i = 0 ; i < this->gas_comps.size(); i++)
{
s_oss << indent1;
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
cxxGasPhase::read_raw(CParser & parser, bool check)
{
int i;
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);
this->Set_new_def(false);
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
{
CParser::ECHO_OPTION eo = parser.get_echo_file();
parser.set_echo_file(CParser::EO_NONE);
opt = parser.getOptionFromLastLine(vopts, next_char, true);
parser.set_echo_file(eo);
}
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.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
useLastLine = false;
break;
case 0: // type
if (!(parser.get_iss() >> i))
{
this->type = cxxGasPhase::GP_PRESSURE;
parser.incr_input_error();
parser.error_msg("Expected enum for type.",
PHRQ_io::OT_CONTINUE);
}
else
{
this->type = (cxxGasPhase::GP_TYPE) i;
}
type_defined = true;
useLastLine = false;
break;
case 1: // total_p
case 5: // pressure
if (!(parser.get_iss() >> this->total_p))
{
this->total_p = 0;
parser.incr_input_error();
parser.error_msg("Expected numeric value for total_p.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
volume_defined = true;
useLastLine = false;
break;
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.",
PHRQ_io::OT_CONTINUE);
}
useLastLine = false;
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
{
cxxGasComp temp_comp(io);
temp_comp.Set_phase_name(str);
cxxGasComp * comp_ptr = this->Find_comp(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->gas_comps.size(); j++)
{
if (Utilities::strcmp_nocase(this->gas_comps[j].Get_phase_name().c_str(), str.c_str()) == 0)
{
this->gas_comps[j] = temp_comp;
}
}
}
else
{
this->gas_comps.push_back(temp_comp);
}
useLastLine = true;
}
}
opt_save = CParser::OPT_DEFAULT;
break;
case 6: // pr_in
if (!(parser.get_iss() >> i))
{
parser.incr_input_error();
parser.error_msg("Expected 0/1 for pr_in.", PHRQ_io::OT_CONTINUE);
}
else
{
this->pr_in = (i == 0) ? false : 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;
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;
}
if (check)
{
// members that must be defined
if (type_defined == false)
{
parser.incr_input_error();
parser.error_msg("Type not defined for GAS_PHASE_RAW input.",
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.",
PHRQ_io::OT_CONTINUE);
}
if (volume_defined == false)
{
parser.incr_input_error();
parser.error_msg("Volume not defined for GAS_PHASE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
}
}
void
cxxGasPhase::totalize(Phreeqc * phreeqc_ptr)
{
this->totals.clear();
// component structures
for (size_t i = 0; i < this->gas_comps.size(); i++)
{
struct phase *phase_ptr;
int l;
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);
this->totals.add_extensive(phase_formula, this->gas_comps[i].Get_moles());
}
else
{
assert(false);
}
}
return;
}
LDBLE cxxGasPhase::Calc_total_moles(void)const
{
LDBLE tot = 0.0;
for (size_t i = 0; i < this->gas_comps.size(); i++)
{
tot += gas_comps[i].Get_moles();
}
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;
}
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 : 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
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]);

97
src/phreeqcpp/GasPhase.h Normal file
View File

@ -0,0 +1,97 @@
#if !defined(GASPHASE_H_INCLUDED)
#define GASPHASE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "phrqtype.h"
#include "NumKeyword.h"
#include "NameDouble.h"
#include "GasComp.h"
class cxxMix;
class cxxGasPhase:public cxxNumKeyword
{
public:
cxxGasPhase(PHRQ_io * io=NULL);
cxxGasPhase(std::map < int, cxxGasPhase > &entity_map,
cxxMix & mx, int n_user, PHRQ_io * io=NULL);
~cxxGasPhase();
enum GP_TYPE
{
GP_PRESSURE = 0,
GP_VOLUME = 1
};
//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);
void totalize(Phreeqc * phreeqc_ptr);
const cxxNameDouble & Get_totals() const
{
return this->totals;
};
std::vector<cxxGasComp> & Get_gas_comps(void) {return gas_comps;};
const std::vector<cxxGasComp> & Get_gas_comps(void)const {return gas_comps;};
void Set_gas_comps(const std::vector<cxxGasComp> 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;};
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)const {return total_moles;};
void Set_total_moles(LDBLE t) {total_moles = t;};
LDBLE Get_temperature(void)const {return temperature;};
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);
protected:
// candidate variables for GAS_PHASE_MODIFY
GP_TYPE type;
LDBLE total_p;
LDBLE volume;
std::vector<cxxGasComp> gas_comps;
// GAS_PHASE_MODIFY with new_def=true variables
bool new_def;
bool solution_equilibria;
int n_solution;
LDBLE temperature;
// internal variables
LDBLE total_moles;
LDBLE v_m;
bool pr_in;
cxxNameDouble totals;
const static std::vector < std::string > vopts;
};
#endif // !defined(GASPHASE_H_INCLUDED)

209
src/phreeqcpp/ISolution.cxx Normal file
View File

@ -0,0 +1,209 @@
// ISolution.cxx: implementation of the cxxSolutionxx class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include <sstream>
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "ISolution.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxISolution::cxxISolution(PHRQ_io *io)
:
units("mMol/kgw")
{
default_pe = "pe";
cxxChemRxn temp_pe_reactions;
pe_reactions[default_pe] = temp_pe_reactions;
this->calc_density = false;
}
cxxISolution::~cxxISolution()
{
}
#ifdef SKIP_OR_MOVE_TO_STRUCTURES
void
cxxISolution::ConvertUnits(Phreeqc * phreeqc_ptr)
//
// Converts from input units to moles per kilogram water
//
{
LDBLE sum_solutes = 0;
// foreach conc
std::map < std::string, cxxISolutionComp >::iterator iter =
this->comps.begin();
for (; iter != this->comps.end(); ++iter)
{
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;
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;
/*
* Convert liters to kg solution
*/
LDBLE 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(phreeqc_ptr);
// 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);
}
}
/*
* 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
*/
LDBLE l_mass_water;
if ((this->units.find("kgs") != std::string::npos) ||
(this->units.find("/l") != std::string::npos))
{
l_mass_water = 1.0 - 1e-3 * sum_solutes;
for (; iter != this->comps.end(); ++iter)
{
iter->second.set_moles(iter->second.get_moles() / l_mass_water);
}
}
/*
* Scale by mass of water in solution
*/
l_mass_water = this->mass_water;
for (; iter != this->comps.end(); ++iter)
{
iter->second.set_moles(iter->second.get_moles() * l_mass_water);
}
}
#endif
#ifdef SKIP
void
cxxISolution::dump_xml(std::ostream & os, unsigned int indent) const const
{
unsigned int i;
for (i = 0; i < indent; ++i)
os << Utilities::INDENT;
os << "<solution>\n";
cxxNumKeyword::dump_xml(os, indent);
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<temp>" << this->get_tc() << "</temp>" << "\n";
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<pH>" << this->get_ph() << "</pH>" << "\n";
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<pe>" << this->get_solution_pe() << "</pe>" << "\n";
assert(this->pe.size() > 0);
assert(this->default_pe >= 0);
assert(this->pe.size() > (unsigned int) this->default_pe);
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<units>" << this->get_units() << "</units>" << "\n";
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<density>" << this->get_density() << "</density>" << "\n";
// foreach conc
if (!this->totals.empty())
{
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<totals>\n";
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 << "</totals>\n";
}
// foreach isotope
if (!this->isotopes.empty())
{
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<isotopes>\n";
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 << "</isotopes>\n";
}
for (i = 0; i < indent + 1; ++i)
os << Utilities::INDENT;
os << "<water>" << this->get_mass_water() << "</water>" << "\n";
for (i = 0; i < indent; ++i)
os << Utilities::INDENT;
os << "</solution>" << "\n";
}
#endif

55
src/phreeqcpp/ISolution.h Normal file
View File

@ -0,0 +1,55 @@
#if !defined(ISOLUTION_H_INCLUDED)
#define ISOLUTION_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include <set> // std::set
#include <iostream>
#include <sstream>
#include <fstream>
#include "ISolutionComp.h"
#include "PHRQ_base.h"
#include "NameDouble.h"
#include "global_structures.h"
class cxxISolution: public PHRQ_base
{
public:
cxxISolution(PHRQ_io *io=NULL);
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)
this->units = std::string(l_units);
else
this->units.clear();
}
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;}
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 * phreeqc_ptr);
protected:
friend class cxxISolutionComp; // for this->pe access
std::string units;
bool calc_density;
std::map < std::string, cxxISolutionComp > comps;
std::map <std::string, cxxChemRxn > pe_reactions;
const char * default_pe;
};
#endif // !defined(ISOLUTION_H_INCLUDED)

View File

@ -0,0 +1,447 @@
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert>
#include "Utils.h"
#include "ISolutionComp.h"
#include "Parser.h"
#include "Solution.h"
#include "phqalloc.h"
cxxISolutionComp::cxxISolutionComp(PHRQ_io *io):
PHRQ_base(io),
moles(0.0),
input_conc(0.0),
phase_si(0.0),
gfw(0.0)
{
}
cxxISolutionComp::~cxxISolutionComp(void)
{
}
#ifdef SKIP_OR_MOVE_TO_STRUCTURES
struct conc *
cxxISolutionComp::cxxISolutionComp2conc(Phreeqc * phreeqc_ptr, const std::map < std::string,
cxxISolutionComp > &totals)
// for ISolutions
// takes a std::vector cxxISolutionComp structures
// returns list of conc structures
{
struct conc *c;
c = (struct conc *)
phreeqc_ptr-> PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc)));
if (c == NULL)
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 = 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 = 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 = 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 = phreeqc_ptr-> string_hsave(it->second.as.c_str());
c[i].gfw = it->second.gfw;
//c[i].skip = 0;
c[i].phase = NULL;
i++;
}
c[i].description = NULL;
return (c);
}
#endif
#ifdef SKIP_OR_MOVE_TO_STRUCTURES
void
cxxISolutionComp::set_gfw(Phreeqc * phreeqc_ptr)
{
// return gfw
if (this->gfw > 0.0)
return;
// calculate gfw from as or from master species gfw
if (this->as.size() != 0)
{
/* use given chemical formula to calculate gfw */
LDBLE l_gfw;
if (phreeqc_ptr-> compute_gfw(this->as.c_str(), &l_gfw) == ERROR)
{
std::ostringstream oss;
oss << "Could not compute gfw, " << this->as;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
//if (this->description == "Alkalinity" && this->as == "CaCO3")
if (strcmp(this->description.c_str(), "Alkalinity") == 0
&& strcmp(this->as.c_str(), "CaCO3"))
{
l_gfw /= 2.;
}
this->gfw = l_gfw;
return;
}
/* use gfw of master species */
std::string str(this->description);
struct master *master_ptr = phreeqc_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);
return;
}
#endif
#ifdef SKIP
cxxISolutionComp::STATUS_TYPE cxxISolutionComp::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.",
PHRQ_io::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;
}
// 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, PHRQ_io::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;
}
}
// 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.",
PHRQ_io::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 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;
}
}
// 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.", PHRQ_io::OT_CONTINUE);
return cxxISolutionComp::ERROR;
}
return cxxISolutionComp::OK;
}
#endif
#ifdef SKIP
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);
s_oss << indent0;
s_oss << "<soln_total";
s_oss << " conc_desc=\"" << this->description << "\"";
s_oss << " conc_moles=\"" << this->moles << "\"";
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 (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)
{
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);
}

View File

@ -0,0 +1,138 @@
#if !defined(ISOLUTIONCOMP_H_INCLUDED)
#define ISOLUTIONCOMP_H_INCLUDED
#include <string.h> // ::strcmp
#include <string>
#include <map> // std::map
#include <vector>
#include <set>
#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
{
public:
cxxISolutionComp(PHRQ_io *io=NULL);
virtual ~cxxISolutionComp(void);
public:
CParser::STATUS_TYPE read(const char *line, cxxSolution *solution_ptr);
void dump_xml(std::ostream & os, unsigned int indent = 0) const;
const std::string &Get_description() const
{
return this->description;
}
void Set_description(const char *l_description)
{
if (l_description != NULL)
this->description = std::string(l_description);
else
this->description.clear();
}
LDBLE Get_moles() const
{
return this->moles;
}
void Set_moles(LDBLE l_moles)
{
this->moles = l_moles;
}
LDBLE Get_input_conc() const
{
return this->input_conc;
}
void Set_input_conc(LDBLE l_input_conc)
{
this->input_conc = l_input_conc;
}
std::string Get_units()const
{
return this->units;
}
void Set_units(const char *l_units)
{
if (l_units != NULL)
this->units = std::string(l_units);
else
this->units.clear();
}
const std::string &Get_equation_name() const
{
return this->equation_name;
}
void Set_equation_name(const char *l_equation_name)
{
if (l_equation_name != NULL)
this->equation_name = std::string(l_equation_name);
else
this->equation_name.clear();
}
LDBLE Get_phase_si() const
{
return this->phase_si;
}
void Set_phase_si(int l_phase_si)
{
this->phase_si = l_phase_si;
}
std::string Get_pe_reaction() const
{
return this->pe_reaction;
}
void Set_pe_reaction(const std::string & pe_r)
{
this->pe_reaction = pe_r;
}
const std::string &Get_as() const
{
return this->as;
}
void Set_as(const char *l_as)
{
if (l_as != NULL)
this->as = std::string(l_as);
else
this->as.clear();
}
LDBLE Get_gfw() const
{
return this->gfw;
};
void Set_gfw(LDBLE l_gfw)
{
this->gfw = l_gfw;
}
bool operator<(const cxxISolutionComp & conc) const
{
return ::strcmp(this->description.c_str(), conc.description.c_str()) < 0;
}
protected:
std::string description;
LDBLE moles;
LDBLE input_conc;
std::string units;
std::string equation_name;
LDBLE phase_si;
std::string pe_reaction;
std::string as;
LDBLE gfw;
};
#endif // ISOLUTIONCOMP_H_INCLUDED

View File

@ -0,0 +1,355 @@
// KineticsComp.cxx: implementation of the cxxKineticsComp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "KineticsComp.h"
//#include "Dictionary.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxKineticsComp::cxxKineticsComp(PHRQ_io *io)
:
PHRQ_base(io)
//
// default constructor for cxxKineticsComp
//
{
tol = 1e-8;
m = -1;
m0 = -1;
moles = 0.0;
initial_moles = 0;
namecoef.type = cxxNameDouble::ND_NAME_COEF;
}
cxxKineticsComp::~cxxKineticsComp()
{
}
#ifdef SKIP
void
cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 << "\"" << "\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 != NULL)
{
s_oss << indent0 << "phase_name=\"" << this->
phase_name << "\"" << "\n";
}
if (this->rate_name != NULL)
{
s_oss << indent0 << "rate_name=\"" << this->
rate_name << "\"" << "\n";
}
s_oss << indent0 << "phase_proportion=\"" << this->
phase_proportion << "\"" << "\n";
// totals
s_oss << indent0;
s_oss << "<totals " << "\n";
this->totals.dump_xml(s_oss, indent + 1);
// formula_totals
s_oss << indent0;
s_oss << "<formula_totals " << "\n";
this->formula_totals.dump_xml(s_oss, indent + 1);
}
#endif
void
cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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 << 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";
// namecoef
s_oss << indent1;
s_oss << "-namecoef" << "\n";
this->namecoef.dump_raw(s_oss, indent + 2);
// d_params
s_oss << indent1;
s_oss << "-d_params" << "\n";
{
int i = 0;
s_oss << indent2;
for (std::vector < LDBLE >::const_iterator it = d_params.begin();
it != d_params.end(); it++)
{
if (i++ == 5)
{
s_oss << "\n";
s_oss << indent2;
i = 0;
}
s_oss << *it << " ";
}
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
cxxKineticsComp::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
std::vector < LDBLE > temp_d_params;
opt_save = CParser::OPT_ERROR;
bool tol_defined(false);
bool m_defined(false);
bool m0_defined(false);
bool d_params_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
break;
case 0: // rate_name not used
parser.warning_msg("Rate_name ignored. Define in -comp.");
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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
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.",
PHRQ_io::OT_CONTINUE);
}
opt_save = 5;
break;
case 6: // d_params
while (parser.copy_token(token, next_char) == CParser::TT_DIGIT)
{
double dd;
sscanf(token.c_str(), "%lf", &dd);
temp_d_params.push_back((LDBLE) dd);
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;
}
if (d_params_defined)
{
this->d_params = temp_d_params;
}
if (check)
{
// members that must be defined
if (tol_defined == false)
{
parser.incr_input_error();
parser.error_msg("Tol not defined for KineticsComp input.",
PHRQ_io::OT_CONTINUE);
}
if (m_defined == false)
{
parser.incr_input_error();
parser.error_msg("M not defined for KineticsComp input.",
PHRQ_io::OT_CONTINUE);
}
if (m0_defined == false)
{
parser.incr_input_error();
parser.error_msg("M0 not defined for KineticsComp input.",
PHRQ_io::OT_CONTINUE);
}
}
}
void
cxxKineticsComp::add(const cxxKineticsComp & addee, LDBLE extensive)
{
if (extensive == 0.0)
return;
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.size() == 0 && addee.rate_name.size() == 0)
{
return;
}
assert(this->rate_name == addee.rate_name);
this->m += addee.m * extensive;
this->m0 += addee.m0 * extensive;
this->moles += addee.moles * extensive;
}
void
cxxKineticsComp::multiply(LDBLE extensive)
{
this->m *= 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
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]);

View File

@ -0,0 +1,81 @@
#if !defined(KINETICSCOMP_H_INCLUDED)
#define KINETICSCOMP_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.h"
class cxxKineticsComp: public PHRQ_base
{
public:
cxxKineticsComp(PHRQ_io *io=NULL);
cxxKineticsComp(struct kinetics_comp *, PHRQ_io *io=NULL);
virtual ~cxxKineticsComp();
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_rate_name() const
{
return this->rate_name;
}
void Set_rate_name(const char * s)
{
if (s != NULL)
this->rate_name = std::string(s);
else
this->rate_name.clear();
}
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;}
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;};
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);
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;
// 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;
cxxNameDouble moles_of_reaction;
const static std::vector < std::string > vopts;
public:
};
#endif // !defined(KINETICSCOMP_H_INCLUDED)

639
src/phreeqcpp/Makefile Normal file
View File

@ -0,0 +1,639 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# src/Makefile. Generated from Makefile.in by configure.
# 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.
# 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.
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
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 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 \
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) 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) 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) \
$(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} /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++
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} /raid/home/dlpark/programs/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 = /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 = .
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} /raid/home/dlpark/programs/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
# 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 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 \
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
.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;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(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
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
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)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
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)/SelectedOutput.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)/UserPunch.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
.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 $@ $<
.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) '$<'`
.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 $@ $<
.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) '$<'`
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
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"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
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
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
# 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:

159
src/phreeqcpp/Makefile.am Normal file
View File

@ -0,0 +1,159 @@
EXTRA_DIST=\
ChartHandler.cpp\
ChartHandler.h\
ChartObject.cpp\
ChartObject.h\
CurveObject.cpp\
CurveObject.h\
Form1.h\
Form1.2005.resX\
Form1.resX\
ZedGraph.dll
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\
Dictionary.cpp\
Dictionary.h\
dumper.cpp\
dumper.h\
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\
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_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\
Serializer.cxx\
Serializer.h\
sit.cpp\
smalldense.cpp\
smalldense.h\
Solution.cxx\
Solution.h\
SolutionIsotope.cxx\
SolutionIsotope.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\
SurfaceCharge.h\
SurfaceComp.cxx\
SurfaceComp.h\
System.cxx\
System.h\
tally.cpp\
Temperature.cxx\
Temperature.h\
tidy.cpp\
transport.cpp\
Use.cpp\
Use.h\
UserPunch.cpp\
UserPunch.h\
utilities.cpp
if BUILD_GMP
phreeqc_SOURCES+=\
cl1mp.cpp
endif
LDADD = $(LIBGMP)

986
src/phreeqcpp/Makefile.old Normal file
View File

@ -0,0 +1,986 @@
# 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/Linux.*/Linux/")
ifeq ($(CFG), Linux)
SPOOL=>&
SPOOL2=
CONCAT=;
else
SPOOL=>
SPOOL2=2>&1
CONCAT=&
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=
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 = ..:../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)
INVERSE_CL1MP=
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 = ..:../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)
LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE}
endif
ifeq ($(CFG), CLASS_DEBUG_64)
# INVERSE_CL1MP=
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)
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) # -DUSE_PHRQ_ALLOC # -DR_SO
VPATH = ..:../PhreeqcKeywords:../common
INCLUDES = -I.. -I../PhreeqcKeywords -I../common
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} # -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4 -lgcov
endif
# -----------------------------------------------------------------------------
#
COMMON_COBJS = \
advection.o \
basicsubs.o \
cl1.o \
cvdense.o \
cvode.o \
dense.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 \
Dictionary.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 \
Serializer.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 ../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 ../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 \
../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 \
../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 \
../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 \
../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 \
../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 ../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 ../ISolution.h ../ISolutionComp.h \
../phqalloc.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 ../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 \
../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 \
../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 ../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
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 ../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 \
../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
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 \
../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 ../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 \
../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 \
../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 \
../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 ../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 \
../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 ../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 \
../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 ../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 \
../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 ../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 \
../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 ../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 \
../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 ../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 \
../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 ../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 ../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 \
../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 ../common/Parser.h \
../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \
../global_structures.h ../NA.h ../phqalloc.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 ../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
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
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 \
../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 ../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 ../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
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 ../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
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 ../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 \
../common/phrqtype.h
nvector_serial.o: ../nvector_serial.cpp ../nvector_serial.h ../nvector.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 ../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 ../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 ../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_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 ../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
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 ../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 \
../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
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 ../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 \
../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
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 ../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 \
../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 ../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 \
../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 ../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 ../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 ../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 ../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 ../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 ../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
Use.o: ../Use.cpp ../Use.h
UserPunch.o: ../UserPunch.cpp ../UserPunch.h ../NumKeyword.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 \
../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:
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../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 ../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
#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.
# =============================================================================

1
src/phreeqcpp/NA.h Normal file
View File

@ -0,0 +1 @@
#define NA -98.7654321

View File

@ -0,0 +1,628 @@
// NameDouble.cxx: implementation of the cxxNameDouble class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include <map> // std::sort
#include <iostream> // std::cout std::cerr
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "NameDouble.h"
#include "Dictionary.h"
//#include "Dictionary.h"
#include "phqalloc.h"
#include "ISolutionComp.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxNameDouble::cxxNameDouble()
//
// default constructor for cxxNameDouble
//
{
this->type = ND_ELT_MOLES;
}
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 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, LDBLE 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(std::map < std::string, cxxISolutionComp > &comps)
//
// constructor for cxxNameDouble from map of cxxISolutionComp
//
{
std::map < std::string, cxxISolutionComp >::iterator it;
for (it = comps.begin(); it != comps.end(); it++)
{
(*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)
//
// 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 = l_type;
}
#endif
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()
{
}
void
cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const
{
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 = "<soln_m_a ";
xmlAtt1 = " m_a_desc=\"";
xmlAtt1 = " m_a_la=\"";
break;
case cxxNameDouble::ND_SPECIES_GAMMA:
xmlElement = "<soln_s_g ";
xmlAtt1 = " m_a_desc=\"";
xmlAtt1 = " m_a_la=\"";
break;
case cxxNameDouble::ND_ELT_MOLES:
xmlElement = "<soln_total ";
xmlAtt1 = " conc_desc=\"";
xmlAtt1 = " conc_moles=\"";
break;
case cxxNameDouble::ND_NAME_COEF:
xmlElement = "<NameCoef ";
xmlAtt1 = " name=\"";
xmlAtt1 = " coef=\"";
break;
}
for (const_iterator it = (*this).begin(); it != (*this).end(); it++)
{
s_oss << indent0;
s_oss << xmlElement << xmlAtt1 << it->first << xmlAtt2 << it->
second << "/>" << "\n";
}
}
void
cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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;
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";
}
}
}
CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser,
std::istream::pos_type & pos)
{
std::string token;
LDBLE
d;
CParser::TOKEN_TYPE j;
j = parser.copy_token(token, pos);
if (j == CParser::TT_EMPTY)
return CParser::PARSER_OK;
if (!(parser.get_iss() >> d))
{
return CParser::PARSER_ERROR;
}
(*this)[token.c_str()] = d;
return CParser::PARSER_OK;
}
void
cxxNameDouble::add_extensive(const cxxNameDouble & addee, LDBLE factor)
//
// Sums two name doubles, this + factor*nd2
//
{
if (factor == 0)
return;
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, LDBLE f1,
LDBLE 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, LDBLE f1,
LDBLE 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())
{
LDBLE a1 = pow((LDBLE) 10., current->second);
LDBLE a2 = pow((LDBLE) 10., it->second);
(*this)[it->first] = log10(f1 * a1 + f2 * a2);
}
else
{
(*this)[it->first] = it->second + log10(f2);
}
}
}
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;
std::string const *ename_ptr;
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)
{
ename_ptr = &(it->first);
}
else
{
indexCh = it->first.find("(");
if (indexCh != std::string::npos)
{
current_ename = it->first.substr(0, indexCh);
ename_ptr = &(current_ename);
}
else
{
ename_ptr = &(it->first);
}
}
if (current_ename == "H" || current_ename == "O" || current_ename == "Charge")
continue;
new_totals[*ename_ptr] = 0;
}
}
// sum totals for elements
{
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_ptr = &old_it->first;
}
else
{
indexCh = old_it->first.find("(");
if (indexCh != std::string::npos)
{
old_ename = old_it->first.substr(0, indexCh);
old_ename_ptr = &old_ename;
}
else
{
old_ename_ptr = &old_it->first;
}
}
int j = strcmp(new_it->first.c_str(), old_ename_ptr->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
cxxNameDouble &nd = *this;
std::set<std::string> 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<std::string>::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;
}
#endif
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 (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)
{
// 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;
}
}
}
}
#endif
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)
//
// 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;
}
else
{
(*this)[key] = total;
}
}
void
cxxNameDouble::multiply(LDBLE extensive)
{
//
// Multiplies by extensive
//
for (cxxNameDouble::iterator it = this->begin(); it != this->end(); it++)
{
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;
}
}
}
struct DblCmp {
bool operator()(const std::pair<std::string, LDBLE> &lhs, const std::pair<std::string, LDBLE> &rhs)
{
return lhs.second > rhs.second;
}
};
std::vector< std::pair<std::string, LDBLE> >
cxxNameDouble::sort_second(void)
{
std::vector< std::pair<std::string, LDBLE> > myvec(this->begin(), this->end());
std::sort(myvec.begin(), myvec.end(), DblCmp());
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<int> &ints, std::vector<double> &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++];
}
}
}

View File

@ -0,0 +1,71 @@
#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 <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
class Phreeqc;
#include "Parser.h"
#include "phrqtype.h"
class Dictionary;
class cxxISolutionComp;
class IPQ_DLL_EXPORT cxxNameDouble:public
std::map < std::string, LDBLE >
{
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(std::map < std::string, cxxISolutionComp > &comps);
cxxNameDouble(struct name_coef *nc, int count);
cxxNameDouble(const cxxNameDouble & old, LDBLE factor);
~cxxNameDouble();
LDBLE Get_total_element(const char *string) const;
cxxNameDouble Simplify_redox(void) const;
void Multiply_activities_redox(std::string, LDBLE f);
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<std::string, LDBLE> > sort_second(void);
void
insert(const char *str, LDBLE d)
{
(*this)[str] = d;
}
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);
enum ND_TYPE type;
};
#endif // !defined(NAMEDOUBLE_H_INCLUDED)

View File

@ -0,0 +1,181 @@
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
// NumKeyword.cxx: implementation of the cxxNumKeyword class.
//
//////////////////////////////////////////////////////////////////////
#include <stdio.h> // ::sscanf
#include "NumKeyword.h"
#include "Parser.h"
#include "Utils.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxNumKeyword::cxxNumKeyword(PHRQ_io *io)
{
this->n_user = 1;
this->n_user_end = 1;
this->Set_io(io);
}
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 << "<n_user>" << this->n_user << "</n_user>" << "\n";
for (i = 0; i < indent + 1; ++i)
os << " ";
os << "<n_user_end>" << this->n_user_end << "</n_user_end>" << "\n";
for (i = 0; i < indent + 1; ++i)
os << " ";
os << "<Description>" << this->description << "</Description>" << "\n";
}
void
cxxNumKeyword::read_number_description(CParser & parser)
{
std::string keyword;
std::istream::pos_type ptr;
// skip keyword
parser.copy_token(keyword, ptr);
// skip whitespace
while (::isspace(parser.get_iss().peek()))
parser.get_iss().ignore();
// read number
if (::isdigit(parser.get_iss().peek()) || parser.get_iss().peek() == '-')
{
parser.get_iss() >> this->n_user;
char ch = (char)parser.get_iss().peek();
if (ch == '-')
{
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
{
this->n_user_end = this->n_user;
}
}
else
{
this->n_user = this->n_user_end = 1;
}
// 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 = (char)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);
}
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)
{
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)
{
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);
}

View File

@ -0,0 +1,67 @@
#if !defined(NUMKEYWORD_H_INCLUDED)
#define NUMKEYWORD_H_INCLUDED
#include <ostream> // std::ostream
#include <string> // std::string
#include "PHRQ_base.h"
class CParser;
class cxxNumKeyword: public PHRQ_base
{
public:
cxxNumKeyword(PHRQ_io *io=NULL);
virtual ~ cxxNumKeyword();
const std::string &Get_description() const
{
return this->description;
}
void Set_description(std::string str)
{
this->description = str;
}
void Set_description(const 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;
}
void Set_n_user_both(int user_end)
{
this->n_user = 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);
void read_number_description(const std::string & line_in);
protected:
int n_user;
int n_user_end;
std::string description;
protected:
void read_number_description(std::istream & is);
};
#endif // !defined(NUMKEYWORD_H_INCLUDED)

7343
src/phreeqcpp/PBasic.cpp Normal file

File diff suppressed because it is too large Load Diff

546
src/phreeqcpp/PBasic.h Normal file
View File

@ -0,0 +1,546 @@
#ifndef _INC_PBasic_H
#define _INC_PBasic_H
#if defined(PHREEQCI_GUI)
#include <windows.h>
#endif
#include <map>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <math.h>
#include <setjmp.h>
#include "phrqtype.h"
#include "PHRQ_base.h"
#include "global_structures.h"
class Phreeqc;
class PBasicStop : public 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];
/* 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
{
varnamestring name;
struct varrec *next;
long dims[maxdims];
char numdims;
bool 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;
class valrec
{
public:
valrec()
{
stringval = false;
UU.val = 0;
}
~valrec() {}
bool stringval;
union
{
LDBLE val;
char *sval;
} UU;
};
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
{
bool gotoflag, elseflag;
tokenrec *t;
};
class PBasic: public PHRQ_base
{
public:
PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL);
virtual ~PBasic();
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,
#if defined (PHREEQ98) || defined (MULTICHART)
tokgraph_x,
tokgraph_y,
tokgraph_sy,
#endif
tokcell_no,
tokexists,
toksurf,
toklk_species,
toklk_named,
toklk_phase,
toksum_species,
toksum_gas,
toksum_s_s,
tokcalc_value,
tokdescription,
toktitle,
toksys,
tokinstr,
tokltrim,
tokrtrim,
toktrim,
tokpad,
tokchange_por,
tokget_por,
tokosmotic,
tokchange_surf,
tokporevolume,
toksc,
tokgamma,
toklg,
tokrho,
tokrho_0,
tokcell_volume,
tokcell_pore_volume,
tokcell_porosity,
tokcell_saturation,
#if defined MULTICHART
tokplot_xy,
#endif
toktotmole,
tokiso,
tokiso_unit,
toktotmol,
toktotmoles,
tokeol_,
tokceil,
tokfloor,
tokkinetics_formula,
tokkinetics_formula_,
tokphase_formula,
tokphase_formula_,
tokspecies_formula,
tokspecies_formula_,
toklist_s_s,
tokpr_p,
tokpr_phi,
tokgas_p,
tokgas_vm,
tokpressure,
tokerase,
tokeps_r,
tokvm,
tokphase_vm,
tokdh_a,
tokdh_b,
tokdh_av,
tokqbrn,
tokkappa,
tokgfw,
toksoln_vol,
tokequi_delta,
tokkin_delta,
tokkin_time,
tokstr_f_,
tokstr_e_,
tokeq_frac,
tokequiv_frac,
tokcallback,
tokdiff_c,
toksetdiff_c,
toksa_declercq,
tokedl_species,
tokviscos,
tokviscos_0,
tokcurrent_a,
tokpot_v,
tokt_sc,
tokaphi
};
#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_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)
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
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);
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);
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);
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(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);
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(bool implied, struct LOC_exec *LINK);
void cmdgoto(struct LOC_exec *LINK);
void cmdif(struct LOC_exec *LINK);
void cmdelse(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);
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 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);
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);
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);
// data members
protected:
Phreeqc * PhreeqcPtr;
char *inbuf;
linerec *linebase;
varrec *varbase;
looprec *loopbase;
long curline;
linerec *stmtline, *dataline;
tokenrec *stmttok, *datatok, *buf;
bool exitflag;
long EXCP_LINE;
static std::map<const std::string, BASIC_TOKEN> command_tokens;
int P_escapecode;
int P_ioresult;
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;
#else
IDErr nIDErrPrompt;
#endif
int nErrLineNumber;
};
#endif /* _INC_PBasic_H */

View File

@ -0,0 +1,401 @@
#include <assert.h>
#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());
status_on = false;
}
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;
}
void Phreeqc::
fpunchf_heading(const char *name)
{
if (pr.punch == TRUE && current_selected_output != NULL)
{
punch_msg(name);
}
}
void Phreeqc::
fpunchf(const char *name, const char *format, double 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)
{
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)
{
try
{
if (phrq_io) phrq_io->fpunchf(name, format, d);
}
catch(std::bad_alloc)
{
malloc_error();
}
}
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();
if (user_index < user_punch_count_headings)
{
//name = user_punch_headings[user_index];
name = current_user_punch->Get_headings()[user_index].c_str();
}
else
{
if (fpunchf_user_s_warning == 0)
{
error_string = sformatf(
"USER_PUNCH: Headings count does not match number of calls to PUNCH.\n");
warning_msg(error_string);
fpunchf_user_s_warning = 1;
}
sprintf(fpunchf_user_buffer, "no_heading_%d",
(user_index - user_punch_count_headings) + 1);
name = fpunchf_user_buffer;
}
try
{
if (phrq_io) phrq_io->fpunchf(name, format, (double) d);
}
catch(std::bad_alloc)
{
malloc_error();
}
}
void Phreeqc::
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)
{
//name = user_punch_headings[user_index];
name = current_user_punch->Get_headings()[user_index].c_str();
}
else
{
if (fpunchf_user_s_warning == 0)
{
error_string = sformatf(
"USER_PUNCH: Headings count does not match number of calls to PUNCH.\n");
warning_msg(error_string);
fpunchf_user_s_warning = 1;
}
sprintf(fpunchf_user_buffer, "no_heading_%d",
(user_index - user_punch_count_headings) + 1);
name = fpunchf_user_buffer;
}
try
{
if (phrq_io) phrq_io->fpunchf(name, format, d);
}
catch(std::bad_alloc)
{
malloc_error();
}
}
int Phreeqc::
fpunchf_end_row(const char *format)
{
if (phrq_io)
{
phrq_io->fpunchf_end_row(format);
}
return OK;
}
/* ---------------------------------------------------------------------- */
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_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_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");
}
status_on = false;
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_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_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, int n_user)
/* ---------------------------------------------------------------------- */
{
if (phrq_io)
return this->phrq_io->punch_open(file_name, std::ios_base::out, n_user);
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_msg(const char * str)
/* ---------------------------------------------------------------------- */
{
if (phrq_io) this->phrq_io->punch_msg(str);
}

View File

@ -0,0 +1,373 @@
// PPassemblage.cxx: implementation of the cxxPPassemblage class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "PPassemblage.h"
#include "cxxMix.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxPPassemblage::cxxPPassemblage(PHRQ_io * io)
//
// default constructor for cxxPPassemblage
//
: cxxNumKeyword(io)
{
new_def = false;
eltList.type = cxxNameDouble::ND_ELT_MOLES;
}
cxxPPassemblage::cxxPPassemblage(const std::map < int,
cxxPPassemblage > &entities, cxxMix & mix,
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;
//
// Mix
//
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())
{
const cxxPPassemblage *entity_ptr =
&(entities.find(it->first)->second);
this->add(*entity_ptr, it->second);
}
}
}
cxxPPassemblage::~cxxPPassemblage()
{
}
void
cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const
{
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 " << "\n";
// eltList
this->eltList.dump_xml(s_oss, indent + 1);
// ppAssemblageComps
s_oss << indent1;
s_oss << "<pure_phases " << "\n";
for (std::map < std::string, cxxPPassemblageComp >::const_iterator it =
pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it)
{
(*it).second.dump_xml(s_oss, indent + 2);
}
}
void
cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const
{
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;
int n_user_local = (n_out != NULL) ? *n_out : this->n_user;
s_oss << "EQUILIBRIUM_PHASES_RAW " << n_user_local << " " << this->
description << "\n";
s_oss << indent1 << "# EXCHANGE_MODIFY candidates; use new_def=true #\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)
{
s_oss << indent1;
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
cxxPPassemblage::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 PPassemblage number and description
this->read_number_description(parser);
this->Set_new_def(false);
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, 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 EQUILIBRIUM_PHASES_RAW keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
opt_save = 0;
break;
case 1: // 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
{
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;
}
}
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 in PPassemblage.",
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;
}
}
void
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(phreeqc_ptr);
this->assemblage_totals.add_extensive((*it).second.Get_totals(), 1.0);
}
return;
}
void
cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive)
//
// Add to existing ppassemblage to "this" ppassemblage
//
{
if (extensive == 0.0)
return;
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->pp_assemblage_comps.begin();
it != this->pp_assemblage_comps.end(); ++it)
{
if ((*it).second.Get_name() == itadd->second.Get_name())
{
(*it).second.add((*itadd).second, extensive);
found = true;
break;
}
}
if (!found)
{
cxxPPassemblageComp entity = (*itadd).second;
entity.multiply(extensive);
std::string str(entity.Get_name());
this->pp_assemblage_comps[str] = entity;
}
}
//cxxNameDouble eltList;
this->eltList.add_extensive(addee.eltList, extensive);
}
#ifdef SKIP
cxxPPassemblageComp * cxxPPassemblage::
Find(const std::string name_in)
{
std::string name(name_in);
Utilities::str_tolower(name);
cxxPPassemblageComp * comp = NULL;
std::map<std::string, cxxPPassemblageComp>::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;
}
#endif
cxxPPassemblageComp * cxxPPassemblage::
Find(const std::string name_in)
{
cxxPPassemblageComp * comp = NULL;
std::map<std::string, cxxPPassemblageComp>::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;
}
/* ---------------------------------------------------------------------- */
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
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]);

View File

@ -0,0 +1,70 @@
#if !defined(PPASSEMBLAGE_H_INCLUDED)
#define PPASSEMBLAGE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NumKeyword.h"
#include "PPassemblageComp.h"
class cxxMix;
class cxxPPassemblage:public cxxNumKeyword
{
public:
cxxPPassemblage(PHRQ_io * io=NULL);
cxxPPassemblage(const std::map < int, cxxPPassemblage > &entity_map,
cxxMix & mx, int n_user, PHRQ_io * io=NULL);
~cxxPPassemblage();
void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const;
void read_raw(CParser & parser, bool check = true);
const cxxNameDouble & Get_assemblage_totals() const
{
return this->assemblage_totals;
};
const cxxNameDouble & Get_eltList() const
{
return this->eltList;
};
void Set_eltList(cxxNameDouble & nd) {this->eltList = nd;}
std::map <std::string, cxxPPassemblageComp > & Get_pp_assemblage_comps()
{
return this->pp_assemblage_comps;
};
const std::map <std::string, cxxPPassemblageComp > & Get_pp_assemblage_comps() const
{
return this->pp_assemblage_comps;
};
void Set_pp_assemblage_comps(std::map <std::string, cxxPPassemblageComp > & 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);
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);
// not written
void dump_xml(std::ostream & os, unsigned int indent = 0) const;
protected:
bool new_def;
std::map <std::string, cxxPPassemblageComp > 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)

View File

@ -0,0 +1,433 @@
// PPassemblageComp.cxx: implementation of the cxxPPassemblageComp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "PPassemblageComp.h"
#include "Dictionary.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxPPassemblageComp::cxxPPassemblageComp(PHRQ_io *io)
:
PHRQ_base(io)
//
// default constructor for cxxPPassemblageComp
//
{
si = 0;
si_org = 0;
moles = 10;
delta = 0;
initial_moles = 0;
force_equality = false;
dissolve_only = false;
precipitate_only = false;
}
cxxPPassemblageComp::~cxxPPassemblageComp()
{
}
void
cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const
{
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 << "\"" << "\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";
s_oss << indent0 << "delta=\"" << this->delta << "\"" << "\n";
s_oss << indent0 << "initial_moles=\"" << this->
initial_moles << "\"" << "\n";
s_oss << indent0 << "force_equality=\"" << this->
force_equality << "\"" << "\n";
s_oss << indent0 << "dissolve_only=\"" << this->
dissolve_only << "\"" << "\n";
s_oss << indent0 << "precipitate_only=\"" << this->
precipitate_only << "\"" << "\n";
}
void
cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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 << 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 << "-moles " << this->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
cxxPPassemblageComp::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_ERROR;
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);
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
break;
case 0: // name
parser.warning_msg("-name ignored. Name is defined with -component.");
break;
case 1: // add_formula
if (!(parser.get_iss() >> str))
{
this->add_formula.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for add_formula.",
PHRQ_io::OT_CONTINUE);
}
else
{
this->add_formula = 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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
dissolve_only_defined = true;
if (this->dissolve_only)
{
this->precipitate_only = false;
}
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.",
PHRQ_io::OT_CONTINUE);
}
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.",
PHRQ_io::OT_CONTINUE);
}
if (this->precipitate_only)
{
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.",
PHRQ_io::OT_CONTINUE);
}
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;
}
// members that must be defined
if (check)
{
if (si_defined == false)
{
parser.incr_input_error();
parser.error_msg("Si 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 (delta_defined == false)
{
parser.incr_input_error();
parser.error_msg("Delta 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);
}
if (dissolve_only_defined == false)
{
parser.incr_input_error();
parser.error_msg("Dissolve_only not defined for PPassemblageComp input.",
PHRQ_io::OT_CONTINUE);
}
if (force_equality_defined == false)
{
parser.incr_input_error();
parser.error_msg
("Force_equality not defined for PPassemblageComp input.",
PHRQ_io::OT_CONTINUE);
}
}
}
void
cxxPPassemblageComp::totalize(Phreeqc * phreeqc_ptr)
{
this->totals.clear();
// component structures
if (this->add_formula.size() != 0)
return;
struct phase *phase_ptr;
int l;
phase_ptr = phreeqc_ptr-> 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;
}
void
cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, LDBLE extensive)
{
LDBLE 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;
}
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 <<
"Cannot mix two Equilibrium_phases with differing add_formulae., "
<< this->name;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
this->si = this->si * f1 + addee.si * f2;
this->si_org = this->si_org * f1 + addee.si_org * f2;
this->moles += addee.moles * extensive;
this->delta += addee.delta * extensive;
this->initial_moles += addee.initial_moles * extensive;
}
void
cxxPPassemblageComp::multiply(LDBLE extensive)
{
this->moles *= 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
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]);

View File

@ -0,0 +1,83 @@
#if !defined(PPASSEMBLAGECOMP_H_INCLUDED)
#define PPASSEMBLAGECOMP_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.h"
class cxxPPassemblageComp: public PHRQ_base
{
public:
cxxPPassemblageComp(PHRQ_io *io=NULL);
virtual ~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;}
void Set_name(const 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(const char * s)
{
if(s != NULL)
this->add_formula = std::string(s);
else
this->add_formula.clear();
}
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;}
void Set_si(LDBLE t) {this->si = t;}
LDBLE Get_si_org() const {return this->si_org;}
void Set_si_org(LDBLE t) {this->si_org = t;}
LDBLE Get_moles() const {return this->moles;}
void Set_moles(LDBLE t) {this->moles = t;}
LDBLE Get_delta() const {return this->delta;}
void Set_delta(LDBLE t) {this->delta = t;}
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;}
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, 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;
std::string add_formula;
LDBLE si;
LDBLE si_org;
LDBLE moles;
LDBLE delta;
LDBLE initial_moles;
bool force_equality;
bool dissolve_only;
bool precipitate_only;
cxxNameDouble totals;
const static std::vector < std::string > vopts;
public:
};
#endif // !defined(PPASSEMBLAGECOMP_H_INCLUDED)

2555
src/phreeqcpp/Phreeqc.cpp Normal file

File diff suppressed because it is too large Load Diff

2248
src/phreeqcpp/Phreeqc.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,225 @@
#include "Keywords.h"
Keywords::Keywords(void)
{
}
Keywords::~Keywords(void)
{
}
Keywords::KEYWORDS Keywords::Keyword_search(std::string key)
{
std::map<const std::string, Keywords::KEYWORDS>::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<Keywords::KEYWORDS, const std::string>::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<const std::string, Keywords::KEYWORDS>::value_type temp_keywords[] = {
std::map<const std::string, Keywords::KEYWORDS>::value_type("eof", Keywords::KEY_END),
std::map<const std::string, Keywords::KEYWORDS>::value_type("end", Keywords::KEY_END),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_species", Keywords::KEY_SOLUTION_SPECIES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_master_species", Keywords::KEY_SOLUTION_MASTER_SPECIES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution", Keywords::KEY_SOLUTION),
std::map<const std::string, Keywords::KEYWORDS>::value_type("phases", Keywords::KEY_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("pure_phases", Keywords::KEY_EQUILIBRIUM_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction", Keywords::KEY_REACTION),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix", Keywords::KEY_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("use", Keywords::KEY_USE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("save", Keywords::KEY_SAVE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("exchange_species", Keywords::KEY_EXCHANGE_SPECIES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("exchange_master_species", Keywords::KEY_EXCHANGE_MASTER_SPECIES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("exchange", Keywords::KEY_EXCHANGE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("surface_species", Keywords::KEY_SURFACE_SPECIES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("surface_master_species", Keywords::KEY_SURFACE_MASTER_SPECIES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("surface", Keywords::KEY_SURFACE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_temperature", Keywords::KEY_REACTION_TEMPERATURE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("inverse_modeling", Keywords::KEY_INVERSE_MODELING),
std::map<const std::string, Keywords::KEYWORDS>::value_type("gas_phase", Keywords::KEY_GAS_PHASE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("transport", Keywords::KEY_TRANSPORT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("debug", Keywords::KEY_KNOBS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("selected_output", Keywords::KEY_SELECTED_OUTPUT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("select_output", Keywords::KEY_SELECTED_OUTPUT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("knobs", Keywords::KEY_KNOBS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("print", Keywords::KEY_PRINT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium_phases", Keywords::KEY_EQUILIBRIUM_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibria", Keywords::KEY_EQUILIBRIUM_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium", Keywords::KEY_EQUILIBRIUM_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("pure", Keywords::KEY_EQUILIBRIUM_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("title", Keywords::KEY_TITLE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("comment", Keywords::KEY_TITLE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("advection", Keywords::KEY_ADVECTION),
std::map<const std::string, Keywords::KEYWORDS>::value_type("kinetics", Keywords::KEY_KINETICS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("incremental_reactions", Keywords::KEY_INCREMENTAL_REACTIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("incremental", Keywords::KEY_INCREMENTAL_REACTIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("rates", Keywords::KEY_RATES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_s", Keywords::KEY_SOLUTION_SPREAD),
std::map<const std::string, Keywords::KEYWORDS>::value_type("user_print", Keywords::KEY_USER_PRINT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("user_punch", Keywords::KEY_USER_PUNCH),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solutions", Keywords::KEY_SOLID_SOLUTIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solution", Keywords::KEY_SOLID_SOLUTIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_spread", Keywords::KEY_SOLUTION_SPREAD),
std::map<const std::string, Keywords::KEYWORDS>::value_type("spread_solution", Keywords::KEY_SOLUTION_SPREAD),
std::map<const std::string, Keywords::KEYWORDS>::value_type("selected_out", Keywords::KEY_SELECTED_OUTPUT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("select_out", Keywords::KEY_SELECTED_OUTPUT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("user_graph", Keywords::KEY_USER_GRAPH),
std::map<const std::string, Keywords::KEYWORDS>::value_type("llnl_aqueous_model_parameters",Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("llnl_aqueous_model", Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("database", Keywords::KEY_DATABASE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("named_analytical_expression", Keywords::KEY_NAMED_EXPRESSIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("named_analytical_expressions", Keywords::KEY_NAMED_EXPRESSIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("named_expressions", Keywords::KEY_NAMED_EXPRESSIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("named_log_k", Keywords::KEY_NAMED_EXPRESSIONS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("isotopes", Keywords::KEY_ISOTOPES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("calculate_values", Keywords::KEY_CALCULATE_VALUES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("isotope_ratios", Keywords::KEY_ISOTOPE_RATIOS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("isotope_alphas", Keywords::KEY_ISOTOPE_ALPHAS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("copy", Keywords::KEY_COPY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("pitzer", Keywords::KEY_PITZER),
std::map<const std::string, Keywords::KEYWORDS>::value_type("sit", Keywords::KEY_SIT),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium_phase", Keywords::KEY_EQUILIBRIUM_PHASES),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_raw", Keywords::KEY_SOLUTION_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("exchange_raw", Keywords::KEY_EXCHANGE_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("surface_raw", Keywords::KEY_SURFACE_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium_phases_raw", Keywords::KEY_EQUILIBRIUM_PHASES_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("kinetics_raw", Keywords::KEY_KINETICS_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solutions_raw", Keywords::KEY_SOLID_SOLUTIONS_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("gas_phase_raw", Keywords::KEY_GAS_PHASE_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_raw", Keywords::KEY_REACTION_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_raw", Keywords::KEY_MIX_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_temperature_raw", Keywords::KEY_REACTION_TEMPERATURE_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("dump", Keywords::KEY_DUMP),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_modify", Keywords::KEY_SOLUTION_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium_phases_modify", Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("exchange_modify", Keywords::KEY_EXCHANGE_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("surface_modify", Keywords::KEY_SURFACE_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solutions_modify", Keywords::KEY_SOLID_SOLUTIONS_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("gas_phase_modify", Keywords::KEY_GAS_PHASE_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("kinetics_modify", Keywords::KEY_KINETICS_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("delete", Keywords::KEY_DELETE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("run_cells", Keywords::KEY_RUN_CELLS),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_modify", Keywords::KEY_REACTION_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_temperature_modify", Keywords::KEY_REACTION_TEMPERATURE_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solution_modify", Keywords::KEY_SOLID_SOLUTIONS_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_pressure", Keywords::KEY_REACTION_PRESSURE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_pressures", Keywords::KEY_REACTION_PRESSURE),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_pressure_raw", Keywords::KEY_REACTION_PRESSURE_RAW),
std::map<const std::string, Keywords::KEYWORDS>::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solution_mix", Keywords::KEY_SOLUTION_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_solution", Keywords::KEY_SOLUTION_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("exchange_mix", Keywords::KEY_EXCHANGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_exchange", Keywords::KEY_EXCHANGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("gas_phase_mix", Keywords::KEY_GAS_PHASE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_gas_phase", Keywords::KEY_GAS_PHASE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("kinetics_mix", Keywords::KEY_KINETICS_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_kinetics", Keywords::KEY_KINETICS_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium_phases_mix", Keywords::KEY_PPASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_equilibrium_phases", Keywords::KEY_PPASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("equilibrium_phase_mix", Keywords::KEY_PPASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_equilibrium_phase", Keywords::KEY_PPASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solutions_mix", Keywords::KEY_SSASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_solid_solutions", Keywords::KEY_SSASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("solid_solution_mix", Keywords::KEY_SSASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_solid_solution", Keywords::KEY_SSASSEMBLAGE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("surface_mix", Keywords::KEY_SURFACE_MIX),
std::map<const std::string, Keywords::KEYWORDS>::value_type("mix_surface", Keywords::KEY_SURFACE_MIX)
};
const std::map<const std::string, Keywords::KEYWORDS> Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]);
const std::map<Keywords::KEYWORDS, std::string>::value_type temp_keyword_names[] = {
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_NONE, "UNKNOWN"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_END, "END"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION_SPECIES, "SOLUTION_SPECIES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION_MASTER_SPECIES, "SOLUTION_MASTER_SPECIES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION, "SOLUTION"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_PHASES, "PHASES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION, "REACTION"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_MIX, "MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_USE, "USE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SAVE, "SAVE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EXCHANGE_SPECIES, "EXCHANGE_SPECIES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EXCHANGE_MASTER_SPECIES, "EXCHANGE_MASTER_SPECIES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EXCHANGE, "EXCHANGE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SURFACE_SPECIES, "SURFACE_SPECIES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SURFACE_MASTER_SPECIES, "SURFACE_MASTER_SPECIES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SURFACE, "SURFACE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_TEMPERATURE, "REACTION_TEMPERATURE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_INVERSE_MODELING, "INVERSE_MODELING"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_GAS_PHASE, "GAS_PHASE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_TRANSPORT, "TRANSPORT"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SELECTED_OUTPUT, "SELECTED_OUTPUT"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_KNOBS, "KNOBS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_PRINT, "PRINT"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EQUILIBRIUM_PHASES, "EQUILIBRIUM_PHASES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_TITLE, "TITLE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_ADVECTION, "ADVECTION"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_KINETICS, "KINETICS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_INCREMENTAL_REACTIONS, "INCREMENTAL_REACTIONS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_RATES, "RATES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_USER_PRINT, "USER_PRINT"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_USER_PUNCH, "USER_PUNCH"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLID_SOLUTIONS, "SOLID_SOLUTIONS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION_SPREAD, "SOLUTION_SPREAD"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_USER_GRAPH, "USER_GRAPH"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS,"LLNL_AQUEOUS_MODEL_PARAMETERS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_DATABASE, "DATABASE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_NAMED_EXPRESSIONS, "NAMED_EXPRESSIONS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_ISOTOPES, "ISOTOPES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_CALCULATE_VALUES, "CALCULATE_VALUES"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_ISOTOPE_RATIOS, "ISOTOPE_RATIOS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_ISOTOPE_ALPHAS, "ISOTOPE_ALPHAS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_COPY, "COPY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_PITZER, "PITZER"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SIT, "SIT"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION_RAW, "SOLUTION_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EXCHANGE_RAW, "EXCHANGE_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SURFACE_RAW, "SURFACE_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_RAW, "EQUILIBRIUM_PHASES_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_KINETICS_RAW, "KINETICS_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLID_SOLUTIONS_RAW, "SOLID_SOLUTIONS_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_GAS_PHASE_RAW, "GAS_PHASE_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_RAW, "REACTION_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_MIX_RAW, "MIX_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_TEMPERATURE_RAW, "REACTION_TEMPERATURE_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_DUMP, "DUMP"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION_MODIFY, "SOLUTION_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY, "EQUILIBRIUM_PHASES_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EXCHANGE_MODIFY, "EXCHANGE_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SURFACE_MODIFY, "SURFACE_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLID_SOLUTIONS_MODIFY, "SOLID_SOLUTIONS_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_GAS_PHASE_MODIFY, "GAS_PHASE_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_KINETICS_MODIFY, "KINETICS_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_DELETE, "DELETE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_RUN_CELLS, "RUN_CELLS"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_MODIFY, "REACTION_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SOLUTION_MIX, "SOLUTION_MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_EXCHANGE_MIX, "EXCHANGE_MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_GAS_PHASE_MIX, "GAS_PHASE_MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_KINETICS_MIX, "KINETICS_MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "EQUILIBRIUM_PHASES_MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "SOLID_SOLUTIONS_MIX"),
std::map<Keywords::KEYWORDS, const std::string>::value_type(Keywords::KEY_SURFACE_MIX, "SURFACE_MIX")
};
const std::map<Keywords::KEYWORDS, const std::string> Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]);

View File

@ -0,0 +1,99 @@
#ifndef _INC_KEYWORDS_H
#define _INC_KEYWORDS_H
#include <string>
#include <map>
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_REACTION_PRESSURE,
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
};
Keywords(void);
~Keywords(void);
static KEYWORDS Keyword_search(std::string key);
static const std::string & Keyword_name_search(KEYWORDS key);
static const std::map<const std::string, KEYWORDS> phreeqc_keywords;
static const std::map<KEYWORDS, const std::string> phreeqc_keyword_names;
};
#endif // _INC_KEYWORDS_H

443
src/phreeqcpp/Pressure.cxx Normal file
View File

@ -0,0 +1,443 @@
// Pressure.cxx: implementation of the cxxPressure class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // 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;
}
cxxPressure::~cxxPressure()
{
}
int
cxxPressure::read(CParser & parser)
{
/*
* 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 set in read_reaction_pressure
PHRQ_io::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 == PHRQ_io::LT_EMPTY ||
lt == PHRQ_io::LT_KEYWORD ||
lt == PHRQ_io::LT_EOF)
{
break;
}
if (lt == PHRQ_io::LT_OPTION)
{
this->error_msg("Expected numeric value for pressures.", PHRQ_io::OT_CONTINUE);
break;
}
if (done)
{
this->error_msg("Unknown input following equal increment definition.", PHRQ_io::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 pressures.",
PHRQ_io::OT_CONTINUE);
}
else
{
this->pressures.push_back(d);
}
continue;
}
// non digit, must be "in"
if (k == CParser::TT_UPPER || k == CParser::TT_LOWER)
{
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);
}
}
} // tokens
} // lines
return lt;
}
void
cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const
{
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 << "\n";
s_oss << indent1;
s_oss << "-count " << this->count << "\n";
s_oss << indent1;
s_oss << "-equal_increments " << this->equalIncrements << "\n";
// Temperature element and attributes
s_oss << indent1;
s_oss << "-pressures" << "\n";
{
int i = 0;
s_oss << indent2;
for (std::vector < LDBLE >::const_iterator it = this->pressures.begin();
it != this->pressures.end(); it++)
{
if (i++ == 5)
{
s_oss << "\n";
s_oss << indent2;
i = 0;
}
s_oss << *it << " ";
}
s_oss << "\n";
}
}
void
cxxPressure::read_raw(CParser & parser, bool check)
{
// clear steps for modify operation, if pressures are read
bool cleared_once = false;
LDBLE d;
CParser::TOKEN_TYPE k;
std::istream::pos_type ptr;
std::istream::pos_type next_char = 0;
std::string token;
int opt_save;
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);
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;
}
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.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
useLastLine = false;
break;
case 0: // pressures
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))
{
parser.incr_input_error();
parser.error_msg("Expected numeric value for pressures.",
PHRQ_io::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.", PHRQ_io::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.", PHRQ_io::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 (check)
{
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
void
cxxPressure::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 << "<temperature " << "\n";
s_oss << indent1;
s_oss << "pitzer_temperature_gammas=\"" << this->
pitzer_temperature_gammas << "\"" << "\n";
// components
s_oss << indent1;
s_oss << "<component " << "\n";
for (std::list < cxxPressureComp >::const_iterator it =
temperatureComps.begin(); it != temperatureComps.end(); ++it)
{
it->dump_xml(s_oss, indent + 2);
}
return;
}
#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();
}
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
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]);

43
src/phreeqcpp/Pressure.h Normal file
View File

@ -0,0 +1,43 @@
#if !defined(PRESSURE_H_INCLUDED)
#define PRESSURE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NumKeyword.h"
class Dictionary;
class cxxPressure:public cxxNumKeyword
{
public:
cxxPressure(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;
int read(CParser & parser);
void read_raw(CParser & parser, bool check = false);
LDBLE Pressure_for_step(int step_number);
std::vector<LDBLE> & Get_pressures(void) {return pressures;}
const std::vector<LDBLE> & 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;}
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;
bool equalIncrements;
const static std::vector < std::string > vopts;
};
#endif // !defined(PRESSURE_H_INCLUDED)

312
src/phreeqcpp/Reaction.cxx Normal file
View File

@ -0,0 +1,312 @@
// Reaction.cxx: implementation of the cxxReaction class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "Reaction.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxReaction::cxxReaction(PHRQ_io *io)
//
// default constructor for cxxReaction
//
: cxxNumKeyword(io)
{
this->Set_units("Mol");
countSteps = 0;
equalIncrements = false;
reactantList.type = cxxNameDouble::ND_NAME_COEF;
elementList.type = cxxNameDouble::ND_ELT_MOLES;
}
cxxReaction::~cxxReaction()
{
}
#ifdef SKIP
void
cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 << "<irrev " << "\n";
s_oss << indent1;
s_oss << "pitzer_irrev_gammas=\"" << this->
pitzer_irrev_gammas << "\"" << "\n";
// components
s_oss << indent1;
s_oss << "<component " << "\n";
for (std::list < cxxReactionComp >::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, int *n_out) const
{
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;
int n_user_local = (n_out != NULL) ? *n_out : this->n_user;
s_oss << "REACTION_RAW " << n_user_local << " " << this->description << "\n";
s_oss << indent1;
s_oss << "-reactant_list" << "\n";
this->reactantList.dump_raw(s_oss, indent + 2);
s_oss << indent1;
s_oss << "-steps" << "\n";
{
int i = 0;
s_oss << indent2;
for (std::vector < LDBLE >::const_iterator it = this->steps.begin();
it != this->steps.end(); it++)
{
if (i++ == 5)
{
s_oss << "\n";
s_oss << indent2;
i = 0;
}
s_oss << *it << " ";
}
s_oss << "\n";
}
s_oss << indent1;
s_oss << "-count_steps " << this->countSteps << "\n";
s_oss << indent1;
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
cxxReaction::read_raw(CParser & parser, const bool check)
{
int j;
LDBLE d;
CParser::TOKEN_TYPE k;
// 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;
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, 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 IRREV_COMP_RAW keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
useLastLine = false;
break;
case 0: // units
j = parser.copy_token(token, next_char);
if (j == CParser::TT_EMPTY)
break;
this->Set_units(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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
opt_save = 2;
useLastLine = false;
break;
case 3: // steps
if (!cleared_once)
{
this->steps.clear();
cleared_once = true;
}
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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
opt_save = CParser::OPT_DEFAULT;
useLastLine = false;
countSteps_defined = true;
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
if (check)
{
// members that must be defined
if (units_defined == false)
{
parser.incr_input_error();
parser.error_msg("Units not defined for REACTION_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (equalIncrements_defined == false)
{
parser.incr_input_error();
parser.
error_msg("Equal_increments not defined for REACTION_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (countSteps_defined == false)
{
parser.incr_input_error();
parser.error_msg("Count_steps not defined for REACTION_RAW input.",
PHRQ_io::OT_CONTINUE);
}
}
}
int cxxReaction::
Get_reaction_steps(void) const
{
if (equalIncrements)
{
return this->countSteps;
}
return (int) this->steps.size();
}
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]);

57
src/phreeqcpp/Reaction.h Normal file
View File

@ -0,0 +1,57 @@
#if !defined(REACTION_H_INCLUDED)
#define REACTION_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NumKeyword.h"
#include "NameDouble.h"
class cxxReaction:public cxxNumKeyword
{
public:
cxxReaction(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=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;}
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<LDBLE> &v) {steps = v;}
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;}
void Set_equalIncrements(bool tf) {equalIncrements = tf;}
const std::string &Get_units(void) const {return this->units;}
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 < LDBLE >steps;
int countSteps;
bool equalIncrements;
std::string units;
const static std::vector < std::string > vopts;
};
#endif // !defined(REACTION_H_INCLUDED)

1140
src/phreeqcpp/ReadClass.cxx Normal file

File diff suppressed because it is too large Load Diff

632
src/phreeqcpp/SS.cxx Normal file
View File

@ -0,0 +1,632 @@
// SSassemblageSS.cxx: implementation of the cxxSS class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Phreeqc.h"
#include "Utils.h" // define first
#include "SS.h"
#include "Dictionary.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSS::cxxSS(PHRQ_io *io)
:
PHRQ_base(io)
//
// default constructor for cxxSS
//
{
total_moles = 0;
dn = 0;
a0 = 0;
a1 = 0;
ag0 = 0;
ag1 = 0;
ss_in = false;
miscibility = false;
spinodal = false;
tk = 298.15;
xb1 = 0;
xb2 = 0;
input_case = SS_PARM_NONE;
for (int i = 0; i < 4; i++)
{
p.push_back(0);
}
}
cxxSS::~cxxSS()
{
}
#ifdef SKIP
void
cxxSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 << "\"" << "\n";
s_oss << indent0 << "add_formula=\"" << this->
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 << "\"" << "\n";
s_oss << indent0 << "dissolve_only=\"" << this->
dissolve_only << "\"" << "\n";
}
#endif
void
cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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);
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";
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
cxxSS::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_ERROR;
bool a0_defined(false);
bool a1_defined(false);
bool ag0_defined(false);
bool ag1_defined(false);
bool miscibility_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;
if (useLastLine == false)
{
opt = parser.get_option(vopts, next_char);
}
else
{
opt = parser.getOptionFromLastLine(vopts, next_char, false);
}
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_KEYWORD;
// Allow return to Exchange for more processing
break;
case 0: // name not used
parser.warning_msg("-ss_name not used, defined in -solid_solution");
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.", PHRQ_io::OT_CONTINUE);
}
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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
a1_defined = true;
opt_save = CParser::OPT_DEFAULT;
break;
case 4: // components
case 12: // component
{
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;
case 5: // miscibility
if (!(parser.get_iss() >> this->miscibility))
{
this->miscibility = 0;
parser.incr_input_error();
parser.error_msg("Expected boolean value for miscibility.",
PHRQ_io::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.", PHRQ_io::OT_CONTINUE);
}
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);
}
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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
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;
}
}
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;
}
if (check)
{
// members that must be defined
if (a0_defined == false)
{
parser.incr_input_error();
parser.error_msg("A0 not defined for SSassemblageSS input.",
PHRQ_io::OT_CONTINUE);
}
if (a1_defined == false)
{
parser.incr_input_error();
parser.error_msg("A1 not defined for SSassemblageSS input.",
PHRQ_io::OT_CONTINUE);
}
if (ag0_defined == false)
{
parser.incr_input_error();
parser.error_msg("Ag0 not defined for SSassemblageSS input.",
PHRQ_io::OT_CONTINUE);
}
if (ag1_defined == false)
{
parser.incr_input_error();
parser.error_msg("Ag1 not defined for SSassemblageSS input.",
PHRQ_io::OT_CONTINUE);
}
if (miscibility_defined == false)
{
parser.incr_input_error();
parser.error_msg("Miscibility 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.",
PHRQ_io::OT_CONTINUE);
}
if (xb2_defined == false)
{
parser.incr_input_error();
parser.error_msg("Xb2 not defined for SSassemblageSS input.",
PHRQ_io::OT_CONTINUE);
}
}
}
void
cxxSS::totalize(Phreeqc * phreeqc_ptr)
{
this->totals.clear();
// component structures
for (size_t i = 0; i < this->ss_comps.size(); i++)
{
struct phase *phase_ptr;
int l;
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);
this->totals.add_extensive(phase_formula, ss_comps[i].Get_moles());
}
else
{
assert(false);
}
}
return;
}
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)
{
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() +
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);
}
}
}
void
cxxSS::multiply(LDBLE extensive)
{
size_t i;
for (i = 0; i < this->ss_comps.size(); i++)
{
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);
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);
}
}
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;
}
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
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]);

128
src/phreeqcpp/SS.h Normal file
View File

@ -0,0 +1,128 @@
#if !defined(SSASSEMBLAGESS_H_INCLUDED)
#define SSASSEMBLAGESS_H_INCLUDED
#include <cassert> // assert
#include <vector>
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "phrqtype.h"
#include "NameDouble.h"
#include "SScomp.h"
class cxxSS: public PHRQ_base
{
public:
cxxSS(PHRQ_io *io=NULL);
virtual ~cxxSS();
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
};
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 std::string & s) {this->name = s;}
void Set_name (const char * s)
{
if (s != NULL)
this->name = std::string(s);
else
this->name.clear();
}
void totalize(Phreeqc * phreeqc_ptr);
const cxxNameDouble & Get_totals() const
{
return (this->totals);
};
cxxSScomp * Find(const char * comp_name);
void add(const cxxSS & comp, LDBLE extensive);
void multiply(LDBLE extensive);
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<cxxSScomp> & Get_ss_comps(void) {return ss_comps;}
const std::vector<cxxSScomp> & Get_ss_comps(void)const {return ss_comps;}
void Set_ss_comps(const std::vector<cxxSScomp> & comps) {ss_comps = comps;}
LDBLE Get_tk(void)const {return this->tk;}
void Set_tk(LDBLE t) {this->tk = t;}
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<LDBLE> & Get_p(void) {return this->p;}
const std::vector<LDBLE> & Get_p(void)const {return this->p;}
void Set_p(const std::vector<LDBLE> & 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
LDBLE ag0, ag1;
std::vector<cxxSScomp> ss_comps;
// SOLID_SOLUTION keyword data
LDBLE a0, a1;
bool miscibility;
bool spinodal;
LDBLE tk, xb1, xb2;
SS_PARAMETER_TYPE input_case;
std::vector<LDBLE> p;
// workspace variable
LDBLE total_moles;
LDBLE dn;
bool ss_in;
cxxNameDouble totals;
const static std::vector < std::string > vopts;
public:
};
#endif // !defined(SSASSEMBLAGESS_H_INCLUDED)

View File

@ -0,0 +1,341 @@
// SSassemblage.cxx: implementation of the cxxSSassemblage class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <float.h>
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "SSassemblage.h"
#include "SS.h"
#include "cxxMix.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSSassemblage::cxxSSassemblage(PHRQ_io * io)
//
// default constructor for cxxSSassemblage
//
: cxxNumKeyword(io)
{
new_def = false;
}
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;
//
// Mix
//
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())
{
const cxxSSassemblage *entity_ptr =
&(entities.find(it->first)->second);
this->add(*entity_ptr, it->second);
}
}
this->new_def = false;
}
cxxSSassemblage::~cxxSSassemblage()
{
}
#ifdef SKIP
void
cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 << "<EQUILIBRIUM_PHASES " << "\n";
// eltList
this->eltList.dump_xml(s_oss, indent + 1);
// SSs
s_oss << indent1;
s_oss << "<pure_phases " << "\n";
for (std::list < cxxSS >::const_iterator it =
SSs.begin(); it != SSs.end(); ++it)
{
it->dump_xml(s_oss, indent + 2);
}
}
#endif
void
cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const
{
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;
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 << 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";
(*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 ? 1 : 0) << "\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)
{
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);
this->Set_new_def(false);
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, 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 SOLID_SOLUTIONS_RAW or SOLID_SOLUTIONS_MODIFY keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
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;
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;
}
}
void
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(phreeqc_ptr);
this->totals.add_extensive((*it).second.Get_totals(), 1.0);
}
return;
}
void
cxxSSassemblage::add(const cxxSSassemblage & addee, LDBLE extensive)
//
// Add to existing ssassemblage to "this" ssassemblage
//
{
if (extensive == 0.0)
return;
for (std::map < std::string, cxxSS >::const_iterator itadd =
addee.SSs.begin(); itadd != addee.SSs.end();
++itadd)
{
std::map < std::string, cxxSS >::iterator it =
this->SSs.find((*itadd).first);
if (it != this->SSs.end())
{
(*it).second.add((*itadd).second, extensive);
}
else
{
cxxSS entity = (*itadd).second;
entity.multiply(extensive);
std::string str(entity.Get_name());
this->SSs[str] = entity;
}
}
}
std::vector<cxxSS *> cxxSSassemblage::
Vectorize(void)
{
std::vector<cxxSS *> ss_v;
std::map<std::string, cxxSS>::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<std::string, cxxSS>::iterator it;
it = this->SSs.find(s);
if (it != this->SSs.end())
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
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]);

View File

@ -0,0 +1,59 @@
#if !defined(SSASSEMBLAGE_H_INCLUDED)
#define SSASSEMBLAGE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NumKeyword.h"
#include "NameDouble.h"
#include "SS.h"
class cxxSS;
//#include "cxxMix.h"
class cxxMix;
class cxxSSassemblage:public cxxNumKeyword
{
public:
cxxSSassemblage(PHRQ_io * io = NULL);
cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map,
cxxMix & mx, int n_user, PHRQ_io * io = NULL);
~cxxSSassemblage();
//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);
void totalize(Phreeqc * phreeqc_ptr);
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;}
std::vector<cxxSS *> 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;
// SOLID_SOLUTION keyword data
bool new_def;
// internal variables
cxxNameDouble totals;
const static std::vector < std::string > vopts;
};
#endif // !defined(SSASSEMBLAGE_H_INCLUDED)

332
src/phreeqcpp/SScomp.cxx Normal file
View File

@ -0,0 +1,332 @@
// SScomp.cxx: implementation of the cxxSScomp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "SScomp.h"
#include "phqalloc.h"
#include "Dictionary.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
{
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 << "# SOLID_SOLUTION_MODIFY candidate identifiers #\n";
s_oss << indent1 << "-moles " << this->moles << "\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
cxxSScomp::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_ERROR;
bool initial_moles_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 Exchange for more processing
break;
case 0: // name
parser.error_msg("-Name ignored. Define with -component.");
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);
}
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);
}
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);
}
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);
}
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);
}
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
// members that must be defined
if (check)
{
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 SKIP
void
cxxSScomp::totalize(Phreeqc * phreeqc_ptr)
{
this->totals.clear();
// component structures
if (this->add_formula.size() != 0)
return;
struct phase *phase_ptr;
int l;
phase_ptr = phreeqc_ptr-> 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
void
cxxSScomp::multiply(LDBLE extensive)
{
this->moles *= 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
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]);

66
src/phreeqcpp/SScomp.h Normal file
View File

@ -0,0 +1,66 @@
#if !defined(SSCOMP_H_INCLUDED)
#define SSCOMP_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.h"
class cxxSScomp: public PHRQ_base
{
public:
cxxSScomp(PHRQ_io *io=NULL);
virtual ~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 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
LDBLE moles;
// Solid solution workspace variables
LDBLE initial_moles;
LDBLE init_moles;
LDBLE delta;
LDBLE fraction_x;
LDBLE log10_lambda;
LDBLE log10_fraction_x;
LDBLE dn, dnc, dnb;
const static std::vector < std::string > vopts;
};
#endif // !defined(SSCOMP_H_INCLUDED)

View File

@ -0,0 +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();
}

View File

@ -0,0 +1,204 @@
#if !defined(SELECTEDOUTPUT_H_INCLUDED)
#define SELECTEDOUTPUT_H_INCLUDED
#include <string> // std::string
#include <vector>
#include <map>
#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)

View File

@ -0,0 +1,200 @@
#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<int> &ints, std::vector<double> &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:
#if !defined(R_SO)
std::cerr << "Unknown pack type in deserialize " << type << std::endl;
exit(4);
#endif
break;
}
}
return true;
}

View File

@ -0,0 +1,42 @@
#if !defined(SERIALIZER_H_INCLUDED)
#define SERIALIZER_H_INCLUDED
#include <iostream>
#include <map>
#include <vector>
#include <sstream>
#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<int> &ints, std::vector<double> &doubles);
Dictionary &GetDictionary(void) {return this->dictionary;}
std::vector<int> &GetInts(void) {return this->ints;}
std::vector<double> &GetDoubles(void) {return this->doubles;}
//std::string &GetWordsString(void) {return this->words_string;}
protected:
std::vector<int> ints;
std::vector<double> doubles;
//std::string words_string;
Dictionary dictionary;
};
#endif // !defined(SERIALIZER_H_INCLUDED)

1727
src/phreeqcpp/Solution.cxx Normal file

File diff suppressed because it is too large Load Diff

146
src/phreeqcpp/Solution.h Normal file
View File

@ -0,0 +1,146 @@
#if !defined(SOLUTION_H_INCLUDED)
#define SOLUTION_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <vector> // std::vector
#include <iostream>
#include "NumKeyword.h"
#include "SolutionIsotope.h"
#include "NameDouble.h"
#include "PHRQ_base.h"
#include "PHRQ_io.h"
#include "ISolution.h"
class cxxMix;
class cxxSolution:public cxxNumKeyword
{
public:
cxxSolution(PHRQ_io *io=NULL);
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);
virtual ~cxxSolution();
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_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;}
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;}
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)
{
this->totals = nd;
this->totals.type = cxxNameDouble::ND_ELT_MOLES;
}
cxxNameDouble & Get_master_activity(void) {return this->master_activity;}
cxxNameDouble & Get_species_gamma(void) {return this->species_gamma;}
std::map<int, double> & Get_species_map(void) {return this->species_map;}
std::map<int, double> & Get_log_gamma_map(void) {return this->log_gamma_map;}
std::map < 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)
delete this->initial_data;
this->initial_data = new cxxISolution(*id);
}
void Create_initial_data()
{
if (this->initial_data != NULL)
delete initial_data;
initial_data = new cxxISolution;
}
void Destroy_initial_data()
{
if (this->initial_data != NULL)
delete initial_data;
initial_data = NULL;
}
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(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 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;
LDBLE patm;
LDBLE potV;
LDBLE tc;
LDBLE ph;
LDBLE pe;
LDBLE mu;
LDBLE ah2o;
LDBLE total_h;
LDBLE total_o;
LDBLE cb;
LDBLE mass_water;
LDBLE density;
LDBLE soln_vol;
LDBLE total_alkalinity;
cxxNameDouble totals;
cxxNameDouble master_activity;
cxxNameDouble species_gamma;
//cxxSolutionIsotopeList isotopes;
std::map < std::string, cxxSolutionIsotope > isotopes;
cxxISolution *initial_data;
const static std::vector < std::string > vopts;
std::map<int, double> species_map;
std::map<int, double> log_gamma_map;
};
#endif // !defined(SOLUTION_H_INCLUDED)

View File

@ -0,0 +1,329 @@
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert>
#include <sstream> // std::ostrstream
#include "Utils.h"
#include "Phreeqc.h"
#include "SolutionIsotope.h"
#include "phqalloc.h"
#include "Dictionary.h"
cxxSolutionIsotope::cxxSolutionIsotope(PHRQ_io *io)
:
PHRQ_base(io),
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;
x_ratio_uncertainty = 0;
coef = 0;
}
cxxSolutionIsotope::~cxxSolutionIsotope(void)
{
}
void
cxxSolutionIsotope::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 << "<soln_isotope=\"" << "\n";
s_oss << indent1;
s_oss << "iso_isotope_number=\"" << this->
isotope_number << "\"" << "\n";
s_oss << indent1;
s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << "\n";
s_oss << indent1;
s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << "\n";
s_oss << indent1;
s_oss << "iso_total=\"" << this->total << "\"" << "\n";
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->
ratio_uncertainty << "\"" << "\n";
}
s_oss << indent0;
s_oss << "\">" << "\n";
}
void
cxxSolutionIsotope::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);
std::string indent1 = indent0;
indent1.append(Utilities::INDENT);
s_oss << indent0;
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 << indent0 << "-ratio_uncertainty " << this->ratio_uncertainty << "\n";
}
s_oss << indent0 << "-x_ratio_uncertainty " << this->x_ratio_uncertainty << "\n";
s_oss << indent0 << "-coef " << this->coef << "\n";
}
void cxxSolutionIsotope::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 isotope_number_defined(false);
bool elt_name_defined(false);
bool total_defined(false);
bool ratio_defined(false);
for (;;)
{
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;
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;
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;
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;
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;
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;
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
{
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);
}
void
cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr,
LDBLE intensive, LDBLE 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);
}
}
void
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
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]);

View File

@ -0,0 +1,85 @@
#if !defined(SOLUTIONISOTOPE_H_INCLUDED)
#define SOLUTIONISOTOPE_H_INCLUDED
#include <ostream> // std::ostream
#include <string> // std::string
#include <list> // std::list
#include "Parser.h"
class Dictionary;
class cxxSolutionIsotope: public PHRQ_base
{
public:
cxxSolutionIsotope(PHRQ_io *io=NULL);
cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io=NULL);
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);
void read_raw(CParser & parser, bool check);
LDBLE Get_isotope_number() const
{
return this->isotope_number;
}
void Set_isotope_number(LDBLE d)
{
this->isotope_number = d;
}
const std::string &Get_elt_name() const {return this->elt_name;}
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 {return this->isotope_name;}
void Set_isotope_name(const char *cstring)
{
if (cstring != NULL)
this->isotope_name = std::string(cstring);
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;}
void Set_ratio(LDBLE t) {this->ratio = t;}
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,
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;
std::string elt_name;
std::string isotope_name;
LDBLE total;
LDBLE ratio;
LDBLE ratio_uncertainty;
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

1566
src/phreeqcpp/StorageBin.cxx Normal file

File diff suppressed because it is too large Load Diff

139
src/phreeqcpp/StorageBin.h Normal file
View File

@ -0,0 +1,139 @@
#if !defined(STORAGEBIN_H_INCLUDED)
#define STORAGEBIN_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "System.h"
#include "PHRQ_io.h"
#include "PHRQ_base.h"
class cxxSolution;
class cxxExchange;
class cxxGasPhase;
class cxxKinetics;
class cxxPPassemblage;
class cxxSSassemblage;
class cxxSurface;
class cxxReaction;
class cxxTemperature;
class cxxUse;
class cxxStorageBin: public PHRQ_base
{
public:
cxxStorageBin(PHRQ_io *io=NULL);
cxxStorageBin(cxxUse &use_ref, PHRQ_io *io=NULL);
virtual ~cxxStorageBin();
void Copy(int destination, int source);
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 Remove_Solution(int n_user);
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);
void Set_PPassemblage(int n_user, cxxPPassemblage * entity);
void Set_PPassemblage(int n_user, cxxPPassemblage & entity);
void Remove_PPassemblage(int n_user);
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);
void Set_SSassemblage(int n_user, cxxSSassemblage * entity);
void Set_SSassemblage(int n_user, cxxSSassemblage & entity);
void Remove_SSassemblage(int n_user);
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);
void Set_System(cxxUse *use_ptr);
void Set_System(int i);
void dump_raw(std::ostream & s_oss, unsigned int indent) const;
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);
void Add(cxxStorageBin &src, int n);
//cxxSolution *mix_cxxSolutions(cxxMix &mixmap);
cxxExchange *mix_cxxExchange(cxxMix & mixmap);
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;};
protected:
// Tidied classes
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;
// Reaction classes
std::map < int, cxxMix > Mixes;
std::map < int, cxxReaction > Reactions;
std::map < int, cxxTemperature > Temperatures;
std::map < int, cxxPressure > Pressures;
cxxSystem system;
};
#endif // !defined(STORAGEBIN_H_INCLUDED)

View File

@ -0,0 +1,350 @@
#include <algorithm> // std::replace
#include "StorageBinList.h"
#include "Parser.h"
StorageBinListItem::StorageBinListItem(void)
{
this->defined = false;
}
StorageBinListItem::~StorageBinListItem(void)
{
}
StorageBinListItem::StorageBinListItem(CParser & parser)
{
this->Clear();
// Read list of numbers or number ranges
for (;;)
{
//read lines
PHRQ_io::LINE_TYPE l = parser.check_line("read StorageBinListLtem", false, true, true, true);
std::istream::pos_type next_char = 0;
if (l == PHRQ_io::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;
}
}
}
}
void StorageBinListItem::Augment(std::string token)
{
this->defined = true;
if (token.size() == 0) return;
// split string accounting for possible negative numbers
size_t 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 <int>::iterator it;
it = temp_set.begin();
i1 = *it;
it++;
i2 = *it;
for (i = i1; i <= i2; i++)
{
this->numbers.insert(i);
}
}
}
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);
}
//
//Class definitions for StorageBinList
//
StorageBinList::StorageBinList(PHRQ_io *io)
:
PHRQ_base(io)
{
}
StorageBinList::StorageBinList(CParser & parser, PHRQ_io *io)
:
PHRQ_base(io)
{
this->Read(parser);
}
StorageBinList::~StorageBinList(void)
{
}
std::set<StorageBinListItem *> StorageBinList::GetAllItems(void)
{
// don't include this->cell
std::set<StorageBinListItem *> 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)
{
std::set<StorageBinListItem *> all = this->GetAllItems();
std::set<StorageBinListItem *>::iterator it = all.begin();
for (; it != all.end(); ++it)
{
(*it)->Clear();
(*it)->Set_defined(tf);
}
}
bool StorageBinList::Read(CParser & parser)
{
bool return_value(true);
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_DEFAULT;
// reset cells
this->cell.Clear();
this->cell.Set_defined(false);
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 = NULL;
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_ss_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:
case 16:
item = &(this->Get_temperature());
break;
case 14:
case 15:
item = &(this->Get_cell());
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))
{
for (;;)
{
CParser::TOKEN_TYPE j = parser.copy_token(token, next_char);
if (item)
{
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("Dump entity type not defined.",
PHRQ_io::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:
case 16:
case 17:
case 18:
break;
case 13: //all
this->SetAll(true);
break;
case 14:
case 15:
//if (cell_list.Get_numbers().empty())
//{
// this->SetAll(true);
//}
//else
//{
//this->TransferAll(cell_list);
//}
break;
default:
case CParser::OPT_DEFAULT:
case CParser::OPT_ERROR:
opt = CParser::OPT_EOF;
parser.error_msg("Unknown input reading DELETE definition.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
return_value = false;
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
// Now check to see if cell_list defined
if (this->Get_cell().Get_defined())
{
if (this->Get_cell().Get_numbers().empty())
{
this->SetAll(true);
}
else
{
this->TransferAll(this->Get_cell());
}
}
return(return_value);
}
void StorageBinList::TransferAll(StorageBinListItem &source)
{
std::set<StorageBinListItem *> items = this->GetAllItems();
std::set < int >::iterator it;
for (it = source.Get_numbers().begin(); it != source.Get_numbers().end(); it++)
{
std::set<StorageBinListItem *>::iterator item = items.begin();
for (; item != items.end(); ++item)
{
(*item)->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]);

View File

@ -0,0 +1,81 @@
#if !defined(STORAGEBINLIST_H_INCLUDED)
#define STORAGEBINLIST_H_INCLUDED
#include <set> // std::set
#include <string> // std::string
#include <list> // std::list
#include <vector> // 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)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;
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<StorageBinListItem *> 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); };
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;
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;
StorageBinListItem cell; // not included in GetAllItems
};
#endif // !defined(STORAGEBINLIST_H_INCLUDED)

852
src/phreeqcpp/Surface.cxx Normal file
View File

@ -0,0 +1,852 @@
// Surface.cxx: implementation of the cxxSurface class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "Surface.h"
#include "cxxMix.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSurface::cxxSurface(PHRQ_io *io)
//
// default constructor for cxxSurface
//
: cxxNumKeyword(io)
{
new_def = false;
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;
solution_equilibria = false;
n_solution = -999;
}
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;
only_counter_ions = false;
thickness = 1e-8;
debye_lengths = 0.0;
DDL_viscosity = 1.0;
DDL_limit = 0.8;
transport = false;
solution_equilibria = false;
n_solution = -999;
//
// Mix surfaces
//
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())
{
this->add(entities.find(it->first)->second, it->second);
}
}
}
cxxSurface::~cxxSurface()
{
}
bool
cxxSurface::Get_related_phases() const
{
for (size_t i = 0; i != this->surface_comps.size(); i++)
{
if (this->surface_comps[i].Get_phase_name().size() == 0)
continue;
return (true);
}
return (false);
}
bool
cxxSurface::Get_related_rate() const
{
for (size_t i = 0; i != this->surface_comps.size(); i++)
{
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
{
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 " << "\n";
s_oss << indent1;
s_oss << "surface_type=\"" << this->type << "\"" << "\n";
s_oss << indent1;
s_oss << "dl_type=\"" << this->dl_type << "\"" << "\n";
s_oss << indent1;
s_oss << "sites_units=\"" << this->sites_units << "\"" << "\n";
s_oss << indent1;
s_oss << "only_counter_ions=\"" << this->
only_counter_ions << "\"" << "\n";
s_oss << indent1;
s_oss << "thickness=\"" << this->thickness << "\"" << "\n";
s_oss << indent1;
s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << "\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";
// surface component structures
s_oss << indent1;
s_oss << "<component " << "\n";
{
for (std::map < std::string, cxxSurfaceComp >::const_iterator it =
this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it)
{
(*it).second.dump_xml(s_oss, indent + 2);
}
}
// surface charge structures
s_oss << indent1;
s_oss << "<charge_component " << "\n";
for (std::map < std::string, cxxSurfaceCharge >::const_iterator 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
{
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;
int n_user_local = (n_out != NULL) ? *n_out : this->n_user;
s_oss << "SURFACE_RAW " << n_user_local << " " << this->description << "\n";
s_oss << indent1 << "# SURFACE_MODIFY candidate identifiers #\n";
s_oss << indent1;
s_oss << "-type " << this->type << "\n";
s_oss << indent1;
s_oss << "-dl_type " << this->dl_type << "\n";
s_oss << indent1;
s_oss << "-only_counter_ions " << this->only_counter_ions << "\n";
s_oss << indent1;
s_oss << "-thickness " << this->thickness << "\n";
s_oss << indent1;
s_oss << "-debye_lengths " << this->debye_lengths << "\n";
s_oss << indent1;
s_oss << "-DDL_viscosity " << this->DDL_viscosity << "\n";
s_oss << indent1;
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 " << comp_ptr->Get_formula() << "\n";
comp_ptr->dump_raw(s_oss, indent + 2);
}
// surface charge
for (size_t i = 0; i != this->surface_charges.size(); i++)
{
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;
}
void
cxxSurface::read_raw(CParser & parser, bool check)
{
int i = 0;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
bool useLastLine(false);
// Read surface number and description
this->read_number_description(parser);
this->Set_new_def(false);
bool only_counter_ions_defined(false);
bool thickness_defined(false);
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 (;;)
{
int opt;
if (useLastLine == false)
{
opt = parser.get_option(vopts, next_char);
}
else
{
opt = parser.getOptionFromLastLine(vopts, next_char, true);
}
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 SURFACE keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
break;
case 0: // diffuse_layer
parser.incr_input_error();
parser.error_msg("Diffuse layer is obsolete, use -type.",
PHRQ_io::OT_CONTINUE);
break;
case 1: // edl
parser.incr_input_error();
parser.error_msg("-edl is obsolete, use -type.",
PHRQ_io::OT_CONTINUE);
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.",
PHRQ_io::OT_CONTINUE);
}
only_counter_ions_defined = true;
break;
case 3: // donnan
parser.incr_input_error();
parser.error_msg("-Donnan is obsolete, use -dl_type.",
PHRQ_io::OT_CONTINUE);
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.",
PHRQ_io::OT_CONTINUE);
}
thickness_defined = true;
break;
case 5: // 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
{
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;
}
}
break;
case 6: // charge_component
{
std::string str;
if (!(parser.get_iss() >> str))
{
parser.incr_input_error();
parser.error_msg("Expected string value for charge name.",
PHRQ_io::OT_CONTINUE);
}
else
{
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
i = 0;
if (!(parser.get_iss() >> i))
{
this->type = NO_EDL;
parser.incr_input_error();
parser.error_msg("Expected numeric value for type.",
PHRQ_io::OT_CONTINUE);
}
this->type = (SURFACE_TYPE) i;
type_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
this->dl_type = (DIFFUSE_LAYER_TYPE) i;
dl_type_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
this->sites_units = (SITES_UNITS) i;
sites_units_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
debye_lengths_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
DDL_viscosity_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
DDL_limit_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
transport_defined = true;
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);
}
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
if (check)
{
// members that must be defined
if (only_counter_ions_defined == false)
{
parser.incr_input_error();
parser.
error_msg("Only_counter_ions 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.",
PHRQ_io::OT_CONTINUE);
}
if (type_defined == false)
{
parser.incr_input_error();
parser.error_msg("Surface type not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (dl_type_defined == false)
{
parser.incr_input_error();
parser.error_msg("Dl_type not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (sites_units_defined == false)
{
parser.incr_input_error();
parser.error_msg("Sites_units not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (debye_lengths_defined == false)
{
parser.incr_input_error();
parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (DDL_viscosity_defined == false)
{
parser.incr_input_error();
parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (DDL_limit_defined == false)
{
parser.incr_input_error();
parser.error_msg("DDL_limit not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
if (transport_defined == false)
{
parser.incr_input_error();
parser.error_msg("Transport not defined for SURFACE_RAW input.",
PHRQ_io::OT_CONTINUE);
}
}
this->Sort_comps();
}
void
cxxSurface::totalize()
{
this->totals.clear();
// component structures
for (size_t i = 0; i != this->surface_comps.size(); i++)
{
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_in, LDBLE extensive)
//
// Add surface to "this" surface
//
{
cxxSurface addee = addee_in;
if (extensive == 0.0)
return;
if (this->surface_comps.size() == 0)
{
this->only_counter_ions = addee.only_counter_ions;
this->dl_type = addee.dl_type;
this->type = addee.type;
this->sites_units = addee.sites_units;
this->thickness = addee.thickness;
this->debye_lengths = addee.debye_lengths;
this->DDL_viscosity = addee.DDL_viscosity;
this->DDL_limit = addee.DDL_limit;
this->solution_equilibria = addee.solution_equilibria;
this->n_solution = addee.n_solution;
this->transport = addee.transport;
}
for (size_t i_add = 0; i_add < addee.Get_surface_comps().size(); i_add++)
{
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++)
{
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;
}
}
if (i_this == this->surface_comps.size())
{
cxxSurfaceComp entity = comp_add_ptr;
entity.multiply(extensive);
this->surface_comps.push_back(entity);
}
}
for (size_t i_add = 0; i_add < addee.Get_surface_charges().size(); i_add++)
{
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++)
{
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;
}
}
if (i_this == this->surface_charges.size())
{
cxxSurfaceCharge entity = charge_add_ptr;
entity.multiply(extensive);
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;
}
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)
{
// sort comps
{
std::map<std::string, cxxSurfaceComp> 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<std::string, cxxSurfaceComp>::iterator it;
for (it = comp_map.begin(); it != comp_map.end(); it++)
{
this->surface_comps.push_back(it->second);
}
}
// sort charge too
{
std::map<std::string, cxxSurfaceCharge> 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<std::string, cxxSurfaceCharge>::iterator it;
for (it = charge_map.begin(); it != charge_map.end(); it++)
{
this->surface_charges.push_back(it->second);
}
}
}
/* ---------------------------------------------------------------------- */
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
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]);

98
src/phreeqcpp/Surface.h Normal file
View File

@ -0,0 +1,98 @@
#if !defined(SURFACE_H_INCLUDED)
#define SURFACE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NumKeyword.h"
#include "SurfaceComp.h"
#include "SurfaceCharge.h"
class cxxMix;
class cxxSurface:public cxxNumKeyword
{
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(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_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();
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();
void add(const cxxSurface & addee, LDBLE extensive);
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;}
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)const {return solution_equilibria;}
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;
bool new_def;
SURFACE_TYPE type;
DIFFUSE_LAYER_TYPE dl_type;
SITES_UNITS sites_units;
bool only_counter_ions;
LDBLE thickness;
LDBLE debye_lengths;
LDBLE DDL_viscosity;
LDBLE DDL_limit;
bool transport;
cxxNameDouble totals;
bool solution_equilibria;
int n_solution;
const static std::vector < std::string > vopts;
};
#endif // !defined(SURFACE_H_INCLUDED)

View File

@ -0,0 +1,579 @@
// SurfaceCharge.cxx: implementation of the cxxSurfaceCharge class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "SurfaceCharge.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSurfaceCharge::cxxSurfaceCharge(PHRQ_io *io)
:
PHRQ_base(io)
//
// default constructor for cxxSurfaceCharge
//
{
specific_area = 0.0;
grams = 0.0;
charge_balance = 0.0;
mass_water = 0.0;
la_psi = 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()
{
}
void
cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const
{
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 << "\"" << "\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 << "capacitance=\"" << this->
capacitance[0] << " " << this->capacitance[0] << "\"" << "\n";
// totals
s_oss << indent0;
s_oss << "<diffuse_layer_totals " << "\n";
this->diffuse_layer_totals.dump_xml(s_oss, indent + 1);
}
void
cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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 << "# 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 << indent0;
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<int, double>::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";
s_oss << indent0 << "-sigma2 " << this->sigma2 << "\n";
s_oss << indent0 << "-sigmaddl " << this->sigmaddl << "\n";
std::map<LDBLE, cxxSurfDL>::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
cxxSurfaceCharge::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_ERROR;
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 capacitance0_defined(false);
bool capacitance1_defined(false);
bool g_map_first(true);
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
break;
case 0: // name
warning_msg("-name ignored. Defined with -charge_component.");
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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
opt_save = 6;
break;
case 7: // la_psi1
parser.warning_msg("-la_psi1 identifier not used");
break;
case 8: // la_psi2
parser.warning_msg("-la_psi2 identifier not used");
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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
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<LDBLE, cxxSurfDL>::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;
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)
break;
}
if (check)
{
// members that must be defined
if (specific_area_defined == false)
{
parser.incr_input_error();
parser.error_msg("Specific_area not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
if (grams_defined == false)
{
parser.incr_input_error();
parser.error_msg("Grams not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
if (charge_balance_defined == false)
{
parser.incr_input_error();
parser.
error_msg("Charge_balance not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
if (mass_water_defined == false)
{
parser.incr_input_error();
parser.error_msg("Mass_water not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
if (la_psi_defined == false)
{
parser.incr_input_error();
parser.error_msg("La_psi not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
if (capacitance0_defined == false)
{
parser.incr_input_error();
parser.error_msg("Capacitance0 not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
if (capacitance1_defined == false)
{
parser.incr_input_error();
parser.error_msg("Capacitance1 not defined for SurfaceCharge input.",
PHRQ_io::OT_CONTINUE);
}
}
}
void
cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, LDBLE extensive)
{
if (extensive == 0.0)
return;
if (this->name.size() == 0 && addee.name.size() == 0)
{
return;
}
assert(this->name == addee.name);
LDBLE 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;
}
this->specific_area = f1 * this->specific_area + f2 * addee.specific_area;
this->grams += addee.grams * extensive;
this->charge_balance += addee.charge_balance * extensive;
this->mass_water += addee.mass_water * extensive;
this->la_psi = this->la_psi * f1 + addee.la_psi * f2;
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)
{
this->grams *= extensive;
this->charge_balance *= 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<LDBLE, cxxSurfDL>::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<int, double>::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
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
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]);

View File

@ -0,0 +1,131 @@
#if !defined(SURFACECHARGE_H_INCLUDED)
#define SURFACECHARGE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.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;}
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;
LDBLE psi_to_z;
};
class cxxSurfaceCharge: public PHRQ_base
{
public:
cxxSurfaceCharge(PHRQ_io *io=NULL);
cxxSurfaceCharge(struct surface_charge *, PHRQ_io *io=NULL);
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);
void add(const cxxSurfaceCharge & comp, LDBLE extensive);
void multiply(LDBLE extensive);
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;}
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<LDBLE, cxxSurfDL> &Get_g_map(void) {return g_map;}
void Set_g_map(std::map<LDBLE, cxxSurfDL> & t) {g_map = t;}
std::map<LDBLE, LDBLE> &Get_z_gMCD_map(void) { return z_gMCD_map; } // z, exp(-zF Psi / RT) * fraction of dl water
std::map<int, double> & 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;
LDBLE specific_area;
LDBLE grams;
LDBLE charge_balance;
LDBLE mass_water;
LDBLE la_psi;
LDBLE capacitance[2];
cxxNameDouble diffuse_layer_totals;
// workspace variables
LDBLE sigma0, sigma1, sigma2, sigmaddl;
std::map<LDBLE, cxxSurfDL> g_map;
std::map<LDBLE, LDBLE> z_gMCD_map;
const static std::vector < std::string > vopts;
std::map<int, double> dl_species_map;
};
#endif // !defined(SURFACECHARGE_H_INCLUDED)

View File

@ -0,0 +1,499 @@
// SurfaceComp.cxx: implementation of the cxxSurfaceComp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "SurfaceComp.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSurfaceComp::cxxSurfaceComp(PHRQ_io *io)
:
PHRQ_base(io)
//
// default constructor for cxxSurfaceComp
//
{
formula_z = 0.0;
moles = 0.0;
totals.type = cxxNameDouble::ND_ELT_MOLES;
la = 0.0;
charge_balance = 0;
phase_proportion = 0.0;
Dw = 0.0;
}
cxxSurfaceComp::~cxxSurfaceComp()
{
}
void
cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const
{
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 << "\"" << "\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";
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";
}
if (this->rate_name.size() != 0)
{
s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << "\n";
}
// totals
s_oss << indent0;
s_oss << "<totals " << "\n";
this->totals.dump_xml(s_oss, indent + 1);
}
void
cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
{
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 << "# 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 << 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 << "-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 << indent0;
s_oss << "-totals" << "\n";
this->totals.dump_raw(s_oss, indent + 1);
}
void
cxxSurfaceComp::read_raw(CParser & parser, bool check)
{
std::string str;
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
opt_save = CParser::OPT_ERROR;
bool master_element_defined(false);
bool charge_name_defined(false);
bool moles_defined(false);
bool la_defined(false);
bool charge_balance_defined(false);
bool formula_z_defined(false);
bool Dw_defined(false);
bool totals_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
break;
case 0: // formula
output_msg("-formula is obsolete in surface comp raw");
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;
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.",
PHRQ_io::OT_CONTINUE);
}
la_defined = true;
break;
case 3: // charge_number not used
parser.warning_msg("-charge_number identifier is obsolete.");
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.",
PHRQ_io::OT_CONTINUE);
}
charge_balance_defined = true;
break;
case 5: // 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;
}
break;
case 6: // rate_name
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;
}
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.",
PHRQ_io::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.",
PHRQ_io::OT_CONTINUE);
}
totals_defined = true;
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.",
PHRQ_io::OT_CONTINUE);
}
formula_z_defined = true;
break;
case 10: // formula_totals
parser.warning_msg("-formula_totals is an obsolete identifier.");
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.",
PHRQ_io::OT_CONTINUE);
}
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;
}
if (check)
{
// members that must be defined
if (charge_name_defined == false)
{
parser.incr_input_error();
parser.error_msg("Charge_name not defined for SurfaceComp input.",
PHRQ_io::OT_CONTINUE);
}
if (formula_z_defined == false)
{
parser.incr_input_error();
parser.error_msg("Formula_z not defined for ExchComp input.",
PHRQ_io::OT_CONTINUE);
}
if (moles_defined == false)
{
parser.incr_input_error();
parser.error_msg("Moles not defined for SurfaceComp input.",
PHRQ_io::OT_CONTINUE);
}
if (la_defined == false)
{
parser.incr_input_error();
parser.error_msg("La not defined for SurfaceComp input.",
PHRQ_io::OT_CONTINUE);
}
if (charge_balance_defined == false)
{
parser.incr_input_error();
parser.error_msg("Charge_balance not defined for SurfaceComp input.",
PHRQ_io::OT_CONTINUE);
}
if (Dw_defined == false)
{
parser.incr_input_error();
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);
}
}
}
void
cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive)
{
if (extensive == 0.0)
return;
if (addee.formula.size() == 0)
return;
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.size() == 0 && addee.formula.size() != 0)
{
this->formula = addee.formula;
}
// this and addee must have same formula
// otherwise generate a new exchcomp with multiply
LDBLE 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;
}
this->moles += addee.moles * extensive;
this->totals.add_extensive(addee.totals, extensive);
this->la = f1 * this->la + f2 * addee.la;
this->charge_balance += addee.charge_balance * extensive;
if (this->phase_name != addee.phase_name)
{
std::ostringstream oss;
oss <<
"Cannot mix two Surface components with same formula and different related phases, "
<< this->formula;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
else if (this->phase_name.size() != 0)
{
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
}
if (this->rate_name != addee.rate_name)
{
std::ostringstream oss;
oss <<
"Cannot mix two exchange components with same formula and different related kinetics, "
<< this->formula;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
else if (this->rate_name.size() != 0)
{
//LDBLE phase_proportion;
this->phase_proportion =
this->phase_proportion * f1 + addee.phase_proportion * f2;
}
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 <<
"Cannot mix exchange components related to phase with exchange components related to kinetics, "
<< this->formula;
error_msg(oss.str().c_str(), CONTINUE);
return;
}
}
void
cxxSurfaceComp::multiply(LDBLE extensive)
{
this->moles *= extensive;
this->totals.multiply(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
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]);

View File

@ -0,0 +1,70 @@
#if !defined(SURFACECOMP_H_INCLUDED)
#define SURFACECOMP_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NameDouble.h"
class cxxSurfaceComp: public PHRQ_base
{
public:
cxxSurfaceComp(PHRQ_io *io=NULL);
virtual ~cxxSurfaceComp();
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 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 : "";}
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;
LDBLE moles;
cxxNameDouble totals;
LDBLE la;
std::string charge_name;
LDBLE charge_balance;
std::string phase_name;
LDBLE phase_proportion;
std::string rate_name;
LDBLE Dw;
std::string master_element;
const static std::vector < std::string > vopts;
public:
};
#endif // !defined(SURFACECOMP_H_INCLUDED)

95
src/phreeqcpp/System.cxx Normal file
View File

@ -0,0 +1,95 @@
#include <algorithm> // std::replace
#include "Phreeqc.h"
#include "System.h"
#include "SSassemblage.h"
#include "Solution.h"
#include "Exchange.h"
#include "GasPhase.h"
#include "cxxKinetics.h"
#include "PPassemblage.h"
#include "SS.h"
#include "SSassemblage.h"
#include "Surface.h"
#include "cxxMix.h"
#include "Reaction.h"
#include "Temperature.h"
cxxSystem::cxxSystem(PHRQ_io *io)
:
PHRQ_base(io)
{
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->pressure = 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->pressure = NULL;
}
void
cxxSystem::totalize(Phreeqc * phreeqc_ptr)
{
//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(phreeqc_ptr);
this->totals.add_extensive(this->ppassemblage->Get_assemblage_totals(), 1.0);
}
if (this->gasphase != NULL)
{
this->gasphase->totalize(phreeqc_ptr);
this->totals.add_extensive(this->gasphase->Get_totals(), 1.0);
}
if (this->ssassemblage != NULL)
{
this->ssassemblage->totalize(phreeqc_ptr);
this->totals.add_extensive(this->ssassemblage->Get_totals(), 1.0);
}
if (this->surface != NULL)
{
this->surface->totalize();
this->totals.add_extensive(this->surface->Get_totals(), 1.0);
}
return;
}

89
src/phreeqcpp/System.h Normal file
View File

@ -0,0 +1,89 @@
#if !defined(SYSTEM_H_INCLUDED)
#define SYSTEM_H_INCLUDED
#include "NameDouble.h"
#include "PHRQ_base.h"
class cxxSolution;
class cxxExchange;
class cxxGasPhase;
class cxxKinetics;
class cxxPPassemblage;
class cxxSSassemblage;
class cxxSurface;
class cxxReaction;
class cxxTemperature;
class cxxPressure;
class cxxMix;
class cxxSystem: public PHRQ_base
{
public:
cxxSystem(PHRQ_io *io=NULL);
virtual ~cxxSystem(void);
void Initialize(void);
void Set_Solution(cxxSolution * entity)
{
this->solution = entity;
}
void Set_Exchange(cxxExchange * entity)
{
this->exchange = entity;
}
void Set_PPassemblage(cxxPPassemblage * entity)
{
this->ppassemblage = entity;
}
void Set_GasPhase(cxxGasPhase * entity)
{
this->gasphase = entity;
}
void Set_SSassemblage(cxxSSassemblage * entity)
{
this->ssassemblage = entity;
}
void Set_Kinetics(cxxKinetics * entity)
{
this->kinetics = entity;
}
void Set_Surface(cxxSurface * entity)
{
this->surface = entity;
}
void Set_Mix(cxxMix * entity)
{
this->mix = entity;
}
void Set_Reaction(cxxReaction * entity)
{
this->reaction = entity;
}
void Set_Temperature(cxxTemperature * entity)
{
this->temperature = entity;
}
void Set_Pressure(cxxPressure * entity)
{
this->pressure = entity;
}
void totalize(Phreeqc * phreeqc_ptr);
cxxNameDouble &Get_Totals(void)
{
return this->totals;
}
protected:
cxxSolution * solution;
cxxExchange * exchange;
cxxPPassemblage * ppassemblage;
cxxGasPhase * gasphase;
cxxSSassemblage * ssassemblage;
cxxKinetics * kinetics;
cxxSurface * surface;
cxxMix * mix;
cxxReaction * reaction;
cxxTemperature * temperature;
cxxPressure * pressure;
cxxNameDouble totals;
};
#endif // !defined(SYSTEM_H_INCLUDED)

View File

@ -0,0 +1,452 @@
// Temperature.cxx: implementation of the cxxTemperature class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <cassert> // assert
#include <algorithm> // std::sort
#include "Utils.h" // define first
#include "Parser.h"
#include "Phreeqc.h"
#include "Temperature.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxTemperature::cxxTemperature(PHRQ_io *io)
//
// default constructor for cxxTemperature
//
: cxxNumKeyword(io)
{
countTemps = 0;
equalIncrements = false;
}
cxxTemperature::~cxxTemperature()
{
}
#ifdef SKIP
void
cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const
{
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 << "<temperature " << "\n";
s_oss << indent1;
s_oss << "pitzer_temperature_gammas=\"" << this->
pitzer_temperature_gammas << "\"" << "\n";
// components
s_oss << indent1;
s_oss << "<component " << "\n";
for (std::list < cxxTemperatureComp >::const_iterator it =
temperatureComps.begin(); it != temperatureComps.end(); ++it)
{
it->dump_xml(s_oss, indent + 2);
}
return;
}
#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
PHRQ_io::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 == PHRQ_io::LT_EMPTY ||
lt == PHRQ_io::LT_KEYWORD ||
lt == PHRQ_io::LT_EOF)
{
break;
}
if (lt == PHRQ_io::LT_OPTION)
{
this->error_msg("Expected numeric value for temperatures.", PHRQ_io::OT_CONTINUE);
break;
}
if (done)
{
this->error_msg("Unknown input following equal increment definition.", PHRQ_io::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.",
PHRQ_io::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
{
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_TEMPERATURE_RAW " << n_user_local << " " << this->description << "\n";
s_oss << indent1;
s_oss << "-count_temps " << this->Get_countTemps() << "\n";
s_oss << indent1;
s_oss << "-equal_increments " << this->equalIncrements << "\n";
// Temperature element and attributes
s_oss << indent1;
s_oss << "-temps " << "\n";
{
int i = 0;
s_oss << indent2;
for (std::vector < LDBLE >::const_iterator it = this->temps.begin();
it != this->temps.end(); it++)
{
if (i++ == 5)
{
s_oss << "\n";
s_oss << indent2;
i = 0;
}
s_oss << *it << " ";
}
s_oss << "\n";
}
}
void
cxxTemperature::read_raw(CParser & parser, bool check)
{
LDBLE d;
CParser::TOKEN_TYPE k;
// clear steps for modify operation, if pressures are read
bool cleared_once = false;
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, 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 TEMPERATURE_COMP_RAW keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
useLastLine = false;
break;
case 0: // temps
if (!cleared_once)
{
this->temps.clear();
cleared_once = true;
}
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.",
PHRQ_io::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.",
PHRQ_io::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.",
PHRQ_io::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 (check)
{
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);
}
}
}
/* ---------------------------------------------------------------------- */
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();
}
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
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]);

View File

@ -0,0 +1,42 @@
#if !defined(TEMPERATURE_H_INCLUDED)
#define TEMPERATURE_H_INCLUDED
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "NumKeyword.h"
class cxxTemperature:public cxxNumKeyword
{
public:
cxxTemperature(PHRQ_io *io=NULL);
~cxxTemperature();
//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 = false);
int read(CParser & parser);
LDBLE Temperature_for_step(int step_number);
std::vector<LDBLE> & Get_temps(void) {return temps;}
const std::vector<LDBLE> & 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;}
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;
bool equalIncrements;
const static std::vector < std::string > vopts;
};
#endif // !defined(TEMPERATURE_H_INCLUDED)

70
src/phreeqcpp/Use.cpp Normal file
View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include "Use.h"
cxxUse::cxxUse()
{
this->init();
}
cxxUse::~cxxUse(void)
{
}
void cxxUse::
init(void)
{
solution_in = false;
n_solution_user = -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;
kinetics_ptr = NULL;
surface_in = false;
n_surface_user = -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;
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;
ss_assemblage_ptr = NULL;
trans_in = false;
advect_in = false;
}

159
src/phreeqcpp/Use.h Normal file
View File

@ -0,0 +1,159 @@
#if !defined(USE_H_INCLUDED)
#define USE_H_INCLUDED
class cxxPPassemblage;
class cxxMix;
class cxxReaction;
class cxxExchange;
class cxxGasPhase;
class cxxPressure;
class cxxTemperature;
class cxxSSassemblage;
class cxxKinetics;
class cxxSurface;
class cxxSolution;
class cxxUse
{
public:
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;}
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;}
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;}
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;}
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;}
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_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;}
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;}
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;}
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(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(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;}
void Set_inverse_ptr(struct inverse * p) {this->inverse_ptr = p;}
void Set_ss_assemblage_ptr(cxxSSassemblage * p) {this->ss_assemblage_ptr = p;}
protected:
bool solution_in;
int n_solution_user;
cxxSolution *solution_ptr;
bool pp_assemblage_in;
int n_pp_assemblage_user;
cxxPPassemblage *pp_assemblage_ptr;
bool mix_in;
int n_mix_user;
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;
cxxKinetics *kinetics_ptr;
bool surface_in;
int n_surface_user;
cxxSurface *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;
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;
cxxSSassemblage *ss_assemblage_ptr;
bool trans_in;
bool advect_in;
};
#endif // !defined(USE_H_INCLUDED)

View File

@ -0,0 +1,23 @@
#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)
{
if (this->PhreeqcPtr != NULL)
{
this->PhreeqcPtr->rate_free(this->rate);
this->PhreeqcPtr->free_check_null(this->rate);
}
}
this->PhreeqcPtr = NULL;
this->rate = NULL;
}

39
src/phreeqcpp/UserPunch.h Normal file
View File

@ -0,0 +1,39 @@
#if !defined(USERPUNCH_H_INCLUDED)
#define USERPUNCH_H_INCLUDED
#include <vector>
#include <string> // 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 <std::string> &Get_headings() {return this->headings;}
const std::vector <std::string> &Get_headings()const {return this->headings;}
void Set_headings(std::vector <std::string> & 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 <std::string> headings;
struct rate * rate;
Phreeqc * PhreeqcPtr;
};
#endif // !defined(USERPUNCH_H_INCLUDED)

BIN
src/phreeqcpp/ZedGraph.dll Normal file

Binary file not shown.

132
src/phreeqcpp/advection.cpp Normal file
View File

@ -0,0 +1,132 @@
#include "Utils.h"
#include "Phreeqc.h"
#include "phqalloc.h"
#include "cxxKinetics.h"
#include "Solution.h"
/* ---------------------------------------------------------------------- */
int Phreeqc::
advection(void)
/* ---------------------------------------------------------------------- */
{
int i;
LDBLE kin_time;
/*
* Calculate advection
*/
state = ADVECTION;
/* mass_water_switch = TRUE; */
/*
* Check existence of all solutions
*/
for (i = 0; i <= count_ad_cells; i++)
{
if (Utilities::Rxn_find(Rxn_solution_map, i) == NULL)
//if (solution_bsearch(i, &n, TRUE) == NULL)
{
input_error++;
error_string = sformatf(
"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 (Utilities::Rxn_find(Rxn_kinetics_map, i) != NULL)
{
input_error++;
error_string = sformatf(
"KINETIC reaction(s) defined, but time_step is not defined in ADVECTION keyword.");
error_msg(error_string, CONTINUE);
break;
}
}
}
/*
* Quit on error
*/
if (get_input_errors() > 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);
Utilities::Rxn_copy(Rxn_solution_map, 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)
Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1);
//solution_duplicate(-2, i - 1);
saver();
}
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;
/* free_model_allocs(); */
mass_water_switch = FALSE;
return (OK);
}

4438
src/phreeqcpp/basicsubs.cpp Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

896
src/phreeqcpp/cl1.cpp Normal file
View File

@ -0,0 +1,896 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#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
register int i, j;
register 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;
long double 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 += (long double) q2[i * q_dim + j].dval * (long double) l_z;
}
q2[klm * q_dim + j].dval = (double)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)
{
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;
--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 */
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: */
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 += (long double) q2[i * q_dim + n].dval;
}
}
}
/* L640: */
#ifdef DEBUG_CL1
output_msg(sformatf( "L640\n"));
#endif
*l_error = (double)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);
}

1134
src/phreeqcpp/cl1mp.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,949 @@
#include "Phreeqc.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"
//#include <sys/signal.h>
//#include <fenv.h>
/* ----------------------------------------------------------------------
* MAIN
* ---------------------------------------------------------------------- */
int
main(int argc, char *argv[])
/*
* Main program for PHREEQC
*/
{
// check for floating point exceptions on Linux
// feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
#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
*/
#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 = 31195;
#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;
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();
this->init();
this->initialize();
/*
* 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[])
/*
* 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
try
{
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;
}
/*
* 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;
}
}
catch (...)
{
int e = get_input_errors();
std::cerr << "Unhandled exception in PHREEQC." << std::endl;
if (e > 0)
{
return e;
}
else
{
return 1;
}
}
return 0;
}
#endif //TEST_COPY
/* ---------------------------------------------------------------------- */
int Phreeqc::
write_banner(void)
/* ---------------------------------------------------------------------- */
{
char buffer[80];
int len, indent;
screen_msg(
" ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n");
screen_msg(
" º º\n");
/* version */
#ifdef NPP
//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
indent = (44 - len) / 2;
screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer,
44 - indent - len, ' '));
screen_msg(
" º º\n");
screen_msg(
" º A hydrogeochemical transport model º\n");
screen_msg(
" º º\n");
screen_msg(
" º by º\n");
screen_msg(
" º D.L. Parkhurst and C.A.J. Appelo º\n");
screen_msg(
" º º\n");
/* date */
#ifdef NPP
len = sprintf(buffer, "%s", "February 27, 2018");
#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, ' '));
screen_msg(
" ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n");
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)
{
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);
strcpy(token, default_name);
strcat(token, ".out");
std::ofstream * local_output_stream = NULL;
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)
{
user_database = (char *) free_check_null(user_database);
#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 = NULL;
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;
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
//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.2, compiled February 27, 2018\n"));
#endif
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 (const PhreeqcStop&)
{
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)
{
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("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)
{
user_database = (char *) free_check_null(user_database);
#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);
user_database = string_duplicate(token);
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 (const 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 )
{
#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));
}
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')
{
strcpy(name, default_name);
}
}
/*
* Open existing file to read
*/
new_stream = new std::ifstream(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: 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 )
{
#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));
}
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')
{
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: 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 )
{
#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));
}
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')
{
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: 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

View File

@ -0,0 +1,108 @@
#include "PHRQ_base.h"
#include <iostream>
#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
}
}

View File

@ -0,0 +1,52 @@
#ifndef _PHRQBASE_H
#define _PHRQBASE_H
#include <sstream>
#if defined(_WINDLL)
#define IPQ_DLL_EXPORT __declspec(dllexport)
#else
#define IPQ_DLL_EXPORT
#endif
class PHRQ_io;
class IPQ_DLL_EXPORT 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 */

View File

@ -0,0 +1,904 @@
#include <assert.h>
#include "PHRQ_io.h"
#include "Parser.h"
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iostream>
#include <sstream>
#include <set>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
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; //**appt
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<std::ostream *> 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<std::ostream *>::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);
std::ostringstream errstr;
errstr << "\n\tReading data from " << file_name <<" ...\n";
output_msg(errstr.str().c_str()); // **appt
}
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;
}

View File

@ -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 <iostream>
#include <exception>
#include <list>
#include "Keywords.h"
#include <time.h>
#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 <std::istream *> istream_list;
std::list <bool> 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 */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,296 @@
#if !defined(PARSER_H_INCLUDED)
#define PARSER_H_INCLUDED
#if defined(WIN32)
#include <windows.h>
#endif
#include <string> // std::string
#include <map> // std::map
#include <vector> // std::vector
#include <sstream> // std::istringstream std::ostringstream
#include <ostream> // std::ostream
#include <istream> // std::istream
#include <cctype> // std::isspace
#include <algorithm> // std::find_if
#include <functional> // 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 <class T>
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<int, int>(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<int, int>(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

View File

@ -0,0 +1,186 @@
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <stdlib.h> // ::tolower
#include <ctype.h> // ::tolower
#include <algorithm> // std::transform
#include <iostream> // std::cout std::cerr
#include <string.h>
#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);
}
*/

View File

@ -0,0 +1,28 @@
#if !defined(UTILITIES_H_INCLUDED)
#define UTILITIES_H_INCLUDED
#include <string>
#include <sstream> // std::istringstream std::ostringstream
#include <ostream> // std::ostream
#include <istream> // std::istream
#include <map> // 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

View File

@ -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 */

557
src/phreeqcpp/cvdense.cpp Normal file
View File

@ -0,0 +1,557 @@
/**************************************************************************
* *
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cvdense.h"
#include "cvode.h"
#include "dense.h"
#include "sundialstypes.h"
#include "nvector.h"
#include "sundialsmath.h"
#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
#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 */
#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);
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);
#if !defined(R_SO)
std::cerr << MSG_CVMEM_NULL << std::endl;
#endif
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);
}

267
src/phreeqcpp/cvdense.h Normal file
View File

@ -0,0 +1,267 @@
#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 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
#include <stdio.h>
#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 */

3853
src/phreeqcpp/cvode.cpp Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More