Added changes for serializing.

Copied files from concrete_parallel, without merging or svn_copy.
Added Dictionary.cpp and Serializer.cxx + header files.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10607 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2015-12-28 23:35:36 +00:00
parent 4dc54757e6
commit af2dbfdce2
45 changed files with 1353 additions and 20 deletions

32
Dictionary.cpp Normal file
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;
}

28
Dictionary.h Normal file
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)

View File

@ -13,6 +13,7 @@
#include "Phreeqc.h"
#include "ExchComp.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@ -406,6 +407,34 @@ cxxExchComp::multiply(LDBLE extensive)
this->phase_proportion *= extensive;
}
void
cxxExchComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->formula));
this->totals.Serialize(dictionary, ints, doubles);
doubles.push_back(this->la);
doubles.push_back(this->charge_balance);
ints.push_back(dictionary.Find(this->phase_name));
doubles.push_back(this->phase_proportion);
ints.push_back(dictionary.Find(this->rate_name));
doubles.push_back(this->formula_z);
}
void
cxxExchComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->formula = dictionary.GetWords()[ints[ii++]];
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
this->la = doubles[dd++];
this->charge_balance = doubles[dd++];
this->phase_name = dictionary.GetWords()[ints[ii++]];
this->phase_proportion = doubles[dd++];
this->rate_name = dictionary.GetWords()[ints[ii++]];
this->formula_z = doubles[dd++];
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("formula"), // 0
std::vector< std::string >::value_type("moles"), // 1

View File

@ -104,8 +104,10 @@ class cxxExchComp: public PHRQ_base
void add(const cxxExchComp & comp, LDBLE extensive);
void multiply(LDBLE extensive);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
protected:
std::string formula;
// EXCHANGE_MODIFY candidates
cxxNameDouble totals;

View File

@ -435,6 +435,51 @@ Sort_comps(void)
}
}
}
/* ---------------------------------------------------------------------- */
void
cxxExchange::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
/* ---------------------------------------------------------------------- */
{
ints.push_back(this->n_user);
ints.push_back((int) this->exchange_comps.size());
for (size_t i = 0; i < this->exchange_comps.size(); i++)
{
exchange_comps[i].Serialize(dictionary, ints, doubles);
}
ints.push_back(this->pitzer_exchange_gammas ? 1 : 0);
ints.push_back(this->new_def ? 1 : 0);
ints.push_back(this->solution_equilibria ? 1 : 0);
ints.push_back(this->n_solution);
this->totals.Serialize(dictionary, ints, doubles);
}
/* ---------------------------------------------------------------------- */
void
cxxExchange::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd)
/* ---------------------------------------------------------------------- */
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
int count = ints[ii++];
this->exchange_comps.clear();
for (int n = 0; n < count; n++)
{
cxxExchComp ec;
ec.Deserialize(dictionary, ints, doubles, ii, dd);
this->exchange_comps.push_back(ec);
}
this->pitzer_exchange_gammas = (ints[ii++] != 0);
this->new_def = (ints[ii++] != 0);
this->solution_equilibria = (ints[ii++] != 0);
this->n_solution = ints[ii++];
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("pitzer_exchange_gammas"), // 0
std::vector< std::string >::value_type("component"), // 1

View File

@ -46,6 +46,8 @@ public:
void totalize();
const cxxNameDouble & Get_totals() const;
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
void add(const cxxExchange & addee, LDBLE extensive);

View File

@ -13,6 +13,7 @@
#include "Phreeqc.h"
#include "GasComp.h"
#include "phqalloc.h"
#include "Dictionary.h"
@ -178,6 +179,25 @@ cxxGasComp::multiply(LDBLE extensive)
this->moles *= extensive;
this->initial_moles *= extensive;
}
void
cxxGasComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->phase_name));
doubles.push_back(this->moles);
doubles.push_back(this->p_read);
doubles.push_back(this->initial_moles);
}
void
cxxGasComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->phase_name = dictionary.GetWords()[ints[ii++]];
this->moles = doubles[dd++];
this->p_read = doubles[dd++];
this->initial_moles = doubles[dd++];
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("phase_name"), // 0
std::vector< std::string >::value_type("name"), // 1

View File

@ -33,11 +33,9 @@ class cxxGasComp: public PHRQ_base
void add(const cxxGasComp & addee, LDBLE extensive);
void multiply(LDBLE extensive);
#ifdef USE_MPI
void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles);
void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd);
#endif
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::string phase_name;
// GAS_PHASE_MODIFY candidates

View File

