mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 00:28:23 +01:00
Still has problems, but roughed in xsolution_save and xexchange_save
as constructor methods for Solution and Exchange. Takes c storage and makes C++ objects after a calculation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2062 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
7830f46d8d
commit
a7a19e57f4
31
ExchComp.h
31
ExchComp.h
@ -21,9 +21,6 @@ public:
|
||||
~cxxExchComp();
|
||||
|
||||
struct master *get_master();
|
||||
char *get_formula()const {return this->formula;}
|
||||
char *get_phase_name()const {return this->phase_name;}
|
||||
char *get_rate_name()const {return this->rate_name;}
|
||||
|
||||
static struct exch_comp *cxxExchComp2exch_comp(std::list<cxxExchComp>& el);
|
||||
|
||||
@ -33,6 +30,34 @@ public:
|
||||
|
||||
void read_raw(CParser& parser);
|
||||
|
||||
char * get_formula()const { return this->formula;}
|
||||
void set_formula(char * cstring) { this->formula = cstring;}
|
||||
double get_moles()const { return this->moles;}
|
||||
void set_moles(double d) { this->moles = d;}
|
||||
double get_la()const { return this->la;}
|
||||
void set_la(double d) { this->la = d;}
|
||||
double get_charge_balance()const { return this->charge_balance;}
|
||||
void set_charge_balance(double d) { this->charge_balance = d;}
|
||||
char * get_phase_name()const { return this->phase_name;}
|
||||
void set_phase_name(char * cstring) { this->phase_name = cstring;}
|
||||
double get_phase_proportion()const { return this->phase_proportion;}
|
||||
void set_phase_proportion(double d) { this->phase_proportion = d;}
|
||||
char * get_rate_name()const { return this->rate_name;}
|
||||
void set_rate_name(char * cstring) { this->rate_name = cstring;}
|
||||
double get_formula_z()const { return this->formula_z;}
|
||||
void set_formula_z(double d) { this->formula_z = d;}
|
||||
void set_totals(struct elt_list *e_l, int count)
|
||||
{this->totals = cxxNameDouble(e_l, count);}
|
||||
void set_totals(struct elt_list *e_l)
|
||||
{this->totals = cxxNameDouble(e_l);}
|
||||
void set_totals(cxxNameDouble nd)
|
||||
{this->totals = nd;}
|
||||
void set_formula_totals(struct elt_list *e_l, int count)
|
||||
{this->formula_totals = cxxNameDouble(e_l, count);}
|
||||
void set_formula_totals(struct elt_list *e_l)
|
||||
{this->formula_totals = cxxNameDouble(e_l);}
|
||||
void set_formula_totals(cxxNameDouble nd)
|
||||
{this->formula_totals = nd;}
|
||||
|
||||
const cxxNameDouble &get_totals()const
|
||||
{
|
||||
|
||||
80
Exchange.cxx
80
Exchange.cxx
@ -85,6 +85,84 @@ cxxNumKeyword()
|
||||
}
|
||||
}
|
||||
|
||||
cxxExchange::cxxExchange(int n_user)
|
||||
//
|
||||
// constructor for cxxExchange from reaction calculation
|
||||
// equivalent of xexchange_save
|
||||
// std::list<cxxExchComp> exchComps;
|
||||
// bool pitzer_exchange_gammas;
|
||||
// cxxNameDouble totals;
|
||||
|
||||
:
|
||||
cxxNumKeyword()
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
//this->set_description(exchange_ptr->description);
|
||||
this->n_user = n_user;
|
||||
this->n_user_end = n_user;
|
||||
this->pitzer_exchange_gammas = (use.exchange_ptr->pitzer_exchange_gammas == TRUE);
|
||||
this->totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
if (x[i]->type == EXCH)
|
||||
{
|
||||
cxxExchComp ec;
|
||||
//char * formula;
|
||||
ec.set_formula (x[i]->exch_comp->formula);
|
||||
//double moles;
|
||||
ec.set_moles (0.0);
|
||||
//cxxNameDouble formula_totals;
|
||||
ec.set_formula_totals (x[i]->exch_comp->formula_totals);
|
||||
//cxxNameDouble totals; see below
|
||||
//double la;
|
||||
ec.set_la (x[i]->master[0]->s->la);
|
||||
//double charge_balance; see below
|
||||
//char *phase_name;
|
||||
ec.set_phase_name (x[i]->exch_comp->phase_name);
|
||||
//double phase_proportion;
|
||||
ec.set_phase_proportion (x[i]->exch_comp->phase_proportion);
|
||||
//char *rate_name;
|
||||
ec.set_rate_name (x[i]->exch_comp->rate_name);
|
||||
//double formula_z;
|
||||
ec.set_formula_z (x[i]->exch_comp->formula_z);
|
||||
|
||||
// calculate charge and totals
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
double charge = 0.0;
|
||||
int j;
|
||||
for (j = 0; j < count_species_list; j++)
|
||||
{
|
||||
if (species_list[j].master_s == x[i]->master[0]->s)
|
||||
{
|
||||
add_elt_list (species_list[j].s->next_elt,
|
||||
species_list[j].s->moles);
|
||||
charge += species_list[j].s->moles * species_list[j].s->z;
|
||||
}
|
||||
}
|
||||
// Keep exchanger related to phase even if none currently in solution
|
||||
if (x[i]->exch_comp->phase_name != NULL && count_elts == 0)
|
||||
{
|
||||
add_elt_list (x[i]->master[0]->s->next_elt, 1e-20);
|
||||
}
|
||||
//double charge_balance
|
||||
ec.set_charge_balance (charge);
|
||||
//cxxNameDouble totals;
|
||||
if (count_elts > 0)
|
||||
{
|
||||
qsort (elt_list, (size_t) count_elts,
|
||||
(size_t) sizeof (struct elt_list), elt_list_compare);
|
||||
elt_list_combine ();
|
||||
}
|
||||
ec.set_totals(elt_list, count_elts);
|
||||
|
||||
// add to comp list
|
||||
this->exchComps.push_back(ec);
|
||||
}
|
||||
}
|
||||
}
|
||||
cxxExchange::~cxxExchange()
|
||||
{
|
||||
}
|
||||
@ -330,4 +408,4 @@ void cxxExchange::totalize()
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ class cxxExchange : public cxxNumKeyword
|
||||
|
||||
public:
|
||||
cxxExchange();
|
||||
cxxExchange(int n_user);
|
||||
cxxExchange(struct exchange *);
|
||||
cxxExchange(const std::map<int, cxxExchange> &exchange_map, cxxMix &mx, int n_user);
|
||||
~cxxExchange();
|
||||
|
||||
@ -381,4 +381,4 @@ void cxxGasPhase::totalize()
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -885,4 +885,4 @@ void cxxISolution::ORCH_write_output(std::ostringstream &outstream)
|
||||
}
|
||||
outstream << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,22 @@ cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr)
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr, int count)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list with known count
|
||||
//
|
||||
{
|
||||
int i;
|
||||
if (elt_list_ptr != NULL) {
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(const cxxNameDouble &old, double factor)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
|
||||
@ -24,6 +24,7 @@ public:
|
||||
|
||||
cxxNameDouble();
|
||||
cxxNameDouble(struct elt_list *);
|
||||
cxxNameDouble(struct elt_list *, int count);
|
||||
cxxNameDouble(struct conc *);
|
||||
cxxNameDouble(struct master_activity *ma, int count, ND_TYPE);
|
||||
cxxNameDouble(struct name_coef *nc, int count);
|
||||
|
||||
178
Solution.cxx
178
Solution.cxx
@ -113,6 +113,140 @@ cxxNumKeyword()
|
||||
}
|
||||
}
|
||||
|
||||
cxxSolution::cxxSolution(int n_user)
|
||||
//
|
||||
// constructor for cxxSolution from results of calculation
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
|
||||
//this->set_description none;
|
||||
this->n_user = n_user;
|
||||
this->n_user_end = n_user;
|
||||
this->tc = tc_x;
|
||||
this->ph = ph_x;
|
||||
this->pe = solution_pe_x;
|
||||
this->mu = mu_x;
|
||||
this->ah2o = ah2o_x;
|
||||
this->total_h = total_h_x;
|
||||
this->total_o = total_o_x;
|
||||
this->cb = cb_x;
|
||||
this->mass_water = mass_water_aq_x;
|
||||
this->total_alkalinity = total_alkalinity;
|
||||
this->totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
this->master_activity.type = cxxNameDouble::ND_SPECIES_LA;
|
||||
this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA;
|
||||
/*
|
||||
* Add in minor isotopes if initial solution calculation
|
||||
*/
|
||||
int i;
|
||||
if (initial_solution_isotopes == TRUE)
|
||||
{
|
||||
struct master *master_ptr, *master_i_ptr;
|
||||
for (i = 0; i < count_master_isotope; i++)
|
||||
{
|
||||
if (master_isotope[i]->moles > 0)
|
||||
{
|
||||
master_i_ptr = master_bsearch (master_isotope[i]->name);
|
||||
master_ptr = master_isotope[i]->elt->master;
|
||||
if (master_isotope[i]->minor_isotope == TRUE)
|
||||
{
|
||||
master_i_ptr->total = master_isotope[i]->moles;
|
||||
if (master_ptr->total > 0)
|
||||
{
|
||||
master_i_ptr->s->la =
|
||||
master_ptr->s->la +
|
||||
log10 (master_i_ptr->total / master_ptr->total);
|
||||
}
|
||||
else
|
||||
{
|
||||
master_i_ptr->s->la = master_ptr->s->la;
|
||||
}
|
||||
}
|
||||
else if (master_isotope[i]->minor_isotope == FALSE
|
||||
&& master_ptr->s != s_hplus && master_ptr->s != s_h2o)
|
||||
{
|
||||
if (master_ptr->s->secondary != NULL)
|
||||
{
|
||||
master_ptr->s->secondary->total = master_isotope[i]->moles;
|
||||
}
|
||||
else
|
||||
{
|
||||
master_ptr->s->primary->total = master_isotope[i]->moles;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
cxxNameDouble totals;
|
||||
cxxNameDouble master_activity;
|
||||
cxxNameDouble species_gamma;
|
||||
cxxSolutionIsotopeList isotopes;
|
||||
*/
|
||||
|
||||
// totals and master_activity
|
||||
for (i = 0; i < count_master; i++)
|
||||
{
|
||||
if (master[i]->s->type == EX ||
|
||||
master[i]->s->type == SURF || master[i]->s->type == SURF_PSI)
|
||||
continue;
|
||||
if (master[i]->s == s_hplus) continue;
|
||||
if (master[i]->s == s_h2o) continue;
|
||||
if (master[i]->in != FALSE)
|
||||
{
|
||||
this->master_activity[master[i]->elt->name] = master[i]->s->la;
|
||||
}
|
||||
if (master[i]->total <= MIN_TOTAL)
|
||||
{
|
||||
master[i]->total = 0.0;
|
||||
master[i]->total_primary = 0.0;
|
||||
continue;
|
||||
}
|
||||
this->totals[master[i]->elt->name] = master[i]->total;
|
||||
}
|
||||
|
||||
// species_gammas for Pitzer
|
||||
if (pitzer_model == TRUE)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < count_s; j++)
|
||||
{
|
||||
if (s[j]->lg != 0.0)
|
||||
{
|
||||
this->species_gamma[s[j]->name] = s[j]->lg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save isotope data
|
||||
|
||||
if (count_isotopes_x > 0)
|
||||
{
|
||||
for (i = 0; i < count_isotopes_x; i++)
|
||||
{
|
||||
cxxSolutionIsotope cxxiso;
|
||||
cxxiso.set_isotope_number (isotopes_x[i].isotope_number);
|
||||
cxxiso.set_elt_name (isotopes_x[i].elt_name);
|
||||
cxxiso.set_isotope_name (isotopes_x[i].isotope_name);
|
||||
cxxiso.set_total (isotopes_x[i].master->total);
|
||||
if (isotopes_x[i].master == s_hplus->secondary)
|
||||
{
|
||||
cxxiso.set_total (2 * mass_water_aq_x / gfw_water);
|
||||
}
|
||||
if (isotopes_x[i].master == s_h2o->secondary)
|
||||
{
|
||||
cxxiso.set_total (mass_water_aq_x / gfw_water);
|
||||
}
|
||||
// cxxiso.ratio
|
||||
// cxxiso.ratio_uncertainty
|
||||
// cxxiso.ratio_uncertainty_defined
|
||||
this->isotopes.push_back(cxxiso);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxSolution::~cxxSolution()
|
||||
{
|
||||
}
|
||||
@ -1057,50 +1191,6 @@ void cxxSolution::set_master_activity(char *string, double d)
|
||||
{
|
||||
this->master_activity[string] = d;
|
||||
}
|
||||
#ifdef SKIP
|
||||
#include "../hst.h"
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxSolution::xsolution_save(int n)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Save solution composition into Solution class
|
||||
*
|
||||
* input: n is pointer number in solution
|
||||
*/
|
||||
this->set_description(" ");
|
||||
this->n_user = n;
|
||||
this->n_user_end = n;
|
||||
this->tc = tc_x;
|
||||
this->ph = ph_x;
|
||||
this->pe = solution_pe_x;
|
||||
this->mu = mu_x;
|
||||
this->ah2o = ah2o_x;
|
||||
this->total_h = total_h_x;
|
||||
this->total_o = total_o_x;
|
||||
this->cb = cb_x;
|
||||
this->mass_water = mass_water_aq_x;
|
||||
this->total_alkalinity = total_alkalinity;
|
||||
/*
|
||||
* Copy totals data
|
||||
*/
|
||||
for (int j = 2; j < count_total; j++) {
|
||||
this->totals.insert(buffer[j].master->elt->name, buffer[j].master->total_primary);
|
||||
}
|
||||
|
||||
for (int j = 0; j < count_activity_list; j++) {
|
||||
this->master_activity.insert(activity_list[j].master->elt->name, activity_list[j].master->s->la);
|
||||
}
|
||||
if (pitzer_model == TRUE) {
|
||||
for (int j= 0; j < count_s; j++) {
|
||||
if (s[j]->lg != 0.0) {
|
||||
this->species_gamma.insert(s[j]->name, s[j]->lg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#include "ISolution.h"
|
||||
#include "Exchange.h"
|
||||
|
||||
@ -22,6 +22,7 @@ class cxxSolution : public cxxNumKeyword
|
||||
public:
|
||||
cxxSolution();
|
||||
cxxSolution(struct solution *);
|
||||
cxxSolution(int n_user);
|
||||
cxxSolution(const std::map<int, cxxSolution> &solution_map, cxxMix &mx, int n_user);
|
||||
~cxxSolution();
|
||||
|
||||
|
||||
@ -27,10 +27,14 @@ public:
|
||||
|
||||
CParser::STATUS_TYPE read_raw(CParser& parser);
|
||||
|
||||
char * get_isotope_name()const { return this->isotope_name;}
|
||||
void set_isotope_name(char * cstring) { this->isotope_name = cstring;}
|
||||
double get_isotope_number()const { return this->isotope_number;}
|
||||
void set_isotope_number(double d) { this->isotope_number = d;}
|
||||
char * get_elt_name()const { return this->elt_name;}
|
||||
void set_elt_name(char * cstring) { this->elt_name = cstring;}
|
||||
char * get_isotope_name()const { return this->isotope_name;}
|
||||
void set_isotope_name(char * cstring) { this->isotope_name = cstring;}
|
||||
double get_total()const { return this->total;}
|
||||
void set_total(double d) { this->total = d;}
|
||||
|
||||
double get_ratio()const { return this->ratio; }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user