@ -657,6 +657,60 @@ cxxGasPhase::Find_comp(const char * comp_name)
}
return NULL;
}
void
cxxGasPhase::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(this->n_user);
ints.push_back((this->type == cxxGasPhase::GP_PRESSURE) ? 0 : 1);
doubles.push_back(this->total_p);
doubles.push_back(this->volume);
ints.push_back((int) this->gas_comps.size());
for (size_t i = 0; i < this->gas_comps.size(); i++)
{
this->gas_comps[i].Serialize(dictionary, ints, doubles);
}
ints.push_back(this->new_def ? 1 : 0);
ints.push_back(this->solution_equilibria ? 1 : 0);
ints.push_back(this->n_solution);
doubles.push_back(this->temperature);
doubles.push_back(this->total_moles);
doubles.push_back(this->v_m);
ints.push_back(this->pr_in ? 1 : 0);
this->totals.Serialize(dictionary, ints, doubles);
}
void
cxxGasPhase::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : this->type = cxxGasPhase::GP_VOLUME;
this->total_p = doubles[dd++];
this->volume = doubles[dd++];
int count = ints[ii++];
this->gas_comps.clear();
for (int i = 0; i < count; i++)
{
cxxGasComp gc;
gc.Deserialize(dictionary, ints, doubles, ii, dd);
this->gas_comps.push_back(gc);
}
this->new_def = (ints[ii++] != 0) ? 1 : 0;
this->solution_equilibria = (ints[ii++] != 0) ? 1 : 0;
this->n_solution = ints[ii++];
this->temperature = doubles[dd++];
this->total_moles = doubles[dd++];
this->v_m = doubles[dd++];
this->pr_in = (ints[ii++] != 0);
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("type"), //0
std::vector< std::string >::value_type("total_p"), //1

View File

@ -67,6 +67,8 @@ class cxxGasPhase:public cxxNumKeyword
void Set_temperature(LDBLE t) {temperature = t;};
LDBLE Calc_total_moles(void)const;
cxxGasComp *Find_comp(const char * comp_name);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
void add(const cxxGasPhase & addee, LDBLE extensive);

View File

@ -12,6 +12,7 @@
#include "KineticsComp.h"
//#include "Dictionary.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@ -306,6 +307,41 @@ cxxKineticsComp::multiply(LDBLE extensive)
this->m0 *= extensive;
this->moles *= extensive;
}
void
cxxKineticsComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->rate_name));
this->namecoef.Serialize(dictionary, ints, doubles);
doubles.push_back(this->tol);
doubles.push_back(this->m);
doubles.push_back(this->m0);
ints.push_back((int) this->d_params.size());
for (size_t i = 0; i < this->d_params.size(); i++)
{
doubles.push_back(d_params[i]);
}
doubles.push_back(this->moles);
doubles.push_back(this->initial_moles);
this->moles_of_reaction.Serialize(dictionary, ints, doubles);
}
void
cxxKineticsComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd)
{
this->rate_name = dictionary.GetWords()[ints[ii++]];
this->namecoef.Deserialize(dictionary, ints, doubles, ii, dd);
this->tol = doubles[dd++];
this->m = doubles[dd++];
this->m0 = doubles[dd++];
int n = ints[ii++];
this->d_params.clear();
for (int j = 0; j < n; j++)
{
this->d_params.push_back(doubles[dd++]);
}
this->moles = doubles[dd++];
this->initial_moles = doubles[dd++];
this->moles_of_reaction.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("rate_name_not_used"), // 0
std::vector< std::string >::value_type("tol"), // 1

View File

@ -57,6 +57,8 @@ public:
void add(const cxxKineticsComp & comp, LDBLE extensive);
void multiply(LDBLE extensive);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::string rate_name;

View File

@ -38,6 +38,8 @@ phreeqc_SOURCES=\
cxxMix.h\
dense.cpp\
dense.h\
Dictionary.cpp\
Dictionary.h\
dumper.cpp\
dumper.h\
dw.cpp\
@ -102,6 +104,8 @@ phreeqc_SOURCES=\
runner.h\
SelectedOutput.cpp\
SelectedOutput.h\
Serializer.cxx\
Serializer.h\
sit.cpp\
smalldense.cpp\
smalldense.h\

View File

@ -12,6 +12,7 @@
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "NameDouble.h"
#include "Dictionary.h"
//#include "Dictionary.h"
#include "phqalloc.h"
#include "ISolutionComp.h"
@ -597,4 +598,31 @@ cxxNameDouble::sort_second(void)
return myvec;
}
void
cxxNameDouble::Serialize(Dictionary &dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
ints.push_back((int) (*this).size());
for (const_iterator it = (*this).begin(); it != (*this).end(); it++)
{
int n = dictionary.Find(it->first);
ints.push_back(n);
doubles.push_back(it->second);
}
}
void
cxxNameDouble::Deserialize(Dictionary &dictionary, std::vector<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

@ -15,6 +15,7 @@
class Phreeqc;
#include "Parser.h"
#include "phrqtype.h"
class Dictionary;
class cxxISolutionComp;
class IPQ_DLL_EXPORT cxxNameDouble:public
@ -60,6 +61,8 @@ class IPQ_DLL_EXPORT cxxNameDouble:public
{
(*this)[str] = d;
}
void Serialize(Dictionary &dictionary, std::vector<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;

View File

@ -321,7 +321,49 @@ Find(const std::string name_in)
}
return comp;
}
/* ---------------------------------------------------------------------- */
void
cxxPPassemblage::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
/* ---------------------------------------------------------------------- */
{
/* int n_user; */
ints.push_back(this->n_user);
ints.push_back(this->new_def ? 1 : 0);
ints.push_back((int) this->pp_assemblage_comps.size());
for (std::map < std::string, cxxPPassemblageComp >::iterator it =
this->pp_assemblage_comps.begin(); it != this->pp_assemblage_comps.end();
it++)
{
(*it).second.Serialize(dictionary, ints, doubles);
}
this->eltList.Serialize(dictionary, ints, doubles);
this->assemblage_totals.Serialize(dictionary, ints, doubles);
}
/* ---------------------------------------------------------------------- */
void
cxxPPassemblage::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
/* ---------------------------------------------------------------------- */
{
/* int n_user; */
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
this->new_def = (ints[ii++] != 0);
int count = ints[ii++];
this->pp_assemblage_comps.clear();
for (int n = 0; n < count; n++)
{
cxxPPassemblageComp ppc;
ppc.Deserialize(dictionary, ints, doubles, ii, dd);
std::string str(ppc.Get_name());
this->pp_assemblage_comps[str] = ppc;
}
this->eltList.Deserialize(dictionary, ints, doubles, ii, dd);
this->assemblage_totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("eltlist"), // 0
std::vector< std::string >::value_type("component"), // 1

View File

@ -51,6 +51,8 @@ class cxxPPassemblage:public cxxNumKeyword
cxxPPassemblageComp *Find(const std::string name);
void totalize(Phreeqc * phreeqc_ptr);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
void add(const cxxPPassemblage & addee, LDBLE extensive);

View File

@ -10,7 +10,7 @@
#include "Utils.h" // define first
#include "Phreeqc.h"
#include "PPassemblageComp.h"
//#include "Dictionary.h"
#include "Dictionary.h"
#include "phqalloc.h"
//////////////////////////////////////////////////////////////////////
@ -383,6 +383,40 @@ cxxPPassemblageComp::multiply(LDBLE extensive)
this->delta *= extensive;
this->initial_moles *= extensive;
}
void
cxxPPassemblageComp::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->name));
ints.push_back(dictionary.Find(this->add_formula));
doubles.push_back(this->si);
doubles.push_back(this->si_org);
doubles.push_back(this->moles);
doubles.push_back(this->delta);
doubles.push_back(this->initial_moles);
ints.push_back( this->force_equality ? 1 : 0);
ints.push_back(this->dissolve_only ? 1 : 0);
ints.push_back(this->precipitate_only ? 1 : 0);
this->totals.Serialize(dictionary, ints, doubles);
}
void
cxxPPassemblageComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd)
{
this->name = dictionary.GetWords()[ints[ii++]];
this->add_formula = dictionary.GetWords()[ints[ii++]];
this->si = doubles[dd++];
this->si_org = doubles[dd++];
this->moles = doubles[dd++];
this->delta = doubles[dd++];
this->initial_moles = doubles[dd++];
this->force_equality = (ints[ii++] != 0);
this->dissolve_only = (ints[ii++] != 0);
this->precipitate_only = (ints[ii++] != 0);
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("name"), // 0
std::vector< std::string >::value_type("add_formula"), // 1

View File

@ -60,6 +60,8 @@ class cxxPPassemblageComp: public PHRQ_base
void add(const cxxPPassemblageComp & comp, LDBLE extensive);
void multiply(LDBLE extensive);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::string name;

View File

@ -1146,6 +1146,19 @@ public:
size_t list_components(std::list<std::string> &list_c);
PHRQ_io * Get_phrq_io(void) {return this->phrq_io;}
void Set_run_cells_one_step(const bool tf) {this->run_cells_one_step = tf;}
std::map<int, cxxSolution> & Get_Rxn_solution_map() {return this->Rxn_solution_map;}
std::map<int, cxxExchange> & Get_Rxn_exchange_map() {return this->Rxn_exchange_map;}
std::map<int, cxxGasPhase> & Get_Rxn_gas_phase_map() {return this->Rxn_gas_phase_map;}
std::map<int, cxxKinetics> & Get_Rxn_kinetics_map() {return this->Rxn_kinetics_map;}
std::map<int, cxxPPassemblage> & Get_Rxn_pp_assemblage_map() {return this->Rxn_pp_assemblage_map;}
std::map<int, cxxSSassemblage> & Get_Rxn_ss_assemblage_map() {return this->Rxn_ss_assemblage_map;}
std::map<int, cxxSurface> & Get_Rxn_surface_map() {return this->Rxn_surface_map;}
std::map<int, cxxTemperature> & Get_Rxn_temperature_map() {return this->Rxn_temperature_map;}
std::map<int, cxxPressure> & Get_Rxn_pressure_map() {return this->Rxn_pressure_map;}
protected:
void init(void);

View File

@ -399,6 +399,42 @@ Get_count(void) const
}
return (int) this->pressures.size();
}
void
cxxPressure::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(this->n_user);
{
ints.push_back((int) this->pressures.size());
for (size_t i = 0; i < this->pressures.size(); i++)
{
doubles.push_back(pressures[i]);
}
}
ints.push_back(this->count);
ints.push_back(this->equalIncrements ? 1 : 0);
}
void
cxxPressure::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
{
int count = ints[ii++];
this->pressures.clear();
for (int i = 0; i < count; i++)
{
this->pressures.push_back(doubles[dd++]);
}
}
this->count = ints[ii++];
this->equalIncrements = (ints[ii++] != 0);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("pressures"), //0
std::vector< std::string >::value_type("equal_increments"), //1

View File

@ -8,6 +8,7 @@
#include <vector> // std::vector
#include "NumKeyword.h"
class Dictionary;
class cxxPressure:public cxxNumKeyword
{
@ -29,7 +30,9 @@ class cxxPressure:public cxxNumKeyword
void Set_count(int i) {count = i;}
bool Get_equalIncrements(void) const {return equalIncrements;}
void Set_equalIncrements(bool tf) {equalIncrements = tf;}
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::vector < LDBLE >pressures;
int count;

79
SS.cxx
View File

@ -10,7 +10,7 @@
#include "Phreeqc.h"
#include "Utils.h" // define first
#include "SS.h"
//#include "Dictionary.h"
#include "Dictionary.h"
#include "phqalloc.h"
@ -532,6 +532,83 @@ cxxSS::Find(const char * comp_name)
}
return NULL;
}
void
cxxSS::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->name));
doubles.push_back(this->ag0);
doubles.push_back(this->ag1);
{
ints.push_back((int) ss_comps.size());
for (size_t i = 0; i < ss_comps.size(); i++)
{
ss_comps[i].Serialize(dictionary, ints, doubles);
}
}
doubles.push_back(this->a0);
doubles.push_back(this->a1);
ints.push_back(this->miscibility ? 1 : 0);
ints.push_back(this->spinodal ? 1 : 0);
doubles.push_back(this->tk);
doubles.push_back(this->xb1);
doubles.push_back(this->xb2);
ints.push_back((int) this->input_case);
{
ints.push_back((int) p.size());
for (size_t i = 0; i < p.size(); i++)
{
doubles.push_back(p[i]);
}
}
doubles.push_back(this->total_moles);
doubles.push_back(this->dn);
ints.push_back(this->ss_in ? 1 : 0);
this->totals.Serialize(dictionary, ints, doubles);
}
void
cxxSS::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->name = dictionary.GetWords()[ints[ii++]];
this->ag0 = doubles[dd++];
this->ag1 = doubles[dd++];
{
int count = ints[ii++];
this->ss_comps.clear();
for (int i = 0; i < count; i++)
{
cxxSScomp ssc;
ssc.Deserialize(dictionary, ints, doubles, ii, dd);
this->ss_comps.push_back(ssc);
}
}
this->a0 = doubles[dd++];
this->a1 = doubles[dd++];
this->miscibility = (ints[ii++] != 0);
this->spinodal = (ints[ii++] != 0);
this->tk = doubles[dd++];
this->xb1 = doubles[dd++];
this->xb2 = doubles[dd++];
this->input_case = (SS_PARAMETER_TYPE) ints[ii++];
{
int count = ints[ii++];
this->p.clear();
for (int i = 0; i < count; i++)
{
p.push_back(doubles[dd++]);
}
}
this->total_moles = doubles[dd++];
this->dn = doubles[dd++];
this->ss_in = (ints[ii++] != 0);
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("ss_name"), // 0
std::vector< std::string >::value_type("total_moles"), // 1

3
SS.h
View File

@ -98,6 +98,9 @@ class cxxSS: public PHRQ_base
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

View File

@ -14,6 +14,7 @@
#include "SS.h"
#include "cxxMix.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
@ -287,6 +288,51 @@ Find(const std::string &s)
return &(it->second);
return NULL;
}
void
cxxSSassemblage::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
/* int n_user; */
ints.push_back(this->n_user);
{
ints.push_back((int) this->SSs.size());
std::map < std::string, cxxSS >::iterator it;
for (it = this->SSs.begin(); it != this->SSs.end(); it++)
{
(*it).second.Serialize(dictionary, ints, doubles);
}
}
ints.push_back(this->new_def ? 1 : 0);
this->totals.Serialize(dictionary, ints, doubles);
}
void
cxxSSassemblage::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
{
int count = ints[ii++];
this->SSs.clear();
for (int n = 0; n < count; n++)
{
cxxSS ssc;
ssc.Deserialize(dictionary, ints, doubles, ii, dd);
std::string str(ssc.Get_name());
this->SSs[str] = ssc;
}
}
this->new_def = (ints[ii++] != 0);
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("solid_solution"), // 0
std::vector< std::string >::value_type("ssassemblage_totals"), // 1

View File

@ -43,7 +43,9 @@ public:
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;

View File

@ -11,6 +11,7 @@
#include "Phreeqc.h"
#include "SScomp.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@ -277,6 +278,44 @@ cxxSScomp::multiply(LDBLE extensive)
this->delta *= extensive;
this->initial_moles *= extensive;
}
void
cxxSScomp::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->name));
doubles.push_back(this->moles);
doubles.push_back(this->initial_moles);
doubles.push_back(this->init_moles);
doubles.push_back(this->delta);
doubles.push_back(this->fraction_x);
doubles.push_back(this->log10_lambda);
doubles.push_back(this->log10_fraction_x);
doubles.push_back(this->dn);
doubles.push_back(this->dnc);
doubles.push_back(this->dnb);
}
void
cxxSScomp::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->name = dictionary.GetWords()[ints[ii++]];
this->moles = doubles[dd++];
this->initial_moles = doubles[dd++];
this->init_moles = doubles[dd++];
this->delta = doubles[dd++];
this->fraction_x = doubles[dd++];
this->log10_lambda = doubles[dd++];
this->log10_fraction_x = doubles[dd++];
this->dn = doubles[dd++];
this->dnc = doubles[dd++];
this->dnb = doubles[dd++];
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("name"), // 0
std::vector< std::string >::value_type("initial_moles"), // 1

View File

@ -44,7 +44,9 @@ class cxxSScomp: public PHRQ_base
void Set_dnb(LDBLE t) {this->dnb = t;}
void multiply(LDBLE extensive);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::string name;
// SOLID_SOLUTION_MODIFY candidate identifier

198
Serializer.cxx Normal file
View File

@ -0,0 +1,198 @@
#include "Serializer.h"
#include "Phreeqc.h"
#include "Utils.h"
#include "Solution.h"
#include "Exchange.h"
#include "Temperature.h"
#include "GasPhase.h"
#include "cxxKinetics.h"
#include "PPassemblage.h"
#include "SSassemblage.h"
#include "Surface.h"
Serializer::Serializer(PHRQ_io *io)
: PHRQ_base(io)
{
}
Serializer::~Serializer(void)
{
}
bool Serializer::Serialize(Phreeqc &phreeqc_ref, int start, int end, bool include_t, bool include_p, PHRQ_io *io)
{
for (int i = start; i <= end; i++)
{
cxxSolution *soln_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_solution_map(), i);
if (soln_ptr)
{
ints.push_back((int) PT_SOLUTION);
soln_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
// Exchangers
{
cxxExchange *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_exchange_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_EXCHANGE);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// GasPhases
{
cxxGasPhase *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_gas_phase_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_GASPHASE);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// Kinetics
{
cxxKinetics *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_kinetics_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_KINETICS);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// PPassemblages
{
cxxPPassemblage *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_pp_assemblage_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_PPASSEMBLAGE);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// SSassemblages
{
cxxSSassemblage *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_ss_assemblage_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_SSASSEMBLAGE);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// Surfaces
{
cxxSurface *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_surface_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_SURFACES);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// Temperature
if (include_t)
{
cxxTemperature *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_temperature_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_TEMPERATURE);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
// Pressure
if (include_p)
{
cxxPressure *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_pressure_map(), i);
if (entity_ptr)
{
ints.push_back((int) PT_PRESSURE);
entity_ptr->Serialize(this->dictionary, this->ints, this->doubles);
}
}
}
return true;
}
bool
Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vector<int> &ints, std::vector<double> &doubles)
{
int ii = 0;
int dd = 0;
while (ii < ints.size())
{
PACK_TYPE type = (PACK_TYPE) ints[ii++];
switch (type)
{
case PT_SOLUTION:
{
cxxSolution soln;
soln.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = soln.Get_n_user();
//std::cerr << "unpacked solution " << n_user << std::endl;
phreeqc_ref.Get_Rxn_solution_map()[n_user] = soln;
}
break;
case PT_EXCHANGE:
{
cxxExchange entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_exchange_map()[n_user] = entity;
}
break;
case PT_GASPHASE:
{
cxxGasPhase entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_gas_phase_map()[n_user] = entity;
}
break;
case PT_KINETICS:
{
cxxKinetics entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_kinetics_map()[n_user] = entity;
}
break;
case PT_PPASSEMBLAGE:
{
cxxPPassemblage entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
//std::cerr << "unpacked pp assemblage " << n_user << std::endl;
phreeqc_ref.Get_Rxn_pp_assemblage_map()[n_user] = entity;
}
break;
case PT_SSASSEMBLAGE:
{
cxxSSassemblage entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_ss_assemblage_map()[n_user] = entity;
}
break;
case PT_SURFACES:
{
cxxSurface entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_surface_map()[n_user] = entity;
}
break;
case PT_TEMPERATURE:
{
cxxTemperature entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_temperature_map()[n_user] = entity;
}
break;
case PT_PRESSURE:
{
cxxPressure entity;
entity.Deserialize(dictionary, ints, doubles, ii, dd);
int n_user = entity.Get_n_user();
phreeqc_ref.Get_Rxn_pressure_map()[n_user] = entity;
}
break;
default:
std::cerr << "Unknown pack type in deserialize " << type << std::endl;
exit(4);
break;
}
}
return true;
}

42
Serializer.h Normal file
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)

View File

@ -13,6 +13,7 @@
#include "Solution.h"
#include "cxxMix.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
@ -1521,6 +1522,157 @@ cxxSolution::Multiply_isotopes(LDBLE extensive)
it->second.Set_total(total);
}
}
/* ---------------------------------------------------------------------- */
void
cxxSolution::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
/* ---------------------------------------------------------------------- */
{
/*
* Make list of list of ints and doubles from solution structure
* This list is not the complete structure, but only enough
* for batch-reaction, advection, and transport calculations
*/
ints.push_back(this->n_user);
ints.push_back(this->new_def ? 1 : 0);
doubles.push_back(this->patm);
doubles.push_back(this->tc);
doubles.push_back(this->ph);
doubles.push_back(this->pe);
doubles.push_back(this->mu);
doubles.push_back(this->ah2o);
doubles.push_back(this->total_h);
doubles.push_back(this->total_o);
doubles.push_back(this->cb);
doubles.push_back(this->mass_water);
doubles.push_back(this->density);
doubles.push_back(this->soln_vol);
doubles.push_back(this->total_alkalinity);
/*
* struct conc *totals;
*/
this->totals.Serialize(dictionary, ints, doubles);
/*
* struct master_activity *master_activity;
*/
this->master_activity.Serialize(dictionary, ints, doubles);
/*
* struct master_activity *species_gamma
*/
this->species_gamma.Serialize(dictionary, ints, doubles);
/*
* isotopes
*/
ints.push_back((int) isotopes.size());
{
std::map < std::string, cxxSolutionIsotope >::iterator it;
for (it = isotopes.begin(); it != isotopes.end(); it++)
{
ints.push_back(dictionary.Find(it->first));
it->second.Serialize(dictionary, ints, doubles);
}
}
/*
* species_map
*/
ints.push_back((int) species_map.size());
{
std::map < int, double >::iterator it;
for (it = species_map.begin(); it != species_map.end(); it++)
{
ints.push_back(it->first);
doubles.push_back(it->second);
}
}
/*
* log_gamma_map
*/
ints.push_back((int) log_gamma_map.size());
{
std::map < int, double >::iterator it;
for (it = log_gamma_map.begin(); it != log_gamma_map.end(); it++)
{
ints.push_back(it->first);
doubles.push_back(it->second);
}
}
}
/* ---------------------------------------------------------------------- */
void
cxxSolution::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd)
/* ---------------------------------------------------------------------- */
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
this->new_def = (ints[ii++] != 0);
this->patm = doubles[dd++];
this->tc = doubles[dd++];
this->ph = doubles[dd++];
this->pe = doubles[dd++];
this->mu = doubles[dd++];
this->ah2o = doubles[dd++];
this->total_h = doubles[dd++];
this->total_o = doubles[dd++];
this->cb = doubles[dd++];
this->mass_water = doubles[dd++];
this->density = doubles[dd++];
this->soln_vol = doubles[dd++];
this->total_alkalinity = doubles[dd++];
/*
* struct conc *totals;
*/
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
/*
* struct master_activity *master_activity;
*/
this->master_activity.Deserialize(dictionary, ints, doubles, ii, dd);
/*
* struct master_activity *species_gamma;
*/
this->species_gamma.Deserialize(dictionary, ints, doubles, ii, dd);
/*
* isotopes
*/
{
isotopes.clear();
int n = ints[ii++];
for (int i = 0; i < n; i++)
{
std::string str = dictionary.GetWords()[ints[ii++]];
cxxSolutionIsotope iso;
iso.Deserialize(dictionary, ints, doubles, ii, dd);
isotopes[str] = iso;
}
}
/*
* species_map
*/
{
species_map.clear();
int n = ints[ii++];
for (int i = 0; i < n; i++)
{
species_map[ints[ii++]] = doubles[dd++];
}
}
/*
* log_gamma_map
*/
{
log_gamma_map.clear();
int n = ints[ii++];
for (int i = 0; i < n; i++)
{
log_gamma_map[ints[ii++]] = doubles[dd++];
}
}
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("totals"), // 0
std::vector< std::string >::value_type("activities"), // 1

View File

@ -111,6 +111,8 @@ class cxxSolution:public cxxNumKeyword
void Update(const cxxNameDouble &nd);
void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd);
void Update_activities(const cxxNameDouble &original_tot);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
bool new_def;

View File

@ -8,7 +8,7 @@
#include "Phreeqc.h"
#include "SolutionIsotope.h"
#include "phqalloc.h"
#include "Dictionary.h"
cxxSolutionIsotope::cxxSolutionIsotope(PHRQ_io *io)
:
@ -285,6 +285,33 @@ cxxSolutionIsotope::multiply(LDBLE extensive)
{
this->total *= extensive;
}
void
cxxSolutionIsotope::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
doubles.push_back(this->isotope_number);
ints.push_back(dictionary.Find(this->elt_name));
ints.push_back(dictionary.Find(this->isotope_name));
doubles.push_back(this->total);
doubles.push_back(this->ratio);
doubles.push_back(this->ratio_uncertainty);
ints.push_back(this->ratio_uncertainty_defined ? 1 : 0);
doubles.push_back(this->x_ratio_uncertainty);
doubles.push_back(this->coef);
}
void
cxxSolutionIsotope::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd)
{
this->isotope_number = doubles[dd++];
this->elt_name = dictionary.GetWords()[ints[ii++]];
this->isotope_name = dictionary.GetWords()[ints[ii++]];
this->total = doubles[dd++];
this->ratio = doubles[dd++];
this->ratio_uncertainty = doubles[dd++];
this->ratio_uncertainty_defined = (ints[ii++] != 0);
this->x_ratio_uncertainty = doubles[dd++];
this->coef = doubles[dd++];
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("isotope_number"), // 0
std::vector< std::string >::value_type("elt_name"), // 1

View File

@ -5,6 +5,7 @@
#include <string> // std::string
#include <list> // std::list
#include "Parser.h"
class Dictionary;
class cxxSolutionIsotope: public PHRQ_base
{
@ -66,6 +67,8 @@ class cxxSolutionIsotope: public PHRQ_base
void add(const cxxSolutionIsotope & isotope_ptr, LDBLE intensive,
LDBLE extensive);
void multiply(LDBLE extensive);
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
LDBLE isotope_number;

View File

@ -745,6 +745,90 @@ Sort_comps(void)
}
}
}
/* ---------------------------------------------------------------------- */
void
cxxSurface::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
/* ---------------------------------------------------------------------- */
{
ints.push_back(this->n_user);
ints.push_back((int) this->surface_comps.size());
{
for (size_t i = 0; i < this->surface_comps.size(); i++)
{
surface_comps[i].Serialize(dictionary, ints, doubles);
}
}
ints.push_back((int) this->surface_charges.size());
{
for (size_t i = 0; i < this->surface_charges.size(); i++)
{
surface_charges[i].Serialize(dictionary, ints, doubles);
}
}
ints.push_back(this->new_def ? 1 : 0);
ints.push_back((int) this->type);
ints.push_back((int) this->dl_type);
ints.push_back((int) this->sites_units);
ints.push_back(this->only_counter_ions ? 1 : 0);
doubles.push_back(this->thickness);
doubles.push_back(this->debye_lengths);
doubles.push_back(this->DDL_viscosity);
doubles.push_back(this->DDL_limit);
ints.push_back(this->transport ? 1 : 0);
this->totals.Serialize(dictionary, ints, doubles);
ints.push_back(this->solution_equilibria ? 1 : 0);
ints.push_back((int) this->n_solution);
}
/* ---------------------------------------------------------------------- */
void
cxxSurface::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
/* ---------------------------------------------------------------------- */
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
{
int count = ints[ii++];
this->surface_comps.clear();
for (int n = 0; n < count; n++)
{
cxxSurfaceComp sc;
sc.Deserialize(dictionary, ints, doubles, ii, dd);
this->surface_comps.push_back(sc);
}
}
{
int count = ints[ii++];
this->surface_charges.clear();
for (int n = 0; n < count; n++)
{
cxxSurfaceCharge sc;
sc.Deserialize(dictionary, ints, doubles, ii, dd);
this->surface_charges.push_back(sc);
}
}
this->new_def = (ints[ii++] != 0);
this->type = (SURFACE_TYPE) ints[ii++];
this->dl_type = (DIFFUSE_LAYER_TYPE) ints[ii++];
this->sites_units = (SITES_UNITS) ints[ii++];
this->only_counter_ions = (ints[ii++] != 0);
this->thickness = doubles[dd++];
this->debye_lengths = doubles[dd++];
this->DDL_viscosity = doubles[dd++];
this->DDL_limit = doubles[dd++];
this->transport = (ints[ii++] != 0);
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
this->solution_equilibria = (ints[ii++] != 0);
this->n_solution = ints[ii++];
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("diffuse_layer"), // 0
std::vector< std::string >::value_type("edl"), // 1

View File

@ -73,7 +73,9 @@ public:
void Set_solution_equilibria(bool tf) {solution_equilibria = tf;}
int Get_n_solution(void)const {return n_solution;}
void Set_n_solution(int i) {n_solution = i;}
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::vector < cxxSurfaceComp > surface_comps;
std::vector < cxxSurfaceCharge > surface_charges;

View File

@ -11,6 +11,7 @@
#include "Phreeqc.h"
#include "SurfaceCharge.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
@ -460,6 +461,102 @@ cxxSurfaceCharge::multiply(LDBLE extensive)
this->mass_water *= extensive;
this->diffuse_layer_totals.multiply(extensive);
}
void
cxxSurfaceCharge::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->name));
doubles.push_back(this->specific_area);
doubles.push_back(this->grams);
doubles.push_back(this->charge_balance);
doubles.push_back(this->mass_water);
doubles.push_back(this->la_psi);
doubles.push_back(this->capacitance[0]);
doubles.push_back(this->capacitance[1]);
this->diffuse_layer_totals.Serialize(dictionary, ints, doubles);
doubles.push_back(this->sigma0);
doubles.push_back(this->sigma1);
doubles.push_back(this->sigma2);
doubles.push_back(this->sigmaddl);
ints.push_back((int) this->g_map.size());
{
std::map<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

View File

@ -32,8 +32,7 @@ public:
LDBLE *Get_dx_moles_address(void) {return &dx_moles;}
LDBLE *Get_dh2o_moles_address(void) {return &dh2o_moles;}
LDBLE *Get_drelated_moles_address(void) {return &drelated_moles;}
protected:
LDBLE g_moles;
LDBLE dg_g_moles; /* g_moles*dgterm */
@ -54,6 +53,9 @@ public:
void Set_dg(LDBLE t) {dg = t;}
LDBLE Get_psi_to_z(void) const {return psi_to_z;}
void Set_psi_to_z(LDBLE t) {psi_to_z = t;}
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
LDBLE g;
LDBLE dg;
@ -104,6 +106,8 @@ public:
std::map<LDBLE, cxxSurfDL> &Get_g_map(void) {return g_map;}
void Set_g_map(std::map<LDBLE, cxxSurfDL> & t) {g_map = t;}
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;

View File

@ -11,6 +11,7 @@
#include "Phreeqc.h"
#include "SurfaceComp.h"
#include "phqalloc.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@ -445,6 +446,40 @@ cxxSurfaceComp::multiply(LDBLE extensive)
this->charge_balance *= extensive;
}
void
cxxSurfaceComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(dictionary.Find(this->formula));
doubles.push_back(this->formula_z);
doubles.push_back(this->moles);
this->totals.Serialize(dictionary, ints, doubles);
doubles.push_back(this->la);
ints.push_back(dictionary.Find(this->charge_name));
doubles.push_back(this->charge_balance);
ints.push_back(dictionary.Find(this->phase_name));
doubles.push_back(this->phase_proportion);
ints.push_back(dictionary.Find(this->rate_name));
doubles.push_back(this->Dw);
ints.push_back(dictionary.Find(this->master_element));
}
void
cxxSurfaceComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd)
{
this->formula = dictionary.GetWords()[ints[ii++]];
this->formula_z = doubles[dd++];
this->moles = doubles[dd++];
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
this->la = doubles[dd++];
this->charge_name = dictionary.GetWords()[ints[ii++]];
this->charge_balance = doubles[dd++];
this->phase_name = dictionary.GetWords()[ints[ii++]];
this->phase_proportion = doubles[dd++];
this->rate_name = dictionary.GetWords()[ints[ii++]];
this->Dw = doubles[dd++];
this->master_element = dictionary.GetWords()[ints[ii++]];
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("formula"), // 0
std::vector< std::string >::value_type("moles"), // 1

View File

@ -46,7 +46,9 @@ public:
void Set_Dw(LDBLE d) {this->Dw = d;}
const std::string &Get_master_element() const {return this->master_element;}
void Set_master_element(const char * f) {this->master_element = f ? f : "";}
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::string formula;
LDBLE formula_z;

View File

@ -410,6 +410,40 @@ Get_countTemps(void) const
}
return (int) this->temps.size();
}
void
cxxTemperature::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles)
{
ints.push_back(this->n_user);
{
ints.push_back((int) this->temps.size());
for (size_t i = 0; i < this->temps.size(); i++)
{
doubles.push_back(temps[i]);
}
}
ints.push_back(this->countTemps);
ints.push_back(this->equalIncrements ? 1 : 0);
}
void
cxxTemperature::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
{
int count = ints[ii++];
this->temps.clear();
for (int i = 0; i < count; i++)
{
this->temps.push_back(doubles[dd++]);
}
}
this->countTemps = ints[ii++];
this->equalIncrements = (ints[ii++] != 0);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("temps"), //0
std::vector< std::string >::value_type("equal_increments"), //1

View File

@ -29,7 +29,9 @@ class cxxTemperature:public cxxNumKeyword
void Set_countTemps(int i) {countTemps = i;}
bool Get_equalIncrements(void) const {return equalIncrements;}
void Set_equalIncrements(bool tf) {equalIncrements = tf;}
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
std::vector < LDBLE >temps;
int countTemps;

View File

@ -13,6 +13,7 @@
#include "cxxMix.h"
#include "phqalloc.h"
#include "PHRQ_io.h"
#include "Dictionary.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
@ -566,6 +567,66 @@ Current_step(bool incremental_reactions, int reaction_step) const
}
return kin_time;
}
void
cxxKinetics::Serialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles)
{
ints.push_back(this->n_user);
ints.push_back((int) this->kinetics_comps.size());
for (size_t i = 0; i < this->kinetics_comps.size(); i++)
{
this->kinetics_comps[i].Serialize(dictionary, ints, doubles);
}
ints.push_back((int) this->steps.size());
for (size_t i = 0; i < this->steps.size(); i++)
{
doubles.push_back(this->steps[i]);
}
ints.push_back(this->count);
ints.push_back(this->equalIncrements ? 1 : 0);
doubles.push_back(this->step_divide);
ints.push_back(this->rk);
ints.push_back(this->bad_step_max);
ints.push_back(this->use_cvode ? 1 : 0);
ints.push_back(this->cvode_steps);
ints.push_back(this->cvode_order);
this->totals.Serialize(dictionary, ints, doubles);
}
void
cxxKinetics::Deserialize(Dictionary & dictionary, std::vector < int >&ints,
std::vector < double >&doubles, int &ii, int &dd)
{
this->n_user = ints[ii++];
this->n_user_end = this->n_user;
this->description = " ";
int n = ints[ii++];
this->kinetics_comps.clear();
for (int i = 0; i < n; i++)
{
cxxKineticsComp kc;
kc.Deserialize(dictionary, ints, doubles, ii, dd);
this->kinetics_comps.push_back(kc);
}
n = ints[ii++];
this->steps.clear();
for (int i = 0; i < n; i++)
{
this->steps.push_back(doubles[dd++]);
}
this->count = ints[ii++];
this->equalIncrements = (ints[ii++] != 0);
this->step_divide = doubles[dd++];
this->rk = ints[ii++];
this->bad_step_max = ints[ii++];
this->use_cvode = (ints[ii++] != 0);
this->cvode_steps = ints[ii++];
this->cvode_order = ints[ii++];
this->totals.Deserialize(dictionary, ints, doubles, ii, dd);
}
const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("step_divide"), // 0
std::vector< std::string >::value_type("rk"), // 1

View File

@ -52,6 +52,8 @@ class cxxKinetics:public cxxNumKeyword
int Get_reaction_steps(void) const;
cxxKineticsComp * Find(const std::string &str);
LDBLE Current_step(const bool incremental_reactions, const int reaction_step) const;
void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles);
void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd);
protected:
void add(const cxxKinetics & addee, LDBLE extensive);

View File

@ -459,10 +459,10 @@ calc_PR(void)
while (P <= 0)
{
P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2);
if (P <= 0.0)
if (P <= 0.0)
{
V_m *= 2.0;
//a_aa_sum /= 2.0;
//a_aa_sum /= 2.0;
}
}
if (iterations > 0 && P < 150 && V_m < 1.01)