mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-15 16:18:22 +01:00
Ran indent program on phreeqcpp
indent -bli0 -i4 -ts4 -npcs -nbc *.cxx git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3168 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
60d57c5062
commit
3313c814a9
115
Dictionary.cxx
115
Dictionary.cxx
@ -2,43 +2,50 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Dictionary.h" // define first
|
||||
#include "Dictionary.h" // define first
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include "output.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
cxxDictionary::cxxDictionary()
|
||||
{
|
||||
// default constructor for cxxStorageBin
|
||||
// default constructor for cxxStorageBin
|
||||
}
|
||||
|
||||
cxxDictionary::~cxxDictionary()
|
||||
{
|
||||
}
|
||||
|
||||
void cxxDictionary::add_phreeqc() {
|
||||
void
|
||||
cxxDictionary::add_phreeqc()
|
||||
{
|
||||
HashTable *Table = strings_hash_table;
|
||||
int i,j;
|
||||
Segment *seg;
|
||||
Element *p,*q;
|
||||
int i, j;
|
||||
Segment *seg;
|
||||
Element *p, *q;
|
||||
|
||||
if (Table != NULL) {
|
||||
for (i = 0; i < Table->SegmentCount; i++) {
|
||||
/* test probably unnecessary */
|
||||
if ((seg = Table->Directory[i]) != NULL) {
|
||||
for (j = 0; j < SegmentSize; j++) {
|
||||
if (Table != NULL)
|
||||
{
|
||||
for (i = 0; i < Table->SegmentCount; i++)
|
||||
{
|
||||
/* test probably unnecessary */
|
||||
if ((seg = Table->Directory[i]) != NULL)
|
||||
{
|
||||
for (j = 0; j < SegmentSize; j++)
|
||||
{
|
||||
p = seg[j];
|
||||
while (p != NULL) {
|
||||
while (p != NULL)
|
||||
{
|
||||
q = p->Next;
|
||||
//p->Data = (char*) free_check_null((void*)p->Data);
|
||||
this->putString((char *) (p->Data));
|
||||
@ -50,56 +57,82 @@ void cxxDictionary::add_phreeqc() {
|
||||
}
|
||||
}
|
||||
|
||||
int cxxDictionary::putString(std::string str) {
|
||||
int
|
||||
cxxDictionary::putString(std::string str)
|
||||
{
|
||||
int n;
|
||||
std::map<std::string, int>::iterator it = stringkey.find(str);
|
||||
if (it != stringkey.end()) {
|
||||
std::map < std::string, int >::iterator it = stringkey.find(str);
|
||||
if (it != stringkey.end())
|
||||
{
|
||||
n = it->second;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
n = (int) stringkey.size();
|
||||
stringkey[str] = n;
|
||||
intkey[n] = str;
|
||||
}
|
||||
return(n);
|
||||
return (n);
|
||||
}
|
||||
|
||||
int cxxDictionary::putString(char * str) {
|
||||
int
|
||||
cxxDictionary::putString(char *str)
|
||||
{
|
||||
std::string str1(str);
|
||||
return (putString(str1));
|
||||
}
|
||||
|
||||
int cxxDictionary::string2int(std::string str) {
|
||||
int
|
||||
cxxDictionary::string2int(std::string str)
|
||||
{
|
||||
int n;
|
||||
std::map<std::string, int>::iterator it = stringkey.find(str);
|
||||
if (it != stringkey.end()) {
|
||||
std::map < std::string, int >::iterator it = stringkey.find(str);
|
||||
if (it != stringkey.end())
|
||||
{
|
||||
n = it->second;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
n = -1;
|
||||
}
|
||||
return(n);
|
||||
return (n);
|
||||
}
|
||||
|
||||
int cxxDictionary::string2int(char * str) {
|
||||
if (str == NULL) return (-1);
|
||||
int
|
||||
cxxDictionary::string2int(char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return (-1);
|
||||
std::string str1(str);
|
||||
return(string2int(str1));
|
||||
return (string2int(str1));
|
||||
}
|
||||
|
||||
|
||||
std::string *cxxDictionary::int2string(int i) {
|
||||
std::map<int, std::string>::iterator it = intkey.find(i);
|
||||
if (it != intkey.end()) {
|
||||
return(&it->second);
|
||||
} else {
|
||||
return(NULL);
|
||||
std::string * cxxDictionary::int2string(int i)
|
||||
{
|
||||
std::map < int,
|
||||
std::string >::iterator
|
||||
it = intkey.find(i);
|
||||
if (it != intkey.end())
|
||||
{
|
||||
return (&it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
char *cxxDictionary::int2char(int i) {
|
||||
std::map<int, std::string>::iterator it = intkey.find(i);
|
||||
if (it != intkey.end()) {
|
||||
return(string_hsave(it->second.c_str()));
|
||||
} else {
|
||||
return(NULL);
|
||||
char *
|
||||
cxxDictionary::int2char(int i)
|
||||
{
|
||||
std::map < int, std::string >::iterator it = intkey.find(i);
|
||||
if (it != intkey.end())
|
||||
{
|
||||
return (string_hsave(it->second.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
942
ExchComp.cxx
942
ExchComp.cxx
File diff suppressed because it is too large
Load Diff
686
Exchange.cxx
686
Exchange.cxx
@ -2,11 +2,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include <iostream> // std::cout std::cerr
|
||||
#include "Utils.h" // define first
|
||||
#include <iostream> // std::cout std::cerr
|
||||
#include "Utils.h" // define first
|
||||
#include "Exchange.h"
|
||||
#include "ExchComp.h"
|
||||
#define EXTERNAL extern
|
||||
@ -14,369 +14,422 @@
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include "output.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxExchange::cxxExchange()
|
||||
//
|
||||
// default constructor for cxxExchange
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxExchange
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
pitzer_exchange_gammas = false;
|
||||
pitzer_exchange_gammas = false;
|
||||
}
|
||||
|
||||
cxxExchange::cxxExchange(struct exchange *exchange_ptr)
|
||||
//
|
||||
// constructor for cxxExchange from struct exchange
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
this->set_description(exchange_ptr->description);
|
||||
n_user = exchange_ptr->n_user;
|
||||
n_user_end = exchange_ptr->n_user_end;
|
||||
pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE);
|
||||
for (i = 0; i < exchange_ptr->count_comps; i++) {
|
||||
cxxExchComp ec(&(exchange_ptr->comps[i]));
|
||||
exchComps.push_back(ec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
cxxExchange::cxxExchange(const std::map<int, cxxExchange> &entities, cxxMix &mix, int n_user)
|
||||
cxxExchange::cxxExchange(struct exchange * exchange_ptr)
|
||||
//
|
||||
// constructor for cxxExchange from struct exchange
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
this->pitzer_exchange_gammas = false;
|
||||
int i;
|
||||
|
||||
this->set_description(exchange_ptr->description);
|
||||
n_user = exchange_ptr->n_user;
|
||||
n_user_end = exchange_ptr->n_user_end;
|
||||
pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE);
|
||||
for (i = 0; i < exchange_ptr->count_comps; i++)
|
||||
{
|
||||
cxxExchComp ec(&(exchange_ptr->comps[i]));
|
||||
exchComps.push_back(ec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities,
|
||||
cxxMix & mix, int n_user):
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
this->pitzer_exchange_gammas = false;
|
||||
//
|
||||
// Mix exchangers
|
||||
//
|
||||
std::map<int, double> *mixcomps = mix.comps();
|
||||
std::map<int, double>::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxExchange *entity_ptr = &(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas;
|
||||
}
|
||||
std::map < int, double >*mixcomps = mix.comps();
|
||||
std::map < int, double >::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxExchange *entity_ptr =
|
||||
&(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas;
|
||||
}
|
||||
#ifdef SKIP
|
||||
if (entity_ptr == NULL)
|
||||
{
|
||||
sprintf(error_string, "Exchange %d not found while mixing.", it->first);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
if (entity_ptr == NULL)
|
||||
{
|
||||
sprintf(error_string, "Exchange %d not found while mixing.",
|
||||
it->first);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxExchange::cxxExchange(int n_user)
|
||||
//
|
||||
// constructor for cxxExchange from reaction calculation
|
||||
// equivalent of xexchange_save
|
||||
// std::list<cxxExchComp> exchComps;
|
||||
// bool pitzer_exchange_gammas;
|
||||
//
|
||||
// constructor for cxxExchange from reaction calculation
|
||||
// equivalent of xexchange_save
|
||||
// std::list<cxxExchComp> exchComps;
|
||||
// bool pitzer_exchange_gammas;
|
||||
// cxxNameDouble totals;
|
||||
|
||||
:
|
||||
:
|
||||
cxxNumKeyword()
|
||||
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
//this->set_description(exchange_ptr->description);
|
||||
this->n_user = n_user;
|
||||
this->n_user_end = n_user;
|
||||
this->pitzer_exchange_gammas = (use.exchange_ptr->pitzer_exchange_gammas == TRUE);
|
||||
this->totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
if (x[i]->type == EXCH)
|
||||
{
|
||||
cxxExchComp ec;
|
||||
//char * formula;
|
||||
ec.set_formula (x[i]->exch_comp->formula);
|
||||
//double moles;
|
||||
ec.set_moles (0.0);
|
||||
//cxxNameDouble formula_totals;
|
||||
ec.set_formula_totals (x[i]->exch_comp->formula_totals);
|
||||
//cxxNameDouble totals; see below
|
||||
//double la;
|
||||
ec.set_la (x[i]->master[0]->s->la);
|
||||
//double charge_balance; see below
|
||||
//char *phase_name;
|
||||
ec.set_phase_name (x[i]->exch_comp->phase_name);
|
||||
//double phase_proportion;
|
||||
ec.set_phase_proportion (x[i]->exch_comp->phase_proportion);
|
||||
//char *rate_name;
|
||||
ec.set_rate_name (x[i]->exch_comp->rate_name);
|
||||
//double formula_z;
|
||||
ec.set_formula_z (x[i]->exch_comp->formula_z);
|
||||
|
||||
// calculate charge and totals
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
double charge = 0.0;
|
||||
int j;
|
||||
for (j = 0; j < count_species_list; j++)
|
||||
{
|
||||
if (species_list[j].master_s == x[i]->master[0]->s)
|
||||
//this->set_description(exchange_ptr->description);
|
||||
this->n_user = n_user;
|
||||
this->n_user_end = n_user;
|
||||
this->pitzer_exchange_gammas =
|
||||
(use.exchange_ptr->pitzer_exchange_gammas == TRUE);
|
||||
this->totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
add_elt_list (species_list[j].s->next_elt,
|
||||
species_list[j].s->moles);
|
||||
charge += species_list[j].s->moles * species_list[j].s->z;
|
||||
}
|
||||
}
|
||||
// Keep exchanger related to phase even if none currently in solution
|
||||
if (x[i]->exch_comp->phase_name != NULL && count_elts == 0)
|
||||
{
|
||||
add_elt_list (x[i]->master[0]->s->next_elt, 1e-20);
|
||||
}
|
||||
//double charge_balance
|
||||
ec.set_charge_balance (charge);
|
||||
//cxxNameDouble totals;
|
||||
if (count_elts > 0)
|
||||
{
|
||||
qsort (elt_list, (size_t) count_elts,
|
||||
(size_t) sizeof (struct elt_list), elt_list_compare);
|
||||
elt_list_combine ();
|
||||
}
|
||||
ec.set_totals(elt_list, count_elts);
|
||||
if (x[i]->type == EXCH)
|
||||
{
|
||||
cxxExchComp ec;
|
||||
//char * formula;
|
||||
ec.set_formula(x[i]->exch_comp->formula);
|
||||
//double moles;
|
||||
ec.set_moles(0.0);
|
||||
//cxxNameDouble formula_totals;
|
||||
ec.set_formula_totals(x[i]->exch_comp->formula_totals);
|
||||
//cxxNameDouble totals; see below
|
||||
//double la;
|
||||
ec.set_la(x[i]->master[0]->s->la);
|
||||
//double charge_balance; see below
|
||||
//char *phase_name;
|
||||
ec.set_phase_name(x[i]->exch_comp->phase_name);
|
||||
//double phase_proportion;
|
||||
ec.set_phase_proportion(x[i]->exch_comp->phase_proportion);
|
||||
//char *rate_name;
|
||||
ec.set_rate_name(x[i]->exch_comp->rate_name);
|
||||
//double formula_z;
|
||||
ec.set_formula_z(x[i]->exch_comp->formula_z);
|
||||
|
||||
// add to comp list
|
||||
this->exchComps.push_back(ec);
|
||||
}
|
||||
}
|
||||
// calculate charge and totals
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
double charge = 0.0;
|
||||
int j;
|
||||
for (j = 0; j < count_species_list; j++)
|
||||
{
|
||||
if (species_list[j].master_s == x[i]->master[0]->s)
|
||||
{
|
||||
add_elt_list(species_list[j].s->next_elt,
|
||||
species_list[j].s->moles);
|
||||
charge += species_list[j].s->moles * species_list[j].s->z;
|
||||
}
|
||||
}
|
||||
// Keep exchanger related to phase even if none currently in solution
|
||||
if (x[i]->exch_comp->phase_name != NULL && count_elts == 0)
|
||||
{
|
||||
add_elt_list(x[i]->master[0]->s->next_elt, 1e-20);
|
||||
}
|
||||
//double charge_balance
|
||||
ec.set_charge_balance(charge);
|
||||
//cxxNameDouble totals;
|
||||
if (count_elts > 0)
|
||||
{
|
||||
qsort(elt_list, (size_t) count_elts,
|
||||
(size_t) sizeof(struct elt_list), elt_list_compare);
|
||||
elt_list_combine();
|
||||
}
|
||||
ec.set_totals(elt_list, count_elts);
|
||||
|
||||
// add to comp list
|
||||
this->exchComps.push_back(ec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxExchange::~cxxExchange()
|
||||
{
|
||||
}
|
||||
|
||||
bool cxxExchange::get_related_phases()
|
||||
{
|
||||
for (std::list<cxxExchComp>::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) {
|
||||
if (it->get_phase_name() == NULL) continue;
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool cxxExchange::get_related_rate()
|
||||
{
|
||||
for (std::list<cxxExchComp>::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) {
|
||||
if (it->get_rate_name() == NULL) continue;
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
struct exchange *cxxExchange::cxxExchange2exchange()
|
||||
//
|
||||
// Builds a exchange structure from instance of cxxExchange
|
||||
//
|
||||
bool
|
||||
cxxExchange::get_related_phases()
|
||||
{
|
||||
struct exchange *exchange_ptr = exchange_alloc();
|
||||
|
||||
exchange_ptr->description = this->get_description();
|
||||
exchange_ptr->n_user = this->n_user;
|
||||
exchange_ptr->n_user_end = this->n_user_end;
|
||||
exchange_ptr->new_def = FALSE;
|
||||
exchange_ptr->solution_equilibria = FALSE;
|
||||
exchange_ptr->n_solution = -2;
|
||||
exchange_ptr->related_phases = (int) this->get_related_phases();
|
||||
exchange_ptr->related_rate = (int) this->get_related_rate();
|
||||
exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas;
|
||||
exchange_ptr->count_comps = (int) this->exchComps.size();
|
||||
exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps);
|
||||
exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps);
|
||||
return(exchange_ptr);
|
||||
for (std::list < cxxExchComp >::const_iterator it =
|
||||
this->exchComps.begin(); it != this->exchComps.end(); ++it)
|
||||
{
|
||||
if (it->get_phase_name() == NULL)
|
||||
continue;
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
void cxxExchange::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
bool
|
||||
cxxExchange::get_related_rate()
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
|
||||
// Exchange element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<exchange " << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_exchange_gammas=\"" << this->pitzer_exchange_gammas << "\"" << std::endl;
|
||||
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list<cxxExchComp>::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
for (std::list < cxxExchComp >::const_iterator it =
|
||||
this->exchComps.begin(); it != this->exchComps.end(); ++it)
|
||||
{
|
||||
if (it->get_rate_name() == NULL)
|
||||
continue;
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
void cxxExchange::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
struct exchange *
|
||||
cxxExchange::cxxExchange2exchange()
|
||||
//
|
||||
// Builds a exchange structure from instance of cxxExchange
|
||||
//
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
struct exchange *exchange_ptr = exchange_alloc();
|
||||
|
||||
// Exchange element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "EXCHANGE_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-pitzer_exchange_gammas " << this->pitzer_exchange_gammas << std::endl;
|
||||
|
||||
// exchComps structures
|
||||
for (std::list<cxxExchComp>::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) {
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
exchange_ptr->description = this->get_description();
|
||||
exchange_ptr->n_user = this->n_user;
|
||||
exchange_ptr->n_user_end = this->n_user_end;
|
||||
exchange_ptr->new_def = FALSE;
|
||||
exchange_ptr->solution_equilibria = FALSE;
|
||||
exchange_ptr->n_solution = -2;
|
||||
exchange_ptr->related_phases = (int) this->get_related_phases();
|
||||
exchange_ptr->related_rate = (int) this->get_related_rate();
|
||||
exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas;
|
||||
exchange_ptr->count_comps = (int) this->exchComps.size();
|
||||
exchange_ptr->comps =
|
||||
(struct exch_comp *) free_check_null(exchange_ptr->comps);
|
||||
exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps);
|
||||
return (exchange_ptr);
|
||||
}
|
||||
|
||||
void cxxExchange::read_raw(CParser& parser)
|
||||
void
|
||||
cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("pitzer_exchange_gammas"); // 0
|
||||
vopts.push_back("component"); // 1
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
//const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Read exchange number and description
|
||||
this->read_number_description(parser);
|
||||
// Exchange element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<exchange " << std::endl;
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool pitzer_exchange_gammas_defined(false);
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_exchange_gammas=\"" << this->
|
||||
pitzer_exchange_gammas << "\"" << std::endl;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in EXCH_COMP_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list < cxxExchComp >::const_iterator it = exchComps.begin();
|
||||
it != exchComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
case 0: // pitzer_exchange_gammas
|
||||
if (!(parser.get_iss() >> this->pitzer_exchange_gammas))
|
||||
{
|
||||
this->pitzer_exchange_gammas = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for pitzer_exchange_gammas.", CParser::OT_CONTINUE);
|
||||
}
|
||||
pitzer_exchange_gammas_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 1: // component
|
||||
{
|
||||
cxxExchComp ec;
|
||||
ec.read_raw(parser);
|
||||
this->exchComps.push_back(ec);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (pitzer_exchange_gammas_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
void cxxExchange::add(const cxxExchange &addee, double extensive)
|
||||
//
|
||||
// Add existing exchange to "this" exchange
|
||||
//
|
||||
|
||||
void
|
||||
cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//std::list<cxxExchComp> exchComps;
|
||||
// exchComps
|
||||
if (extensive == 0.0) return;
|
||||
for (std::list<cxxExchComp>::const_iterator itadd = addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list<cxxExchComp>::iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it)
|
||||
{
|
||||
if (it->get_formula() == itadd->get_formula())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
cxxExchComp exc = *itadd;
|
||||
exc.multiply(extensive);
|
||||
//exc.add(*itadd, extensive);
|
||||
this->exchComps.push_back(exc);
|
||||
}
|
||||
}
|
||||
//bool pitzer_exchange_gammas;
|
||||
this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas;
|
||||
//const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Exchange element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "EXCHANGE_RAW " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-pitzer_exchange_gammas " << this->
|
||||
pitzer_exchange_gammas << std::endl;
|
||||
|
||||
// exchComps structures
|
||||
for (std::list < cxxExchComp >::const_iterator it = exchComps.begin();
|
||||
it != exchComps.end(); ++it)
|
||||
{
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cxxExchange::read_raw(CParser & parser)
|
||||
{
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("pitzer_exchange_gammas"); // 0
|
||||
vopts.push_back("component"); // 1
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
// Read exchange number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool pitzer_exchange_gammas_defined(false);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in EXCH_COMP_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 0: // pitzer_exchange_gammas
|
||||
if (!(parser.get_iss() >> this->pitzer_exchange_gammas))
|
||||
{
|
||||
this->pitzer_exchange_gammas = false;
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected boolean value for pitzer_exchange_gammas.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
pitzer_exchange_gammas_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 1: // component
|
||||
{
|
||||
cxxExchComp ec;
|
||||
ec.read_raw(parser);
|
||||
this->exchComps.push_back(ec);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (pitzer_exchange_gammas_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
void
|
||||
cxxExchange::add(const cxxExchange & addee, double extensive)
|
||||
//
|
||||
// Add existing exchange to "this" exchange
|
||||
//
|
||||
{
|
||||
//std::list<cxxExchComp> exchComps;
|
||||
// exchComps
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
for (std::list < cxxExchComp >::const_iterator itadd =
|
||||
addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list < cxxExchComp >::iterator it = this->exchComps.begin();
|
||||
it != this->exchComps.end(); ++it)
|
||||
{
|
||||
if (it->get_formula() == itadd->get_formula())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
cxxExchComp exc = *itadd;
|
||||
exc.multiply(extensive);
|
||||
//exc.add(*itadd, extensive);
|
||||
this->exchComps.push_back(exc);
|
||||
}
|
||||
}
|
||||
//bool pitzer_exchange_gammas;
|
||||
this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas;
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxExchange::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxExchange::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/* int n_user; */
|
||||
ints.push_back(this->n_user);
|
||||
|
||||
|
||||
ints.push_back((int) this->pitzer_exchange_gammas);
|
||||
ints.push_back((int) this->exchComps.size());
|
||||
for (std::list<cxxExchComp>::iterator it = this->exchComps.begin(); it != this->exchComps.end(); it++) {
|
||||
for (std::list < cxxExchComp >::iterator it = this->exchComps.begin();
|
||||
it != this->exchComps.end(); it++)
|
||||
{
|
||||
it->mpi_pack(ints, doubles);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
void
|
||||
cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i = *ii;
|
||||
@ -386,11 +439,12 @@ void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
this->n_user_end = this->n_user;
|
||||
this->description = " ";
|
||||
|
||||
|
||||
|
||||
this->pitzer_exchange_gammas = (ints[i++] == TRUE);
|
||||
int count = ints[i++];
|
||||
this->exchComps.clear();
|
||||
for (int n = 0; n < count; n++) {
|
||||
for (int n = 0; n < count; n++)
|
||||
{
|
||||
cxxExchComp ec;
|
||||
ec.mpi_unpack(ints, &i, doubles, &d);
|
||||
this->exchComps.push_back(ec);
|
||||
@ -399,14 +453,16 @@ void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
void cxxExchange::totalize()
|
||||
void
|
||||
cxxExchange::totalize()
|
||||
{
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (std::list<cxxExchComp>::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it)
|
||||
{
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
this->totals.add("Charge", it->get_charge_balance());
|
||||
}
|
||||
return;
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (std::list < cxxExchComp >::const_iterator it = exchComps.begin();
|
||||
it != exchComps.end(); ++it)
|
||||
{
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
this->totals.add("Charge", it->get_charge_balance());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
600
GasPhase.cxx
600
GasPhase.cxx
@ -2,121 +2,140 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "GasPhase.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include "output.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxGasPhase::cxxGasPhase()
|
||||
//
|
||||
// default constructor for cxxGasPhase
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxGasPhase
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
total_p = 0;
|
||||
volume = 0;
|
||||
gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF;
|
||||
total_p = 0;
|
||||
volume = 0;
|
||||
gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF;
|
||||
}
|
||||
|
||||
cxxGasPhase::cxxGasPhase(struct gas_phase *gas_phase_ptr)
|
||||
//
|
||||
// constructor for cxxGasPhase from struct gas_phase
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxGasPhase from struct gas_phase
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
this->set_description(gas_phase_ptr->description);
|
||||
n_user = gas_phase_ptr->n_user;
|
||||
n_user_end = gas_phase_ptr->n_user_end;
|
||||
if (gas_phase_ptr->type == PRESSURE) {
|
||||
type = cxxGasPhase::GP_PRESSURE;
|
||||
} else {
|
||||
type = cxxGasPhase::GP_VOLUME;
|
||||
}
|
||||
total_p = gas_phase_ptr->total_p;
|
||||
volume = gas_phase_ptr->volume;
|
||||
this->set_description(gas_phase_ptr->description);
|
||||
n_user = gas_phase_ptr->n_user;
|
||||
n_user_end = gas_phase_ptr->n_user_end;
|
||||
if (gas_phase_ptr->type == PRESSURE)
|
||||
{
|
||||
type = cxxGasPhase::GP_PRESSURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = cxxGasPhase::GP_VOLUME;
|
||||
}
|
||||
total_p = gas_phase_ptr->total_p;
|
||||
volume = gas_phase_ptr->volume;
|
||||
|
||||
// gas_phase components
|
||||
for (i = 0; i < gas_phase_ptr->count_comps; i++) {
|
||||
if (gas_phase_ptr->comps[i].name == NULL) continue;
|
||||
gasPhaseComps[gas_phase_ptr->comps[i].name] = gas_phase_ptr->comps[i].moles;
|
||||
}
|
||||
// gas_phase components
|
||||
for (i = 0; i < gas_phase_ptr->count_comps; i++)
|
||||
{
|
||||
if (gas_phase_ptr->comps[i].name == NULL)
|
||||
continue;
|
||||
gasPhaseComps[gas_phase_ptr->comps[i].name] =
|
||||
gas_phase_ptr->comps[i].moles;
|
||||
}
|
||||
}
|
||||
cxxGasPhase::cxxGasPhase(const std::map<int, cxxGasPhase> &entities, cxxMix &mix, int n_user)
|
||||
:
|
||||
cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities,
|
||||
cxxMix & mix, int n_user):
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF;
|
||||
total_p = 0;
|
||||
volume = 0;
|
||||
bool first = true;
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF;
|
||||
total_p = 0;
|
||||
volume = 0;
|
||||
bool first = true;
|
||||
//
|
||||
// Mix
|
||||
//
|
||||
//cxxNameDouble gasPhaseComps;
|
||||
std::map<int, double> *mixcomps = mix.comps();
|
||||
std::map<int, double>::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxGasPhase *entity_ptr = &(entities.find(it->first)->second);
|
||||
this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps, it->second);
|
||||
//GP_TYPE type;
|
||||
//double total_p;
|
||||
//double volume;
|
||||
if (first)
|
||||
{
|
||||
this->type = entity_ptr->type;
|
||||
this->total_p = entity_ptr->total_p * it->second;
|
||||
this->volume = entity_ptr->volume * it->second;
|
||||
first = false;
|
||||
} else
|
||||
{
|
||||
if (this->type != entity_ptr->type)
|
||||
//cxxNameDouble gasPhaseComps;
|
||||
std::map < int, double >*mixcomps = mix.comps();
|
||||
std::map < int, double >::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Can not mix two gas_phases with differing types." ;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxGasPhase *entity_ptr =
|
||||
&(entities.find(it->first)->second);
|
||||
this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps,
|
||||
it->second);
|
||||
//GP_TYPE type;
|
||||
//double total_p;
|
||||
//double volume;
|
||||
if (first)
|
||||
{
|
||||
this->type = entity_ptr->type;
|
||||
this->total_p = entity_ptr->total_p * it->second;
|
||||
this->volume = entity_ptr->volume * it->second;
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->type != entity_ptr->type)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Can not mix two gas_phases with differing types.";
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
|
||||
this->total_p += entity_ptr->total_p * it->second;
|
||||
this->volume += entity_ptr->volume * it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->total_p += entity_ptr->total_p * it->second;
|
||||
this->volume += entity_ptr->volume * it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxGasPhase::~cxxGasPhase()
|
||||
{
|
||||
}
|
||||
|
||||
struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp()
|
||||
struct gas_comp *
|
||||
cxxGasPhase::cxxGasPhaseComp2gas_comp()
|
||||
{
|
||||
//struct gas_comp *gas_comp_ptr(NULL);
|
||||
struct gas_comp *gas_comp_ptr = NULL;
|
||||
if (this->gasPhaseComps.size() > 0) {
|
||||
if (this->gasPhaseComps.size() > 0)
|
||||
{
|
||||
int i = 0;
|
||||
int n;
|
||||
gas_comp_ptr = (struct gas_comp *) PHRQ_malloc((size_t) (this->gasPhaseComps.size() * sizeof(struct gas_comp)));
|
||||
if (gas_comp_ptr == NULL) malloc_error();
|
||||
for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) {
|
||||
gas_comp_ptr =
|
||||
(struct gas_comp *)
|
||||
PHRQ_malloc((size_t)
|
||||
(this->gasPhaseComps.size() *
|
||||
sizeof(struct gas_comp)));
|
||||
if (gas_comp_ptr == NULL)
|
||||
malloc_error();
|
||||
for (cxxNameDouble::iterator it = this->gasPhaseComps.begin();
|
||||
it != this->gasPhaseComps.end(); it++)
|
||||
{
|
||||
gas_comp_ptr[i].name = it->first;
|
||||
gas_comp_ptr[i].phase = phase_bsearch(it->first, &n, TRUE);
|
||||
gas_comp_ptr[i].p_read = 0;
|
||||
@ -125,225 +144,273 @@ struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp()
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return(gas_comp_ptr);
|
||||
return (gas_comp_ptr);
|
||||
}
|
||||
|
||||
struct gas_phase *cxxGasPhase::cxxGasPhase2gas_phase()
|
||||
//
|
||||
// Builds a gas_phase structure from instance of cxxGasPhase
|
||||
//
|
||||
struct gas_phase *
|
||||
cxxGasPhase::cxxGasPhase2gas_phase()
|
||||
//
|
||||
// Builds a gas_phase structure from instance of cxxGasPhase
|
||||
//
|
||||
{
|
||||
struct gas_phase *gas_phase_ptr = gas_phase_alloc();
|
||||
|
||||
gas_phase_ptr->description = this->get_description();
|
||||
gas_phase_ptr->n_user = this->n_user;
|
||||
gas_phase_ptr->n_user_end = this->n_user_end;
|
||||
gas_phase_ptr->new_def = FALSE;
|
||||
gas_phase_ptr->solution_equilibria = FALSE;
|
||||
gas_phase_ptr->n_solution = -2;
|
||||
if (this->type == cxxGasPhase::GP_PRESSURE) {
|
||||
gas_phase_ptr->type = PRESSURE;
|
||||
} else {
|
||||
gas_phase_ptr->type = VOLUME;
|
||||
struct gas_phase *gas_phase_ptr = gas_phase_alloc();
|
||||
|
||||
gas_phase_ptr->description = this->get_description();
|
||||
gas_phase_ptr->n_user = this->n_user;
|
||||
gas_phase_ptr->n_user_end = this->n_user_end;
|
||||
gas_phase_ptr->new_def = FALSE;
|
||||
gas_phase_ptr->solution_equilibria = FALSE;
|
||||
gas_phase_ptr->n_solution = -2;
|
||||
if (this->type == cxxGasPhase::GP_PRESSURE)
|
||||
{
|
||||
gas_phase_ptr->type = PRESSURE;
|
||||
}
|
||||
gas_phase_ptr->total_p = this->total_p;
|
||||
gas_phase_ptr->volume = this->volume;
|
||||
gas_phase_ptr->temperature = 273.15;
|
||||
else
|
||||
{
|
||||
gas_phase_ptr->type = VOLUME;
|
||||
}
|
||||
gas_phase_ptr->total_p = this->total_p;
|
||||
gas_phase_ptr->volume = this->volume;
|
||||
gas_phase_ptr->temperature = 273.15;
|
||||
|
||||
// comps
|
||||
gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size();
|
||||
gas_phase_ptr->comps = (struct gas_comp *) free_check_null(gas_phase_ptr->comps);
|
||||
gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp();
|
||||
// comps
|
||||
gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size();
|
||||
gas_phase_ptr->comps =
|
||||
(struct gas_comp *) free_check_null(gas_phase_ptr->comps);
|
||||
gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp();
|
||||
|
||||
return(gas_phase_ptr);
|
||||
return (gas_phase_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxGasPhase::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// GasPhase element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<gas_phase " << std::endl;
|
||||
// GasPhase element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<gas_phase " << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_gas_phase_gammas=\"" << this->pitzer_gas_phase_gammas << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_gas_phase_gammas=\"" << this->
|
||||
pitzer_gas_phase_gammas << "\"" << std::endl;
|
||||
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list<cxxGasPhaseComp>::const_iterator it = gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list < cxxGasPhaseComp >::const_iterator it =
|
||||
gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxGasPhase::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// GasPhase element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "GAS_PHASE_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
// GasPhase element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "GAS_PHASE_RAW " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-type " << this->type << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-type " << this->type << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-total_p " << this->total_p << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-total_p " << this->total_p << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-volume " << this->volume << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-volume " << this->volume << std::endl;
|
||||
|
||||
// gasPhaseComps
|
||||
// gasPhaseComps
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
this->gasPhaseComps.dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
void cxxGasPhase::read_raw(CParser& parser)
|
||||
void
|
||||
cxxGasPhase::read_raw(CParser & parser)
|
||||
{
|
||||
|
||||
int i;
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("type"); //0
|
||||
vopts.push_back("total_p"); //1
|
||||
vopts.push_back("volume"); //2
|
||||
vopts.push_back("component"); //3
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("type"); //0
|
||||
vopts.push_back("total_p"); //1
|
||||
vopts.push_back("volume"); //2
|
||||
vopts.push_back("component"); //3
|
||||
}
|
||||
|
||||
// Read gas_phase number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool type_defined(false);
|
||||
bool total_p_defined(false);
|
||||
bool volume_defined(false);
|
||||
// Read gas_phase number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in GAS_PHASE_COMP_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool type_defined(false);
|
||||
bool total_p_defined(false);
|
||||
bool volume_defined(false);
|
||||
|
||||
case 0: // type
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in GAS_PHASE_COMP_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 0: // type
|
||||
if (!(parser.get_iss() >> i))
|
||||
//if (!(parser.get_iss() >> (cxxGasPhase::GP_TYPE) this->type))
|
||||
{
|
||||
this->type = cxxGasPhase::GP_PRESSURE;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected enum for type.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
//if (!(parser.get_iss() >> (cxxGasPhase::GP_TYPE) this->type))
|
||||
{
|
||||
this->type = cxxGasPhase::GP_PRESSURE;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected enum for type.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->type = (cxxGasPhase::GP_TYPE) i;
|
||||
}
|
||||
type_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
type_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 1: // total_p
|
||||
if (!(parser.get_iss() >> this->total_p))
|
||||
{
|
||||
this->total_p = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for total_p.", CParser::OT_CONTINUE);
|
||||
}
|
||||
total_p_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 1: // total_p
|
||||
if (!(parser.get_iss() >> this->total_p))
|
||||
{
|
||||
this->total_p = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for total_p.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
total_p_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 2: // volume
|
||||
if (!(parser.get_iss() >> this->volume))
|
||||
{
|
||||
this->volume = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for volume.", CParser::OT_CONTINUE);
|
||||
}
|
||||
volume_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 2: // volume
|
||||
if (!(parser.get_iss() >> this->volume))
|
||||
{
|
||||
this->volume = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for volume.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
volume_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 3: // component
|
||||
if ( this->gasPhaseComps.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected gas component name and moles for gasPhaseComps.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 3;
|
||||
useLastLine = false;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (type_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Type not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (total_p_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (volume_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
case 3: // component
|
||||
if (this->gasPhaseComps.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected gas component name and moles for gasPhaseComps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 3;
|
||||
useLastLine = false;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (type_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Type not defined for GAS_PHASE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (total_p_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (volume_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Volume not defined for GAS_PHASE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxGasPhase::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxGasPhase::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
ints.push_back(this->n_user);
|
||||
this->gasPhaseComps.mpi_pack(ints, doubles);
|
||||
if (this->type == cxxGasPhase::GP_PRESSURE) {
|
||||
if (this->type == cxxGasPhase::GP_PRESSURE)
|
||||
{
|
||||
ints.push_back(0);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ints.push_back(1);
|
||||
}
|
||||
doubles.push_back(this->total_p);
|
||||
doubles.push_back(this->volume);
|
||||
doubles.push_back(this->volume);
|
||||
}
|
||||
void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
void
|
||||
cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
int i = *ii;
|
||||
int d = *dd;
|
||||
@ -352,33 +419,40 @@ void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
this->description = " ";
|
||||
this->gasPhaseComps.mpi_unpack(ints, &i, doubles, &d);
|
||||
int n = ints[i++];
|
||||
if (n == 0) {
|
||||
if (n == 0)
|
||||
{
|
||||
this->type = cxxGasPhase::GP_PRESSURE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this->type = cxxGasPhase::GP_VOLUME;
|
||||
}
|
||||
this->total_p = doubles[d++];
|
||||
this->volume = doubles[d++];
|
||||
this->volume = doubles[d++];
|
||||
*ii = i;
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
void cxxGasPhase::totalize()
|
||||
void
|
||||
cxxGasPhase::totalize()
|
||||
{
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (cxxNameDouble::const_iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) {
|
||||
struct phase *phase_ptr;
|
||||
int l;
|
||||
phase_ptr = phase_bsearch(it->first, &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
cxxNameDouble phase_formula(phase_ptr->next_elt);
|
||||
this->totals.add_extensive(phase_formula, it->second);
|
||||
} else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return;
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (cxxNameDouble::const_iterator it = this->gasPhaseComps.begin();
|
||||
it != this->gasPhaseComps.end(); it++)
|
||||
{
|
||||
struct phase *phase_ptr;
|
||||
int l;
|
||||
phase_ptr = phase_bsearch(it->first, &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
cxxNameDouble phase_formula(phase_ptr->next_elt);
|
||||
this->totals.add_extensive(phase_formula, it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
1698
ISolution.cxx
1698
ISolution.cxx
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "ISolutionComp.h"
|
||||
@ -12,38 +12,32 @@
|
||||
#include "phqalloc.h"
|
||||
#include "output.h"
|
||||
|
||||
cxxISolutionComp::cxxISolutionComp(void)
|
||||
: description(NULL)
|
||||
, moles(0.0)
|
||||
, input_conc(0.0)
|
||||
, units(NULL)
|
||||
, equation_name(NULL)
|
||||
, phase_si(0.0)
|
||||
, n_pe(-1)
|
||||
, as(NULL)
|
||||
, gfw(0.0)
|
||||
//, skip(0);
|
||||
//, phase(NULL)
|
||||
cxxISolutionComp::cxxISolutionComp(void):description(NULL), moles(0.0), input_conc(0.0), units(NULL),
|
||||
equation_name(NULL), phase_si(0.0), n_pe(-1), as(NULL),
|
||||
gfw(0.0)
|
||||
//, skip(0);
|
||||
//, phase(NULL)
|
||||
{
|
||||
}
|
||||
cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr)
|
||||
{
|
||||
description = conc_ptr->description;
|
||||
moles = conc_ptr->moles;
|
||||
input_conc = conc_ptr->input_conc;
|
||||
units = conc_ptr->units;
|
||||
equation_name = conc_ptr->equation_name;
|
||||
phase_si = conc_ptr->phase_si;
|
||||
n_pe = conc_ptr->n_pe;
|
||||
as = conc_ptr->as;
|
||||
gfw = conc_ptr->gfw;
|
||||
//skip = conc_ptr->skip;
|
||||
//phase = conc_ptr->phase;
|
||||
description = conc_ptr->description;
|
||||
moles = conc_ptr->moles;
|
||||
input_conc = conc_ptr->input_conc;
|
||||
units = conc_ptr->units;
|
||||
equation_name = conc_ptr->equation_name;
|
||||
phase_si = conc_ptr->phase_si;
|
||||
n_pe = conc_ptr->n_pe;
|
||||
as = conc_ptr->as;
|
||||
gfw = conc_ptr->gfw;
|
||||
//skip = conc_ptr->skip;
|
||||
//phase = conc_ptr->phase;
|
||||
}
|
||||
|
||||
cxxISolutionComp::~cxxISolutionComp(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
struct conc *cxxISolutionComp::concarray(std::map <char *, double, CHARSTAR_LESS> &totals)
|
||||
// for Solutions, not ISolutions
|
||||
@ -72,205 +66,253 @@ struct conc *cxxISolutionComp::concarray(std::map <char *, double, CHARSTAR_LESS
|
||||
return(c);
|
||||
}
|
||||
*/
|
||||
struct conc *cxxISolutionComp::cxxISolutionComp2conc(const std::map <char *, cxxISolutionComp, CHARSTAR_LESS> &totals)
|
||||
// for ISolutions
|
||||
// takes a std::vector cxxISolutionComp structures
|
||||
// returns list of conc structures
|
||||
struct conc *
|
||||
cxxISolutionComp::cxxISolutionComp2conc(const std::map < char *,
|
||||
cxxISolutionComp,
|
||||
CHARSTAR_LESS > &totals)
|
||||
// for ISolutions
|
||||
// takes a std::vector cxxISolutionComp structures
|
||||
// returns list of conc structures
|
||||
{
|
||||
struct conc *c;
|
||||
c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc)));
|
||||
if (c == NULL) malloc_error();
|
||||
int i = 0;
|
||||
for (std::map<char *, cxxISolutionComp, CHARSTAR_LESS>::const_iterator it = totals.begin(); it != totals.end(); ++it) {
|
||||
c[i].description = it->second.description;
|
||||
c[i].moles = it->second.moles;
|
||||
c[i].input_conc = it->second.input_conc;
|
||||
c[i].units = it->second.units;
|
||||
c[i].equation_name = it->second.equation_name;
|
||||
c[i].phase_si = it->second.phase_si;
|
||||
c[i].n_pe = it->second.n_pe;
|
||||
c[i].as = it->second.as;
|
||||
c[i].gfw = it->second.gfw;
|
||||
//c[i].skip = 0;
|
||||
c[i].phase = NULL;
|
||||
i++;
|
||||
}
|
||||
c[i].description = NULL;
|
||||
return(c);
|
||||
struct conc *c;
|
||||
c = (struct conc *)
|
||||
PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc)));
|
||||
if (c == NULL)
|
||||
malloc_error();
|
||||
int i = 0;
|
||||
for (std::map < char *, cxxISolutionComp,
|
||||
CHARSTAR_LESS >::const_iterator it = totals.begin();
|
||||
it != totals.end(); ++it)
|
||||
{
|
||||
c[i].description = it->second.description;
|
||||
c[i].moles = it->second.moles;
|
||||
c[i].input_conc = it->second.input_conc;
|
||||
c[i].units = it->second.units;
|
||||
c[i].equation_name = it->second.equation_name;
|
||||
c[i].phase_si = it->second.phase_si;
|
||||
c[i].n_pe = it->second.n_pe;
|
||||
c[i].as = it->second.as;
|
||||
c[i].gfw = it->second.gfw;
|
||||
//c[i].skip = 0;
|
||||
c[i].phase = NULL;
|
||||
i++;
|
||||
}
|
||||
c[i].description = NULL;
|
||||
return (c);
|
||||
}
|
||||
|
||||
void cxxISolutionComp::set_gfw()
|
||||
void
|
||||
cxxISolutionComp::set_gfw()
|
||||
{
|
||||
// return gfw
|
||||
if (this->gfw > 0.0) return;
|
||||
if (this->gfw > 0.0)
|
||||
return;
|
||||
// calculate gfw from as or from master species gfw
|
||||
if (this->as != NULL)
|
||||
{
|
||||
/* use given chemical formula to calculate gfw */
|
||||
double gfw;
|
||||
if (compute_gfw (this->as, &gfw) == ERROR)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Could not compute gfw, " << this->as;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
//if (this->description == "Alkalinity" && this->as == "CaCO3")
|
||||
if (strcmp(this->description,"Alkalinity") == 0 && strcmp(this->as, "CaCO3"))
|
||||
{
|
||||
gfw /= 2.;
|
||||
}
|
||||
this->gfw = gfw;
|
||||
return;
|
||||
}
|
||||
/* use gfw of master species */
|
||||
std::string str(this->description);
|
||||
struct master *master_ptr = master_bsearch (str.c_str());
|
||||
if (master_ptr != NULL)
|
||||
{
|
||||
/* use gfw for element redox state */
|
||||
this->gfw = master_ptr->gfw;
|
||||
return;
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << "Could not find gfw, " << this->description;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
if (this->as != NULL)
|
||||
{
|
||||
/* use given chemical formula to calculate gfw */
|
||||
double gfw;
|
||||
if (compute_gfw(this->as, &gfw) == ERROR)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Could not compute gfw, " << this->as;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
//if (this->description == "Alkalinity" && this->as == "CaCO3")
|
||||
if (strcmp(this->description, "Alkalinity") == 0
|
||||
&& strcmp(this->as, "CaCO3"))
|
||||
{
|
||||
gfw /= 2.;
|
||||
}
|
||||
this->gfw = gfw;
|
||||
return;
|
||||
}
|
||||
/* use gfw of master species */
|
||||
std::string str(this->description);
|
||||
struct master *master_ptr = master_bsearch(str.c_str());
|
||||
if (master_ptr != NULL)
|
||||
{
|
||||
/* use gfw for element redox state */
|
||||
this->gfw = master_ptr->gfw;
|
||||
return;
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << "Could not find gfw, " << this->description;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#ifdef SKIP
|
||||
cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser& parser, cxxISolution& solution)
|
||||
cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser,
|
||||
cxxISolution & solution)
|
||||
{
|
||||
// std::string& str = parser.line();
|
||||
std::string str = parser.line();
|
||||
// std::string& str = parser.line();
|
||||
std::string str = parser.line();
|
||||
|
||||
// defaults set in ctor
|
||||
// defaults set in ctor
|
||||
|
||||
// Remove space between "kg" and "solution" or "water" in units
|
||||
Utilities::replace("Kg", "kg", str);
|
||||
Utilities::replace("KG", "kg", str);
|
||||
while (Utilities::replace("kg ", "kg", str));
|
||||
// Remove space between "kg" and "solution" or "water" in units
|
||||
Utilities::replace("Kg", "kg", str);
|
||||
Utilities::replace("KG", "kg", str);
|
||||
while (Utilities::replace("kg ", "kg", str));
|
||||
|
||||
std::istream::pos_type ptr = 0;
|
||||
std::istream::pos_type ptr = 0;
|
||||
|
||||
//
|
||||
// Read master species list for mass balance equation
|
||||
//
|
||||
std::string token;
|
||||
std::string token1;
|
||||
int count_redox_states = 0;
|
||||
CParser::TOKEN_TYPE j;
|
||||
while ( ((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER ) ||
|
||||
( token[0] == '[' ) ||
|
||||
( Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0 ) ||
|
||||
( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) )
|
||||
{
|
||||
++count_redox_states;
|
||||
Utilities::replace("(+", "(", token);
|
||||
if (count_redox_states > 1) token1 += " ";
|
||||
token1 += token;
|
||||
}
|
||||
if (count_redox_states == 0) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("No element or master species given for concentration input.", CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
description = token1;
|
||||
//
|
||||
// Read master species list for mass balance equation
|
||||
//
|
||||
std::string token;
|
||||
std::string token1;
|
||||
int
|
||||
count_redox_states = 0;
|
||||
CParser::TOKEN_TYPE j;
|
||||
while (((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER) ||
|
||||
(token[0] == '[') ||
|
||||
(Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0) ||
|
||||
(Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0))
|
||||
{
|
||||
++count_redox_states;
|
||||
Utilities::replace("(+", "(", token);
|
||||
if (count_redox_states > 1)
|
||||
token1 += " ";
|
||||
token1 += token;
|
||||
}
|
||||
if (count_redox_states == 0)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("No element or master species given for concentration input.",
|
||||
CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
description = token1;
|
||||
|
||||
// Determine if reading alkalinity, allow equivalents for units
|
||||
Utilities::str_tolower(token1);
|
||||
bool alk = false;
|
||||
if (token1.find("alk") == 0) {
|
||||
alk = true;
|
||||
}
|
||||
// Determine if reading alkalinity, allow equivalents for units
|
||||
Utilities::str_tolower(token1);
|
||||
bool
|
||||
alk = false;
|
||||
if (token1.find("alk") == 0)
|
||||
{
|
||||
alk = true;
|
||||
}
|
||||
|
||||
// Read concentration
|
||||
if (!(std::istringstream(token) >> this->input_conc)) {
|
||||
std::ostringstream err;
|
||||
err << "Concentration data error for " << token1 << " in solution input.";
|
||||
parser.error_msg(err, CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
// Read concentration
|
||||
if (!(std::istringstream(token) >> this->input_conc))
|
||||
{
|
||||
std::ostringstream err;
|
||||
err << "Concentration data error for " << token1 <<
|
||||
" in solution input.";
|
||||
parser.error_msg(err, CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
|
||||
// Read optional data
|
||||
token1 = token;
|
||||
|
||||
// Check for units info
|
||||
if (parser.check_units(token1, alk, false, solution.get_units(), false) == CParser::OK) {
|
||||
if (parser.check_units(token1, alk, false, solution.get_units(), true) == CParser::OK) {
|
||||
this->units = token1;
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
} else {
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
}
|
||||
// Read optional data
|
||||
token1 = token;
|
||||
|
||||
// Check for "as" followed by formula to be used for gfw
|
||||
token1 = token;
|
||||
Utilities::str_tolower(token1);
|
||||
if (token1.compare("as") == 0)
|
||||
{
|
||||
parser.copy_token(token, ptr);
|
||||
this->as = token;
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
}
|
||||
// Check for "gfw" followed by gram formula weight
|
||||
else if (token1.compare("gfw") == 0)
|
||||
{
|
||||
if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) {
|
||||
parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
} else {
|
||||
parser.get_iss() >> this->gfw;
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
}
|
||||
}
|
||||
// Check for units info
|
||||
if (parser.check_units(token1, alk, false, solution.get_units(), false) ==
|
||||
CParser::OK)
|
||||
{
|
||||
if (parser.
|
||||
check_units(token1, alk, false, solution.get_units(),
|
||||
true) == CParser::OK)
|
||||
{
|
||||
this->units = token1;
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for redox couple for pe
|
||||
if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) {
|
||||
this->n_pe = cxxPe_Data::store(solution.pe, token);
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
} else if (token.find("/") != std::string::npos) {
|
||||
if (parser.parse_couple(token) == CParser::OK) {
|
||||
this->n_pe = cxxPe_Data::store(solution.pe, token);
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
} else {
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
}
|
||||
// Check for "as" followed by formula to be used for gfw
|
||||
token1 = token;
|
||||
Utilities::str_tolower(token1);
|
||||
if (token1.compare("as") == 0)
|
||||
{
|
||||
parser.copy_token(token, ptr);
|
||||
this->as = token;
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
}
|
||||
// Check for "gfw" followed by gram formula weight
|
||||
else if (token1.compare("gfw") == 0)
|
||||
{
|
||||
if (parser.copy_token(token, ptr) != CParser::TT_DIGIT)
|
||||
{
|
||||
parser.error_msg("Expecting gram formula weight.",
|
||||
CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.get_iss() >> this->gfw;
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Must have phase
|
||||
this->equation_name = token;
|
||||
if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK;
|
||||
// Check for redox couple for pe
|
||||
if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0)
|
||||
{
|
||||
this->n_pe = cxxPe_Data::store(solution.pe, token);
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
}
|
||||
else if (token.find("/") != std::string::npos)
|
||||
{
|
||||
if (parser.parse_couple(token) == CParser::OK)
|
||||
{
|
||||
this->n_pe = cxxPe_Data::store(solution.pe, token);
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for saturation index
|
||||
if (!(std::istringstream(token) >> this->phase_si))
|
||||
{
|
||||
parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
return cxxISolutionComp::OK;
|
||||
// Must have phase
|
||||
this->equation_name = token;
|
||||
if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY)
|
||||
return cxxISolutionComp::OK;
|
||||
|
||||
// Check for saturation index
|
||||
if (!(std::istringstream(token) >> this->phase_si))
|
||||
{
|
||||
parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE);
|
||||
return cxxISolutionComp::ERROR;
|
||||
}
|
||||
return cxxISolutionComp::OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxISolutionComp::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxISolutionComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
unsigned int i;
|
||||
std::string indent0("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
unsigned int i;
|
||||
std::string indent0("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
|
||||
s_oss << indent0;
|
||||
s_oss << "<soln_total" ;
|
||||
s_oss << indent0;
|
||||
s_oss << "<soln_total";
|
||||
|
||||
s_oss << " conc_desc=\"" << this->description << "\"" ;
|
||||
s_oss << " conc_desc=\"" << this->description << "\"";
|
||||
|
||||
s_oss << " conc_moles=\"" << this->moles << "\"" ;
|
||||
s_oss << " conc_moles=\"" << this->moles << "\"";
|
||||
|
||||
s_oss << "\">" << std::endl;
|
||||
s_oss << "\">" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
636
KineticsComp.cxx
636
KineticsComp.cxx
@ -2,330 +2,394 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "KineticsComp.h"
|
||||
#include "Dictionary.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxKineticsComp::cxxKineticsComp()
|
||||
//
|
||||
// default constructor for cxxKineticsComp
|
||||
//
|
||||
//
|
||||
// default constructor for cxxKineticsComp
|
||||
//
|
||||
{
|
||||
rate_name = NULL;
|
||||
tol = 1e-8;
|
||||
m = 0.0;
|
||||
m0 = 0.0;
|
||||
moles = 0.0;
|
||||
namecoef.type = cxxNameDouble::ND_NAME_COEF;
|
||||
rate_name = NULL;
|
||||
tol = 1e-8;
|
||||
m = 0.0;
|
||||
m0 = 0.0;
|
||||
moles = 0.0;
|
||||
namecoef.type = cxxNameDouble::ND_NAME_COEF;
|
||||
}
|
||||
|
||||
cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr)
|
||||
//
|
||||
// constructor for cxxKineticsComp from struct kinetics_comp
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxKineticsComp from struct kinetics_comp
|
||||
//
|
||||
:
|
||||
namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list)
|
||||
{
|
||||
rate_name = kinetics_comp_ptr->rate_name;
|
||||
tol = kinetics_comp_ptr->tol;
|
||||
m = kinetics_comp_ptr->m;
|
||||
m0 = kinetics_comp_ptr->m0;
|
||||
moles = kinetics_comp_ptr->moles;
|
||||
for (int i = 0; i < kinetics_comp_ptr->count_d_params; i++) {
|
||||
this->d_params.push_back(kinetics_comp_ptr->d_params[i]);
|
||||
}
|
||||
rate_name = kinetics_comp_ptr->rate_name;
|
||||
tol = kinetics_comp_ptr->tol;
|
||||
m = kinetics_comp_ptr->m;
|
||||
m0 = kinetics_comp_ptr->m0;
|
||||
moles = kinetics_comp_ptr->moles;
|
||||
for (int i = 0; i < kinetics_comp_ptr->count_d_params; i++)
|
||||
{
|
||||
this->d_params.push_back(kinetics_comp_ptr->d_params[i]);
|
||||
}
|
||||
}
|
||||
|
||||
cxxKineticsComp::~cxxKineticsComp()
|
||||
{
|
||||
}
|
||||
|
||||
struct kinetics_comp *cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list<cxxKineticsComp>& el)
|
||||
//
|
||||
// Builds kinetics_comp structure from of cxxKineticsComp
|
||||
//
|
||||
struct kinetics_comp *
|
||||
cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp >
|
||||
&el)
|
||||
//
|
||||
// Builds kinetics_comp structure from of cxxKineticsComp
|
||||
//
|
||||
{
|
||||
struct kinetics_comp *kinetics_comp_ptr = (struct kinetics_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp)));
|
||||
if (kinetics_comp_ptr == NULL) malloc_error();
|
||||
struct kinetics_comp *kinetics_comp_ptr =
|
||||
(struct kinetics_comp *)
|
||||
PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp)));
|
||||
if (kinetics_comp_ptr == NULL)
|
||||
malloc_error();
|
||||
|
||||
int i = 0;
|
||||
for (std::list<cxxKineticsComp>::iterator it = el.begin(); it != el.end(); ++it) {
|
||||
kinetics_comp_ptr[i].rate_name = it->rate_name;
|
||||
kinetics_comp_ptr[i].list = it->namecoef.name_coef();
|
||||
kinetics_comp_ptr[i].count_list = (int) it->namecoef.size();
|
||||
kinetics_comp_ptr[i].tol = it->tol;
|
||||
kinetics_comp_ptr[i].m = it->m;
|
||||
kinetics_comp_ptr[i].initial_moles = 0.;
|
||||
kinetics_comp_ptr[i].m0 = it->m0;
|
||||
kinetics_comp_ptr[i].moles = it->moles;
|
||||
kinetics_comp_ptr[i].count_c_params = 0;
|
||||
kinetics_comp_ptr[i].c_params = NULL;
|
||||
int i = 0;
|
||||
for (std::list < cxxKineticsComp >::iterator it = el.begin();
|
||||
it != el.end(); ++it)
|
||||
{
|
||||
kinetics_comp_ptr[i].rate_name = it->rate_name;
|
||||
kinetics_comp_ptr[i].list = it->namecoef.name_coef();
|
||||
kinetics_comp_ptr[i].count_list = (int) it->namecoef.size();
|
||||
kinetics_comp_ptr[i].tol = it->tol;
|
||||
kinetics_comp_ptr[i].m = it->m;
|
||||
kinetics_comp_ptr[i].initial_moles = 0.;
|
||||
kinetics_comp_ptr[i].m0 = it->m0;
|
||||
kinetics_comp_ptr[i].moles = it->moles;
|
||||
kinetics_comp_ptr[i].count_c_params = 0;
|
||||
kinetics_comp_ptr[i].c_params = NULL;
|
||||
/*
|
||||
kinetics_comp_ptr[i].count_d_params = 0;
|
||||
kinetics_comp_ptr[i].d_params = NULL;
|
||||
*/
|
||||
|
||||
kinetics_comp_ptr[i].count_d_params = (int) it->d_params.size();
|
||||
kinetics_comp_ptr[i].d_params = NULL;
|
||||
if (it->d_params.size() > 0) {
|
||||
kinetics_comp_ptr[i].d_params = (double *) PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double)));
|
||||
if (kinetics_comp_ptr[i].d_params == NULL) malloc_error();
|
||||
std::copy(it->d_params.begin(), it->d_params.end(), kinetics_comp_ptr[i].d_params);
|
||||
}
|
||||
kinetics_comp_ptr[i].count_d_params = (int) it->d_params.size();
|
||||
kinetics_comp_ptr[i].d_params = NULL;
|
||||
if (it->d_params.size() > 0)
|
||||
{
|
||||
kinetics_comp_ptr[i].d_params =
|
||||
(double *)
|
||||
PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double)));
|
||||
if (kinetics_comp_ptr[i].d_params == NULL)
|
||||
malloc_error();
|
||||
std::copy(it->d_params.begin(), it->d_params.end(),
|
||||
kinetics_comp_ptr[i].d_params);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return(kinetics_comp_ptr);
|
||||
}
|
||||
return (kinetics_comp_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxKineticsComp::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Kinetics_Comp element and attributes
|
||||
// Kinetics_Comp element and attributes
|
||||
|
||||
s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl;
|
||||
s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl;
|
||||
s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl;
|
||||
if (this->phase_name != NULL) {
|
||||
s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl;
|
||||
}
|
||||
if (this->rate_name != NULL) {
|
||||
s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl;
|
||||
}
|
||||
s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl;
|
||||
s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl;
|
||||
s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl;
|
||||
s_oss << indent0 << "charge_balance=\"" << this->
|
||||
charge_balance << "\"" << std::endl;
|
||||
if (this->phase_name != NULL)
|
||||
{
|
||||
s_oss << indent0 << "phase_name=\"" << this->
|
||||
phase_name << "\"" << std::endl;
|
||||
}
|
||||
if (this->rate_name != NULL)
|
||||
{
|
||||
s_oss << indent0 << "rate_name=\"" << this->
|
||||
rate_name << "\"" << std::endl;
|
||||
}
|
||||
s_oss << indent0 << "phase_proportion=\"" << this->
|
||||
phase_proportion << "\"" << std::endl;
|
||||
|
||||
// totals
|
||||
s_oss << indent0;
|
||||
s_oss << "<totals " << std::endl;
|
||||
this->totals.dump_xml(s_oss, indent + 1);
|
||||
// totals
|
||||
s_oss << indent0;
|
||||
s_oss << "<totals " << std::endl;
|
||||
this->totals.dump_xml(s_oss, indent + 1);
|
||||
|
||||
// formula_totals
|
||||
s_oss << indent0;
|
||||
s_oss << "<formula_totals " << std::endl;
|
||||
this->formula_totals.dump_xml(s_oss, indent + 1);
|
||||
// formula_totals
|
||||
s_oss << indent0;
|
||||
s_oss << "<formula_totals " << std::endl;
|
||||
this->formula_totals.dump_xml(s_oss, indent + 1);
|
||||
}
|
||||
#endif
|
||||
void cxxKineticsComp::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Kinetics_Comp element and attributes
|
||||
// Kinetics_Comp element and attributes
|
||||
|
||||
s_oss << indent0 << "-rate_name " << this->rate_name << std::endl;
|
||||
s_oss << indent0 << "-tol " << this->tol << std::endl;
|
||||
s_oss << indent0 << "-m " << this->m << std::endl;
|
||||
s_oss << indent0 << "-m0 " << this->m0 << std::endl;
|
||||
s_oss << indent0 << "-moles " << this->moles << std::endl;
|
||||
s_oss << indent0 << "-rate_name " << this->
|
||||
rate_name << std::endl;
|
||||
s_oss << indent0 << "-tol " << this->tol << std::endl;
|
||||
s_oss << indent0 << "-m " << this->m << std::endl;
|
||||
s_oss << indent0 << "-m0 " << this->m0 << std::endl;
|
||||
s_oss << indent0 << "-moles " << this->moles << std::endl;
|
||||
|
||||
// namecoef
|
||||
s_oss << indent0;
|
||||
s_oss << "-namecoef" << std::endl;
|
||||
this->namecoef.dump_raw(s_oss, indent + 1);
|
||||
// namecoef
|
||||
s_oss << indent0;
|
||||
s_oss << "-namecoef" << std::endl;
|
||||
this->namecoef.dump_raw(s_oss, indent + 1);
|
||||
|
||||
// d_params
|
||||
s_oss << indent0;
|
||||
s_oss << "-d_params" << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent1;
|
||||
for (std::vector<double>::const_iterator it = d_params.begin(); it != d_params.end(); it++) {
|
||||
if (i++ == 5) {
|
||||
s_oss << std::endl;
|
||||
s_oss << indent1;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
// d_params
|
||||
s_oss << indent0;
|
||||
s_oss << "-d_params" << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent1;
|
||||
for (std::vector < double >::const_iterator it = d_params.begin();
|
||||
it != d_params.end(); it++)
|
||||
{
|
||||
if (i++ == 5)
|
||||
{
|
||||
s_oss << std::endl;
|
||||
s_oss << indent1;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void cxxKineticsComp::read_raw(CParser& parser)
|
||||
void
|
||||
cxxKineticsComp::read_raw(CParser & parser)
|
||||
{
|
||||
std::string str;
|
||||
double d;
|
||||
std::string str;
|
||||
double d;
|
||||
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("rate_name"); // 0
|
||||
vopts.push_back("tol"); // 1
|
||||
vopts.push_back("m"); // 2
|
||||
vopts.push_back("m0"); // 3
|
||||
vopts.push_back("moles"); // 4
|
||||
vopts.push_back("namecoef"); // 5
|
||||
vopts.push_back("d_params"); // 6
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("rate_name"); // 0
|
||||
vopts.push_back("tol"); // 1
|
||||
vopts.push_back("m"); // 2
|
||||
vopts.push_back("m0"); // 3
|
||||
vopts.push_back("moles"); // 4
|
||||
vopts.push_back("namecoef"); // 5
|
||||
vopts.push_back("d_params"); // 6
|
||||
}
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool rate_name_defined(false);
|
||||
bool tol_defined(false);
|
||||
bool m_defined(false);
|
||||
bool m0_defined(false);
|
||||
bool moles_defined(false);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool rate_name_defined(false);
|
||||
bool tol_defined(false);
|
||||
bool m_defined(false);
|
||||
bool m0_defined(false);
|
||||
bool moles_defined(false);
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Kinetics for more processing
|
||||
//parser.error_msg("Unknown input in KINETICS_COMP read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
|
||||
case 0: // rate_name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->rate_name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
this->rate_name = string_hsave(str.c_str());
|
||||
}
|
||||
rate_name_defined = true;
|
||||
break;
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Kinetics for more processing
|
||||
//parser.error_msg("Unknown input in KINETICS_COMP read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
|
||||
case 1: // tol
|
||||
if (!(parser.get_iss() >> this->tol))
|
||||
{
|
||||
this->tol = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for tol.", CParser::OT_CONTINUE);
|
||||
}
|
||||
tol_defined = true;
|
||||
break;
|
||||
case 0: // rate_name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->rate_name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for rate_name.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->rate_name = string_hsave(str.c_str());
|
||||
}
|
||||
rate_name_defined = true;
|
||||
break;
|
||||
|
||||
case 2: // m
|
||||
if (!(parser.get_iss() >> this->m))
|
||||
{
|
||||
this->m = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for m.", CParser::OT_CONTINUE);
|
||||
}
|
||||
m_defined = true;
|
||||
break;
|
||||
case 1: // tol
|
||||
if (!(parser.get_iss() >> this->tol))
|
||||
{
|
||||
this->tol = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for tol.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
tol_defined = true;
|
||||
break;
|
||||
|
||||
case 3: // m0
|
||||
if (!(parser.get_iss() >> this->m0))
|
||||
{
|
||||
this->m0 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for m0.", CParser::OT_CONTINUE);
|
||||
}
|
||||
m0_defined = true;
|
||||
break;
|
||||
case 2: // m
|
||||
if (!(parser.get_iss() >> this->m))
|
||||
{
|
||||
this->m = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for m.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
m_defined = true;
|
||||
break;
|
||||
|
||||
case 3: // m0
|
||||
if (!(parser.get_iss() >> this->m0))
|
||||
{
|
||||
this->m0 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for m0.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
m0_defined = true;
|
||||
break;
|
||||
|
||||
|
||||
case 4: // moles
|
||||
if (!(parser.get_iss() >> this->moles))
|
||||
{
|
||||
this->moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE);
|
||||
}
|
||||
moles_defined = true;
|
||||
break;
|
||||
case 4: // moles
|
||||
if (!(parser.get_iss() >> this->moles))
|
||||
{
|
||||
this->moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for moles.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
moles_defined = true;
|
||||
break;
|
||||
|
||||
|
||||
case 5: // namecoef
|
||||
if ( this->namecoef.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected element name and molality for namecoef.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 5;
|
||||
break;
|
||||
case 5: // namecoef
|
||||
if (this->namecoef.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected element name and molality for namecoef.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 5;
|
||||
break;
|
||||
|
||||
case 6: // d_params
|
||||
while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) {
|
||||
sscanf(token.c_str(), "%lf", &d);
|
||||
this->d_params.push_back(d);
|
||||
}
|
||||
opt_save = 6;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (rate_name_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Rate_name not defined for KineticsComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (tol_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Tol not defined for KineticsComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (m_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("M not defined for KineticsComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (m0_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("M0 not defined for KineticsComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (moles_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Moles not defined for KineticsComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
case 6: // d_params
|
||||
while (parser.copy_token(token, next_char) == CParser::TT_DIGIT)
|
||||
{
|
||||
sscanf(token.c_str(), "%lf", &d);
|
||||
this->d_params.push_back(d);
|
||||
}
|
||||
opt_save = 6;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (rate_name_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Rate_name not defined for KineticsComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (tol_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Tol not defined for KineticsComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (m_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("M not defined for KineticsComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (m0_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("M0 not defined for KineticsComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (moles_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Moles not defined for KineticsComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxKineticsComp::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxKineticsComp::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
ints.push_back(dictionary.string2int(this->rate_name));
|
||||
this->namecoef.mpi_pack(ints, doubles);
|
||||
doubles.push_back(this->tol);
|
||||
doubles.push_back(this->m);
|
||||
doubles.push_back(this->m0);
|
||||
doubles.push_back(this->moles);
|
||||
doubles.push_back(this->m);
|
||||
doubles.push_back(this->m0);
|
||||
doubles.push_back(this->moles);
|
||||
ints.push_back((int) this->d_params.size());
|
||||
for (std::vector<double>::iterator it = this->d_params.begin(); it != this->d_params.end(); it++) {
|
||||
for (std::vector < double >::iterator it = this->d_params.begin();
|
||||
it != this->d_params.end(); it++)
|
||||
{
|
||||
doubles.push_back(*it);
|
||||
}
|
||||
}
|
||||
void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
void
|
||||
cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
int i = *ii;
|
||||
@ -333,50 +397,56 @@ void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
this->rate_name = dictionary.int2char(ints[i++]);
|
||||
this->namecoef.mpi_unpack(ints, &i, doubles, &d);
|
||||
this->tol = doubles[d++];
|
||||
this->m = doubles[d++];
|
||||
this->m0 = doubles[d++];
|
||||
this->moles = doubles[d++];
|
||||
this->m = doubles[d++];
|
||||
this->m0 = doubles[d++];
|
||||
this->moles = doubles[d++];
|
||||
int n = ints[i++];
|
||||
this->d_params.clear();
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
this->d_params.push_back(doubles[d++]);
|
||||
}
|
||||
*ii = i;
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
void cxxKineticsComp::add(const cxxKineticsComp &addee, double extensive)
|
||||
void
|
||||
cxxKineticsComp::add(const cxxKineticsComp & addee, double extensive)
|
||||
{
|
||||
if (extensive == 0.0) return;
|
||||
if (addee.rate_name == NULL) return;
|
||||
// this and addee must have same name
|
||||
// otherwise generate a new KineticsComp with multiply
|
||||
if (this->rate_name == NULL && addee.rate_name == NULL) {
|
||||
return;
|
||||
}
|
||||
//char * rate_name;
|
||||
assert (this->rate_name == addee.rate_name);
|
||||
//cxxNameDouble namecoef;
|
||||
//double tol;
|
||||
//double m;
|
||||
this->m += addee.m * extensive;
|
||||
//double m0;
|
||||
this->m0 += addee.m0 * extensive;
|
||||
//double moles;
|
||||
this->moles += addee.moles * extensive;
|
||||
//std::vector<double> d_params;
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
if (addee.rate_name == NULL)
|
||||
return;
|
||||
// this and addee must have same name
|
||||
// otherwise generate a new KineticsComp with multiply
|
||||
if (this->rate_name == NULL && addee.rate_name == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//char * rate_name;
|
||||
assert(this->rate_name == addee.rate_name);
|
||||
//cxxNameDouble namecoef;
|
||||
//double tol;
|
||||
//double m;
|
||||
this->m += addee.m * extensive;
|
||||
//double m0;
|
||||
this->m0 += addee.m0 * extensive;
|
||||
//double moles;
|
||||
this->moles += addee.moles * extensive;
|
||||
//std::vector<double> d_params;
|
||||
}
|
||||
|
||||
void cxxKineticsComp::multiply(double extensive)
|
||||
void
|
||||
cxxKineticsComp::multiply(double extensive)
|
||||
{
|
||||
//char * rate_name;
|
||||
//cxxNameDouble namecoef;
|
||||
//double tol;
|
||||
//double m;
|
||||
this->m *= extensive;
|
||||
//double m0;
|
||||
this->m0 *= extensive;
|
||||
//double moles;
|
||||
this->moles *= extensive;
|
||||
//std::vector<double> d_params;
|
||||
//char * rate_name;
|
||||
//cxxNameDouble namecoef;
|
||||
//double tol;
|
||||
//double m;
|
||||
this->m *= extensive;
|
||||
//double m0;
|
||||
this->m0 *= extensive;
|
||||
//double moles;
|
||||
this->moles *= extensive;
|
||||
//std::vector<double> d_params;
|
||||
}
|
||||
|
||||
702
NameDouble.cxx
702
NameDouble.cxx
@ -2,11 +2,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include <iostream> // std::cout std::cerr
|
||||
#include "Utils.h" // define first
|
||||
#include <iostream> // std::cout std::cerr
|
||||
#include "Utils.h" // define first
|
||||
#include "NameDouble.h"
|
||||
#include "Dictionary.h"
|
||||
#define EXTERNAL extern
|
||||
@ -14,415 +14,511 @@
|
||||
#include "output.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <map> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <map> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxNameDouble::cxxNameDouble()
|
||||
//
|
||||
// default constructor for cxxNameDouble
|
||||
//
|
||||
cxxNameDouble::cxxNameDouble()
|
||||
//
|
||||
// default constructor for cxxNameDouble
|
||||
//
|
||||
{
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
{
|
||||
int i;
|
||||
if (elt_list_ptr != NULL) {
|
||||
for (i = 0; elt_list_ptr[i].elt != NULL; i++) {
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
int i;
|
||||
if (elt_list_ptr != NULL)
|
||||
{
|
||||
for (i = 0; elt_list_ptr[i].elt != NULL; i++)
|
||||
{
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr, int count)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list with known count
|
||||
//
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list with known count
|
||||
//
|
||||
{
|
||||
int i;
|
||||
if (elt_list_ptr != NULL) {
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
int i;
|
||||
if (elt_list_ptr != NULL)
|
||||
{
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(const cxxNameDouble &old, double factor)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
cxxNameDouble::cxxNameDouble(const cxxNameDouble & old, double factor)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
{
|
||||
for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) {
|
||||
if (old.type == ND_ELT_MOLES) {
|
||||
if (it->second * factor > 0) {
|
||||
for (cxxNameDouble::const_iterator it = old.begin(); it != old.end();
|
||||
it++)
|
||||
{
|
||||
if (old.type == ND_ELT_MOLES)
|
||||
{
|
||||
if (it->second * factor > 0)
|
||||
{
|
||||
(*this)[(it->first)] = it->second * factor;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
(*this)[(it->first)] = it->second * factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->type = old.type;
|
||||
}
|
||||
cxxNameDouble::cxxNameDouble(struct conc *tots)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
{
|
||||
int i;
|
||||
for (i = 0; tots[i].description != NULL; i++) {
|
||||
(*this)[tots[i].description] = tots[i].moles;
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
int i;
|
||||
for (i = 0; tots[i].description != NULL; i++)
|
||||
{
|
||||
(*this)[tots[i].description] = tots[i].moles;
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDouble::ND_TYPE type)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count,
|
||||
cxxNameDouble::ND_TYPE type)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (ma[i].description == NULL) continue;
|
||||
(*this)[ma[i].description] = ma[i].la;
|
||||
}
|
||||
this->type = type;
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (ma[i].description == NULL)
|
||||
continue;
|
||||
(*this)[ma[i].description] = ma[i].la;
|
||||
}
|
||||
this->type = type;
|
||||
}
|
||||
cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (nc[i].name == NULL) continue;
|
||||
(*this)[nc[i].name] = nc[i].coef;
|
||||
}
|
||||
this->type = ND_NAME_COEF;
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (nc[i].name == NULL)
|
||||
continue;
|
||||
(*this)[nc[i].name] = nc[i].coef;
|
||||
}
|
||||
this->type = ND_NAME_COEF;
|
||||
}
|
||||
|
||||
cxxNameDouble::~cxxNameDouble()
|
||||
{
|
||||
}
|
||||
|
||||
struct elt_list *cxxNameDouble::elt_list()
|
||||
//
|
||||
// Builds a exch_comp structure from instance of cxxNameDouble
|
||||
//
|
||||
struct elt_list *
|
||||
cxxNameDouble::elt_list()
|
||||
//
|
||||
// Builds a exch_comp structure from instance of cxxNameDouble
|
||||
//
|
||||
{
|
||||
assert (this->type == cxxNameDouble::ND_ELT_MOLES);
|
||||
struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((size_t)((this->size() + 1) *sizeof(struct elt_list)));
|
||||
if (elt_list_ptr == NULL) malloc_error();
|
||||
int i = 0;
|
||||
for (iterator it = this->begin(); it != this->end(); ++it) {
|
||||
elt_list_ptr[i].elt = element_store(it->first);
|
||||
elt_list_ptr[i].coef = it->second;
|
||||
i++;
|
||||
}
|
||||
elt_list_ptr[i].elt = NULL;
|
||||
elt_list_ptr[i].coef = 0;
|
||||
return(elt_list_ptr);
|
||||
assert(this->type == cxxNameDouble::ND_ELT_MOLES);
|
||||
struct elt_list *elt_list_ptr =
|
||||
(struct elt_list *)
|
||||
PHRQ_malloc((size_t) ((this->size() + 1) * sizeof(struct elt_list)));
|
||||
if (elt_list_ptr == NULL)
|
||||
malloc_error();
|
||||
int i = 0;
|
||||
for (iterator it = this->begin(); it != this->end(); ++it)
|
||||
{
|
||||
elt_list_ptr[i].elt = element_store(it->first);
|
||||
elt_list_ptr[i].coef = it->second;
|
||||
i++;
|
||||
}
|
||||
elt_list_ptr[i].elt = NULL;
|
||||
elt_list_ptr[i].coef = 0;
|
||||
return (elt_list_ptr);
|
||||
}
|
||||
|
||||
struct master_activity *cxxNameDouble::master_activity()const
|
||||
//
|
||||
// Builds a list of master_activity structures from instance of cxxNameDouble
|
||||
//
|
||||
struct master_activity *
|
||||
cxxNameDouble::master_activity() const const
|
||||
//
|
||||
// Builds a list of master_activity structures from instance of cxxNameDouble
|
||||
//
|
||||
{
|
||||
int i = 0;
|
||||
assert (this->type == cxxNameDouble::ND_SPECIES_LA || this->type == cxxNameDouble::ND_SPECIES_GAMMA);
|
||||
struct master_activity *master_activity_ptr = NULL;
|
||||
switch ((*this).type) {
|
||||
case cxxNameDouble::ND_SPECIES_LA:
|
||||
{
|
||||
master_activity_ptr= (struct master_activity *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct master_activity)));
|
||||
if (master_activity_ptr == NULL) malloc_error();
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++) {
|
||||
master_activity_ptr[i].description = (char *)it->first;
|
||||
master_activity_ptr[i].la = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
master_activity_ptr[i].description = NULL;
|
||||
break;
|
||||
case cxxNameDouble::ND_SPECIES_GAMMA:
|
||||
{
|
||||
if ((*this).size() > 0) {
|
||||
master_activity_ptr = (struct master_activity *) PHRQ_malloc((size_t) (((*this).size()) * sizeof(struct master_activity)));
|
||||
if (master_activity_ptr == NULL) malloc_error();
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++) {
|
||||
master_activity_ptr[i].description = (char *)it->first;
|
||||
master_activity_ptr[i].la = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case cxxNameDouble::ND_ELT_MOLES:
|
||||
case cxxNameDouble::ND_NAME_COEF:
|
||||
break;
|
||||
}
|
||||
return(master_activity_ptr);
|
||||
}
|
||||
|
||||
struct conc *cxxNameDouble::conc()const
|
||||
// for Solutions, not ISolutions
|
||||
// takes a map of (elt name, moles)
|
||||
// returns list of conc structures
|
||||
{
|
||||
struct conc *c;
|
||||
assert (this->type == cxxNameDouble::ND_ELT_MOLES);
|
||||
c = (struct conc *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc)));
|
||||
if (c == NULL) malloc_error();
|
||||
int i = 0;
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) {
|
||||
c[i].description = (char *)it->first;
|
||||
c[i].moles = it->second;
|
||||
c[i].input_conc = it->second;
|
||||
c[i].units = NULL;
|
||||
c[i].equation_name = NULL;
|
||||
c[i].phase_si = 0.0;
|
||||
c[i].n_pe = 0;
|
||||
c[i].as = NULL;
|
||||
c[i].gfw = 0.0;
|
||||
//c[i].skip = 0;
|
||||
c[i].phase = NULL;
|
||||
i++;
|
||||
}
|
||||
c[i].description = NULL;
|
||||
return(c);
|
||||
}
|
||||
|
||||
struct name_coef *cxxNameDouble::name_coef()const
|
||||
//
|
||||
// Builds a name_coef structure from instance of cxxNameDouble
|
||||
//
|
||||
{
|
||||
assert (this->type == cxxNameDouble::ND_NAME_COEF);
|
||||
struct name_coef *name_coef_ptr = (struct name_coef *) PHRQ_malloc((size_t)((this->size()) *sizeof(struct name_coef)));
|
||||
if (name_coef_ptr == NULL) malloc_error();
|
||||
int i = 0;
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) {
|
||||
name_coef_ptr[i].name = it->first;
|
||||
name_coef_ptr[i].coef = it->second;
|
||||
i++;
|
||||
}
|
||||
return(name_coef_ptr);
|
||||
}
|
||||
|
||||
void cxxNameDouble::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
std::string xmlElement, xmlAtt1, xmlAtt2;
|
||||
|
||||
switch ((*this).type) {
|
||||
case cxxNameDouble::ND_SPECIES_LA:
|
||||
xmlElement = "<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=\"";
|
||||
int i = 0;
|
||||
assert(this->type == cxxNameDouble::ND_SPECIES_LA
|
||||
|| this->type == cxxNameDouble::ND_SPECIES_GAMMA);
|
||||
struct master_activity *master_activity_ptr = NULL;
|
||||
switch ((*this).type)
|
||||
{
|
||||
case cxxNameDouble::ND_SPECIES_LA:
|
||||
{
|
||||
master_activity_ptr =
|
||||
(struct master_activity *)
|
||||
PHRQ_malloc((size_t)
|
||||
(((*this).size() +
|
||||
1) * sizeof(struct master_activity)));
|
||||
if (master_activity_ptr == NULL)
|
||||
malloc_error();
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end();
|
||||
it++)
|
||||
{
|
||||
master_activity_ptr[i].description = (char *) it->first;
|
||||
master_activity_ptr[i].la = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
master_activity_ptr[i].description = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++) {
|
||||
s_oss << indent0;
|
||||
s_oss << xmlElement << xmlAtt1 << it->first << xmlAtt2 << it->second << "/>" << std::endl;
|
||||
}
|
||||
case cxxNameDouble::ND_SPECIES_GAMMA:
|
||||
{
|
||||
if ((*this).size() > 0)
|
||||
{
|
||||
master_activity_ptr =
|
||||
(struct master_activity *)
|
||||
PHRQ_malloc((size_t)
|
||||
(((*this).size()) *
|
||||
sizeof(struct master_activity)));
|
||||
if (master_activity_ptr == NULL)
|
||||
malloc_error();
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end();
|
||||
it++)
|
||||
{
|
||||
master_activity_ptr[i].description = (char *) it->first;
|
||||
master_activity_ptr[i].la = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case cxxNameDouble::ND_ELT_MOLES:
|
||||
case cxxNameDouble::ND_NAME_COEF:
|
||||
break;
|
||||
}
|
||||
return (master_activity_ptr);
|
||||
}
|
||||
|
||||
void cxxNameDouble::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
struct conc *
|
||||
cxxNameDouble::conc() const const
|
||||
// for Solutions, not ISolutions
|
||||
// takes a map of (elt name, moles)
|
||||
// returns list of conc structures
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++) {
|
||||
s_oss << indent0;
|
||||
s_oss << it->first << " " << it->second << std::endl;
|
||||
}
|
||||
struct conc *c;
|
||||
assert(this->type == cxxNameDouble::ND_ELT_MOLES);
|
||||
c = (struct conc *)
|
||||
PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc)));
|
||||
if (c == NULL)
|
||||
malloc_error();
|
||||
int i = 0;
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); ++it)
|
||||
{
|
||||
c[i].description = (char *) it->first;
|
||||
c[i].moles = it->second;
|
||||
c[i].input_conc = it->second;
|
||||
c[i].units = NULL;
|
||||
c[i].equation_name = NULL;
|
||||
c[i].phase_si = 0.0;
|
||||
c[i].n_pe = 0;
|
||||
c[i].as = NULL;
|
||||
c[i].gfw = 0.0;
|
||||
//c[i].skip = 0;
|
||||
c[i].phase = NULL;
|
||||
i++;
|
||||
}
|
||||
c[i].description = NULL;
|
||||
return (c);
|
||||
}
|
||||
CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_type& pos)
|
||||
|
||||
struct name_coef *
|
||||
cxxNameDouble::name_coef() const const
|
||||
//
|
||||
// Builds a name_coef structure from instance of cxxNameDouble
|
||||
//
|
||||
{
|
||||
std::string token;
|
||||
char * ctoken;
|
||||
double d;
|
||||
|
||||
CParser::TOKEN_TYPE j;
|
||||
|
||||
//m_line_iss.seekg(pos);
|
||||
|
||||
j = parser.copy_token(token, pos);
|
||||
|
||||
if (j == CParser::TT_EMPTY) return CParser::PARSER_OK;
|
||||
|
||||
if( !(parser.get_iss() >> d)) {
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
ctoken = string_hsave(token.c_str());
|
||||
(*this)[ctoken] = d;
|
||||
return CParser::PARSER_OK;
|
||||
assert(this->type == cxxNameDouble::ND_NAME_COEF);
|
||||
struct name_coef *name_coef_ptr =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc((size_t) ((this->size()) * sizeof(struct name_coef)));
|
||||
if (name_coef_ptr == NULL)
|
||||
malloc_error();
|
||||
int i = 0;
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); ++it)
|
||||
{
|
||||
name_coef_ptr[i].name = it->first;
|
||||
name_coef_ptr[i].coef = it->second;
|
||||
i++;
|
||||
}
|
||||
return (name_coef_ptr);
|
||||
}
|
||||
|
||||
void cxxNameDouble::add_extensive(const cxxNameDouble &addee, double factor)
|
||||
void
|
||||
cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
std::string xmlElement, xmlAtt1, xmlAtt2;
|
||||
|
||||
switch ((*this).type)
|
||||
{
|
||||
case cxxNameDouble::ND_SPECIES_LA:
|
||||
xmlElement = "<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 << "/>" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++)
|
||||
{
|
||||
s_oss << indent0;
|
||||
s_oss << it->first << " " << it->second << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser,
|
||||
std::istream::pos_type & pos)
|
||||
{
|
||||
std::string token;
|
||||
char *
|
||||
ctoken;
|
||||
double
|
||||
d;
|
||||
|
||||
CParser::TOKEN_TYPE j;
|
||||
|
||||
//m_line_iss.seekg(pos);
|
||||
|
||||
j = parser.copy_token(token, pos);
|
||||
|
||||
if (j == CParser::TT_EMPTY)
|
||||
return CParser::PARSER_OK;
|
||||
|
||||
if (!(parser.get_iss() >> d))
|
||||
{
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
ctoken = string_hsave(token.c_str());
|
||||
(*this)[ctoken] = d;
|
||||
return CParser::PARSER_OK;
|
||||
}
|
||||
|
||||
void
|
||||
cxxNameDouble::add_extensive(const cxxNameDouble & addee, double factor)
|
||||
//
|
||||
// Sums two name doubles, this + factor*nd2
|
||||
//
|
||||
{
|
||||
if (factor == 0) return;
|
||||
assert (factor > 0.0);
|
||||
for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++)
|
||||
{
|
||||
cxxNameDouble::iterator current = (*this).find(it->first);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
(*this)[it->first] = current->second + it->second * factor;
|
||||
} else {
|
||||
(*this)[it->first] = it->second * factor;
|
||||
}
|
||||
}
|
||||
if (factor == 0)
|
||||
return;
|
||||
assert(factor > 0.0);
|
||||
for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end();
|
||||
it++)
|
||||
{
|
||||
cxxNameDouble::iterator current = (*this).find(it->first);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
(*this)[it->first] = current->second + it->second * factor;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*this)[it->first] = it->second * factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
void cxxNameDouble::add_intensive(const cxxNameDouble &addee, double f1, double f2)
|
||||
void
|
||||
cxxNameDouble::add_intensive(const cxxNameDouble & addee, double f1,
|
||||
double f2)
|
||||
//
|
||||
// Sums two name doubles, this*f1 + f2*nd2
|
||||
//
|
||||
{
|
||||
assert(f1 >= 0 && f2 >= 0);
|
||||
for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++)
|
||||
{
|
||||
cxxNameDouble::iterator current = (*this).find(it->first);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
(*this)[it->first] = f1*current->second + f2*it->second;
|
||||
} else {
|
||||
(*this)[it->first] = f2 * it->second;
|
||||
}
|
||||
}
|
||||
assert(f1 >= 0 && f2 >= 0);
|
||||
for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end();
|
||||
it++)
|
||||
{
|
||||
cxxNameDouble::iterator current = (*this).find(it->first);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
(*this)[it->first] = f1 * current->second + f2 * it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*this)[it->first] = f2 * it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
void cxxNameDouble::add_log_activities(const cxxNameDouble &addee, double f1, double f2)
|
||||
void
|
||||
cxxNameDouble::add_log_activities(const cxxNameDouble & addee, double f1,
|
||||
double f2)
|
||||
//
|
||||
// Sums two name doubles, this*f1 + f2*nd2, assuming log values
|
||||
//
|
||||
{
|
||||
assert (f1 >= 0 && f2 >= 0);
|
||||
for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++)
|
||||
{
|
||||
cxxNameDouble::iterator current = (*this).find(it->first);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
double a1 = pow(10., current->second);
|
||||
double a2 = pow(10., it->second);
|
||||
(*this)[it->first] = log10(f1*a1 + f2*a2);
|
||||
} else {
|
||||
//double a2 = pow(10. it->second);
|
||||
//(*this)[it->first] = log10(f2 * a2);
|
||||
(*this)[it->first] = it->second + log10(f2);
|
||||
}
|
||||
}
|
||||
assert(f1 >= 0 && f2 >= 0);
|
||||
for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end();
|
||||
it++)
|
||||
{
|
||||
cxxNameDouble::iterator current = (*this).find(it->first);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
double a1 = pow(10., current->second);
|
||||
double a2 = pow(10., it->second);
|
||||
(*this)[it->first] = log10(f1 * a1 + f2 * a2);
|
||||
}
|
||||
else
|
||||
{
|
||||
//double a2 = pow(10. it->second);
|
||||
//(*this)[it->first] = log10(f2 * a2);
|
||||
(*this)[it->first] = it->second + log10(f2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cxxNameDouble::add(const char * token, double total)
|
||||
void
|
||||
cxxNameDouble::add(const char *token, double total)
|
||||
//
|
||||
// add to total for a specified element
|
||||
//
|
||||
{
|
||||
char key[MAX_LENGTH];
|
||||
strcpy(key, token);
|
||||
char key[MAX_LENGTH];
|
||||
strcpy(key, token);
|
||||
|
||||
cxxNameDouble::iterator current = (*this).find(key);
|
||||
if (current != (*this).end()) {
|
||||
(*this)[key] = current->second + total;
|
||||
} else {
|
||||
(*this)[key] = total;
|
||||
}
|
||||
cxxNameDouble::iterator current = (*this).find(key);
|
||||
if (current != (*this).end())
|
||||
{
|
||||
(*this)[key] = current->second + total;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*this)[key] = total;
|
||||
}
|
||||
}
|
||||
void cxxNameDouble::multiply(double extensive)
|
||||
void
|
||||
cxxNameDouble::multiply(double extensive)
|
||||
{
|
||||
//
|
||||
// Multiplies by extensive
|
||||
//
|
||||
|
||||
for (cxxNameDouble::iterator it = this->begin(); it != this->end(); it++)
|
||||
{
|
||||
it->second *= extensive;
|
||||
}
|
||||
for (cxxNameDouble::iterator it = this->begin(); it != this->end(); it++)
|
||||
{
|
||||
it->second *= extensive;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxNameDouble::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles) {
|
||||
void
|
||||
cxxNameDouble::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
ints.push_back( (int) (*this).size() );
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++) {
|
||||
ints.push_back((int) (*this).size());
|
||||
for (const_iterator it = (*this).begin(); it != (*this).end(); it++)
|
||||
{
|
||||
assert(it->first != NULL);
|
||||
int n = dictionary.string2int(it->first);
|
||||
ints.push_back(n);
|
||||
doubles.push_back(it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
void cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd)
|
||||
void
|
||||
cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
int i = *ii;
|
||||
int d = *dd;
|
||||
extern cxxDictionary dictionary;
|
||||
//ints.push_back( (*this).size() );
|
||||
ints[i++] = (int) this->size();
|
||||
for (const_iterator it = this->begin(); it != this->end(); it++) {
|
||||
for (const_iterator it = this->begin(); it != this->end(); it++)
|
||||
{
|
||||
int n = dictionary.string2int(it->first);
|
||||
if (n < 0) {
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << it->first << std::endl;
|
||||
error_msg("Name in NameDouble was not defined in dictionary?\n", STOP);
|
||||
error_msg("Name in NameDouble was not defined in dictionary?\n",
|
||||
STOP);
|
||||
}
|
||||
//ints.push_back(n);
|
||||
ints[i++] = n;
|
||||
//doubles.push_back(it->second);
|
||||
doubles[d++] = it->second;
|
||||
}
|
||||
}
|
||||
*ii = i;
|
||||
*dd = d;
|
||||
}
|
||||
void cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
void
|
||||
cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
int i = *ii;
|
||||
int d = *dd;
|
||||
extern cxxDictionary dictionary;
|
||||
this->clear();
|
||||
int count = ints[i++];
|
||||
for (int j = 0; j < count; j++) {
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
int n = ints[i++];
|
||||
assert(n >= 0);
|
||||
std::string *str = dictionary.int2string(n);
|
||||
if (str != NULL) {
|
||||
std::string * str = dictionary.int2string(n);
|
||||
if (str != NULL)
|
||||
{
|
||||
char *cstr = string_hsave(str->c_str());
|
||||
(*this)[cstr] = doubles[d++];
|
||||
}
|
||||
}
|
||||
}
|
||||
*ii = i;
|
||||
*dd = d;
|
||||
}
|
||||
|
||||
205
NumKeyword.cxx
205
NumKeyword.cxx
@ -1,5 +1,5 @@
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
// NumKeyword.cxx: implementation of the cxxNumKeyword class.
|
||||
//
|
||||
@ -21,120 +21,131 @@ cxxNumKeyword::~cxxNumKeyword()
|
||||
{
|
||||
}
|
||||
|
||||
void cxxNumKeyword::dump_xml(std::ostream& os, unsigned int indent)const
|
||||
void
|
||||
cxxNumKeyword::dump_xml(std::ostream & os, unsigned int indent) const const
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int i;
|
||||
|
||||
for(i = 0; i < indent + 1; ++i) os << " ";
|
||||
os << "<n_user>" << this->n_user << "</n_user>" << "\n";
|
||||
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 << "<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";
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
os << " ";
|
||||
os << "<Description>" << this->description << "</Description>" << "\n";
|
||||
}
|
||||
|
||||
void cxxNumKeyword::read_number_description(CParser& parser)
|
||||
void
|
||||
cxxNumKeyword::read_number_description(CParser & parser)
|
||||
{
|
||||
std::string keyword;
|
||||
std::istream::pos_type ptr;
|
||||
std::string keyword;
|
||||
std::istream::pos_type ptr;
|
||||
|
||||
// skip keyword
|
||||
parser.copy_token(keyword, ptr);
|
||||
// skip keyword
|
||||
parser.copy_token(keyword, ptr);
|
||||
|
||||
std::istream::pos_type ptr1 = ptr;
|
||||
std::string::size_type pos;
|
||||
std::string token;
|
||||
if (parser.copy_token(token, ptr) != CParser::TT_DIGIT)
|
||||
{
|
||||
this->n_user = 1;
|
||||
this->n_user_end = 1;
|
||||
} else {
|
||||
std::istringstream iss(token);
|
||||
iss >> this->n_user;
|
||||
this->n_user_end = this->n_user;
|
||||
std::string token1;
|
||||
iss >> token1;
|
||||
if ( (pos = token1.find_first_of("-")) != std::string::npos ) {
|
||||
token1.replace(pos, 1, " ");
|
||||
std::istringstream iss1(token1);
|
||||
iss1 >> this->n_user_end;
|
||||
// ptr1 = ptr;
|
||||
}
|
||||
}
|
||||
/*
|
||||
else if ( (pos = token.find_first_of("-")) != std::string::npos )
|
||||
{
|
||||
token.replace(pos, 1, " ");
|
||||
std::istringstream iss(token);
|
||||
if (!(iss >> this->n_user >> this->n_user_end))
|
||||
{
|
||||
std::ostringstream err_oss;
|
||||
if (parser.next_keyword() >= 0)
|
||||
{
|
||||
err_oss << "Reading number range for " << keyword << ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
err_oss << "Reading number range for keyword.";
|
||||
}
|
||||
parser.error_msg(err_oss, CParser::OT_CONTINUE);
|
||||
parser.incr_input_error();
|
||||
}
|
||||
ptr1 = ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
iss >> this->n_user;
|
||||
this->n_user_end = this->n_user;
|
||||
ptr1 = ptr;
|
||||
}
|
||||
*/
|
||||
// reset get position
|
||||
//parser.get_iss().seekg(ptr1);
|
||||
std::istream::pos_type ptr1 = ptr;
|
||||
std::string::size_type pos;
|
||||
std::string token;
|
||||
if (parser.copy_token(token, ptr) != CParser::TT_DIGIT)
|
||||
{
|
||||
this->n_user = 1;
|
||||
this->n_user_end = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
iss >> this->n_user;
|
||||
this->n_user_end = this->n_user;
|
||||
std::string token1;
|
||||
iss >> token1;
|
||||
if ((pos = token1.find_first_of("-")) != std::string::npos)
|
||||
{
|
||||
token1.replace(pos, 1, " ");
|
||||
std::istringstream iss1(token1);
|
||||
iss1 >> this->n_user_end;
|
||||
// ptr1 = ptr;
|
||||
}
|
||||
}
|
||||
/*
|
||||
else if ( (pos = token.find_first_of("-")) != std::string::npos )
|
||||
{
|
||||
token.replace(pos, 1, " ");
|
||||
std::istringstream iss(token);
|
||||
if (!(iss >> this->n_user >> this->n_user_end))
|
||||
{
|
||||
std::ostringstream err_oss;
|
||||
if (parser.next_keyword() >= 0)
|
||||
{
|
||||
err_oss << "Reading number range for " << keyword << ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
err_oss << "Reading number range for keyword.";
|
||||
}
|
||||
parser.error_msg(err_oss, CParser::OT_CONTINUE);
|
||||
parser.incr_input_error();
|
||||
}
|
||||
ptr1 = ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
iss >> this->n_user;
|
||||
this->n_user_end = this->n_user;
|
||||
ptr1 = ptr;
|
||||
}
|
||||
*/
|
||||
// reset get position
|
||||
//parser.get_iss().seekg(ptr1);
|
||||
|
||||
// skip whitespace
|
||||
while (::isspace(parser.get_iss().peek())) parser.get_iss().ignore();
|
||||
// skip whitespace
|
||||
while (::isspace(parser.get_iss().peek()))
|
||||
parser.get_iss().ignore();
|
||||
|
||||
// copy description
|
||||
std::getline(parser.get_iss(), this->description);
|
||||
// copy description
|
||||
std::getline(parser.get_iss(), this->description);
|
||||
}
|
||||
|
||||
|
||||
void cxxNumKeyword::read_number_description(std::istream& is)
|
||||
void
|
||||
cxxNumKeyword::read_number_description(std::istream & is)
|
||||
{
|
||||
// KEYWORD [[1[-20]] [This is the description]]
|
||||
// KEYWORD [[1[-20]] [This is the description]]
|
||||
|
||||
// eat keyword
|
||||
std::string token;
|
||||
is >> token;
|
||||
// eat keyword
|
||||
std::string token;
|
||||
is >> token;
|
||||
|
||||
// skip whitespace
|
||||
while (::isspace(is.peek())) is.ignore();
|
||||
// skip whitespace
|
||||
while (::isspace(is.peek()))
|
||||
is.ignore();
|
||||
|
||||
if (::isdigit(is.peek()))
|
||||
{
|
||||
is >> this->n_user;
|
||||
char ch = is.peek();
|
||||
if (ch == '-')
|
||||
{
|
||||
is >> ch; // eat '-'
|
||||
is >> this->n_user_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->n_user_end = this->n_user;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->n_user = this->n_user_end = 1;
|
||||
}
|
||||
if (::isdigit(is.peek()))
|
||||
{
|
||||
is >> this->n_user;
|
||||
char ch = is.peek();
|
||||
if (ch == '-')
|
||||
{
|
||||
is >> ch; // eat '-'
|
||||
is >> this->n_user_end;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->n_user_end = this->n_user;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->n_user = this->n_user_end = 1;
|
||||
}
|
||||
|
||||
while (::isspace(is.peek())) is.ignore();
|
||||
while (::isspace(is.peek()))
|
||||
is.ignore();
|
||||
|
||||
std::getline(is, this->description);
|
||||
std::getline(is, this->description);
|
||||
}
|
||||
|
||||
|
||||
568
PPassemblage.cxx
568
PPassemblage.cxx
@ -2,227 +2,268 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "PPassemblage.h"
|
||||
#include "PPassemblageComp.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxPPassemblage::cxxPPassemblage()
|
||||
//
|
||||
// default constructor for cxxPPassemblage
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxPPassemblage
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
eltList.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
eltList.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr)
|
||||
//
|
||||
// constructor for cxxPPassemblage from struct PPassemblage
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxPPassemblage from struct PPassemblage
|
||||
//
|
||||
:
|
||||
cxxNumKeyword(),
|
||||
eltList(pp_assemblage_ptr->next_elt)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
this->set_description(pp_assemblage_ptr->description);
|
||||
n_user = pp_assemblage_ptr->n_user;
|
||||
n_user_end = pp_assemblage_ptr->n_user_end;
|
||||
for (i = 0; i < pp_assemblage_ptr->count_comps; i++) {
|
||||
cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i]));
|
||||
ppAssemblageComps.push_back(ppComp);
|
||||
}
|
||||
this->set_description(pp_assemblage_ptr->description);
|
||||
n_user = pp_assemblage_ptr->n_user;
|
||||
n_user_end = pp_assemblage_ptr->n_user_end;
|
||||
for (i = 0; i < pp_assemblage_ptr->count_comps; i++)
|
||||
{
|
||||
cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i]));
|
||||
ppAssemblageComps.push_back(ppComp);
|
||||
}
|
||||
}
|
||||
cxxPPassemblage::cxxPPassemblage(const std::map<int, cxxPPassemblage> &entities, cxxMix &mix, int n_user)
|
||||
:
|
||||
cxxPPassemblage::cxxPPassemblage(const std::map < int,
|
||||
cxxPPassemblage > &entities, cxxMix & mix,
|
||||
int n_user):
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
eltList.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
eltList.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
//
|
||||
// Mix
|
||||
//
|
||||
std::map<int, double> *mixcomps = mix.comps();
|
||||
std::map<int, double>::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxPPassemblage *entity_ptr = &(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
}
|
||||
}
|
||||
std::map < int, double >*mixcomps = mix.comps();
|
||||
std::map < int, double >::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxPPassemblage *entity_ptr =
|
||||
&(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxPPassemblage::~cxxPPassemblage()
|
||||
{
|
||||
}
|
||||
|
||||
struct pp_assemblage *cxxPPassemblage::cxxPPassemblage2pp_assemblage()
|
||||
//
|
||||
// Builds a pp_assemblage structure from instance of cxxPPassemblage
|
||||
//
|
||||
struct pp_assemblage *
|
||||
cxxPPassemblage::cxxPPassemblage2pp_assemblage()
|
||||
//
|
||||
// Builds a pp_assemblage structure from instance of cxxPPassemblage
|
||||
//
|
||||
{
|
||||
struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc();
|
||||
|
||||
pp_assemblage_ptr->description = this->get_description();
|
||||
pp_assemblage_ptr->n_user = this->n_user;
|
||||
pp_assemblage_ptr->n_user_end = this->n_user_end;
|
||||
pp_assemblage_ptr->new_def = FALSE;
|
||||
pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size();
|
||||
pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases);
|
||||
pp_assemblage_ptr->pure_phases = cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->ppAssemblageComps);
|
||||
pp_assemblage_ptr->next_elt = this->eltList.elt_list();
|
||||
return(pp_assemblage_ptr);
|
||||
struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc();
|
||||
|
||||
pp_assemblage_ptr->description = this->get_description();
|
||||
pp_assemblage_ptr->n_user = this->n_user;
|
||||
pp_assemblage_ptr->n_user_end = this->n_user_end;
|
||||
pp_assemblage_ptr->new_def = FALSE;
|
||||
pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size();
|
||||
pp_assemblage_ptr->pure_phases =
|
||||
(struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases);
|
||||
pp_assemblage_ptr->pure_phases =
|
||||
cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->
|
||||
ppAssemblageComps);
|
||||
pp_assemblage_ptr->next_elt = this->eltList.elt_list();
|
||||
return (pp_assemblage_ptr);
|
||||
}
|
||||
|
||||
void cxxPPassemblage::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// PPassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<EQUILIBRIUM_PHASES " << std::endl;
|
||||
// PPassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<EQUILIBRIUM_PHASES " << std::endl;
|
||||
|
||||
// eltList
|
||||
this->eltList.dump_xml(s_oss, indent + 1);
|
||||
// eltList
|
||||
this->eltList.dump_xml(s_oss, indent + 1);
|
||||
|
||||
// ppAssemblageComps
|
||||
s_oss << indent1;
|
||||
s_oss << "<pure_phases " << std::endl;
|
||||
for (std::list<cxxPPassemblageComp>::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// ppAssemblageComps
|
||||
s_oss << indent1;
|
||||
s_oss << "<pure_phases " << std::endl;
|
||||
for (std::list < cxxPPassemblageComp >::const_iterator it =
|
||||
ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
void cxxPPassemblage::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// PPassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "EQUILIBRIUM_PHASES_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
// PPassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "EQUILIBRIUM_PHASES_RAW " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
// eltList
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-eltList " << std::endl;
|
||||
this->eltList.dump_raw(s_oss, indent + 2);
|
||||
// eltList
|
||||
|
||||
// ppAssemblagComps
|
||||
for (std::list<cxxPPassemblageComp>::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) {
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
s_oss << indent1;
|
||||
s_oss << "-eltList " << std::endl;
|
||||
this->eltList.dump_raw(s_oss, indent + 2);
|
||||
|
||||
// ppAssemblagComps
|
||||
for (std::list < cxxPPassemblageComp >::const_iterator it =
|
||||
ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
void cxxPPassemblage::read_raw(CParser& parser)
|
||||
void
|
||||
cxxPPassemblage::read_raw(CParser & parser)
|
||||
{
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("eltlist"); // 0
|
||||
vopts.push_back("component"); // 1
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("eltlist"); // 0
|
||||
vopts.push_back("component"); // 1
|
||||
}
|
||||
|
||||
// Read PPassemblage number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
// Read PPassemblage number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in EQUILIBRIUM_PHASES_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
|
||||
case 0: // eltList
|
||||
if ( this->eltList.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected element name and moles for totals.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 0;
|
||||
break;
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.
|
||||
error_msg("Unknown input in EQUILIBRIUM_PHASES_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 1: // component
|
||||
{
|
||||
cxxPPassemblageComp ppComp;
|
||||
ppComp.read_raw(parser);
|
||||
this->ppAssemblageComps.push_back(ppComp);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
case 0: // eltList
|
||||
if (this->eltList.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Expected element name and moles for totals.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 0;
|
||||
break;
|
||||
|
||||
case 1: // component
|
||||
{
|
||||
cxxPPassemblageComp ppComp;
|
||||
ppComp.read_raw(parser);
|
||||
this->ppAssemblageComps.push_back(ppComp);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxPPassemblage::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxPPassemblage::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/* int n_user; */
|
||||
ints.push_back(this->n_user);
|
||||
ints.push_back((int) this->ppAssemblageComps.size());
|
||||
for (std::list<cxxPPassemblageComp>::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); it++) {
|
||||
for (std::list < cxxPPassemblageComp >::iterator it =
|
||||
this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end();
|
||||
it++)
|
||||
{
|
||||
it->mpi_pack(ints, doubles);
|
||||
}
|
||||
this->eltList.mpi_pack(ints, doubles);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
void
|
||||
cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i = *ii;
|
||||
@ -234,7 +275,8 @@ void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
int count = ints[i++];
|
||||
this->ppAssemblageComps.clear();
|
||||
for (int n = 0; n < count; n++) {
|
||||
for (int n = 0; n < count; n++)
|
||||
{
|
||||
cxxPPassemblageComp ppc;
|
||||
ppc.mpi_unpack(ints, &i, doubles, &d);
|
||||
this->ppAssemblageComps.push_back(ppc);
|
||||
@ -245,119 +287,145 @@ void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxPPassemblage::totalize()
|
||||
void
|
||||
cxxPPassemblage::totalize()
|
||||
{
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (std::list<cxxPPassemblageComp>::iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
it->totalize();
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
}
|
||||
return;
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (std::list < cxxPPassemblageComp >::iterator it =
|
||||
ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
it->totalize();
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cxxPPassemblage::add(const cxxPPassemblage &addee, double extensive)
|
||||
//
|
||||
// Add to existing ppassemblage to "this" ppassemblage
|
||||
//
|
||||
void
|
||||
cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive)
|
||||
//
|
||||
// Add to existing ppassemblage to "this" ppassemblage
|
||||
//
|
||||
{
|
||||
if (extensive == 0.0) return;
|
||||
//std::list<cxxPPassemblageComp> ppAssemblageComps;
|
||||
for (std::list<cxxPPassemblageComp>::const_iterator itadd = addee.ppAssemblageComps.begin(); itadd != addee.ppAssemblageComps.end(); ++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list<cxxPPassemblageComp>::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
if (it->get_name() == itadd->get_name())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
cxxPPassemblageComp entity = *itadd;
|
||||
entity.multiply(extensive);
|
||||
this->ppAssemblageComps.push_back(entity);
|
||||
}
|
||||
}
|
||||
//cxxNameDouble eltList;
|
||||
this->eltList.add_extensive(addee.eltList, extensive);
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
//std::list<cxxPPassemblageComp> ppAssemblageComps;
|
||||
for (std::list < cxxPPassemblageComp >::const_iterator itadd =
|
||||
addee.ppAssemblageComps.begin();
|
||||
itadd != addee.ppAssemblageComps.end(); ++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list < cxxPPassemblageComp >::iterator it =
|
||||
this->ppAssemblageComps.begin();
|
||||
it != this->ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
if (it->get_name() == itadd->get_name())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
cxxPPassemblageComp entity = *itadd;
|
||||
entity.multiply(extensive);
|
||||
this->ppAssemblageComps.push_back(entity);
|
||||
}
|
||||
}
|
||||
//cxxNameDouble eltList;
|
||||
this->eltList.add_extensive(addee.eltList, extensive);
|
||||
}
|
||||
|
||||
#ifdef ORCHESTRA
|
||||
void cxxPPassemblage::ORCH_write_chemistry(std::ostream &chemistry_dat)
|
||||
void
|
||||
cxxPPassemblage::ORCH_write_chemistry(std::ostream & chemistry_dat)
|
||||
{
|
||||
chemistry_dat << std::endl << "//********* Mineral equilibria" << std::endl;
|
||||
chemistry_dat << std::endl << "//********* Mineral equilibria" << std::
|
||||
endl;
|
||||
//
|
||||
// Write minerals
|
||||
//
|
||||
for (std::list<cxxPPassemblageComp>::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
struct phase *phase_ptr;
|
||||
int n;
|
||||
phase_ptr = phase_bsearch(it->get_name(), &n, FALSE);
|
||||
assert (phase_ptr != NULL);
|
||||
std::string phase_name(phase_ptr->name);
|
||||
std::replace(phase_name.begin(), phase_name.end(), '(', '[');
|
||||
std::replace(phase_name.begin(), phase_name.end(), ')', ']');
|
||||
chemistry_dat << "@mineral(" << phase_name << ")" << std::endl;
|
||||
chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, -phase_ptr->lk);
|
||||
struct rxn_token *next_token = phase_ptr->rxn_x->token;
|
||||
next_token++;
|
||||
while (next_token->s != NULL || next_token->name != NULL)
|
||||
{
|
||||
chemistry_dat << ", " << next_token->coef;
|
||||
if (next_token->s != NULL)
|
||||
{
|
||||
chemistry_dat << ", " << next_token->s->name;
|
||||
} else {
|
||||
chemistry_dat << ", " << next_token->name;
|
||||
}
|
||||
next_token++;
|
||||
}
|
||||
chemistry_dat << ")" << std::endl;
|
||||
}
|
||||
for (std::list < cxxPPassemblageComp >::iterator it =
|
||||
this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end();
|
||||
++it)
|
||||
{
|
||||
struct phase *phase_ptr;
|
||||
int n;
|
||||
phase_ptr = phase_bsearch(it->get_name(), &n, FALSE);
|
||||
assert(phase_ptr != NULL);
|
||||
std::string phase_name(phase_ptr->name);
|
||||
std::replace(phase_name.begin(), phase_name.end(), '(', '[');
|
||||
std::replace(phase_name.begin(), phase_name.end(), ')', ']');
|
||||
chemistry_dat << "@mineral(" << phase_name << ")" << std::endl;
|
||||
chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0,
|
||||
-phase_ptr->
|
||||
lk);
|
||||
struct rxn_token *next_token = phase_ptr->rxn_x->token;
|
||||
next_token++;
|
||||
while (next_token->s != NULL || next_token->name != NULL)
|
||||
{
|
||||
chemistry_dat << ", " << next_token->coef;
|
||||
if (next_token->s != NULL)
|
||||
{
|
||||
chemistry_dat << ", " << next_token->s->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
chemistry_dat << ", " << next_token->name;
|
||||
}
|
||||
next_token++;
|
||||
}
|
||||
chemistry_dat << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void cxxPPassemblage::ORCH_write_output_vars(std::ostream &outstream)
|
||||
void
|
||||
cxxPPassemblage::ORCH_write_output_vars(std::ostream & outstream)
|
||||
{
|
||||
//
|
||||
// Write ppassemblage output variables
|
||||
//
|
||||
outstream << "\tstart_ppassemblage";
|
||||
for (std::list<cxxPPassemblageComp>::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it)
|
||||
{
|
||||
outstream << "\t" << it->get_name() << ".min";
|
||||
}
|
||||
outstream << "\tend_ppassemblage";
|
||||
//
|
||||
// Write ppassemblage output variables
|
||||
//
|
||||
outstream << "\tstart_ppassemblage";
|
||||
for (std::list < cxxPPassemblageComp >::iterator it =
|
||||
this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end();
|
||||
++it)
|
||||
{
|
||||
outstream << "\t" << it->get_name() << ".min";
|
||||
}
|
||||
outstream << "\tend_ppassemblage";
|
||||
}
|
||||
|
||||
void cxxPPassemblage::ORCH_read(std::vector <std::pair <std::string, double> > output_vector, std::vector < std::pair < std::string, double > >::iterator &it)
|
||||
void
|
||||
cxxPPassemblage::ORCH_read(std::vector < std::pair < std::string,
|
||||
double >>output_vector,
|
||||
std::vector < std::pair < std::string,
|
||||
double >>::iterator & it)
|
||||
{
|
||||
while (it->first.compare("end_ppassemblage") != 0)
|
||||
{
|
||||
it++;
|
||||
}
|
||||
while (it->first.compare("end_ppassemblage") != 0)
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
void cxxPPassemblage::ORCH_store_global(std::map < std::string, double > output_map)
|
||||
void
|
||||
cxxPPassemblage::ORCH_store_global(std::map < std::string, double >output_map)
|
||||
{
|
||||
int i;
|
||||
std::map < std::string, double >::iterator it;
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
// MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O
|
||||
switch (x[i]->type)
|
||||
{
|
||||
case PP:
|
||||
std::string name(x[i]->phase->name);
|
||||
name.append(".min");
|
||||
it = output_map.find(name);
|
||||
assert (it != output_map.end());
|
||||
x[i]->moles = it->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int i;
|
||||
std::map < std::string, double >::iterator it;
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
// MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O
|
||||
switch (x[i]->type)
|
||||
{
|
||||
case PP:
|
||||
std::string name(x[i]->phase->name);
|
||||
name.append(".min");
|
||||
it = output_map.find(name);
|
||||
assert(it != output_map.end());
|
||||
x[i]->moles = it->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "PPassemblageComp.h"
|
||||
#include "Dictionary.h"
|
||||
#define EXTERNAL extern
|
||||
@ -13,294 +13,356 @@
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include "output.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxPPassemblageComp::cxxPPassemblageComp()
|
||||
//
|
||||
// default constructor for cxxPPassemblageComp
|
||||
//
|
||||
//
|
||||
// default constructor for cxxPPassemblageComp
|
||||
//
|
||||
{
|
||||
name = NULL;
|
||||
add_formula = NULL;
|
||||
si = 0;
|
||||
moles = 0;
|
||||
delta = 0;
|
||||
initial_moles = 0;
|
||||
force_equality = false;
|
||||
dissolve_only = false;
|
||||
name = NULL;
|
||||
add_formula = NULL;
|
||||
si = 0;
|
||||
moles = 0;
|
||||
delta = 0;
|
||||
initial_moles = 0;
|
||||
force_equality = false;
|
||||
dissolve_only = false;
|
||||
}
|
||||
|
||||
cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase *pure_phase_ptr)
|
||||
//
|
||||
// constructor for cxxPPassemblageComp from struct pure_phase
|
||||
//
|
||||
|
||||
cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr)
|
||||
//
|
||||
// constructor for cxxPPassemblageComp from struct pure_phase
|
||||
//
|
||||
{
|
||||
name = pure_phase_ptr->name;
|
||||
add_formula = pure_phase_ptr->add_formula;
|
||||
si = pure_phase_ptr->si;
|
||||
moles = pure_phase_ptr->moles;
|
||||
delta = pure_phase_ptr->delta;
|
||||
initial_moles = pure_phase_ptr->initial_moles;
|
||||
force_equality = ( pure_phase_ptr->force_equality == TRUE);
|
||||
dissolve_only = ( pure_phase_ptr->dissolve_only == TRUE);
|
||||
name = pure_phase_ptr->name;
|
||||
add_formula = pure_phase_ptr->add_formula;
|
||||
si = pure_phase_ptr->si;
|
||||
moles = pure_phase_ptr->moles;
|
||||
delta = pure_phase_ptr->delta;
|
||||
initial_moles = pure_phase_ptr->initial_moles;
|
||||
force_equality = (pure_phase_ptr->force_equality == TRUE);
|
||||
dissolve_only = (pure_phase_ptr->dissolve_only == TRUE);
|
||||
}
|
||||
|
||||
cxxPPassemblageComp::~cxxPPassemblageComp()
|
||||
{
|
||||
}
|
||||
|
||||
struct phase *cxxPPassemblageComp::get_phase() {
|
||||
int i;
|
||||
return phase_bsearch(this->name, &i, FALSE);
|
||||
struct phase *
|
||||
cxxPPassemblageComp::get_phase()
|
||||
{
|
||||
int i;
|
||||
return phase_bsearch(this->name, &i, FALSE);
|
||||
}
|
||||
|
||||
struct pure_phase *cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list<cxxPPassemblageComp>& el)
|
||||
//
|
||||
// Builds pure_phase structure from of cxxPPassemblageComp
|
||||
//
|
||||
struct pure_phase *
|
||||
cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list <
|
||||
cxxPPassemblageComp > &el)
|
||||
//
|
||||
// Builds pure_phase structure from of cxxPPassemblageComp
|
||||
//
|
||||
{
|
||||
struct pure_phase *pure_phase_ptr = (struct pure_phase *) PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase)));
|
||||
if (pure_phase_ptr == NULL) malloc_error();
|
||||
struct pure_phase *pure_phase_ptr =
|
||||
(struct pure_phase *)
|
||||
PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase)));
|
||||
if (pure_phase_ptr == NULL)
|
||||
malloc_error();
|
||||
|
||||
int i = 0;
|
||||
for (std::list<cxxPPassemblageComp>::iterator it = el.begin(); it != el.end(); ++it) {
|
||||
pure_phase_ptr[i].phase = it->get_phase();
|
||||
pure_phase_ptr[i].name = it->name;
|
||||
pure_phase_ptr[i].add_formula = it->add_formula;
|
||||
pure_phase_ptr[i].si = it->si;
|
||||
pure_phase_ptr[i].moles = it->moles;
|
||||
pure_phase_ptr[i].delta = it->delta;
|
||||
pure_phase_ptr[i].initial_moles = it->initial_moles;
|
||||
pure_phase_ptr[i].force_equality = (int) it->force_equality;
|
||||
pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only;
|
||||
i++;
|
||||
}
|
||||
return(pure_phase_ptr);
|
||||
int i = 0;
|
||||
for (std::list < cxxPPassemblageComp >::iterator it = el.begin();
|
||||
it != el.end(); ++it)
|
||||
{
|
||||
pure_phase_ptr[i].phase = it->get_phase();
|
||||
pure_phase_ptr[i].name = it->name;
|
||||
pure_phase_ptr[i].add_formula = it->add_formula;
|
||||
pure_phase_ptr[i].si = it->si;
|
||||
pure_phase_ptr[i].moles = it->moles;
|
||||
pure_phase_ptr[i].delta = it->delta;
|
||||
pure_phase_ptr[i].initial_moles = it->initial_moles;
|
||||
pure_phase_ptr[i].force_equality = (int) it->force_equality;
|
||||
pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only;
|
||||
i++;
|
||||
}
|
||||
return (pure_phase_ptr);
|
||||
}
|
||||
|
||||
void cxxPPassemblageComp::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Pure_Phase element and attributes
|
||||
// Pure_Phase element and attributes
|
||||
|
||||
s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl;
|
||||
s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << std::endl;
|
||||
s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl;
|
||||
s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl;
|
||||
s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "force_equality=\"" << this->force_equality << "\"" << std::endl;
|
||||
s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl;
|
||||
s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl;
|
||||
s_oss << indent0 << "add_formula=\"" << this->
|
||||
add_formula << "\"" << std::endl;
|
||||
s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl;
|
||||
s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl;
|
||||
s_oss << indent0 << "initial_moles=\"" << this->
|
||||
initial_moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "force_equality=\"" << this->
|
||||
force_equality << "\"" << std::endl;
|
||||
s_oss << indent0 << "dissolve_only=\"" << this->
|
||||
dissolve_only << "\"" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void cxxPPassemblageComp::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Pure_Phase element and attributes
|
||||
// Pure_Phase element and attributes
|
||||
|
||||
if (this->name != NULL) s_oss << indent0 << "-name " << this->name << std::endl;
|
||||
if (this->add_formula != NULL) s_oss << indent0 << "-add_formula " << this->add_formula << std::endl;
|
||||
s_oss << indent0 << "-si " << this->si << std::endl;
|
||||
s_oss << indent0 << "-moles " << this->moles << std::endl;
|
||||
s_oss << indent0 << "-delta " << this->delta << std::endl;
|
||||
s_oss << indent0 << "-initial_moles " << this->initial_moles << std::endl;
|
||||
s_oss << indent0 << "-force_equality " << this->force_equality << std::endl;
|
||||
s_oss << indent0 << "-dissolve_only " << this->dissolve_only << std::endl;
|
||||
if (this->name != NULL)
|
||||
s_oss << indent0 << "-name " << this->
|
||||
name << std::endl;
|
||||
if (this->add_formula != NULL)
|
||||
s_oss << indent0 << "-add_formula " << this->
|
||||
add_formula << std::endl;
|
||||
s_oss << indent0 << "-si " << this->si << std::endl;
|
||||
s_oss << indent0 << "-moles " << this->moles << std::endl;
|
||||
s_oss << indent0 << "-delta " << this->delta << std::endl;
|
||||
s_oss << indent0 << "-initial_moles " << this->
|
||||
initial_moles << std::endl;
|
||||
s_oss << indent0 << "-force_equality " << this->
|
||||
force_equality << std::endl;
|
||||
s_oss << indent0 << "-dissolve_only " << this->
|
||||
dissolve_only << std::endl;
|
||||
}
|
||||
|
||||
void cxxPPassemblageComp::read_raw(CParser& parser)
|
||||
void
|
||||
cxxPPassemblageComp::read_raw(CParser & parser)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("name"); // 0
|
||||
vopts.push_back("add_formula"); // 1
|
||||
vopts.push_back("si"); // 2
|
||||
vopts.push_back("moles"); // 3
|
||||
vopts.push_back("delta"); // 4
|
||||
vopts.push_back("initial_moles"); // 5
|
||||
vopts.push_back("dissolve_only"); // 6
|
||||
vopts.push_back("force_equality"); // 7
|
||||
}
|
||||
std::string str;
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("name"); // 0
|
||||
vopts.push_back("add_formula"); // 1
|
||||
vopts.push_back("si"); // 2
|
||||
vopts.push_back("moles"); // 3
|
||||
vopts.push_back("delta"); // 4
|
||||
vopts.push_back("initial_moles"); // 5
|
||||
vopts.push_back("dissolve_only"); // 6
|
||||
vopts.push_back("force_equality"); // 7
|
||||
}
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool name_defined(false);
|
||||
bool si_defined(false);
|
||||
bool moles_defined(false);
|
||||
bool delta_defined(false);
|
||||
bool initial_moles_defined(false);
|
||||
bool dissolve_only_defined(false);
|
||||
bool force_equality_defined(false);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool name_defined(false);
|
||||
bool si_defined(false);
|
||||
bool moles_defined(false);
|
||||
bool delta_defined(false);
|
||||
bool initial_moles_defined(false);
|
||||
bool dissolve_only_defined(false);
|
||||
bool force_equality_defined(false);
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Exchange for more processing
|
||||
//parser.error_msg("Unknown input in PURE_PHASE read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
|
||||
case 0: // name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
this->name = string_hsave(str.c_str());
|
||||
}
|
||||
name_defined = true;
|
||||
break;
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Exchange for more processing
|
||||
//parser.error_msg("Unknown input in PURE_PHASE read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
|
||||
case 1: // add_formula
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->add_formula = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for add_formula.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
this->add_formula = string_hsave(str.c_str());
|
||||
}
|
||||
break;
|
||||
case 0: // name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for name.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->name = string_hsave(str.c_str());
|
||||
}
|
||||
name_defined = true;
|
||||
break;
|
||||
|
||||
case 2: // si
|
||||
if (!(parser.get_iss() >> this->si))
|
||||
{
|
||||
this->si = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for si.", CParser::OT_CONTINUE);
|
||||
}
|
||||
si_defined = true;
|
||||
break;
|
||||
case 1: // add_formula
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->add_formula = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for add_formula.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->add_formula = string_hsave(str.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // moles
|
||||
if (!(parser.get_iss() >> this->moles))
|
||||
{
|
||||
this->moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE);
|
||||
}
|
||||
moles_defined = true;
|
||||
break;
|
||||
case 2: // si
|
||||
if (!(parser.get_iss() >> this->si))
|
||||
{
|
||||
this->si = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for si.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
si_defined = true;
|
||||
break;
|
||||
|
||||
case 4: // delta
|
||||
if (!(parser.get_iss() >> this->delta))
|
||||
{
|
||||
this->delta = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for delta.", CParser::OT_CONTINUE);
|
||||
}
|
||||
delta_defined = true;
|
||||
break;
|
||||
case 3: // moles
|
||||
if (!(parser.get_iss() >> this->moles))
|
||||
{
|
||||
this->moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for moles.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
moles_defined = true;
|
||||
break;
|
||||
|
||||
case 5: // initial_moles
|
||||
if (!(parser.get_iss() >> this->initial_moles))
|
||||
{
|
||||
this->initial_moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for initial_moles.", CParser::OT_CONTINUE);
|
||||
}
|
||||
initial_moles_defined = true;
|
||||
break;
|
||||
case 4: // delta
|
||||
if (!(parser.get_iss() >> this->delta))
|
||||
{
|
||||
this->delta = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for delta.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
delta_defined = true;
|
||||
break;
|
||||
|
||||
case 5: // initial_moles
|
||||
if (!(parser.get_iss() >> this->initial_moles))
|
||||
{
|
||||
this->initial_moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for initial_moles.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
initial_moles_defined = true;
|
||||
break;
|
||||
|
||||
|
||||
case 6: // dissolve_only
|
||||
if (!(parser.get_iss() >> this->dissolve_only))
|
||||
{
|
||||
this->dissolve_only = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for dissolve_only.", CParser::OT_CONTINUE);
|
||||
}
|
||||
dissolve_only_defined = true;
|
||||
break;
|
||||
case 6: // dissolve_only
|
||||
if (!(parser.get_iss() >> this->dissolve_only))
|
||||
{
|
||||
this->dissolve_only = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for dissolve_only.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
dissolve_only_defined = true;
|
||||
break;
|
||||
|
||||
case 7: // force_equality
|
||||
if (!(parser.get_iss() >> this->force_equality))
|
||||
{
|
||||
this->force_equality = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for force_equality.", CParser::OT_CONTINUE);
|
||||
}
|
||||
force_equality_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (name_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Name not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (si_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Si not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (moles_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (delta_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Delta not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (initial_moles_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Initial_moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (dissolve_only_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (force_equality_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Force_equality not defined for PPassemblageComp input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
case 7: // force_equality
|
||||
if (!(parser.get_iss() >> this->force_equality))
|
||||
{
|
||||
this->force_equality = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for force_equality.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
force_equality_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (name_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Name not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (si_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Si not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (moles_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Moles not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (delta_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Delta not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (initial_moles_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Initial_moles not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (dissolve_only_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Dissolve_only not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (force_equality_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Force_equality not defined for PPassemblageComp input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxPPassemblageComp::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxPPassemblageComp::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
|
||||
@ -313,7 +375,9 @@ void cxxPPassemblageComp::mpi_pack(std::vector<int>& ints, std::vector<double>&
|
||||
ints.push_back((int) this->force_equality);
|
||||
ints.push_back((int) this->dissolve_only);
|
||||
}
|
||||
void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
void
|
||||
cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
int i = *ii;
|
||||
@ -330,82 +394,96 @@ void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *d
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxPPassemblageComp::totalize()
|
||||
|
||||
void
|
||||
cxxPPassemblageComp::totalize()
|
||||
{
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
if (this->add_formula != NULL) return;
|
||||
struct phase *phase_ptr;
|
||||
int l;
|
||||
phase_ptr = phase_bsearch(this->name, &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
cxxNameDouble phase_formula(phase_ptr->next_elt);
|
||||
this->totals.add_extensive(phase_formula, this->moles);
|
||||
} else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
return;
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
if (this->add_formula != NULL)
|
||||
return;
|
||||
struct phase *phase_ptr;
|
||||
int l;
|
||||
phase_ptr = phase_bsearch(this->name, &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
cxxNameDouble phase_formula(phase_ptr->next_elt);
|
||||
this->totals.add_extensive(phase_formula, this->moles);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void cxxPPassemblageComp::add(const cxxPPassemblageComp &addee, double extensive)
|
||||
void
|
||||
cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive)
|
||||
{
|
||||
double ext1, ext2, f1, f2;
|
||||
if (extensive == 0.0) return;
|
||||
if (addee.name == NULL) return;
|
||||
// this and addee must have same name
|
||||
// otherwise generate a new PPassemblagComp with multiply
|
||||
double ext1, ext2, f1, f2;
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
if (addee.name == NULL)
|
||||
return;
|
||||
// this and addee must have same name
|
||||
// otherwise generate a new PPassemblagComp with multiply
|
||||
|
||||
ext1 = this->moles;
|
||||
ext2 = addee.moles * extensive;
|
||||
if (ext1 + ext2 != 0) {
|
||||
f1 = ext1/(ext1 + ext2);
|
||||
f2 = ext2/(ext1 + ext2);
|
||||
} else {
|
||||
f1 = 0.5;
|
||||
f2 = 0.5;
|
||||
}
|
||||
//char * name;
|
||||
//char *add_formula;
|
||||
ext1 = this->moles;
|
||||
ext2 = addee.moles * extensive;
|
||||
if (ext1 + ext2 != 0)
|
||||
{
|
||||
f1 = ext1 / (ext1 + ext2);
|
||||
f2 = ext2 / (ext1 + ext2);
|
||||
}
|
||||
else
|
||||
{
|
||||
f1 = 0.5;
|
||||
f2 = 0.5;
|
||||
}
|
||||
//char * name;
|
||||
//char *add_formula;
|
||||
|
||||
if (this->name == NULL && addee.name == NULL) {
|
||||
return;
|
||||
}
|
||||
assert (this->name == addee.name);
|
||||
if (this->add_formula != addee.add_formula) {
|
||||
std::ostringstream oss;
|
||||
oss << "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
//double si;
|
||||
this->si = this->si * f1 + addee.si * f2;
|
||||
//double moles;
|
||||
this->moles += addee.moles * extensive;
|
||||
//double delta;
|
||||
this->delta += addee.delta * extensive;
|
||||
//double initial_moles;
|
||||
this->initial_moles += addee.initial_moles * extensive;
|
||||
//bool force_equality;
|
||||
//bool dissolve_only;
|
||||
if (this->name == NULL && addee.name == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert(this->name == addee.name);
|
||||
if (this->add_formula != addee.add_formula)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss <<
|
||||
"Can not mix two Equilibrium_phases with differing add_formulae., "
|
||||
<< this->name;
|
||||
error_msg(oss.str().c_str(), CONTINUE);
|
||||
input_error++;
|
||||
return;
|
||||
}
|
||||
//double si;
|
||||
this->si = this->si * f1 + addee.si * f2;
|
||||
//double moles;
|
||||
this->moles += addee.moles * extensive;
|
||||
//double delta;
|
||||
this->delta += addee.delta * extensive;
|
||||
//double initial_moles;
|
||||
this->initial_moles += addee.initial_moles * extensive;
|
||||
//bool force_equality;
|
||||
//bool dissolve_only;
|
||||
|
||||
}
|
||||
|
||||
void cxxPPassemblageComp::multiply(double extensive)
|
||||
void
|
||||
cxxPPassemblageComp::multiply(double extensive)
|
||||
{
|
||||
//char * name;
|
||||
//char *add_formula;
|
||||
//double si;
|
||||
//double moles;
|
||||
this->moles *= extensive;
|
||||
//double delta;
|
||||
this->delta *= extensive;
|
||||
//double initial_moles;
|
||||
this->initial_moles *= extensive;
|
||||
//bool force_equality;
|
||||
//bool dissolve_only;
|
||||
//char * name;
|
||||
//char *add_formula;
|
||||
//double si;
|
||||
//double moles;
|
||||
this->moles *= extensive;
|
||||
//double delta;
|
||||
this->delta *= extensive;
|
||||
//double initial_moles;
|
||||
this->initial_moles *= extensive;
|
||||
//bool force_equality;
|
||||
//bool dissolve_only;
|
||||
}
|
||||
|
||||
1996
Parser.cxx
1996
Parser.cxx
File diff suppressed because it is too large
Load Diff
524
Reaction.cxx
524
Reaction.cxx
@ -2,63 +2,68 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "Reaction.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxReaction::cxxReaction()
|
||||
//
|
||||
// default constructor for cxxReaction
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxReaction
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
units = string_hsave("Mol");
|
||||
countSteps = 0;
|
||||
equalIncrements = false;
|
||||
reactantList.type = cxxNameDouble::ND_NAME_COEF;
|
||||
elementList.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
units = string_hsave("Mol");
|
||||
countSteps = 0;
|
||||
equalIncrements = false;
|
||||
reactantList.type = cxxNameDouble::ND_NAME_COEF;
|
||||
elementList.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxReaction::cxxReaction(struct irrev *irrev_ptr)
|
||||
//
|
||||
// constructor for cxxReaction from struct irrev
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxReaction from struct irrev
|
||||
//
|
||||
:
|
||||
cxxNumKeyword(),
|
||||
reactantList(irrev_ptr->list, irrev_ptr->count_list),
|
||||
elementList(irrev_ptr->elts)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
this->set_description(irrev_ptr->description);
|
||||
this->n_user = irrev_ptr->n_user;
|
||||
this->n_user_end = irrev_ptr->n_user_end;
|
||||
this->units = irrev_ptr->units;
|
||||
this->set_description(irrev_ptr->description);
|
||||
this->n_user = irrev_ptr->n_user;
|
||||
this->n_user_end = irrev_ptr->n_user_end;
|
||||
this->units = irrev_ptr->units;
|
||||
// steps
|
||||
if (irrev_ptr->count_steps < 0) {
|
||||
for (i = 0; i < 1; i++) {
|
||||
if (irrev_ptr->count_steps < 0)
|
||||
{
|
||||
for (i = 0; i < 1; i++)
|
||||
{
|
||||
this->steps.push_back(irrev_ptr->steps[i]);
|
||||
}
|
||||
this->countSteps = -irrev_ptr->count_steps;
|
||||
this->equalIncrements = true;
|
||||
} else {
|
||||
for (i = 0; i < irrev_ptr->count_steps; i++) {
|
||||
this->countSteps = -irrev_ptr->count_steps;
|
||||
this->equalIncrements = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < irrev_ptr->count_steps; i++)
|
||||
{
|
||||
this->steps.push_back(irrev_ptr->steps[i]);
|
||||
}
|
||||
this->countSteps = irrev_ptr->count_steps;
|
||||
this->equalIncrements = false;
|
||||
this->countSteps = irrev_ptr->count_steps;
|
||||
this->equalIncrements = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,257 +72,314 @@ cxxReaction::~cxxReaction()
|
||||
}
|
||||
|
||||
|
||||
struct irrev *cxxReaction::cxxReaction2irrev()
|
||||
//
|
||||
// Builds a irrev structure from instance of cxxReaction
|
||||
//
|
||||
struct irrev *
|
||||
cxxReaction::cxxReaction2irrev()
|
||||
//
|
||||
// Builds a irrev structure from instance of cxxReaction
|
||||
//
|
||||
{
|
||||
struct irrev *irrev_ptr;
|
||||
irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof (struct irrev));
|
||||
if (irrev_ptr == NULL) malloc_error();
|
||||
struct irrev *irrev_ptr;
|
||||
irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof(struct irrev));
|
||||
if (irrev_ptr == NULL)
|
||||
malloc_error();
|
||||
|
||||
irrev_ptr->description = this->get_description();
|
||||
irrev_ptr->n_user = this->n_user;
|
||||
irrev_ptr->n_user_end = this->n_user_end;
|
||||
irrev_ptr->description = this->get_description();
|
||||
irrev_ptr->n_user = this->n_user;
|
||||
irrev_ptr->n_user_end = this->n_user_end;
|
||||
|
||||
irrev_ptr->list = this->reactantList.name_coef();
|
||||
irrev_ptr->count_list = (int) this->reactantList.size();
|
||||
if (this->elementList.size() > 0) {
|
||||
irrev_ptr->elts = this->elementList.elt_list();
|
||||
} else {
|
||||
irrev_ptr->list = this->reactantList.name_coef();
|
||||
irrev_ptr->count_list = (int) this->reactantList.size();
|
||||
if (this->elementList.size() > 0)
|
||||
{
|
||||
irrev_ptr->elts = this->elementList.elt_list();
|
||||
}
|
||||
else
|
||||
{
|
||||
// NULL value causes reaction stoichiometry to be calculated
|
||||
irrev_ptr->elts = NULL;
|
||||
irrev_ptr->elts = NULL;
|
||||
}
|
||||
// steps
|
||||
irrev_ptr->steps = NULL;
|
||||
if (this->steps.size() > 0) {
|
||||
irrev_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double)));
|
||||
if (irrev_ptr->steps == NULL) malloc_error();
|
||||
std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps);
|
||||
}
|
||||
if (this->equalIncrements) {
|
||||
irrev_ptr->count_steps = -this->countSteps;
|
||||
} else {
|
||||
irrev_ptr->count_steps = (int) this->steps.size();
|
||||
if (this->steps.size() > 0)
|
||||
{
|
||||
irrev_ptr->steps =
|
||||
(double *)
|
||||
PHRQ_malloc((size_t) (this->steps.size() * sizeof(double)));
|
||||
if (irrev_ptr->steps == NULL)
|
||||
malloc_error();
|
||||
std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps);
|
||||
}
|
||||
irrev_ptr->units = this->units;
|
||||
return(irrev_ptr);
|
||||
if (this->equalIncrements)
|
||||
{
|
||||
irrev_ptr->count_steps = -this->countSteps;
|
||||
}
|
||||
else
|
||||
{
|
||||
irrev_ptr->count_steps = (int) this->steps.size();
|
||||
}
|
||||
irrev_ptr->units = this->units;
|
||||
return (irrev_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxReaction::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Reaction element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<irrev " << std::endl;
|
||||
// Reaction element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<irrev " << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_irrev_gammas=\"" << this->pitzer_irrev_gammas << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_irrev_gammas=\"" << this->
|
||||
pitzer_irrev_gammas << "\"" << std::endl;
|
||||
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list<cxxReactionComp>::const_iterator it = irrevComps.begin(); it != irrevComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list < cxxReactionComp >::const_iterator it =
|
||||
irrevComps.begin(); it != irrevComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxReaction::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Reaction element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "REACTION_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
// Reaction element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "REACTION_RAW " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-units " << this->units << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-units " << this->units << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-reactant_list " << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-reactant_list " << std::endl;
|
||||
this->reactantList.dump_raw(s_oss, indent + 2);
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-element_list " << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-element_list " << std::endl;
|
||||
this->elementList.dump_raw(s_oss, indent + 2);
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-steps " << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent2;
|
||||
for (std::vector<double>::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) {
|
||||
if (i++ == 5) {
|
||||
s_oss << std::endl;
|
||||
s_oss << indent2;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
s_oss << indent1;
|
||||
s_oss << "-steps " << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent2;
|
||||
for (std::vector < double >::const_iterator it = this->steps.begin();
|
||||
it != this->steps.end(); it++)
|
||||
{
|
||||
if (i++ == 5)
|
||||
{
|
||||
s_oss << std::endl;
|
||||
s_oss << indent2;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-equal_increments " << this->equalIncrements << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-equal_increments " << this->equalIncrements << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-count_steps " << this->countSteps << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-count_steps " << this->countSteps << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void cxxReaction::read_raw(CParser& parser)
|
||||
void
|
||||
cxxReaction::read_raw(CParser & parser)
|
||||
{
|
||||
|
||||
int j;
|
||||
double d;
|
||||
double d;
|
||||
CParser::TOKEN_TYPE k;
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("units"); //0
|
||||
vopts.push_back("reactant_list"); //1
|
||||
vopts.push_back("element_list"); //2
|
||||
vopts.push_back("steps"); //3
|
||||
vopts.push_back("equal_increments"); //4
|
||||
vopts.push_back("count_steps"); //5
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("units"); //0
|
||||
vopts.push_back("reactant_list"); //1
|
||||
vopts.push_back("element_list"); //2
|
||||
vopts.push_back("steps"); //3
|
||||
vopts.push_back("equal_increments"); //4
|
||||
vopts.push_back("count_steps"); //5
|
||||
}
|
||||
|
||||
// Read irrev number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool units_defined(false);
|
||||
bool equalIncrements_defined(false);
|
||||
bool countSteps_defined(false);
|
||||
// Read irrev number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in IRREV_COMP_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool units_defined(false);
|
||||
bool equalIncrements_defined(false);
|
||||
bool countSteps_defined(false);
|
||||
|
||||
case 0: // units
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in IRREV_COMP_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 0: // units
|
||||
j = parser.copy_token(token, next_char);
|
||||
if (j == CParser::TT_EMPTY) break;
|
||||
if (j == CParser::TT_EMPTY)
|
||||
break;
|
||||
this->units = string_hsave(token.c_str());
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
units_defined = true;
|
||||
break;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
units_defined = true;
|
||||
break;
|
||||
|
||||
case 1: // reactant_list
|
||||
if ( this->reactantList.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected reactant formula and coefficient.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 1;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 1: // reactant_list
|
||||
if (this->reactantList.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected reactant formula and coefficient.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 1;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 2: // element_list
|
||||
if ( this->elementList.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected element formula and coefficient.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 2;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 2: // element_list
|
||||
if (this->elementList.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected element formula and coefficient.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 2;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 3: // steps
|
||||
while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) {
|
||||
case 3: // steps
|
||||
while ((k =
|
||||
parser.copy_token(token, next_char)) == CParser::TT_DIGIT)
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
if (!(iss >> d)) {
|
||||
if (!(iss >> d))
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for steps.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
parser.error_msg("Expected numeric value for steps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->steps.push_back(d);
|
||||
}
|
||||
}
|
||||
opt_save = 3;
|
||||
useLastLine = false;
|
||||
break;
|
||||
}
|
||||
opt_save = 3;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 4: // equal_increments
|
||||
if (!(parser.get_iss() >> this->equalIncrements))
|
||||
{
|
||||
this->equalIncrements = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
equalIncrements_defined = true;
|
||||
break;
|
||||
case 4: // equal_increments
|
||||
if (!(parser.get_iss() >> this->equalIncrements))
|
||||
{
|
||||
this->equalIncrements = 0;
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Expected boolean value for equalIncrements.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
equalIncrements_defined = true;
|
||||
break;
|
||||
|
||||
case 5: // countSteps
|
||||
if (!(parser.get_iss() >> this->countSteps))
|
||||
{
|
||||
this->countSteps = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for countSteps.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
countSteps_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (units_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Units not defined for REACTION_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (equalIncrements_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Equal_increments not defined for REACTION_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (countSteps_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Count_steps not defined for REACTION_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
case 5: // countSteps
|
||||
if (!(parser.get_iss() >> this->countSteps))
|
||||
{
|
||||
this->countSteps = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for countSteps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
countSteps_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (units_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Units not defined for REACTION_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (equalIncrements_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Equal_increments not defined for REACTION_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (countSteps_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Count_steps not defined for REACTION_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
540
ReadClass.cxx
540
ReadClass.cxx
@ -1,5 +1,5 @@
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
#include "Parser.h"
|
||||
#include "Solution.h"
|
||||
@ -20,12 +20,13 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
extern int reading_database (void);
|
||||
extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword,
|
||||
int print);
|
||||
extern int reading_database(void);
|
||||
extern int check_line(const char *string, int allow_empty, int allow_eof,
|
||||
int allow_keyword, int print);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_solution_raw (void)
|
||||
int
|
||||
read_solution_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -54,10 +55,12 @@ int read_solution_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("solution_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("solution_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -68,16 +71,17 @@ int read_solution_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -91,24 +95,31 @@ int read_solution_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL) {
|
||||
if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL)
|
||||
{
|
||||
solution_free(solution[n]);
|
||||
solution[n] = soln_ptr;
|
||||
} else {
|
||||
n=count_solution++;
|
||||
if (count_solution >= max_solution) {
|
||||
space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) );
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_solution++;
|
||||
if (count_solution >= max_solution)
|
||||
{
|
||||
space((void **) ((void *) &(solution)), count_solution,
|
||||
&max_solution, sizeof(struct solution *));
|
||||
}
|
||||
solution[n] = soln_ptr;
|
||||
solution_sort ();
|
||||
solution_sort();
|
||||
}
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_exchange_raw (void)
|
||||
int
|
||||
read_exchange_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -137,10 +148,12 @@ int read_exchange_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("exchange_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("exchange_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -151,16 +164,17 @@ int read_exchange_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -173,26 +187,33 @@ int read_exchange_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL) {
|
||||
if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
exchange_free(&exchange[n]);
|
||||
exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user);
|
||||
} else {
|
||||
n=count_exchange++;
|
||||
if (count_exchange >= max_exchange) {
|
||||
space ((void **) ((void *) &(exchange)), count_exchange, &max_exchange, sizeof (struct exchange *) );
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_exchange++;
|
||||
if (count_exchange >= max_exchange)
|
||||
{
|
||||
space((void **) ((void *) &(exchange)), count_exchange,
|
||||
&max_exchange, sizeof(struct exchange *));
|
||||
}
|
||||
exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user);
|
||||
exchange_sort ();
|
||||
exchange_sort();
|
||||
}
|
||||
exchange_free(exchange_ptr);
|
||||
free_check_null(exchange_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_surface_raw (void)
|
||||
int
|
||||
read_surface_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -221,10 +242,12 @@ int read_surface_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("surface_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("surface_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -235,16 +258,17 @@ int read_surface_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -257,26 +281,33 @@ int read_surface_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (surface_bsearch(surface_ptr->n_user, &n) != NULL) {
|
||||
if (surface_bsearch(surface_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
surface_free(&surface[n]);
|
||||
surface_copy(surface_ptr, &surface[n], surface_ptr->n_user);
|
||||
} else {
|
||||
n=count_surface++;
|
||||
if (count_surface >= max_surface) {
|
||||
space ((void **) ((void *) &(surface)), count_surface, &max_surface, sizeof (struct surface *) );
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_surface++;
|
||||
if (count_surface >= max_surface)
|
||||
{
|
||||
space((void **) ((void *) &(surface)), count_surface,
|
||||
&max_surface, sizeof(struct surface *));
|
||||
}
|
||||
surface_copy(surface_ptr, &surface[n], surface_ptr->n_user);
|
||||
surface_sort ();
|
||||
surface_sort();
|
||||
}
|
||||
surface_free(surface_ptr);
|
||||
free_check_null(surface_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_equilibrium_phases_raw (void)
|
||||
int
|
||||
read_equilibrium_phases_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -305,10 +336,13 @@ int read_equilibrium_phases_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("equilibrium_phases_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value =
|
||||
check_line("equilibrium_phases_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -319,48 +353,59 @@ int read_equilibrium_phases_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
cxxPPassemblage ex;
|
||||
ex.read_raw(parser);
|
||||
struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage();
|
||||
struct pp_assemblage *pp_assemblage_ptr =
|
||||
ex.cxxPPassemblage2pp_assemblage();
|
||||
int n;
|
||||
|
||||
/*
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL) {
|
||||
if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
pp_assemblage_free(&pp_assemblage[n]);
|
||||
pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user);
|
||||
} else {
|
||||
n=count_pp_assemblage++;
|
||||
if (count_pp_assemblage >= max_pp_assemblage) {
|
||||
space ((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, &max_pp_assemblage, sizeof (struct pp_assemblage *) );
|
||||
pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n],
|
||||
pp_assemblage_ptr->n_user);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_pp_assemblage++;
|
||||
if (count_pp_assemblage >= max_pp_assemblage)
|
||||
{
|
||||
space((void **) ((void *) &(pp_assemblage)), count_pp_assemblage,
|
||||
&max_pp_assemblage, sizeof(struct pp_assemblage *));
|
||||
}
|
||||
pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user);
|
||||
pp_assemblage_sort ();
|
||||
pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n],
|
||||
pp_assemblage_ptr->n_user);
|
||||
pp_assemblage_sort();
|
||||
}
|
||||
pp_assemblage_free(pp_assemblage_ptr);
|
||||
free_check_null(pp_assemblage_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_kinetics_raw (void)
|
||||
int
|
||||
read_kinetics_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -389,10 +434,12 @@ int read_kinetics_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("kinetics_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("kinetics_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -403,16 +450,17 @@ int read_kinetics_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -425,26 +473,33 @@ int read_kinetics_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL) {
|
||||
if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
kinetics_free(&kinetics[n]);
|
||||
kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user);
|
||||
} else {
|
||||
n=count_kinetics++;
|
||||
if (count_kinetics >= max_kinetics) {
|
||||
space ((void **) ((void *) &(kinetics)), count_kinetics, &max_kinetics, sizeof (struct kinetics *) );
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_kinetics++;
|
||||
if (count_kinetics >= max_kinetics)
|
||||
{
|
||||
space((void **) ((void *) &(kinetics)), count_kinetics,
|
||||
&max_kinetics, sizeof(struct kinetics *));
|
||||
}
|
||||
kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user);
|
||||
kinetics_sort ();
|
||||
kinetics_sort();
|
||||
}
|
||||
kinetics_free(kinetics_ptr);
|
||||
free_check_null(kinetics_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_solid_solutions_raw (void)
|
||||
int
|
||||
read_solid_solutions_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -473,10 +528,13 @@ int read_solid_solutions_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value =
|
||||
check_line("solid_solution_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -487,48 +545,60 @@ int read_solid_solutions_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
cxxSSassemblage ex;
|
||||
ex.read_raw(parser);
|
||||
struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage();
|
||||
struct s_s_assemblage *s_s_assemblage_ptr =
|
||||
ex.cxxSSassemblage2s_s_assemblage();
|
||||
int n;
|
||||
|
||||
/*
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) {
|
||||
if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
s_s_assemblage_free(&s_s_assemblage[n]);
|
||||
s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user);
|
||||
} else {
|
||||
n=count_s_s_assemblage++;
|
||||
if (count_s_s_assemblage >= max_s_s_assemblage) {
|
||||
space ((void **) ((void *) &(s_s_assemblage)), count_s_s_assemblage, &max_s_s_assemblage, sizeof (struct s_s_assemblage *) );
|
||||
s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n],
|
||||
s_s_assemblage_ptr->n_user);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_s_s_assemblage++;
|
||||
if (count_s_s_assemblage >= max_s_s_assemblage)
|
||||
{
|
||||
space((void **) ((void *) &(s_s_assemblage)),
|
||||
count_s_s_assemblage, &max_s_s_assemblage,
|
||||
sizeof(struct s_s_assemblage *));
|
||||
}
|
||||
s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user);
|
||||
s_s_assemblage_sort ();
|
||||
s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n],
|
||||
s_s_assemblage_ptr->n_user);
|
||||
s_s_assemblage_sort();
|
||||
}
|
||||
s_s_assemblage_free(s_s_assemblage_ptr);
|
||||
free_check_null(s_s_assemblage_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_gas_phase_raw (void)
|
||||
int
|
||||
read_gas_phase_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -557,10 +627,12 @@ int read_gas_phase_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("gas_phase_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("gas_phase_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -571,16 +643,17 @@ int read_gas_phase_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -593,26 +666,33 @@ int read_gas_phase_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL) {
|
||||
if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
gas_phase_free(&gas_phase[n]);
|
||||
gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user);
|
||||
} else {
|
||||
n=count_gas_phase++;
|
||||
if (count_gas_phase >= max_gas_phase) {
|
||||
space ((void **) ((void *) &(gas_phase)), count_gas_phase, &max_gas_phase, sizeof (struct gas_phase *) );
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_gas_phase++;
|
||||
if (count_gas_phase >= max_gas_phase)
|
||||
{
|
||||
space((void **) ((void *) &(gas_phase)), count_gas_phase,
|
||||
&max_gas_phase, sizeof(struct gas_phase *));
|
||||
}
|
||||
gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user);
|
||||
gas_phase_sort ();
|
||||
gas_phase_sort();
|
||||
}
|
||||
gas_phase_free(gas_phase_ptr);
|
||||
free_check_null(gas_phase_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_reaction_raw (void)
|
||||
int
|
||||
read_reaction_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -641,10 +721,12 @@ int read_reaction_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("reaction_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("reaction_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -655,16 +737,17 @@ int read_reaction_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -677,25 +760,34 @@ int read_reaction_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL) {
|
||||
if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
irrev_free(&irrev[n]);
|
||||
irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user);
|
||||
} else {
|
||||
n=count_irrev++;
|
||||
irrev = (struct irrev *) PHRQ_realloc(irrev, (size_t) count_irrev * sizeof (struct irrev));
|
||||
if (irrev == NULL) malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_irrev++;
|
||||
irrev =
|
||||
(struct irrev *) PHRQ_realloc(irrev,
|
||||
(size_t) count_irrev *
|
||||
sizeof(struct irrev));
|
||||
if (irrev == NULL)
|
||||
malloc_error();
|
||||
irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user);
|
||||
irrev_sort ();
|
||||
irrev_sort();
|
||||
}
|
||||
irrev_free(irrev_ptr);
|
||||
free_check_null(irrev_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_mix_raw (void)
|
||||
int
|
||||
read_mix_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -724,10 +816,12 @@ int read_mix_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("mix_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("mix_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -738,16 +832,17 @@ int read_mix_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -760,25 +855,34 @@ int read_mix_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (mix_bsearch(mix_ptr->n_user, &n) != NULL) {
|
||||
if (mix_bsearch(mix_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
mix_free(&mix[n]);
|
||||
mix_copy(mix_ptr, &mix[n], mix_ptr->n_user);
|
||||
} else {
|
||||
n=count_mix++;
|
||||
mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof (struct mix));
|
||||
if (mix == NULL) malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_mix++;
|
||||
mix =
|
||||
(struct mix *) PHRQ_realloc(mix,
|
||||
(size_t) count_mix *
|
||||
sizeof(struct mix));
|
||||
if (mix == NULL)
|
||||
malloc_error();
|
||||
mix_copy(mix_ptr, &mix[n], mix_ptr->n_user);
|
||||
mix_sort ();
|
||||
mix_sort();
|
||||
}
|
||||
mix_free(mix_ptr);
|
||||
free_check_null(mix_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int read_temperature_raw (void)
|
||||
int
|
||||
read_temperature_raw(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -807,10 +911,12 @@ int read_temperature_raw (void)
|
||||
*/
|
||||
int save_echo_input = pr.echo_input;
|
||||
pr.echo_input = FALSE;
|
||||
for (;;) {
|
||||
return_value = check_line("temperature_raw",TRUE,TRUE,TRUE,FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD ) break;
|
||||
for (;;)
|
||||
{
|
||||
return_value = check_line("temperature_raw", TRUE, TRUE, TRUE, FALSE);
|
||||
/* empty, eof, keyword, print */
|
||||
if (return_value == EOF || return_value == KEYWORD)
|
||||
break;
|
||||
keywordLines.append(line);
|
||||
keywordLines.append("\n");
|
||||
}
|
||||
@ -821,16 +927,17 @@ int read_temperature_raw (void)
|
||||
std::ostringstream oss_err;
|
||||
|
||||
CParser parser(iss_in, oss_out, oss_err);
|
||||
assert (!reading_database ());
|
||||
if (pr.echo_input == FALSE)
|
||||
assert(!reading_database());
|
||||
if (pr.echo_input == FALSE)
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
} else
|
||||
parser.set_echo_file(CParser::EO_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
parser.set_echo_file(CParser::EO_NOKEYWORDS);
|
||||
}
|
||||
//For testing, need to read line to get started
|
||||
std::vector<std::string> vopts;
|
||||
std::vector < std::string > vopts;
|
||||
std::istream::pos_type next_char;
|
||||
parser.get_option(vopts, next_char);
|
||||
|
||||
@ -843,20 +950,29 @@ int read_temperature_raw (void)
|
||||
* This is not quite right, may not produce sort order, forced sort
|
||||
*/
|
||||
|
||||
if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL) {
|
||||
if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL)
|
||||
{
|
||||
temperature_free(&temperature[n]);
|
||||
temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user);
|
||||
} else {
|
||||
n=count_temperature++;
|
||||
temperature = (struct temperature *) PHRQ_realloc(temperature, (size_t) count_temperature * sizeof (struct temperature));
|
||||
if (temperature == NULL) malloc_error();
|
||||
temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user);
|
||||
temperature_sort ();
|
||||
temperature_copy(temperature_ptr, &temperature[n],
|
||||
temperature_ptr->n_user);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_temperature++;
|
||||
temperature =
|
||||
(struct temperature *) PHRQ_realloc(temperature,
|
||||
(size_t) count_temperature *
|
||||
sizeof(struct temperature));
|
||||
if (temperature == NULL)
|
||||
malloc_error();
|
||||
temperature_copy(temperature_ptr, &temperature[n],
|
||||
temperature_ptr->n_user);
|
||||
temperature_sort();
|
||||
}
|
||||
temperature_free(temperature_ptr);
|
||||
free_check_null(temperature_ptr);
|
||||
|
||||
// Need to output the next keyword
|
||||
output_msg (OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return(return_value);
|
||||
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
1134
SAXPhreeqc.cxx
1134
SAXPhreeqc.cxx
File diff suppressed because it is too large
Load Diff
394
SSassemblage.cxx
394
SSassemblage.cxx
@ -2,206 +2,241 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "SSassemblage.h"
|
||||
#include "SSassemblageSS.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxSSassemblage::cxxSSassemblage()
|
||||
//
|
||||
// default constructor for cxxSSassemblage
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxSSassemblage
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
}
|
||||
|
||||
cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage *s_s_assemblage_ptr)
|
||||
//
|
||||
// constructor for cxxSSassemblage from struct SSassemblage
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
int i;
|
||||
this->set_description(s_s_assemblage_ptr->description);
|
||||
n_user = s_s_assemblage_ptr->n_user;
|
||||
n_user_end = s_s_assemblage_ptr->n_user_end;
|
||||
for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) {
|
||||
cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i]));
|
||||
ssAssemblageSSs.push_back(ssSS);
|
||||
}
|
||||
}
|
||||
cxxSSassemblage::cxxSSassemblage(const std::map<int, cxxSSassemblage> &entities, cxxMix &mix, int n_user)
|
||||
cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage * s_s_assemblage_ptr)
|
||||
//
|
||||
// constructor for cxxSSassemblage from struct SSassemblage
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
//std::list<cxxSSassemblageSS> ssAssemblageSSs;
|
||||
int i;
|
||||
this->set_description(s_s_assemblage_ptr->description);
|
||||
n_user = s_s_assemblage_ptr->n_user;
|
||||
n_user_end = s_s_assemblage_ptr->n_user_end;
|
||||
for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++)
|
||||
{
|
||||
cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i]));
|
||||
ssAssemblageSSs.push_back(ssSS);
|
||||
}
|
||||
}
|
||||
cxxSSassemblage::cxxSSassemblage(const std::map < int,
|
||||
cxxSSassemblage > &entities, cxxMix & mix,
|
||||
int n_user):
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
//std::list<cxxSSassemblageSS> ssAssemblageSSs;
|
||||
//
|
||||
// Mix
|
||||
//
|
||||
std::map<int, double> *mixcomps = mix.comps();
|
||||
std::map<int, double>::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxSSassemblage *entity_ptr = &(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
}
|
||||
}
|
||||
std::map < int, double >*mixcomps = mix.comps();
|
||||
std::map < int, double >::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxSSassemblage *entity_ptr =
|
||||
&(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxSSassemblage::~cxxSSassemblage()
|
||||
{
|
||||
}
|
||||
|
||||
struct s_s_assemblage *cxxSSassemblage::cxxSSassemblage2s_s_assemblage()
|
||||
//
|
||||
// Builds a s_s_assemblage structure from instance of cxxSSassemblage
|
||||
//
|
||||
struct s_s_assemblage *
|
||||
cxxSSassemblage::cxxSSassemblage2s_s_assemblage()
|
||||
//
|
||||
// Builds a s_s_assemblage structure from instance of cxxSSassemblage
|
||||
//
|
||||
{
|
||||
struct s_s_assemblage *s_s_assemblage_ptr = s_s_assemblage_alloc();
|
||||
|
||||
s_s_assemblage_ptr->description = this->get_description();
|
||||
s_s_assemblage_ptr->n_user = this->n_user;
|
||||
s_s_assemblage_ptr->n_user_end = this->n_user_end;
|
||||
s_s_assemblage_ptr->new_def = FALSE;
|
||||
s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size();
|
||||
s_s_assemblage_ptr->s_s = cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs);
|
||||
return(s_s_assemblage_ptr);
|
||||
struct s_s_assemblage *s_s_assemblage_ptr = s_s_assemblage_alloc();
|
||||
|
||||
s_s_assemblage_ptr->description = this->get_description();
|
||||
s_s_assemblage_ptr->n_user = this->n_user;
|
||||
s_s_assemblage_ptr->n_user_end = this->n_user_end;
|
||||
s_s_assemblage_ptr->new_def = FALSE;
|
||||
s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size();
|
||||
s_s_assemblage_ptr->s_s =
|
||||
cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs);
|
||||
return (s_s_assemblage_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxSSassemblage::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// SSassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<EQUILIBRIUM_PHASES " << std::endl;
|
||||
// SSassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<EQUILIBRIUM_PHASES " << std::endl;
|
||||
|
||||
// eltList
|
||||
this->eltList.dump_xml(s_oss, indent + 1);
|
||||
// eltList
|
||||
this->eltList.dump_xml(s_oss, indent + 1);
|
||||
|
||||
// ssAssemblageSSs
|
||||
s_oss << indent1;
|
||||
s_oss << "<pure_phases " << std::endl;
|
||||
for (std::list<cxxSSassemblageSS>::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// ssAssemblageSSs
|
||||
s_oss << indent1;
|
||||
s_oss << "<pure_phases " << std::endl;
|
||||
for (std::list < cxxSSassemblageSS >::const_iterator it =
|
||||
ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void cxxSSassemblage::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// SSassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "SOLID_SOLUTIONS_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
// SSassemblage element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "SOLID_SOLUTIONS_RAW " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
// ssAssemblageSSs
|
||||
for (std::list<cxxSSassemblageSS>::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) {
|
||||
s_oss << indent1;
|
||||
s_oss << "-solid_solution" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
// ssAssemblageSSs
|
||||
for (std::list < cxxSSassemblageSS >::const_iterator it =
|
||||
ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it)
|
||||
{
|
||||
s_oss << indent1;
|
||||
s_oss << "-solid_solution" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
void cxxSSassemblage::read_raw(CParser& parser)
|
||||
void
|
||||
cxxSSassemblage::read_raw(CParser & parser)
|
||||
{
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("solid_solution"); // 0
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("solid_solution"); // 0
|
||||
}
|
||||
|
||||
// Read SSassemblage number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
// Read SSassemblage number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in EQUILIBRIUM_PHASES_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
|
||||
case 0: // solid_solution
|
||||
{
|
||||
cxxSSassemblageSS ssSS;
|
||||
ssSS.read_raw(parser);
|
||||
this->ssAssemblageSSs.push_back(ssSS);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.
|
||||
error_msg("Unknown input in EQUILIBRIUM_PHASES_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 0: // solid_solution
|
||||
{
|
||||
cxxSSassemblageSS ssSS;
|
||||
ssSS.read_raw(parser);
|
||||
this->ssAssemblageSSs.push_back(ssSS);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxSSassemblage::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxSSassemblage::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/* int n_user; */
|
||||
ints.push_back(this->n_user);
|
||||
ints.push_back((int) this->ssAssemblageSSs.size());
|
||||
for (std::list<cxxSSassemblageSS>::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) {
|
||||
for (std::list < cxxSSassemblageSS >::iterator it =
|
||||
this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end();
|
||||
it++)
|
||||
{
|
||||
it->mpi_pack(ints, doubles);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
void
|
||||
cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i = *ii;
|
||||
@ -213,7 +248,8 @@ void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
int count = ints[i++];
|
||||
this->ssAssemblageSSs.clear();
|
||||
for (int n = 0; n < count; n++) {
|
||||
for (int n = 0; n < count; n++)
|
||||
{
|
||||
cxxSSassemblageSS ssc;
|
||||
ssc.mpi_unpack(ints, &i, doubles, &d);
|
||||
this->ssAssemblageSSs.push_back(ssc);
|
||||
@ -222,43 +258,51 @@ void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxSSassemblage::totalize()
|
||||
|
||||
void
|
||||
cxxSSassemblage::totalize()
|
||||
{
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (std::list<cxxSSassemblageSS>::iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it)
|
||||
{
|
||||
it->totalize();
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
}
|
||||
return;
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (std::list < cxxSSassemblageSS >::iterator it =
|
||||
ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it)
|
||||
{
|
||||
it->totalize();
|
||||
this->totals.add_extensive(it->get_totals(), 1.0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cxxSSassemblage::add(const cxxSSassemblage &addee, double extensive)
|
||||
//
|
||||
// Add to existing ssassemblage to "this" ssassemblage
|
||||
//
|
||||
void
|
||||
cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive)
|
||||
//
|
||||
// Add to existing ssassemblage to "this" ssassemblage
|
||||
//
|
||||
{
|
||||
if (extensive == 0.0) return;
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
|
||||
for (std::list<cxxSSassemblageSS>::const_iterator itadd = addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); ++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list<cxxSSassemblageSS>::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); ++it)
|
||||
{
|
||||
if (it->get_name() == itadd->get_name())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
cxxSSassemblageSS entity = *itadd;
|
||||
entity.multiply(extensive);
|
||||
this->ssAssemblageSSs.push_back(entity);
|
||||
}
|
||||
}
|
||||
for (std::list < cxxSSassemblageSS >::const_iterator itadd =
|
||||
addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end();
|
||||
++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list < cxxSSassemblageSS >::iterator it =
|
||||
this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end();
|
||||
++it)
|
||||
{
|
||||
if (it->get_name() == itadd->get_name())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
cxxSSassemblageSS entity = *itadd;
|
||||
entity.multiply(extensive);
|
||||
this->ssAssemblageSSs.push_back(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "SSassemblageSS.h"
|
||||
#include "NameDouble.h"
|
||||
#include "Dictionary.h"
|
||||
@ -13,437 +13,492 @@
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxSSassemblageSS::cxxSSassemblageSS()
|
||||
//
|
||||
// default constructor for cxxSSassemblageSS
|
||||
//
|
||||
//
|
||||
// default constructor for cxxSSassemblageSS
|
||||
//
|
||||
{
|
||||
name = NULL;
|
||||
//total_moles = 0;
|
||||
a0 = 0;
|
||||
a1 = 0;
|
||||
ag0 = 0;
|
||||
ag1 = 0;
|
||||
miscibility = false;
|
||||
//spinodal = false;
|
||||
//tk = 25.;
|
||||
xb1 = 0;
|
||||
xb2 = 0;
|
||||
//SS_PARAMETER_TYPE type = SS_PARM_NONE;
|
||||
//double p[4];
|
||||
name = NULL;
|
||||
//total_moles = 0;
|
||||
a0 = 0;
|
||||
a1 = 0;
|
||||
ag0 = 0;
|
||||
ag1 = 0;
|
||||
miscibility = false;
|
||||
//spinodal = false;
|
||||
//tk = 25.;
|
||||
xb1 = 0;
|
||||
xb2 = 0;
|
||||
//SS_PARAMETER_TYPE type = SS_PARM_NONE;
|
||||
//double p[4];
|
||||
}
|
||||
|
||||
cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr)
|
||||
//
|
||||
// constructor for cxxSSassemblageSS from struct s_s
|
||||
//
|
||||
|
||||
//
|
||||
// constructor for cxxSSassemblageSS from struct s_s
|
||||
//
|
||||
{
|
||||
name = s_s_ptr->name;
|
||||
//total_moles = s_s_ptr->total_moles;
|
||||
a0 = s_s_ptr->a0;
|
||||
a1 = s_s_ptr->a1;
|
||||
ag0 = s_s_ptr->ag0;
|
||||
ag1 = s_s_ptr->ag1;
|
||||
miscibility = (s_s_ptr->miscibility == TRUE);
|
||||
//spinodal = (s_s_ptr->spinodal == TRUE);
|
||||
//tk = s_s_ptr->tk;
|
||||
xb1 = s_s_ptr->xb1;
|
||||
xb2 = s_s_ptr->xb2;
|
||||
//type = s_s_ptr->input_case;
|
||||
/*
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[i] = s_s_ptr->p[i];
|
||||
}
|
||||
*/
|
||||
int i;
|
||||
for (i = 0; i < s_s_ptr->count_comps; i++) {
|
||||
comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles;
|
||||
}
|
||||
name = s_s_ptr->name;
|
||||
//total_moles = s_s_ptr->total_moles;
|
||||
a0 = s_s_ptr->a0;
|
||||
a1 = s_s_ptr->a1;
|
||||
ag0 = s_s_ptr->ag0;
|
||||
ag1 = s_s_ptr->ag1;
|
||||
miscibility = (s_s_ptr->miscibility == TRUE);
|
||||
//spinodal = (s_s_ptr->spinodal == TRUE);
|
||||
//tk = s_s_ptr->tk;
|
||||
xb1 = s_s_ptr->xb1;
|
||||
xb2 = s_s_ptr->xb2;
|
||||
//type = s_s_ptr->input_case;
|
||||
/*
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[i] = s_s_ptr->p[i];
|
||||
}
|
||||
*/
|
||||
int i;
|
||||
for (i = 0; i < s_s_ptr->count_comps; i++)
|
||||
{
|
||||
comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles;
|
||||
}
|
||||
}
|
||||
|
||||
cxxSSassemblageSS::~cxxSSassemblageSS()
|
||||
{
|
||||
}
|
||||
|
||||
struct s_s *cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list<cxxSSassemblageSS>& el)
|
||||
//
|
||||
// Builds s_s structure from of cxxSSassemblageSS
|
||||
//
|
||||
struct s_s *
|
||||
cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > &el)
|
||||
//
|
||||
// Builds s_s structure from of cxxSSassemblageSS
|
||||
//
|
||||
{
|
||||
|
||||
//
|
||||
// generate s_s structures
|
||||
//
|
||||
struct s_s *s_s_ptr = (struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s)));
|
||||
if (s_s_ptr == NULL) malloc_error();
|
||||
int j = 0;
|
||||
for (std::list<cxxSSassemblageSS>::iterator it = el.begin(); it != el.end(); ++it) {
|
||||
s_s_ptr[j].name = it->name;
|
||||
//s_s_ptr[j].total_moles = it->total_moles;
|
||||
s_s_ptr[j].total_moles = 0;
|
||||
s_s_ptr[j].dn = 0;
|
||||
s_s_ptr[j].a0 = it->a0;
|
||||
s_s_ptr[j].a1 = it->a1;
|
||||
s_s_ptr[j].ag0 = it->ag0;
|
||||
s_s_ptr[j].ag1 = it->ag1;
|
||||
//s_s_ptr[j].ag0 = 0;
|
||||
//s_s_ptr[j].ag1 = 0;
|
||||
s_s_ptr[j].s_s_in = TRUE;
|
||||
s_s_ptr[j].miscibility = it->miscibility;
|
||||
//s_s_ptr[j].spinodal = it->spinodal;
|
||||
s_s_ptr[j].spinodal = FALSE;
|
||||
//s_s_ptr[j].tk = it->tk;
|
||||
s_s_ptr[j].tk = 273.15;
|
||||
s_s_ptr[j].xb1 = it->xb1;
|
||||
s_s_ptr[j].xb2 = it->xb2;
|
||||
s_s_ptr[j].input_case = 0;
|
||||
s_s_ptr[j].p[0] = 0;
|
||||
s_s_ptr[j].p[1] = 0;
|
||||
s_s_ptr[j].p[2] = 0;
|
||||
s_s_ptr[j].p[3] = 0;
|
||||
//
|
||||
// generate s_s_comp structures
|
||||
//
|
||||
s_s_ptr[j].count_comps = (int) it->comps.size();
|
||||
s_s_ptr[j].comps = NULL;
|
||||
if (it->comps.size() > 0) {
|
||||
int i = 0;
|
||||
int n;
|
||||
struct s_s_comp *s_s_comp_ptr = (struct s_s_comp *) PHRQ_malloc((size_t) (it->comps.size() * sizeof(struct s_s_comp)));
|
||||
if (s_s_comp_ptr == NULL) malloc_error();
|
||||
for (cxxNameDouble::iterator itc = it->comps.begin(); itc != it->comps.end(); ++ itc) {
|
||||
s_s_comp_ptr[i].name = itc->first;
|
||||
s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE);
|
||||
s_s_comp_ptr[i].initial_moles = 0;
|
||||
s_s_comp_ptr[i].moles = itc->second;
|
||||
s_s_comp_ptr[i].init_moles = 0;
|
||||
s_s_comp_ptr[i].delta = 0;
|
||||
s_s_comp_ptr[i].fraction_x = 0;
|
||||
s_s_comp_ptr[i].log10_lambda = 0;
|
||||
s_s_comp_ptr[i].log10_fraction_x = 0;
|
||||
s_s_comp_ptr[i].dn = 0;
|
||||
s_s_comp_ptr[i].dnc = 0;
|
||||
s_s_comp_ptr[i].dnb = 0;
|
||||
i++;
|
||||
}
|
||||
s_s_ptr[j].comps = s_s_comp_ptr;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return(s_s_ptr);
|
||||
//
|
||||
// generate s_s structures
|
||||
//
|
||||
struct s_s *s_s_ptr =
|
||||
(struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s)));
|
||||
if (s_s_ptr == NULL)
|
||||
malloc_error();
|
||||
int j = 0;
|
||||
for (std::list < cxxSSassemblageSS >::iterator it = el.begin();
|
||||
it != el.end(); ++it)
|
||||
{
|
||||
s_s_ptr[j].name = it->name;
|
||||
//s_s_ptr[j].total_moles = it->total_moles;
|
||||
s_s_ptr[j].total_moles = 0;
|
||||
s_s_ptr[j].dn = 0;
|
||||
s_s_ptr[j].a0 = it->a0;
|
||||
s_s_ptr[j].a1 = it->a1;
|
||||
s_s_ptr[j].ag0 = it->ag0;
|
||||
s_s_ptr[j].ag1 = it->ag1;
|
||||
//s_s_ptr[j].ag0 = 0;
|
||||
//s_s_ptr[j].ag1 = 0;
|
||||
s_s_ptr[j].s_s_in = TRUE;
|
||||
s_s_ptr[j].miscibility = it->miscibility;
|
||||
//s_s_ptr[j].spinodal = it->spinodal;
|
||||
s_s_ptr[j].spinodal = FALSE;
|
||||
//s_s_ptr[j].tk = it->tk;
|
||||
s_s_ptr[j].tk = 273.15;
|
||||
s_s_ptr[j].xb1 = it->xb1;
|
||||
s_s_ptr[j].xb2 = it->xb2;
|
||||
s_s_ptr[j].input_case = 0;
|
||||
s_s_ptr[j].p[0] = 0;
|
||||
s_s_ptr[j].p[1] = 0;
|
||||
s_s_ptr[j].p[2] = 0;
|
||||
s_s_ptr[j].p[3] = 0;
|
||||
//
|
||||
// generate s_s_comp structures
|
||||
//
|
||||
s_s_ptr[j].count_comps = (int) it->comps.size();
|
||||
s_s_ptr[j].comps = NULL;
|
||||
if (it->comps.size() > 0)
|
||||
{
|
||||
int i = 0;
|
||||
int n;
|
||||
struct s_s_comp *s_s_comp_ptr =
|
||||
(struct s_s_comp *)
|
||||
PHRQ_malloc((size_t)
|
||||
(it->comps.size() * sizeof(struct s_s_comp)));
|
||||
if (s_s_comp_ptr == NULL)
|
||||
malloc_error();
|
||||
for (cxxNameDouble::iterator itc = it->comps.begin();
|
||||
itc != it->comps.end(); ++itc)
|
||||
{
|
||||
s_s_comp_ptr[i].name = itc->first;
|
||||
s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE);
|
||||
s_s_comp_ptr[i].initial_moles = 0;
|
||||
s_s_comp_ptr[i].moles = itc->second;
|
||||
s_s_comp_ptr[i].init_moles = 0;
|
||||
s_s_comp_ptr[i].delta = 0;
|
||||
s_s_comp_ptr[i].fraction_x = 0;
|
||||
s_s_comp_ptr[i].log10_lambda = 0;
|
||||
s_s_comp_ptr[i].log10_fraction_x = 0;
|
||||
s_s_comp_ptr[i].dn = 0;
|
||||
s_s_comp_ptr[i].dnc = 0;
|
||||
s_s_comp_ptr[i].dnb = 0;
|
||||
i++;
|
||||
}
|
||||
s_s_ptr[j].comps = s_s_comp_ptr;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return (s_s_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxSSassemblageSS::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// S_S element and attributes
|
||||
// S_S element and attributes
|
||||
|
||||
s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl;
|
||||
s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << std::endl;
|
||||
s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl;
|
||||
s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl;
|
||||
s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl;
|
||||
s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl;
|
||||
s_oss << indent0 << "add_formula=\"" << this->
|
||||
add_formula << "\"" << std::endl;
|
||||
s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl;
|
||||
s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl;
|
||||
s_oss << indent0 << "initial_moles=\"" << this->
|
||||
initial_moles << "\"" << std::endl;
|
||||
s_oss << indent0 << "dissolve_only=\"" << this->
|
||||
dissolve_only << "\"" << std::endl;
|
||||
|
||||
}
|
||||
#endif
|
||||
void cxxSSassemblageSS::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
|
||||
// S_S element and attributes
|
||||
// S_S element and attributes
|
||||
|
||||
s_oss << indent0 << "-name " << this->name << std::endl;
|
||||
//s_oss << indent0 << "-total_moles " << this->total_moles << std::endl;
|
||||
s_oss << indent0 << "-a0 " << this->a0 << std::endl;
|
||||
s_oss << indent0 << "-a1 " << this->a1 << std::endl;
|
||||
s_oss << indent0 << "-ag0 " << this->ag0 << std::endl;
|
||||
s_oss << indent0 << "-ag1 " << this->ag1 << std::endl;
|
||||
s_oss << indent0 << "-miscibility " << this->miscibility << std::endl;
|
||||
//s_oss << indent0 << "-spinodal " << this->spinodal << std::endl;
|
||||
//s_oss << indent0 << "-tk " << this->tk << std::endl;
|
||||
s_oss << indent0 << "-xb1 " << this->xb1 << std::endl;
|
||||
s_oss << indent0 << "-xb2 " << this->xb2 << std::endl;
|
||||
s_oss << indent0 << "-component " << std::endl;
|
||||
this->comps.dump_raw(s_oss, indent + 1);
|
||||
s_oss << indent0 << "-name " << this->name << std::endl;
|
||||
//s_oss << indent0 << "-total_moles " << this->total_moles << std::endl;
|
||||
s_oss << indent0 << "-a0 " << this->a0 << std::endl;
|
||||
s_oss << indent0 << "-a1 " << this->a1 << std::endl;
|
||||
s_oss << indent0 << "-ag0 " << this->ag0 << std::endl;
|
||||
s_oss << indent0 << "-ag1 " << this->ag1 << std::endl;
|
||||
s_oss << indent0 << "-miscibility " << this->
|
||||
miscibility << std::endl;
|
||||
//s_oss << indent0 << "-spinodal " << this->spinodal << std::endl;
|
||||
//s_oss << indent0 << "-tk " << this->tk << std::endl;
|
||||
s_oss << indent0 << "-xb1 " << this->xb1 << std::endl;
|
||||
s_oss << indent0 << "-xb2 " << this->xb2 << std::endl;
|
||||
s_oss << indent0 << "-component " << std::endl;
|
||||
this->comps.dump_raw(s_oss, indent + 1);
|
||||
}
|
||||
|
||||
void cxxSSassemblageSS::read_raw(CParser& parser)
|
||||
void
|
||||
cxxSSassemblageSS::read_raw(CParser & parser)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("name"); // 0
|
||||
vopts.push_back("total_moles"); // 1
|
||||
vopts.push_back("a0"); // 2
|
||||
vopts.push_back("a1"); // 3
|
||||
vopts.push_back("components"); // 4
|
||||
vopts.push_back("miscibility"); // 5
|
||||
vopts.push_back("spinodal"); // 6
|
||||
vopts.push_back("tk"); // 7
|
||||
vopts.push_back("xb1"); // 8
|
||||
vopts.push_back("xb2"); // 9
|
||||
vopts.push_back("ag0"); // 10
|
||||
vopts.push_back("ag1"); // 11
|
||||
}
|
||||
std::string str;
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("name"); // 0
|
||||
vopts.push_back("total_moles"); // 1
|
||||
vopts.push_back("a0"); // 2
|
||||
vopts.push_back("a1"); // 3
|
||||
vopts.push_back("components"); // 4
|
||||
vopts.push_back("miscibility"); // 5
|
||||
vopts.push_back("spinodal"); // 6
|
||||
vopts.push_back("tk"); // 7
|
||||
vopts.push_back("xb1"); // 8
|
||||
vopts.push_back("xb2"); // 9
|
||||
vopts.push_back("ag0"); // 10
|
||||
vopts.push_back("ag1"); // 11
|
||||
}
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool name_defined(false);
|
||||
//bool total_moles_defined(false);
|
||||
bool a0_defined(false);
|
||||
bool a1_defined(false);
|
||||
bool ag0_defined(false);
|
||||
bool ag1_defined(false);
|
||||
bool miscibility_defined(false);
|
||||
//bool spinodal_defined(false);
|
||||
//bool tk_defined(false);
|
||||
bool xb1_defined(false);
|
||||
bool xb2_defined(false);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool name_defined(false);
|
||||
//bool total_moles_defined(false);
|
||||
bool a0_defined(false);
|
||||
bool a1_defined(false);
|
||||
bool ag0_defined(false);
|
||||
bool ag1_defined(false);
|
||||
bool miscibility_defined(false);
|
||||
//bool spinodal_defined(false);
|
||||
//bool tk_defined(false);
|
||||
bool xb1_defined(false);
|
||||
bool xb2_defined(false);
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Exchange for more processing
|
||||
//parser.error_msg("Unknown input in S_S read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
|
||||
case 0: // name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
this->name = string_hsave(str.c_str());
|
||||
}
|
||||
name_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Exchange for more processing
|
||||
//parser.error_msg("Unknown input in S_S read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
|
||||
case 1: // total_moles
|
||||
/*
|
||||
if (!(parser.get_iss() >> this->total_moles))
|
||||
{
|
||||
this->total_moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for total_moles.", CParser::OT_CONTINUE);
|
||||
}
|
||||
total_moles_defined = true;
|
||||
*/
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
case 0: // name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for name.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->name = string_hsave(str.c_str());
|
||||
}
|
||||
name_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 2: // a0
|
||||
if (!(parser.get_iss() >> this->a0))
|
||||
{
|
||||
this->a0 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for a0.", CParser::OT_CONTINUE);
|
||||
}
|
||||
a0_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 3: // a1
|
||||
if (!(parser.get_iss() >> this->a1))
|
||||
{
|
||||
this->a1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for a1.", CParser::OT_CONTINUE);
|
||||
}
|
||||
a1_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 4: // components
|
||||
if ( this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected phase name and moles for comps.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 4;
|
||||
break;
|
||||
|
||||
case 5: // miscibility
|
||||
if (!(parser.get_iss() >> this->miscibility))
|
||||
{
|
||||
this->miscibility = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for miscibility.", CParser::OT_CONTINUE);
|
||||
}
|
||||
miscibility_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 6: // spinodal
|
||||
case 1: // total_moles
|
||||
/*
|
||||
if (!(parser.get_iss() >> this->spinodal))
|
||||
{
|
||||
this->spinodal = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for spinodal.", CParser::OT_CONTINUE);
|
||||
}
|
||||
spinodal_defined = true;
|
||||
*/
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
if (!(parser.get_iss() >> this->total_moles))
|
||||
{
|
||||
this->total_moles = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for total_moles.", CParser::OT_CONTINUE);
|
||||
}
|
||||
total_moles_defined = true;
|
||||
*/
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 7: // tk
|
||||
case 2: // a0
|
||||
if (!(parser.get_iss() >> this->a0))
|
||||
{
|
||||
this->a0 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for a0.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
a0_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 3: // a1
|
||||
if (!(parser.get_iss() >> this->a1))
|
||||
{
|
||||
this->a1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for a1.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
a1_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 4: // components
|
||||
if (this->comps.read_raw(parser, next_char) != CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected phase name and moles for comps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 4;
|
||||
break;
|
||||
|
||||
case 5: // miscibility
|
||||
if (!(parser.get_iss() >> this->miscibility))
|
||||
{
|
||||
this->miscibility = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for miscibility.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
miscibility_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 6: // spinodal
|
||||
/*
|
||||
if (!(parser.get_iss() >> this->tk))
|
||||
{
|
||||
this->tk = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for tk.", CParser::OT_CONTINUE);
|
||||
}
|
||||
tk_defined = true;
|
||||
*/
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
if (!(parser.get_iss() >> this->spinodal))
|
||||
{
|
||||
this->spinodal = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for spinodal.", CParser::OT_CONTINUE);
|
||||
}
|
||||
spinodal_defined = true;
|
||||
*/
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 8: // xb1
|
||||
if (!(parser.get_iss() >> this->xb1))
|
||||
{
|
||||
this->xb1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for xb1.", CParser::OT_CONTINUE);
|
||||
}
|
||||
xb1_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
case 7: // tk
|
||||
/*
|
||||
if (!(parser.get_iss() >> this->tk))
|
||||
{
|
||||
this->tk = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for tk.", CParser::OT_CONTINUE);
|
||||
}
|
||||
tk_defined = true;
|
||||
*/
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 9: // xb2
|
||||
if (!(parser.get_iss() >> this->xb2))
|
||||
{
|
||||
this->xb2 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for xb2.", CParser::OT_CONTINUE);
|
||||
}
|
||||
xb2_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
case 8: // xb1
|
||||
if (!(parser.get_iss() >> this->xb1))
|
||||
{
|
||||
this->xb1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for xb1.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
xb1_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 10: // ag0
|
||||
if (!(parser.get_iss() >> this->ag0))
|
||||
{
|
||||
this->ag0 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for ag0.", CParser::OT_CONTINUE);
|
||||
}
|
||||
ag0_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
case 9: // xb2
|
||||
if (!(parser.get_iss() >> this->xb2))
|
||||
{
|
||||
this->xb2 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for xb2.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
xb2_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 11: // ag1
|
||||
if (!(parser.get_iss() >> this->ag1))
|
||||
{
|
||||
this->ag1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for ag1.", CParser::OT_CONTINUE);
|
||||
}
|
||||
ag1_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
case 10: // ag0
|
||||
if (!(parser.get_iss() >> this->ag0))
|
||||
{
|
||||
this->ag0 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for ag0.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
ag0_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
case 11: // ag1
|
||||
if (!(parser.get_iss() >> this->ag1))
|
||||
{
|
||||
this->ag1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for ag1.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
ag1_defined = true;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (name_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Name not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
/*
|
||||
if (total_moles_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
*/
|
||||
if (a0_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("A0 not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (a1_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("A1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (ag0_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Ag0 not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (ag1_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Ag1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (miscibility_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Miscibility not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (name_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Name not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
/*
|
||||
if (spinodal_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (tk_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
*/
|
||||
if (xb1_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Xb1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (xb2_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Xb2 not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (total_moles_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
*/
|
||||
if (a0_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("A0 not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (a1_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("A1 not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (ag0_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Ag0 not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (ag1_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Ag1 not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (miscibility_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Miscibility not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
/*
|
||||
if (spinodal_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (tk_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
*/
|
||||
if (xb1_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Xb1 not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (xb2_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Xb2 not defined for SSassemblageSS input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxSSassemblageSS::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxSSassemblageSS::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
ints.push_back(dictionary.string2int(this->name));
|
||||
@ -456,7 +511,9 @@ void cxxSSassemblageSS::mpi_pack(std::vector<int>& ints, std::vector<double>& do
|
||||
doubles.push_back(this->xb1);
|
||||
doubles.push_back(this->xb2);
|
||||
}
|
||||
void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
void
|
||||
cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
int i = *ii;
|
||||
@ -475,50 +532,57 @@ void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxSSassemblageSS::totalize()
|
||||
void
|
||||
cxxSSassemblageSS::totalize()
|
||||
{
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (cxxNameDouble::const_iterator it = this->comps.begin(); it != this->comps.end(); it++) {
|
||||
struct phase *phase_ptr;
|
||||
int l;
|
||||
phase_ptr = phase_bsearch(it->first, &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
cxxNameDouble phase_formula(phase_ptr->next_elt);
|
||||
this->totals.add_extensive(phase_formula, it->second);
|
||||
} else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return;
|
||||
this->totals.clear();
|
||||
// component structures
|
||||
for (cxxNameDouble::const_iterator it = this->comps.begin();
|
||||
it != this->comps.end(); it++)
|
||||
{
|
||||
struct phase *phase_ptr;
|
||||
int l;
|
||||
phase_ptr = phase_bsearch(it->first, &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
cxxNameDouble phase_formula(phase_ptr->next_elt);
|
||||
this->totals.add_extensive(phase_formula, it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cxxSSassemblageSS::add(const cxxSSassemblageSS &addee, double extensive)
|
||||
void
|
||||
cxxSSassemblageSS::add(const cxxSSassemblageSS & addee, double extensive)
|
||||
{
|
||||
if (extensive == 0.0) return;
|
||||
if (addee.name == NULL) return;
|
||||
// this and addee must have same name
|
||||
// otherwise generate a new PPassemblagComp with multiply
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
if (addee.name == NULL)
|
||||
return;
|
||||
// this and addee must have same name
|
||||
// otherwise generate a new PPassemblagComp with multiply
|
||||
|
||||
//char *name;
|
||||
//cxxNameDouble comps;
|
||||
this->comps.add_extensive(addee.comps, extensive);
|
||||
//double a0, a1;
|
||||
//double ag0, ag1;
|
||||
//bool miscibility;
|
||||
//double xb1, xb2;
|
||||
//char *name;
|
||||
//cxxNameDouble comps;
|
||||
this->comps.add_extensive(addee.comps, extensive);
|
||||
//double a0, a1;
|
||||
//double ag0, ag1;
|
||||
//bool miscibility;
|
||||
//double xb1, xb2;
|
||||
}
|
||||
|
||||
void cxxSSassemblageSS::multiply(double extensive)
|
||||
void
|
||||
cxxSSassemblageSS::multiply(double extensive)
|
||||
{
|
||||
//char *name;
|
||||
//cxxNameDouble comps;
|
||||
this->comps.multiply(extensive);
|
||||
//double a0, a1;
|
||||
//double ag0, ag1;
|
||||
//bool miscibility;
|
||||
//double xb1, xb2;
|
||||
//char *name;
|
||||
//cxxNameDouble comps;
|
||||
this->comps.multiply(extensive);
|
||||
//double a0, a1;
|
||||
//double ag0, ag1;
|
||||
//bool miscibility;
|
||||
//double xb1, xb2;
|
||||
}
|
||||
|
||||
|
||||
2758
Solution.cxx
2758
Solution.cxx
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
#include "SolutionIsotope.h"
|
||||
#include "Utils.h"
|
||||
@ -9,21 +9,21 @@
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert>
|
||||
#include <sstream> // std::ostrstream
|
||||
#include <sstream> // std::ostrstream
|
||||
|
||||
cxxSolutionIsotope::cxxSolutionIsotope(void)
|
||||
: isotope_number(0.0)
|
||||
cxxSolutionIsotope::cxxSolutionIsotope(void):
|
||||
isotope_number(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr)
|
||||
{
|
||||
isotope_number = isotope_ptr->isotope_number;
|
||||
elt_name = isotope_ptr->elt_name;
|
||||
isotope_name = isotope_ptr->isotope_name;
|
||||
total = isotope_ptr->total;
|
||||
ratio = isotope_ptr->ratio;
|
||||
ratio_uncertainty = isotope_ptr->ratio_uncertainty;
|
||||
isotope_number = isotope_ptr->isotope_number;
|
||||
elt_name = isotope_ptr->elt_name;
|
||||
isotope_name = isotope_ptr->isotope_name;
|
||||
total = isotope_ptr->total;
|
||||
ratio = isotope_ptr->ratio;
|
||||
ratio_uncertainty = isotope_ptr->ratio_uncertainty;
|
||||
}
|
||||
|
||||
|
||||
@ -31,227 +31,280 @@ cxxSolutionIsotope::~cxxSolutionIsotope(void)
|
||||
{
|
||||
}
|
||||
|
||||
struct isotope *cxxSolutionIsotope::list2isotope(std::list <cxxSolutionIsotope> &isolist)
|
||||
// takes a std::list of cxxSolutionIsotope structures
|
||||
// returns array of isotope structures
|
||||
struct isotope *
|
||||
cxxSolutionIsotope::list2isotope(std::list < cxxSolutionIsotope > &isolist)
|
||||
// takes a std::list of cxxSolutionIsotope structures
|
||||
// returns array of isotope structures
|
||||
{
|
||||
struct isotope *iso;
|
||||
if (isolist.size() <= 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
iso = (struct isotope *) PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope)));
|
||||
if (iso == NULL) malloc_error();
|
||||
int i = 0;
|
||||
for (std::list <cxxSolutionIsotope>::iterator it = isolist.begin(); it != isolist.end(); ++it) {
|
||||
iso[i].isotope_number = it->isotope_number;
|
||||
iso[i].elt_name = it->elt_name;
|
||||
iso[i].total = it->total;
|
||||
iso[i].ratio = it->ratio;
|
||||
iso[i].ratio_uncertainty = it->ratio_uncertainty;
|
||||
iso[i].master = it->master();
|
||||
iso[i].primary = it->primary();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return(iso);
|
||||
struct isotope *iso;
|
||||
if (isolist.size() <= 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
iso =
|
||||
(struct isotope *)
|
||||
PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope)));
|
||||
if (iso == NULL)
|
||||
malloc_error();
|
||||
int i = 0;
|
||||
for (std::list < cxxSolutionIsotope >::iterator it = isolist.begin();
|
||||
it != isolist.end(); ++it)
|
||||
{
|
||||
iso[i].isotope_number = it->isotope_number;
|
||||
iso[i].elt_name = it->elt_name;
|
||||
iso[i].total = it->total;
|
||||
iso[i].ratio = it->ratio;
|
||||
iso[i].ratio_uncertainty = it->ratio_uncertainty;
|
||||
iso[i].master = it->master();
|
||||
iso[i].primary = it->primary();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (iso);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
std::string cxxSolutionIsotope::get_name()const
|
||||
std::string cxxSolutionIsotope::get_name() constconst
|
||||
{
|
||||
std::ostringstream oss;
|
||||
//std::ostrstream oss;
|
||||
oss << this->isotope_number << this->elt_name;
|
||||
return oss.str();
|
||||
std::ostringstream oss;
|
||||
//std::ostrstream oss;
|
||||
oss << this->isotope_number << this->elt_name;
|
||||
return oss.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxSolutionIsotope::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int i;
|
||||
|
||||
std::string indent0(""), indent1("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
std::string indent0(""), indent1("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
|
||||
s_oss << indent0;
|
||||
s_oss << "<soln_isotope=\"" << std::endl;
|
||||
s_oss << indent0;
|
||||
s_oss << "<soln_isotope=\"" << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_isotope_number=\"" << this->isotope_number << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_isotope_number=\"" << this->
|
||||
isotope_number << "\"" << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_total=\"" << this->total << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_total=\"" << this->total << "\"" << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_ratio=\"" << this->ratio << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_ratio=\"" << this->ratio << "\"" << std::endl;
|
||||
|
||||
if (this->ratio_uncertainty != NAN) {
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_ratio_uncertainty=\"" << this->ratio_uncertainty << "\"" << std::endl;
|
||||
}
|
||||
s_oss << indent0;
|
||||
s_oss << "\">" << std::endl;
|
||||
if (this->ratio_uncertainty != NAN)
|
||||
{
|
||||
s_oss << indent1;
|
||||
s_oss << "iso_ratio_uncertainty=\"" << this->
|
||||
ratio_uncertainty << "\"" << std::endl;
|
||||
}
|
||||
s_oss << indent0;
|
||||
s_oss << "\">" << std::endl;
|
||||
}
|
||||
|
||||
void cxxSolutionIsotope::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int i;
|
||||
|
||||
std::string indent0("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
std::string indent0("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
|
||||
s_oss << indent0;
|
||||
s_oss << this->isotope_name << " ";
|
||||
s_oss << this->isotope_number << " ";
|
||||
s_oss << this->elt_name << " ";
|
||||
s_oss << this->total << " ";
|
||||
s_oss << this->ratio << " ";
|
||||
if (this->ratio_uncertainty != NAN) {
|
||||
s_oss << this->ratio_uncertainty << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
s_oss << indent0;
|
||||
s_oss << this->isotope_name << " ";
|
||||
s_oss << this->isotope_number << " ";
|
||||
s_oss << this->elt_name << " ";
|
||||
s_oss << this->total << " ";
|
||||
s_oss << this->ratio << " ";
|
||||
if (this->ratio_uncertainty != NAN)
|
||||
{
|
||||
s_oss << this->ratio_uncertainty << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
|
||||
CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser& parser)
|
||||
CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser)
|
||||
{
|
||||
std::string token;
|
||||
std::istream::pos_type next_char;
|
||||
CParser::TOKEN_TYPE j;
|
||||
std::string token;
|
||||
std::istream::pos_type next_char;
|
||||
CParser::TOKEN_TYPE j;
|
||||
|
||||
// isotope_name
|
||||
j = parser.copy_token(token, next_char);
|
||||
// isotope_name
|
||||
j = parser.copy_token(token, next_char);
|
||||
|
||||
if (j == CParser::TT_EMPTY) {
|
||||
this->isotope_name = NULL;
|
||||
return(CParser::PARSER_OK);
|
||||
}
|
||||
this->isotope_name = string_hsave(token.c_str());
|
||||
if (j == CParser::TT_EMPTY)
|
||||
{
|
||||
this->isotope_name = NULL;
|
||||
return (CParser::PARSER_OK);
|
||||
}
|
||||
this->isotope_name = string_hsave(token.c_str());
|
||||
|
||||
// isotope_number
|
||||
if( !(parser.get_iss() >> isotope_number)) {
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
// isotope_number
|
||||
if (!(parser.get_iss() >> isotope_number))
|
||||
{
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
|
||||
// elt_name
|
||||
if( !(parser.get_iss() >> token)) {
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
this->elt_name = string_hsave(token.c_str());
|
||||
// elt_name
|
||||
if (!(parser.get_iss() >> token))
|
||||
{
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
this->elt_name = string_hsave(token.c_str());
|
||||
|
||||
// total
|
||||
if( !(parser.get_iss() >> this->total)) {
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
// total
|
||||
if (!(parser.get_iss() >> this->total))
|
||||
{
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
|
||||
// ratio
|
||||
if( !(parser.get_iss() >> this->ratio)) {
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
// ratio
|
||||
if (!(parser.get_iss() >> this->ratio))
|
||||
{
|
||||
return CParser::PARSER_ERROR;
|
||||
}
|
||||
|
||||
// ratio_uncertainty
|
||||
j = parser.copy_token(token, next_char);
|
||||
if (j == CParser::TT_EMPTY) {
|
||||
this->ratio_uncertainty = NAN;
|
||||
} else if (j != CParser::TT_DIGIT) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
std::istringstream(token) >> this->ratio_uncertainty;
|
||||
}
|
||||
// ratio_uncertainty
|
||||
j = parser.copy_token(token, next_char);
|
||||
if (j == CParser::TT_EMPTY)
|
||||
{
|
||||
this->ratio_uncertainty = NAN;
|
||||
}
|
||||
else if (j != CParser::TT_DIGIT)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Expected numeric value for mass of water in solution.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::istringstream(token) >> this->ratio_uncertainty;
|
||||
}
|
||||
|
||||
return CParser::PARSER_OK;
|
||||
return CParser::PARSER_OK;
|
||||
}
|
||||
|
||||
bool cxxSolutionIsotope::operator<(const cxxSolutionIsotope& isotope)const
|
||||
bool
|
||||
cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const const
|
||||
{
|
||||
int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name);
|
||||
if (i != 0) return (i < 0);
|
||||
return ( this->isotope_number < isotope.isotope_number );
|
||||
int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name);
|
||||
if (i != 0)
|
||||
return (i < 0);
|
||||
return (this->isotope_number < isotope.isotope_number);
|
||||
}
|
||||
|
||||
struct master *cxxSolutionIsotope::master(void)
|
||||
struct master *
|
||||
cxxSolutionIsotope::master(void)
|
||||
{
|
||||
return (master_bsearch(this->elt_name));
|
||||
return (master_bsearch(this->elt_name));
|
||||
}
|
||||
|
||||
struct master *cxxSolutionIsotope::primary(void)
|
||||
struct master *
|
||||
cxxSolutionIsotope::primary(void)
|
||||
{
|
||||
return (master_bsearch_primary(this->elt_name));
|
||||
return (master_bsearch_primary(this->elt_name));
|
||||
}
|
||||
|
||||
void cxxSolutionIsotope::add(const cxxSolutionIsotope &isotope_ptr, double intensive, double extensive)
|
||||
void
|
||||
cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr,
|
||||
double intensive, double extensive)
|
||||
{
|
||||
if ((this->isotope_number == isotope_ptr.isotope_number) &&
|
||||
(this->elt_name == isotope_ptr.elt_name) &&
|
||||
(this->isotope_name == isotope_ptr.isotope_name)) {
|
||||
this->total += isotope_ptr.total * extensive;
|
||||
this->ratio += isotope_ptr.ratio * intensive;
|
||||
this->ratio_uncertainty += isotope_ptr.ratio_uncertainty * intensive;
|
||||
this->ratio_uncertainty_defined = (this->ratio_uncertainty_defined || isotope_ptr.ratio_uncertainty_defined);
|
||||
if ((this->isotope_number == isotope_ptr.isotope_number) &&
|
||||
(this->elt_name == isotope_ptr.elt_name) &&
|
||||
(this->isotope_name == isotope_ptr.isotope_name))
|
||||
{
|
||||
this->total += isotope_ptr.total * extensive;
|
||||
this->ratio += isotope_ptr.ratio * intensive;
|
||||
this->ratio_uncertainty += isotope_ptr.ratio_uncertainty * intensive;
|
||||
this->ratio_uncertainty_defined = (this->ratio_uncertainty_defined
|
||||
|| isotope_ptr.
|
||||
ratio_uncertainty_defined);
|
||||
}
|
||||
}
|
||||
void cxxSolutionIsotope::multiply(double extensive)
|
||||
void
|
||||
cxxSolutionIsotope::multiply(double extensive)
|
||||
{
|
||||
this->total *= extensive;
|
||||
this->total *= extensive;
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser& parser)
|
||||
cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser)
|
||||
{
|
||||
if ( !(parser.get_iss() >> this->isotope_number) ) {
|
||||
assert(parser.get_iss().fail());
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected isotope name to"
|
||||
" begin with an isotopic number.", CParser::OT_CONTINUE);
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
if (!(parser.get_iss() >> this->isotope_number))
|
||||
{
|
||||
assert(parser.get_iss().fail());
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected isotope name to"
|
||||
" begin with an isotopic number.",
|
||||
CParser::OT_CONTINUE);
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
|
||||
// read and save element name
|
||||
std::istringstream::int_type c = parser.get_iss().peek();
|
||||
if ( c == std::char_traits<char>::eof() || !(::isupper(c)) ) {
|
||||
parser.error_msg("Expecting element name.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
parser.incr_input_error();
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
if ( !(parser.get_iss() >> this->elt_name) ) {
|
||||
// should never get here
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
assert(!this->elt_name.empty() && ::isupper(this->elt_name[0]));
|
||||
// read and save element name
|
||||
std::istringstream::int_type c = parser.get_iss().peek();
|
||||
if (c == std::char_traits < char >::eof() || !(::isupper(c)))
|
||||
{
|
||||
parser.error_msg("Expecting element name.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
parser.incr_input_error();
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
if (!(parser.get_iss() >> this->elt_name))
|
||||
{
|
||||
// should never get here
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
assert(!this->elt_name.empty() &&::isupper(this->elt_name[0]));
|
||||
|
||||
// read and store isotope ratio
|
||||
if ( !(parser.get_iss() >> this->ratio) ) {
|
||||
assert(parser.get_iss().fail());
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for isotope ratio.", CParser::OT_CONTINUE);
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
// read and store isotope ratio
|
||||
if (!(parser.get_iss() >> this->ratio))
|
||||
{
|
||||
assert(parser.get_iss().fail());
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for isotope ratio.",
|
||||
CParser::OT_CONTINUE);
|
||||
return ERROR;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
|
||||
// read and store isotope ratio
|
||||
this->ratio_uncertainty_defined = false;
|
||||
if ( !(parser.get_iss() >> this->ratio_uncertainty)) {
|
||||
if ( !parser.get_iss().eof() ) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for uncertainty in isotope ratio.", CParser::OT_CONTINUE);
|
||||
return ERROR;
|
||||
}
|
||||
} else {
|
||||
this->ratio_uncertainty_defined = true;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
return OK;
|
||||
// read and store isotope ratio
|
||||
this->ratio_uncertainty_defined = false;
|
||||
if (!(parser.get_iss() >> this->ratio_uncertainty))
|
||||
{
|
||||
if (!parser.get_iss().eof())
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected numeric value for uncertainty in isotope ratio.",
|
||||
CParser::OT_CONTINUE);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ratio_uncertainty_defined = true;
|
||||
}
|
||||
assert(parser.get_iss().good() || parser.get_iss().eof());
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,93 +1,111 @@
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "SolutionIsotopeList.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
cxxSolutionIsotopeList::cxxSolutionIsotopeList(void)
|
||||
//
|
||||
// default constructor for cxxSolution
|
||||
//
|
||||
//
|
||||
// default constructor for cxxSolution
|
||||
//
|
||||
{
|
||||
}
|
||||
|
||||
cxxSolutionIsotopeList::~cxxSolutionIsotopeList(void)
|
||||
//
|
||||
// default destructor for cxxSolution
|
||||
//
|
||||
//
|
||||
// default destructor for cxxSolution
|
||||
//
|
||||
{
|
||||
}
|
||||
|
||||
cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr)
|
||||
{
|
||||
int i;
|
||||
// Isotopes
|
||||
for (i = 0; i < solution_ptr->count_isotopes; i++) {
|
||||
//cxxSolutionIsotope iso(&solution_ptr->isotopes[i]);
|
||||
(*this).push_back(&solution_ptr->isotopes[i]);
|
||||
}
|
||||
}
|
||||
void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive)
|
||||
{
|
||||
for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) {
|
||||
//for (std::list <cxxSolutionIsotope>::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) {
|
||||
bool found = false;
|
||||
for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it)
|
||||
{
|
||||
//for (std::list <cxxSolutionIsotope>::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) {
|
||||
if ((it->isotope_number == itold->isotope_number) &&
|
||||
(it->elt_name == itold->elt_name) &&
|
||||
(it->isotope_name == itold->isotope_name))
|
||||
// Isotopes
|
||||
for (i = 0; i < solution_ptr->count_isotopes; i++)
|
||||
{
|
||||
it->total += itold->total * extensive;
|
||||
it->ratio += itold->ratio * intensive;
|
||||
it->ratio_uncertainty += itold->ratio_uncertainty * intensive;
|
||||
it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined);
|
||||
found = true;
|
||||
break;
|
||||
//cxxSolutionIsotope iso(&solution_ptr->isotopes[i]);
|
||||
(*this).push_back(&solution_ptr->isotopes[i]);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
cxxSolutionIsotope iso;
|
||||
iso.total = itold->total * extensive;
|
||||
iso.ratio = itold->ratio * intensive;
|
||||
iso.ratio_uncertainty = itold->ratio_uncertainty * intensive;
|
||||
iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined;
|
||||
this->push_back(iso);
|
||||
}
|
||||
}
|
||||
}
|
||||
void cxxSolutionIsotopeList::multiply(double extensive)
|
||||
void
|
||||
cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive,
|
||||
double extensive)
|
||||
{
|
||||
for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it)
|
||||
{
|
||||
it->total *= extensive;
|
||||
}
|
||||
for (cxxSolutionIsotopeList::const_iterator itold = old.begin();
|
||||
itold != old.end(); ++itold)
|
||||
{
|
||||
//for (std::list <cxxSolutionIsotope>::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) {
|
||||
bool found = false;
|
||||
for (cxxSolutionIsotopeList::iterator it = this->begin();
|
||||
it != this->end(); ++it)
|
||||
{
|
||||
//for (std::list <cxxSolutionIsotope>::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) {
|
||||
if ((it->isotope_number == itold->isotope_number) &&
|
||||
(it->elt_name == itold->elt_name) &&
|
||||
(it->isotope_name == itold->isotope_name))
|
||||
{
|
||||
it->total += itold->total * extensive;
|
||||
it->ratio += itold->ratio * intensive;
|
||||
it->ratio_uncertainty += itold->ratio_uncertainty * intensive;
|
||||
it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined
|
||||
|| itold->
|
||||
ratio_uncertainty_defined);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
cxxSolutionIsotope iso;
|
||||
iso.total = itold->total * extensive;
|
||||
iso.ratio = itold->ratio * intensive;
|
||||
iso.ratio_uncertainty = itold->ratio_uncertainty * intensive;
|
||||
iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined;
|
||||
this->push_back(iso);
|
||||
}
|
||||
}
|
||||
}
|
||||
struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope()
|
||||
void
|
||||
cxxSolutionIsotopeList::multiply(double extensive)
|
||||
{
|
||||
struct isotope *iso;
|
||||
if (this->size() <= 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope)));
|
||||
if (iso == NULL) malloc_error();
|
||||
int i = 0;
|
||||
for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) {
|
||||
iso[i].isotope_number = it->isotope_number;
|
||||
iso[i].elt_name = it->elt_name;
|
||||
iso[i].total = it->total;
|
||||
iso[i].ratio = it->ratio;
|
||||
iso[i].ratio_uncertainty = it->ratio_uncertainty;
|
||||
iso[i].master = it->master();
|
||||
iso[i].primary = it->primary();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return(iso);
|
||||
for (cxxSolutionIsotopeList::iterator it = this->begin();
|
||||
it != this->end(); ++it)
|
||||
{
|
||||
it->total *= extensive;
|
||||
}
|
||||
}
|
||||
struct isotope *
|
||||
cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope()
|
||||
{
|
||||
struct isotope *iso;
|
||||
if (this->size() <= 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
iso =
|
||||
(struct isotope *)
|
||||
PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope)));
|
||||
if (iso == NULL)
|
||||
malloc_error();
|
||||
int i = 0;
|
||||
for (cxxSolutionIsotopeList::iterator it = this->begin();
|
||||
it != this->end(); ++it)
|
||||
{
|
||||
iso[i].isotope_number = it->isotope_number;
|
||||
iso[i].elt_name = it->elt_name;
|
||||
iso[i].total = it->total;
|
||||
iso[i].ratio = it->ratio;
|
||||
iso[i].ratio_uncertainty = it->ratio_uncertainty;
|
||||
iso[i].master = it->master();
|
||||
iso[i].primary = it->primary();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (iso);
|
||||
}
|
||||
|
||||
|
||||
1232
StorageBin.cxx
1232
StorageBin.cxx
File diff suppressed because it is too large
Load Diff
1243
Surface.cxx
1243
Surface.cxx
File diff suppressed because it is too large
Load Diff
@ -2,10 +2,10 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "SurfaceCharge.h"
|
||||
#include "Dictionary.h"
|
||||
#define EXTERNAL extern
|
||||
@ -13,397 +13,474 @@
|
||||
#include "output.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxSurfaceCharge::cxxSurfaceCharge()
|
||||
//
|
||||
// default constructor for cxxSurfaceCharge
|
||||
//
|
||||
//
|
||||
// default constructor for cxxSurfaceCharge
|
||||
//
|
||||
{
|
||||
name = NULL;
|
||||
specific_area = 0.0;
|
||||
grams = 0.0;
|
||||
charge_balance = 0.0;
|
||||
mass_water = 0.0;
|
||||
la_psi = 0.0;
|
||||
la_psi1 = 0.0;
|
||||
la_psi2 = 0.0;
|
||||
capacitance[0] = 1.0;
|
||||
capacitance[1] = 5.0;
|
||||
diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
name = NULL;
|
||||
specific_area = 0.0;
|
||||
grams = 0.0;
|
||||
charge_balance = 0.0;
|
||||
mass_water = 0.0;
|
||||
la_psi = 0.0;
|
||||
la_psi1 = 0.0;
|
||||
la_psi2 = 0.0;
|
||||
capacitance[0] = 1.0;
|
||||
capacitance[1] = 5.0;
|
||||
diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr)
|
||||
//
|
||||
// constructor for cxxSurfaceCharge from struct surface_charge
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxSurfaceCharge from struct surface_charge
|
||||
//
|
||||
:
|
||||
diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals)
|
||||
{
|
||||
name = surf_charge_ptr->name;
|
||||
specific_area = surf_charge_ptr->specific_area;
|
||||
grams = surf_charge_ptr->grams;
|
||||
charge_balance = surf_charge_ptr->charge_balance;
|
||||
mass_water = surf_charge_ptr->mass_water;
|
||||
la_psi = surf_charge_ptr->la_psi;
|
||||
la_psi1 = surf_charge_ptr->la_psi1;
|
||||
la_psi2 = surf_charge_ptr->la_psi2;
|
||||
capacitance[0] = surf_charge_ptr->capacitance[0];
|
||||
capacitance[1] = surf_charge_ptr->capacitance[1];
|
||||
name = surf_charge_ptr->name;
|
||||
specific_area = surf_charge_ptr->specific_area;
|
||||
grams = surf_charge_ptr->grams;
|
||||
charge_balance = surf_charge_ptr->charge_balance;
|
||||
mass_water = surf_charge_ptr->mass_water;
|
||||
la_psi = surf_charge_ptr->la_psi;
|
||||
la_psi1 = surf_charge_ptr->la_psi1;
|
||||
la_psi2 = surf_charge_ptr->la_psi2;
|
||||
capacitance[0] = surf_charge_ptr->capacitance[0];
|
||||
capacitance[1] = surf_charge_ptr->capacitance[1];
|
||||
}
|
||||
|
||||
cxxSurfaceCharge::~cxxSurfaceCharge()
|
||||
{
|
||||
}
|
||||
|
||||
struct master *cxxSurfaceCharge::get_psi_master()
|
||||
{
|
||||
struct master *master_ptr = NULL;
|
||||
std::string str = this->name;
|
||||
struct master *
|
||||
cxxSurfaceCharge::get_psi_master()
|
||||
{
|
||||
struct master *master_ptr = NULL;
|
||||
std::string str = this->name;
|
||||
|
||||
str.append("_psi");
|
||||
master_ptr = master_bsearch(str.c_str());
|
||||
if (master_ptr == NULL) {
|
||||
std::ostringstream error_oss;
|
||||
error_oss << "Surface charge psi_master not found." << this->name << std::endl;
|
||||
//Utilities::error_msg(error_oss.str(), CONTINUE);
|
||||
str.append("_psi");
|
||||
master_ptr = master_bsearch(str.c_str());
|
||||
if (master_ptr == NULL)
|
||||
{
|
||||
std::ostringstream error_oss;
|
||||
error_oss << "Surface charge psi_master not found." << this->
|
||||
name << std::endl;
|
||||
//Utilities::error_msg(error_oss.str(), CONTINUE);
|
||||
error_msg(error_oss.str().c_str(), CONTINUE);
|
||||
}
|
||||
return(master_ptr);
|
||||
}
|
||||
return (master_ptr);
|
||||
}
|
||||
|
||||
struct surface_charge *cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list<cxxSurfaceCharge>& el)
|
||||
//
|
||||
// Builds surface_charge structure from of cxxSurfaceCharge
|
||||
//
|
||||
struct surface_charge *
|
||||
cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list <
|
||||
cxxSurfaceCharge > &el)
|
||||
//
|
||||
// Builds surface_charge structure from of cxxSurfaceCharge
|
||||
//
|
||||
{
|
||||
struct surface_charge *surf_charge_ptr = (struct surface_charge *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge)));
|
||||
if (surf_charge_ptr == NULL) malloc_error();
|
||||
struct surface_charge *surf_charge_ptr =
|
||||
(struct surface_charge *)
|
||||
PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge)));
|
||||
if (surf_charge_ptr == NULL)
|
||||
malloc_error();
|
||||
|
||||
int i = 0;
|
||||
for (std::list<cxxSurfaceCharge>::iterator it = el.begin(); it != el.end(); ++it) {
|
||||
surf_charge_ptr[i].name = it->name;
|
||||
surf_charge_ptr[i].specific_area = it->specific_area;
|
||||
surf_charge_ptr[i].grams = it->grams;
|
||||
surf_charge_ptr[i].charge_balance = it->charge_balance;
|
||||
surf_charge_ptr[i].mass_water = it->mass_water;
|
||||
surf_charge_ptr[i].la_psi = it->la_psi;
|
||||
surf_charge_ptr[i].la_psi1 = it->la_psi1;
|
||||
surf_charge_ptr[i].la_psi2 = it->la_psi2;
|
||||
surf_charge_ptr[i].capacitance[0] = it->capacitance[0];
|
||||
surf_charge_ptr[i].capacitance[1] = it->capacitance[1];
|
||||
surf_charge_ptr[i].sigma0 = 0;
|
||||
surf_charge_ptr[i].sigma1 = 0;
|
||||
surf_charge_ptr[i].sigma2 = 0;
|
||||
surf_charge_ptr[i].sigmaddl = 0;
|
||||
surf_charge_ptr[i].diffuse_layer_totals = it->diffuse_layer_totals.elt_list();
|
||||
//surf_charge_ptr[i].psi_master = it->get_psi_master();
|
||||
surf_charge_ptr[i].count_g = 0;
|
||||
surf_charge_ptr[i].g = NULL;
|
||||
i++;
|
||||
}
|
||||
return(surf_charge_ptr);
|
||||
int i = 0;
|
||||
for (std::list < cxxSurfaceCharge >::iterator it = el.begin();
|
||||
it != el.end(); ++it)
|
||||
{
|
||||
surf_charge_ptr[i].name = it->name;
|
||||
surf_charge_ptr[i].specific_area = it->specific_area;
|
||||
surf_charge_ptr[i].grams = it->grams;
|
||||
surf_charge_ptr[i].charge_balance = it->charge_balance;
|
||||
surf_charge_ptr[i].mass_water = it->mass_water;
|
||||
surf_charge_ptr[i].la_psi = it->la_psi;
|
||||
surf_charge_ptr[i].la_psi1 = it->la_psi1;
|
||||
surf_charge_ptr[i].la_psi2 = it->la_psi2;
|
||||
surf_charge_ptr[i].capacitance[0] = it->capacitance[0];
|
||||
surf_charge_ptr[i].capacitance[1] = it->capacitance[1];
|
||||
surf_charge_ptr[i].sigma0 = 0;
|
||||
surf_charge_ptr[i].sigma1 = 0;
|
||||
surf_charge_ptr[i].sigma2 = 0;
|
||||
surf_charge_ptr[i].sigmaddl = 0;
|
||||
surf_charge_ptr[i].diffuse_layer_totals =
|
||||
it->diffuse_layer_totals.elt_list();
|
||||
//surf_charge_ptr[i].psi_master = it->get_psi_master();
|
||||
surf_charge_ptr[i].count_g = 0;
|
||||
surf_charge_ptr[i].g = NULL;
|
||||
i++;
|
||||
}
|
||||
return (surf_charge_ptr);
|
||||
}
|
||||
|
||||
void cxxSurfaceCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Surf_Charge element and attributes
|
||||
// Surf_Charge element and attributes
|
||||
|
||||
s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl;
|
||||
s_oss << indent0 << "specific_area=\"" << this->specific_area << "\"" << std::endl;
|
||||
s_oss << indent0 << "grams=\"" << this->grams << "\"" << std::endl;
|
||||
s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl;
|
||||
s_oss << indent0 << "mass_water=\"" << this->mass_water << "\"" << std::endl;
|
||||
s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl;
|
||||
s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << std::endl;
|
||||
s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << std::endl;
|
||||
s_oss << indent0 << "capacitance=\"" << this->capacitance[0] << " " << this->capacitance[0] << "\"" << std::endl;
|
||||
s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl;
|
||||
s_oss << indent0 << "specific_area=\"" << this->
|
||||
specific_area << "\"" << std::endl;
|
||||
s_oss << indent0 << "grams=\"" << this->grams << "\"" << std::endl;
|
||||
s_oss << indent0 << "charge_balance=\"" << this->
|
||||
charge_balance << "\"" << std::endl;
|
||||
s_oss << indent0 << "mass_water=\"" << this->
|
||||
mass_water << "\"" << std::endl;
|
||||
s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl;
|
||||
s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << std::endl;
|
||||
s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << std::endl;
|
||||
s_oss << indent0 << "capacitance=\"" << this->
|
||||
capacitance[0] << " " << this->capacitance[0] << "\"" << std::endl;
|
||||
|
||||
// totals
|
||||
s_oss << indent0;
|
||||
s_oss << "<diffuse_layer_totals " << std::endl;
|
||||
this->diffuse_layer_totals.dump_xml(s_oss, indent + 1);
|
||||
// totals
|
||||
s_oss << indent0;
|
||||
s_oss << "<diffuse_layer_totals " << std::endl;
|
||||
this->diffuse_layer_totals.dump_xml(s_oss, indent + 1);
|
||||
|
||||
}
|
||||
|
||||
void cxxSurfaceCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Surf_Charge element and attributes
|
||||
// Surf_Charge element and attributes
|
||||
|
||||
s_oss << indent0 << "-name " << this->name << std::endl;
|
||||
s_oss << indent0 << "-specific_area " << this->specific_area << std::endl;
|
||||
s_oss << indent0 << "-grams " << this->grams << std::endl;
|
||||
s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl;
|
||||
s_oss << indent0 << "-mass_water " << this->mass_water << std::endl;
|
||||
s_oss << indent0 << "-la_psi " << this->la_psi << std::endl;
|
||||
s_oss << indent0 << "-la_psi1 " << this->la_psi1 << std::endl;
|
||||
s_oss << indent0 << "-la_psi2 " << this->la_psi2 << std::endl;
|
||||
s_oss << indent0 << "-capacitance0 " << this->capacitance[0] << std::endl;
|
||||
s_oss << indent0 << "-capacitance1 " << this->capacitance[1] << std::endl;
|
||||
s_oss << indent0 << "-name " << this->name << std::endl;
|
||||
s_oss << indent0 << "-specific_area " << this->
|
||||
specific_area << std::endl;
|
||||
s_oss << indent0 << "-grams " << this->grams << std::endl;
|
||||
s_oss << indent0 << "-charge_balance " << this->
|
||||
charge_balance << std::endl;
|
||||
s_oss << indent0 << "-mass_water " << this->
|
||||
mass_water << std::endl;
|
||||
s_oss << indent0 << "-la_psi " << this->
|
||||
la_psi << std::endl;
|
||||
s_oss << indent0 << "-la_psi1 " << this->
|
||||
la_psi1 << std::endl;
|
||||
s_oss << indent0 << "-la_psi2 " << this->
|
||||
la_psi2 << std::endl;
|
||||
s_oss << indent0 << "-capacitance0 " << this->
|
||||
capacitance[0] << std::endl;
|
||||
s_oss << indent0 << "-capacitance1 " << this->
|
||||
capacitance[1] << std::endl;
|
||||
|
||||
// totals
|
||||
s_oss << indent0;
|
||||
s_oss << "-diffuse_layer_totals" << std::endl;
|
||||
this->diffuse_layer_totals.dump_raw(s_oss, indent + 1);
|
||||
// totals
|
||||
s_oss << indent0;
|
||||
s_oss << "-diffuse_layer_totals" << std::endl;
|
||||
this->diffuse_layer_totals.dump_raw(s_oss, indent + 1);
|
||||
|
||||
}
|
||||
|
||||
void cxxSurfaceCharge::read_raw(CParser& parser)
|
||||
void
|
||||
cxxSurfaceCharge::read_raw(CParser & parser)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("name"); // 0
|
||||
vopts.push_back("specific_area"); // 1
|
||||
vopts.push_back("grams"); // 2
|
||||
vopts.push_back("charge_balance"); // 3
|
||||
vopts.push_back("mass_water"); // 4
|
||||
vopts.push_back("la_psi"); // 5
|
||||
vopts.push_back("diffuse_layer_totals"); // 6
|
||||
vopts.push_back("la_psi1"); // 7
|
||||
vopts.push_back("la_psi2"); // 8
|
||||
vopts.push_back("capacitance0"); // 9
|
||||
vopts.push_back("capacitance1"); // 10
|
||||
}
|
||||
std::string str;
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(10);
|
||||
vopts.push_back("name"); // 0
|
||||
vopts.push_back("specific_area"); // 1
|
||||
vopts.push_back("grams"); // 2
|
||||
vopts.push_back("charge_balance"); // 3
|
||||
vopts.push_back("mass_water"); // 4
|
||||
vopts.push_back("la_psi"); // 5
|
||||
vopts.push_back("diffuse_layer_totals"); // 6
|
||||
vopts.push_back("la_psi1"); // 7
|
||||
vopts.push_back("la_psi2"); // 8
|
||||
vopts.push_back("capacitance0"); // 9
|
||||
vopts.push_back("capacitance1"); // 10
|
||||
}
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool name_defined(false);
|
||||
bool specific_area_defined(false);
|
||||
bool grams_defined(false);
|
||||
bool charge_balance_defined(false);
|
||||
bool mass_water_defined(false);
|
||||
bool la_psi_defined(false);
|
||||
bool la_psi1_defined(false);
|
||||
bool la_psi2_defined(false);
|
||||
bool capacitance0_defined(false);
|
||||
bool capacitance1_defined(false);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool name_defined(false);
|
||||
bool specific_area_defined(false);
|
||||
bool grams_defined(false);
|
||||
bool charge_balance_defined(false);
|
||||
bool mass_water_defined(false);
|
||||
bool la_psi_defined(false);
|
||||
bool la_psi1_defined(false);
|
||||
bool la_psi2_defined(false);
|
||||
bool capacitance0_defined(false);
|
||||
bool capacitance1_defined(false);
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Surface for more processing
|
||||
//parser.error_msg("Unknown input in SURF_CHARGE read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
for (;;)
|
||||
{
|
||||
int opt = parser.get_option(vopts, next_char);
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
|
||||
case 0: // name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
this->name = string_hsave(str.c_str());
|
||||
}
|
||||
name_defined = true;
|
||||
break;
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_KEYWORD;
|
||||
// Allow return to Surface for more processing
|
||||
//parser.error_msg("Unknown input in SURF_CHARGE read.", CParser::OT_CONTINUE);
|
||||
//parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
break;
|
||||
|
||||
case 1: // specific_area
|
||||
if (!(parser.get_iss() >> this->specific_area))
|
||||
{
|
||||
this->specific_area = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for specific_area.", CParser::OT_CONTINUE);
|
||||
}
|
||||
specific_area_defined = true;
|
||||
break;
|
||||
case 0: // name
|
||||
if (!(parser.get_iss() >> str))
|
||||
{
|
||||
this->name = NULL;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected string value for name.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->name = string_hsave(str.c_str());
|
||||
}
|
||||
name_defined = true;
|
||||
break;
|
||||
|
||||
case 2: // grams
|
||||
if (!(parser.get_iss() >> this->grams))
|
||||
{
|
||||
this->grams = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for grams.", CParser::OT_CONTINUE);
|
||||
}
|
||||
grams_defined = true;
|
||||
break;
|
||||
case 1: // specific_area
|
||||
if (!(parser.get_iss() >> this->specific_area))
|
||||
{
|
||||
this->specific_area = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for specific_area.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
specific_area_defined = true;
|
||||
break;
|
||||
|
||||
case 2: // grams
|
||||
if (!(parser.get_iss() >> this->grams))
|
||||
{
|
||||
this->grams = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for grams.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
grams_defined = true;
|
||||
break;
|
||||
|
||||
|
||||
case 3: // charge_balance
|
||||
if (!(parser.get_iss() >> this->charge_balance))
|
||||
{
|
||||
this->charge_balance = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE);
|
||||
}
|
||||
charge_balance_defined = true;
|
||||
break;
|
||||
case 3: // charge_balance
|
||||
if (!(parser.get_iss() >> this->charge_balance))
|
||||
{
|
||||
this->charge_balance = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for charge_balance.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
charge_balance_defined = true;
|
||||
break;
|
||||
|
||||
case 4: // mass_water
|
||||
if (!(parser.get_iss() >> this->mass_water))
|
||||
{
|
||||
this->mass_water = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for mass_water.", CParser::OT_CONTINUE);
|
||||
}
|
||||
mass_water_defined = true;
|
||||
break;
|
||||
case 4: // mass_water
|
||||
if (!(parser.get_iss() >> this->mass_water))
|
||||
{
|
||||
this->mass_water = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for mass_water.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
mass_water_defined = true;
|
||||
break;
|
||||
|
||||
|
||||
case 5: // la_psi
|
||||
if (!(parser.get_iss() >> this->la_psi))
|
||||
{
|
||||
this->la_psi = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE);
|
||||
}
|
||||
la_psi_defined = true;
|
||||
break;
|
||||
case 5: // la_psi
|
||||
if (!(parser.get_iss() >> this->la_psi))
|
||||
{
|
||||
this->la_psi = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for la_psi.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
la_psi_defined = true;
|
||||
break;
|
||||
|
||||
|
||||
case 6: // diffuse_layer_totals
|
||||
if ( this->diffuse_layer_totals.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 6;
|
||||
break;
|
||||
case 6: // diffuse_layer_totals
|
||||
if (this->diffuse_layer_totals.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected element name and molality for SurfaceCharge diffuse_layer_totals.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 6;
|
||||
break;
|
||||
|
||||
case 7: // la_psi1
|
||||
if (!(parser.get_iss() >> this->la_psi1))
|
||||
{
|
||||
this->la_psi1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for la_psi1.", CParser::OT_CONTINUE);
|
||||
}
|
||||
la_psi1_defined = true;
|
||||
break;
|
||||
case 7: // la_psi1
|
||||
if (!(parser.get_iss() >> this->la_psi1))
|
||||
{
|
||||
this->la_psi1 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for la_psi1.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
la_psi1_defined = true;
|
||||
break;
|
||||
|
||||
case 8: // la_psi2
|
||||
if (!(parser.get_iss() >> this->la_psi2))
|
||||
{
|
||||
this->la_psi2 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE);
|
||||
}
|
||||
la_psi2_defined = true;
|
||||
break;
|
||||
case 8: // la_psi2
|
||||
if (!(parser.get_iss() >> this->la_psi2))
|
||||
{
|
||||
this->la_psi2 = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for la_psi.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
la_psi2_defined = true;
|
||||
break;
|
||||
|
||||
case 9: // capacitance0
|
||||
if (!(parser.get_iss() >> this->capacitance[0]))
|
||||
{
|
||||
this->capacitance[0] = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for capacitance0.", CParser::OT_CONTINUE);
|
||||
}
|
||||
capacitance0_defined = true;
|
||||
break;
|
||||
case 9: // capacitance0
|
||||
if (!(parser.get_iss() >> this->capacitance[0]))
|
||||
{
|
||||
this->capacitance[0] = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for capacitance0.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
capacitance0_defined = true;
|
||||
break;
|
||||
|
||||
case 10: // capacitance1
|
||||
if (!(parser.get_iss() >> this->capacitance[1]))
|
||||
{
|
||||
this->capacitance[1] = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for capacitance1.", CParser::OT_CONTINUE);
|
||||
}
|
||||
capacitance1_defined = true;
|
||||
break;
|
||||
case 10: // capacitance1
|
||||
if (!(parser.get_iss() >> this->capacitance[1]))
|
||||
{
|
||||
this->capacitance[1] = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for capacitance1.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
capacitance1_defined = true;
|
||||
break;
|
||||
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (name_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Name not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (specific_area_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Specific_area not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (grams_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Grams not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (charge_balance_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Charge_balance not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (mass_water_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Mass_water not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (la_psi_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("La_psi not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (la_psi1_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("La_psi1 not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (la_psi2_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("La_psi2 not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (capacitance0_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (capacitance1_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (name_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Name not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (specific_area_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Specific_area not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (grams_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Grams not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (charge_balance_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Charge_balance not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (mass_water_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Mass_water not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (la_psi_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("La_psi not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (la_psi1_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("La_psi1 not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (la_psi2_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("La_psi2 not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (capacitance0_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Capacitance0 not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (capacitance1_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Capacitance1 not defined for SurfaceCharge input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxSurfaceCharge::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxSurfaceCharge::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
|
||||
ints.push_back(dictionary.string2int(this->name));
|
||||
doubles.push_back(this->specific_area);
|
||||
doubles.push_back(this->grams);
|
||||
doubles.push_back(this->charge_balance);
|
||||
doubles.push_back(this->mass_water);
|
||||
doubles.push_back(this->la_psi);
|
||||
doubles.push_back(this->la_psi1);
|
||||
doubles.push_back(this->la_psi2);
|
||||
doubles.push_back(this->capacitance[0]);
|
||||
doubles.push_back(this->capacitance[1]);
|
||||
doubles.push_back(this->charge_balance);
|
||||
doubles.push_back(this->mass_water);
|
||||
doubles.push_back(this->la_psi);
|
||||
doubles.push_back(this->la_psi1);
|
||||
doubles.push_back(this->la_psi2);
|
||||
doubles.push_back(this->capacitance[0]);
|
||||
doubles.push_back(this->capacitance[1]);
|
||||
this->diffuse_layer_totals.mpi_pack(ints, doubles);
|
||||
}
|
||||
void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
void
|
||||
cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
extern cxxDictionary dictionary;
|
||||
int i = *ii;
|
||||
@ -423,62 +500,72 @@ void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
void cxxSurfaceCharge::add(const cxxSurfaceCharge &addee, double extensive)
|
||||
void
|
||||
cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive)
|
||||
{
|
||||
if (extensive == 0.0) return;
|
||||
//char * name;
|
||||
//double specific_area;
|
||||
//double grams;
|
||||
//double charge_balance;
|
||||
//double mass_water;
|
||||
//double la_psi, la_psi1, la_psi2;
|
||||
//double capacitance[2];
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
//char * name;
|
||||
//double specific_area;
|
||||
//double grams;
|
||||
//double charge_balance;
|
||||
//double mass_water;
|
||||
//double la_psi, la_psi1, la_psi2;
|
||||
//double capacitance[2];
|
||||
|
||||
//char * name;
|
||||
if (this->name == NULL && addee.name == NULL) {
|
||||
return;
|
||||
}
|
||||
assert (this->name == addee.name);
|
||||
|
||||
double ext1, ext2, f1, f2;
|
||||
ext1 = this->specific_area * this->grams;
|
||||
ext2 = addee.specific_area * addee.grams * extensive;
|
||||
if (ext1 + ext2 != 0) {
|
||||
f1 = ext1/(ext1 + ext2);
|
||||
f2 = ext2/(ext1 + ext2);
|
||||
} else {
|
||||
f1 = 0.5;
|
||||
f2 = 0.5;
|
||||
}
|
||||
//char * name;
|
||||
if (this->name == NULL && addee.name == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert(this->name == addee.name);
|
||||
|
||||
//double specific_area;
|
||||
this->specific_area = f1*this->specific_area + f2*addee.specific_area;
|
||||
//double grams;
|
||||
this->grams += addee.grams * extensive;
|
||||
//double charge_balance;
|
||||
this->charge_balance += addee.charge_balance * extensive;
|
||||
//double mass_water;
|
||||
this->mass_water += addee.mass_water * extensive;
|
||||
//double la_psi, la_psi1, la_psi2;
|
||||
this->la_psi = this->la_psi*f1 + addee.la_psi*f2;
|
||||
this->la_psi1 = this->la_psi1*f1 + addee.la_psi1*f2;
|
||||
this->la_psi2 = this->la_psi2*f1 + addee.la_psi2*f2;
|
||||
//double capacitance[2];
|
||||
this->capacitance[0] = this->capacitance[0]*f1 + this->capacitance[0]*f2;
|
||||
this->capacitance[1] = this->capacitance[1]*f1 + this->capacitance[1]*f2;
|
||||
double ext1, ext2, f1, f2;
|
||||
ext1 = this->specific_area * this->grams;
|
||||
ext2 = addee.specific_area * addee.grams * extensive;
|
||||
if (ext1 + ext2 != 0)
|
||||
{
|
||||
f1 = ext1 / (ext1 + ext2);
|
||||
f2 = ext2 / (ext1 + ext2);
|
||||
}
|
||||
else
|
||||
{
|
||||
f1 = 0.5;
|
||||
f2 = 0.5;
|
||||
}
|
||||
|
||||
//double specific_area;
|
||||
this->specific_area = f1 * this->specific_area + f2 * addee.specific_area;
|
||||
//double grams;
|
||||
this->grams += addee.grams * extensive;
|
||||
//double charge_balance;
|
||||
this->charge_balance += addee.charge_balance * extensive;
|
||||
//double mass_water;
|
||||
this->mass_water += addee.mass_water * extensive;
|
||||
//double la_psi, la_psi1, la_psi2;
|
||||
this->la_psi = this->la_psi * f1 + addee.la_psi * f2;
|
||||
this->la_psi1 = this->la_psi1 * f1 + addee.la_psi1 * f2;
|
||||
this->la_psi2 = this->la_psi2 * f1 + addee.la_psi2 * f2;
|
||||
//double capacitance[2];
|
||||
this->capacitance[0] =
|
||||
this->capacitance[0] * f1 + this->capacitance[0] * f2;
|
||||
this->capacitance[1] =
|
||||
this->capacitance[1] * f1 + this->capacitance[1] * f2;
|
||||
}
|
||||
void cxxSurfaceCharge::multiply(double extensive)
|
||||
|
||||
void
|
||||
cxxSurfaceCharge::multiply(double extensive)
|
||||
{
|
||||
//char * name;
|
||||
//double specific_area;
|
||||
//double grams;
|
||||
this->grams *= extensive;
|
||||
//double charge_balance;
|
||||
this->charge_balance *= extensive;
|
||||
//double mass_water;
|
||||
this->mass_water *= extensive;
|
||||
//double la_psi, la_psi1, la_psi2;
|
||||
//double capacitance[2];
|
||||
//cxxNameDouble diffuse_layer_totals;
|
||||
this->diffuse_layer_totals.multiply(extensive);
|
||||
//char * name;
|
||||
//double specific_area;
|
||||
//double grams;
|
||||
this->grams *= extensive;
|
||||
//double charge_balance;
|
||||
this->charge_balance *= extensive;
|
||||
//double mass_water;
|
||||
this->mass_water *= extensive;
|
||||
//double la_psi, la_psi1, la_psi2;
|
||||
//double capacitance[2];
|
||||
//cxxNameDouble diffuse_layer_totals;
|
||||
this->diffuse_layer_totals.multiply(extensive);
|
||||
}
|
||||
|
||||
972
SurfaceComp.cxx
972
SurfaceComp.cxx
File diff suppressed because it is too large
Load Diff
942
System.cxx
942
System.cxx
@ -1,436 +1,520 @@
|
||||
#include "System.h"
|
||||
#include <algorithm> // std::replace
|
||||
extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat);
|
||||
cxxSystem::cxxSystem(void)
|
||||
{
|
||||
this->solution = NULL;
|
||||
this->exchange = NULL;
|
||||
this->ppassemblage = NULL;
|
||||
this->gasphase = NULL;
|
||||
this->ssassemblage = NULL;
|
||||
this->kinetics = NULL;
|
||||
this->surface = NULL;
|
||||
this->mix = NULL;
|
||||
this->reaction = NULL;
|
||||
this->temperature = NULL;
|
||||
}
|
||||
#include <algorithm> // std::replace
|
||||
extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat);
|
||||
cxxSystem::cxxSystem(void)
|
||||
{
|
||||
this->solution = NULL;
|
||||
this->exchange = NULL;
|
||||
this->ppassemblage = NULL;
|
||||
this->gasphase = NULL;
|
||||
this->ssassemblage = NULL;
|
||||
this->kinetics = NULL;
|
||||
this->surface = NULL;
|
||||
this->mix = NULL;
|
||||
this->reaction = NULL;
|
||||
this->temperature = NULL;
|
||||
}
cxxSystem::~cxxSystem(void)
|
||||
{
|
||||
}
void
|
||||
cxxSystem::Initialize(void)
|
||||
{
|
||||
this->solution = NULL;
|
||||
this->exchange = NULL;
|
||||
this->ppassemblage = NULL;
|
||||
this->gasphase = NULL;
|
||||
this->ssassemblage = NULL;
|
||||
this->kinetics = NULL;
|
||||
this->surface = NULL;
|
||||
this->mix = NULL;
|
||||
this->reaction = NULL;
|
||||
this->temperature = NULL;
|
||||
}
void
|
||||
cxxSystem::totalize(void)
|
||||
{
|
||||
|
||||
//initialize
|
||||
this->totals.clear();
|
||||
|
||||
//add solution
|
||||
if (this->solution != NULL)
|
||||
|
||||
{
|
||||
char token[MAX_LENGTH];
|
||||
strcpy(token, "O");
|
||||
this->totals[token] = this->solution->get_total_o();
|
||||
strcpy(token, "H");
|
||||
this->totals[token] = this->solution->get_total_h();
|
||||
strcpy(token, "Charge");
|
||||
this->totals[token] = this->solution->get_cb();
|
||||
this->totals.add_extensive(this->solution->get_totals(), 1.0);
|
||||
}
|
||||
if (this->exchange != NULL)
|
||||
|
||||
{
|
||||
this->exchange->totalize();
|
||||
this->totals.add_extensive(this->exchange->get_totals(), 1.0);
|
||||
}
|
||||
if (this->ppassemblage != NULL)
|
||||
|
||||
{
|
||||
this->ppassemblage->totalize();
|
||||
this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0);
|
||||
}
|
||||
if (this->gasphase != NULL)
|
||||
|
||||
{
|
||||
this->gasphase->totalize();
|
||||
this->totals.add_extensive(this->gasphase->get_totals(), 1.0);
|
||||
}
|
||||
if (this->ssassemblage != NULL)
|
||||
|
||||
{
|
||||
this->ssassemblage->totalize();
|
||||
this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0);
|
||||
}
|
||||
if (this->surface != NULL)
|
||||
|
||||
{
|
||||
this->ssassemblage->totalize();
|
||||
this->totals.add_extensive(this->surface->get_totals(), 1.0);
|
||||
}
|
||||
|
||||
//Need to handle the following 3 reactions:
|
||||
//
|
||||
//this->kinetics = NULL;
|
||||
//this->mix = NULL;
|
||||
//this->reaction = NULL;
|
||||
//this->temperature = NULL;
|
||||
//this->totals.dump_raw(std::cerr, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cxxSystem::~cxxSystem(void)
|
||||
{
|
||||
}
|
||||
|
||||
void cxxSystem::Initialize(void)
|
||||
{
|
||||
this->solution = NULL;
|
||||
this->exchange = NULL;
|
||||
this->ppassemblage = NULL;
|
||||
this->gasphase = NULL;
|
||||
this->ssassemblage = NULL;
|
||||
this->kinetics = NULL;
|
||||
this->surface = NULL;
|
||||
this->mix = NULL;
|
||||
this->reaction = NULL;
|
||||
this->temperature = NULL;
|
||||
}
|
||||
void cxxSystem::totalize(void)
|
||||
{
|
||||
//initialize
|
||||
this->totals.clear();
|
||||
//add solution
|
||||
if (this->solution != NULL)
|
||||
{
|
||||
char token[MAX_LENGTH];
|
||||
strcpy(token, "O");
|
||||
this->totals[token] = this->solution->get_total_o();
|
||||
strcpy(token, "H");
|
||||
this->totals[token] = this->solution->get_total_h();
|
||||
strcpy(token, "Charge");
|
||||
this->totals[token] = this->solution->get_cb();
|
||||
this->totals.add_extensive(this->solution->get_totals(), 1.0);
|
||||
}
|
||||
if (this->exchange != NULL)
|
||||
{
|
||||
this->exchange->totalize();
|
||||
this->totals.add_extensive(this->exchange->get_totals(), 1.0);
|
||||
}
|
||||
if (this->ppassemblage != NULL)
|
||||
{
|
||||
this->ppassemblage->totalize();
|
||||
this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0);
|
||||
}
|
||||
if (this->gasphase != NULL)
|
||||
{
|
||||
this->gasphase->totalize();
|
||||
this->totals.add_extensive(this->gasphase->get_totals(), 1.0);
|
||||
}
|
||||
if (this->ssassemblage != NULL)
|
||||
{
|
||||
this->ssassemblage->totalize();
|
||||
this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0);
|
||||
}
|
||||
if (this->surface != NULL)
|
||||
{
|
||||
this->ssassemblage->totalize();
|
||||
this->totals.add_extensive(this->surface->get_totals(), 1.0);
|
||||
}
|
||||
|
||||
//Need to handle the following 3 reactions:
|
||||
//
|
||||
//this->kinetics = NULL;
|
||||
//this->mix = NULL;
|
||||
//this->reaction = NULL;
|
||||
//this->temperature = NULL;
|
||||
//this->totals.dump_raw(std::cerr, 1);
|
||||
return;
|
||||
}
|
||||
#ifdef ORCHESTRA
|
||||
void cxxSystem::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat)
|
||||
{
|
||||
//
|
||||
// chemistry file
|
||||
//
|
||||
this->totalize();
|
||||
// calculate orchestra components from PHREEQC totals
|
||||
this->ORCH_components();
|
||||
// write definitions for chemistry
|
||||
chemistry_dat << std::endl << "@class: species_reactions () {" << std::endl;
|
||||
this->ORCH_write_chemistry_water(chemistry_dat);
|
||||
this->ORCH_write_chemistry_primary(chemistry_dat);
|
||||
this->ORCH_write_chemistry_total_O_H(chemistry_dat);
|
||||
ORCH_write_chemistry_species(chemistry_dat);
|
||||
|
||||
// add definitions for pure phases
|
||||
if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_chemistry(chemistry_dat);
|
||||
|
||||
// add definitions for other PHREEQC entities here
|
||||
|
||||
// finish up
|
||||
chemistry_dat << std::endl << "}" << std::endl;
|
||||
//
|
||||
// input file
|
||||
//
|
||||
input_dat << std::endl << "@class: input_file_data () {" << std::endl;
|
||||
this->ORCH_write_input(input_dat);
|
||||
input_dat << std::endl << "}" << std::endl;
|
||||
//
|
||||
// output file
|
||||
//
|
||||
output_dat << std::endl << "Output_every: 1" << std::endl;
|
||||
output_dat << "Var:";
|
||||
this->ORCH_write_output_vars(output_dat);
|
||||
// add definitions for pure phases
|
||||
if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_output_vars(output_dat);
|
||||
|
||||
//finish up
|
||||
output_dat << std::endl;
|
||||
};
|
||||
|
||||
void cxxSystem::ORCH_write_chemistry_water(std::ostream &chemistry_dat)
|
||||
{
|
||||
//
|
||||
// Write water entities
|
||||
//
|
||||
chemistry_dat << std::endl << "//********* The water entities" << std::endl;
|
||||
|
||||
// e-, total hydrogen
|
||||
chemistry_dat << "@entity(e-, diss, 0)" << std::endl;
|
||||
chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl;
|
||||
chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std::endl;
|
||||
|
||||
// H+, charge balance
|
||||
chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl;
|
||||
chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std::endl;
|
||||
|
||||
// H2O
|
||||
chemistry_dat << "@entity(" << s_h2o->name << ", diss, 55.506)" << std::endl;
|
||||
chemistry_dat << std::endl;
|
||||
}
|
||||
|
||||
void cxxSystem::ORCH_write_chemistry_primary(std::ostream &chemistry_dat)
|
||||
{
|
||||
chemistry_dat << std::endl << "//********* The primary species" << std::endl;
|
||||
//
|
||||
// Write other master species definitions, i.e. primary entities
|
||||
//
|
||||
chemistry_dat << "@species(H+, 1)" << std::endl;
|
||||
for(cxxNameDouble::iterator iter = this->totals.begin() ; iter != this->totals.end(); ++iter)
|
||||
{
|
||||
std::string name(iter->first);
|
||||
if (name == "H(1)" || name == "E" || name == "H" || name == "O" || name == "Charge") continue;
|
||||
struct element *elt;
|
||||
char *element_name = string_hsave(name.c_str());
|
||||
elt = element_store(element_name);
|
||||
assert(elt != NULL);
|
||||
struct species *s_ptr;
|
||||
s_ptr = elt->master->s;
|
||||
assert(s_ptr != NULL);
|
||||
chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr->z << ")" << std::endl;
|
||||
// regular mole balance
|
||||
chemistry_dat << "@primary_entity(" << s_ptr->name << ", 1e-9, liter, 1.0e-9)" << std::endl;
|
||||
}
|
||||
chemistry_dat << std::endl;
|
||||
}
|
||||
|
||||
void cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat)
|
||||
{
|
||||
chemistry_dat << std::endl << "//********* Define total hydrogen and oxygen" << std::endl;
|
||||
|
||||
// Write H total equation
|
||||
chemistry_dat << "@var: total_hydrogen 0" << std::endl;
|
||||
chemistry_dat << "@calc: (5, \"total_hydrogen = 0";
|
||||
int i;
|
||||
for (i = 0; i < count_s_x; i++)
|
||||
{
|
||||
// write in terms of orchestra components
|
||||
if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE))
|
||||
{
|
||||
if (s_x[i]->h != 0)
|
||||
{
|
||||
chemistry_dat << "+";
|
||||
if (s_x[i]->h != 1)
|
||||
{
|
||||
chemistry_dat << s_x[i]->h << "*";
|
||||
}
|
||||
chemistry_dat << "{" << s_x[i]->name << ".liter}";
|
||||
}
|
||||
}
|
||||
}
|
||||
chemistry_dat << "\")" << std::endl;
|
||||
|
||||
// Write O total equation
|
||||
chemistry_dat << "@var: total_oxygen 0" << std::endl;
|
||||
chemistry_dat << "@calc: (5, \"total_oxygen = 0";
|
||||
for (i = 0; i < count_s_x; i++)
|
||||
{
|
||||
if (s_x[i]->o != 0)
|
||||
{
|
||||
// write in terms of orchestra components
|
||||
if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE))
|
||||
{
|
||||
chemistry_dat << "+";
|
||||
if (s_x[i]->o != 1)
|
||||
{
|
||||
chemistry_dat << s_x[i]->o << "*";
|
||||
}
|
||||
chemistry_dat << "{" << s_x[i]->name << ".liter}";
|
||||
}
|
||||
}
|
||||
}
|
||||
chemistry_dat << "\")" << std::endl;
|
||||
chemistry_dat << std::endl;
|
||||
}
|
||||
void cxxSystem::ORCH_write_input(std::ostream &input_dat)
|
||||
{
|
||||
|
||||
|
||||
void
|
||||
cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat,
|
||||
std::ostream & output_dat)
|
||||
{
|
||||
|
||||
//
|
||||
// chemistry file
|
||||
//
|
||||
this->totalize();
|
||||
|
||||
// calculate orchestra components from PHREEQC totals
|
||||
this->ORCH_components();
|
||||
|
||||
// write definitions for chemistry
|
||||
chemistry_dat << std::
|
||||
endl << "@class: species_reactions () {" << std::endl;
|
||||
this->ORCH_write_chemistry_water(chemistry_dat);
|
||||
this->ORCH_write_chemistry_primary(chemistry_dat);
|
||||
this->ORCH_write_chemistry_total_O_H(chemistry_dat);
|
||||
ORCH_write_chemistry_species(chemistry_dat);
|
||||
|
||||
// add definitions for pure phases
|
||||
if (this->ppassemblage != NULL)
|
||||
this->ppassemblage->ORCH_write_chemistry(chemistry_dat);
|
||||
|
||||
// add definitions for other PHREEQC entities here
|
||||
|
||||
// finish up
|
||||
chemistry_dat << std::endl << "}" << std::endl;
|
||||
|
||||
//
|
||||
// input file
|
||||
//
|
||||
input_dat << std::endl << "@class: input_file_data () {" << std::endl;
|
||||
this->ORCH_write_input(input_dat);
|
||||
input_dat << std::endl << "}" << std::endl;
|
||||
|
||||
//
|
||||
// output file
|
||||
//
|
||||
output_dat << std::endl << "Output_every: 1" << std::endl;
|
||||
output_dat << "Var:";
|
||||
this->ORCH_write_output_vars(output_dat);
|
||||
|
||||
// add definitions for pure phases
|
||||
if (this->ppassemblage != NULL)
|
||||
this->ppassemblage->ORCH_write_output_vars(output_dat);
|
||||
|
||||
//finish up
|
||||
output_dat << std::endl;
|
||||
};
|
||||
void
|
||||
cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat)
|
||||
{
|
||||
|
||||
//
|
||||
// Write water entities
|
||||
//
|
||||
chemistry_dat << std::
|
||||
endl << "//********* The water entities" << std::endl;
|
||||
|
||||
// e-, total hydrogen
|
||||
chemistry_dat << "@entity(e-, diss, 0)" << std::endl;
|
||||
chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl;
|
||||
chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std::
|
||||
endl;
|
||||
|
||||
// H+, charge balance
|
||||
chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl;
|
||||
chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std::
|
||||
endl;
|
||||
|
||||
// H2O
|
||||
chemistry_dat << "@entity(" << s_h2o->
|
||||
name << ", diss, 55.506)" << std::endl;
|
||||
chemistry_dat << std::endl;
|
||||
}
void
|
||||
|
||||
cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat)
|
||||
{
|
||||
chemistry_dat << std::endl << "//********* The primary species" << std::
|
||||
endl;
|
||||
|
||||
//
|
||||
// Write other master species definitions, i.e. primary entities
|
||||
//
|
||||
chemistry_dat << "@species(H+, 1)" << std::endl;
|
||||
for (cxxNameDouble::iterator iter = this->totals.begin();
|
||||
iter != this->totals.end(); ++iter)
|
||||
|
||||
{
|
||||
std::string name(iter->first);
|
||||
if (name == "H(1)" || name == "E" || name == "H" || name == "O"
|
||||
|| name == "Charge")
|
||||
continue;
|
||||
struct element *elt;
|
||||
char *element_name = string_hsave(name.c_str());
|
||||
elt = element_store(element_name);
|
||||
assert(elt != NULL);
|
||||
struct species *s_ptr;
|
||||
s_ptr = elt->master->s;
|
||||
assert(s_ptr != NULL);
|
||||
chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr->
|
||||
z << ")" << std::endl;
|
||||
|
||||
// regular mole balance
|
||||
chemistry_dat << "@primary_entity(" << s_ptr->
|
||||
name << ", 1e-9, liter, 1.0e-9)" << std::endl;
|
||||
}
chemistry_dat << std::endl;
|
||||
}
void
|
||||
|
||||
cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat)
|
||||
{
|
||||
chemistry_dat << std::
|
||||
endl << "//********* Define total hydrogen and oxygen" << std::endl;
|
||||
|
||||
// Write H total equation
|
||||
chemistry_dat << "@var: total_hydrogen 0" << std::endl;
|
||||
chemistry_dat << "@calc: (5, \"total_hydrogen = 0";
|
||||
int i;
|
||||
for (i = 0; i < count_s_x; i++)
|
||||
|
||||
{
|
||||
|
||||
// write in terms of orchestra components
|
||||
if (s_x[i]->primary != NULL
|
||||
|| (s_x[i]->secondary != NULL
|
||||
&& s_x[i]->secondary->in == TRUE))
|
||||
|
||||
{
|
||||
if (s_x[i]->h != 0)
|
||||
|
||||
{
|
||||
chemistry_dat << "+";
|
||||
if (s_x[i]->h != 1)
|
||||
|
||||
{
|
||||
chemistry_dat << s_x[i]->h << "*";
|
||||
}
|
||||
chemistry_dat << "{" << s_x[i]->name << ".liter}";
|
||||
}
|
||||
}
|
||||
}
|
||||
chemistry_dat << "\")" << std::endl;
|
||||
|
||||
// Write O total equation
|
||||
chemistry_dat << "@var: total_oxygen 0" << std::endl;
|
||||
chemistry_dat << "@calc: (5, \"total_oxygen = 0";
|
||||
for (i = 0; i < count_s_x; i++)
|
||||
|
||||
{
|
||||
if (s_x[i]->o != 0)
|
||||
|
||||
{
|
||||
|
||||
// write in terms of orchestra components
|
||||
if (s_x[i]->primary != NULL
|
||||
|| (s_x[i]->secondary != NULL
|
||||
&& s_x[i]->secondary->in == TRUE))
|
||||
|
||||
{
|
||||
chemistry_dat << "+";
|
||||
if (s_x[i]->o != 1)
|
||||
|
||||
{
|
||||
chemistry_dat << s_x[i]->o << "*";
|
||||
}
|
||||
chemistry_dat << "{" << s_x[i]->name << ".liter}";
|
||||
}
|
||||
}
|
||||
}
|
||||
chemistry_dat << "\")" << std::endl;
|
||||
chemistry_dat << std::endl;
|
||||
}
|
||||
void
|
||||
cxxSystem::ORCH_write_input(std::ostream & input_dat)
|
||||
{
|
||||
|
||||
//
|
||||
// Write orchestra input file info
|
||||
//
|
||||
std::ostringstream headings, data;
|
||||
data.precision(DBL_DIG - 1);
|
||||
headings << "var: ";
|
||||
data << "data: ";
|
||||
std::ostringstream headings, data;
|
||||
data.precision(DBL_DIG - 1);
|
||||
headings << "var: ";
|
||||
data << "data: ";
|
||||
headings << "tempc\t";
|
||||
data << this->solution->get_tc() << "\t";
|
||||
headings << "pH\t";
|
||||
data << this->solution->get_ph() << "\t";
|
||||
headings << "pe\t";
|
||||
data << this->solution->get_pe() << "\t";
|
||||
headings << "H2O.act\t";
|
||||
data << 1 << "\t";
|
||||
headings << "I\t";
|
||||
data << this->solution->get_mu() << "\t";
|
||||
for (cxxNameDouble::iterator iter = this->orch_totals.begin();
|
||||
iter != this->orch_totals.end(); ++iter)
|
||||
|
||||
{
|
||||
headings << iter->first << ".liter" << "\t";
|
||||
data << iter->second << "\t";
|
||||
}
|
||||
|
||||
// activity estimate
|
||||
for (cxxNameDouble::iterator iter = this->totals.begin();
|
||||
iter != this->totals.end(); ++iter)
|
||||
|
||||
{
|
||||
if (iter->first == "O" || iter->first == "Charge")
|
||||
continue;
|
||||
std::string master_name;
|
||||
struct master *master_ptr;
|
||||
master_ptr = master_bsearch(iter->first);
|
||||
assert(master_ptr != NULL);
|
||||
cxxNameDouble ma = this->solution->get_master_activity();
|
||||
cxxNameDouble::iterator it = ma.find(iter->first);
|
||||
if (it == ma.end())
|
||||
|
||||
{
|
||||
it = ma.find(master_ptr->s->secondary->elt->name);
|
||||
}
|
||||
headings << master_ptr->s->name << ".act\t";
|
||||
if (it != ma.end())
|
||||
|
||||
{
|
||||
data << pow(10., it->second) << "\t";
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
data << 1e-9 << "\t";
|
||||
}
|
||||
}
|
||||
|
||||
// Isotopes
|
||||
//s_oss << "-Isotopes" << std::endl;
|
||||
/*
|
||||
{
|
||||
for (std::list<cxxSolutionIsotope>::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) {
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Write data to string
|
||||
input_dat << headings.str() << std::endl;
|
||||
input_dat << data.str() << std::endl;
|
||||
return;
|
||||
}
|
||||
void
|
||||
cxxSystem::ORCH_components(void)
|
||||
{
|
||||
|
||||
// translate from H, O, charge to H+tot, e-tot, and H2Otot
|
||||
cxxNameDouble::iterator it;
|
||||
cxxNameDouble temp_totals;
|
||||
|
||||
//
|
||||
// Set names in orch_totals to master species names
|
||||
//
|
||||
this->orch_totals.clear();
|
||||
temp_totals = this->totals;
|
||||
temp_totals.erase("H");
|
||||
temp_totals.erase("O");
|
||||
temp_totals.erase("Charge");
|
||||
|
||||
//temp_totals.dump_raw(std::cerr, 1);
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
assert(elt_ptr != NULL);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
assert(master_ptr != NULL);
|
||||
double coef = master_ptr->coef;
|
||||
if (master_ptr->coef == 0)
|
||||
|
||||
{
|
||||
coef = 1;
|
||||
}
|
||||
this->orch_totals[master_ptr->s->name] = it->second / coef;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate h2otot
|
||||
//
|
||||
it = this->totals.find("O");
|
||||
assert(it != this->totals.end());
|
||||
double h2otot = it->second;
|
||||
|
||||
// subtract O in master species
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
h2otot -= it->second * master_ptr->s->o;
|
||||
}
|
||||
//
|
||||
// Calculate htot
|
||||
//
|
||||
it = this->totals.find("H");
|
||||
assert(it != this->totals.end());
|
||||
double htot = it->second - 2 * h2otot;
|
||||
|
||||
// subtract O in master species
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
htot -= it->second * master_ptr->s->h;
|
||||
}
|
||||
//
|
||||
// Calculate etot
|
||||
//
|
||||
it = this->totals.find("Charge");
|
||||
assert(it != this->totals.end());
|
||||
double etot = -it->second + htot;
|
||||
|
||||
// subtract O in master species
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
etot += it->second * master_ptr->s->z;
|
||||
}
|
||||
//
|
||||
// store h2otot, htot, etot in orch_totals
|
||||
//
|
||||
this->orch_totals["H2O"] = h2otot;
|
||||
this->orch_totals["H+"] = htot;
|
||||
this->orch_totals["e-"] = etot;
|
||||
this->orch_totals.dump_raw(std::cerr, 1);
|
||||
}
void
|
||||
|
||||
cxxSystem::ORCH_write_output_vars(std::ostream & outstream)
|
||||
{
|
||||
outstream << "\tnr_iter";
|
||||
|
||||
//
|
||||
// Serialize solution
|
||||
//
|
||||
outstream << "\tstart_solution";
|
||||
|
||||
//tc
|
||||
outstream << "\ttempc";
|
||||
|
||||
//pH
|
||||
outstream << "\tpH";
|
||||
|
||||
//pe
|
||||
outstream << "\tpe";
|
||||
|
||||
//mu
|
||||
outstream << "\tI";
|
||||
|
||||
//ah2o
|
||||
outstream << "\tH2O.act";
|
||||
|
||||
//total_h;
|
||||
outstream << "\ttotal_hydrogen";
|
||||
|
||||
//total_o;
|
||||
outstream << "\ttotal_oxygen";
|
||||
|
||||
//cb
|
||||
outstream << "\tchargebalance";
|
||||
|
||||
//mass_water;
|
||||
outstream << "\tH2O.con";
|
||||
|
||||
//total_alkalinity;
|
||||
outstream << "\tAlkalinity";
|
||||
|
||||
//orchestra master variables
|
||||
outstream << "\tH+.diss";
|
||||
outstream << "\te-.diss";
|
||||
outstream << "\tH2O.diss";
|
||||
|
||||
//
|
||||
// Write totals
|
||||
for (cxxNameDouble::iterator it = this->orch_totals.begin();
|
||||
it != this->orch_totals.end(); it++)
|
||||
|
||||
{
|
||||
if (it->first == "H+" || it->first == "H2O" || it->first == "e-")
|
||||
continue;
|
||||
outstream << "\t" << it->first << ".diss";
|
||||
}
|
||||
outstream << "\tend_totals";
|
||||
for (cxxNameDouble::iterator it = this->orch_totals.begin();
|
||||
it != this->orch_totals.end(); it++)
|
||||
|
||||
{
|
||||
if (it->first == "H+" || it->first == "H2O" || it->first == "e-")
|
||||
continue;
|
||||
outstream << "\t" << it->first << ".act";
|
||||
}
|
||||
outstream << "\tend_master_activities";
|
||||
|
||||
//
|
||||
// Write all species activities and concentrations
|
||||
//
|
||||
int i;
|
||||
for (i = 0; i < count_s_x; i++)
|
||||
{
|
||||
std::string name(s_x[i]->name);
|
||||
std::replace(name.begin(), name.end(), '(', '[');
|
||||
std::replace(name.begin(), name.end(), ')', ']');
|
||||
outstream << "\t" << name.c_str() << ".act" << "\t" << name.
|
||||
c_str() << ".con";
|
||||
}
|
||||
outstream << "\tend_species";
|
||||
}
|
||||
|
||||
|
||||
headings << "tempc\t";
|
||||
data << this->solution->get_tc() << "\t";
|
||||
|
||||
headings << "pH\t";
|
||||
data << this->solution->get_ph() << "\t";
|
||||
|
||||
headings << "pe\t";
|
||||
data << this->solution->get_pe() << "\t";
|
||||
|
||||
headings << "H2O.act\t";
|
||||
data << 1 << "\t";
|
||||
|
||||
headings << "I\t";
|
||||
data << this->solution->get_mu() << "\t";
|
||||
|
||||
for (cxxNameDouble::iterator iter = this->orch_totals.begin(); iter != this->orch_totals.end(); ++iter)
|
||||
{
|
||||
headings << iter->first << ".liter" << "\t";
|
||||
data << iter->second << "\t";
|
||||
}
|
||||
|
||||
// activity estimate
|
||||
for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter)
|
||||
{
|
||||
if (iter->first == "O" || iter->first == "Charge") continue;
|
||||
std::string master_name;
|
||||
struct master *master_ptr;
|
||||
master_ptr = master_bsearch (iter->first);
|
||||
assert (master_ptr != NULL);
|
||||
|
||||
cxxNameDouble ma = this->solution->get_master_activity();
|
||||
cxxNameDouble::iterator it = ma.find(iter->first);
|
||||
if (it == ma.end())
|
||||
{
|
||||
it = ma.find(master_ptr->s->secondary->elt->name);
|
||||
}
|
||||
headings << master_ptr->s->name << ".act\t";
|
||||
if (it != ma.end())
|
||||
{
|
||||
data << pow(10., it->second) << "\t";
|
||||
} else
|
||||
{
|
||||
data << 1e-9 << "\t";
|
||||
}
|
||||
}
|
||||
|
||||
// Isotopes
|
||||
//s_oss << "-Isotopes" << std::endl;
|
||||
/*
|
||||
{
|
||||
for (std::list<cxxSolutionIsotope>::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) {
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Write data to string
|
||||
input_dat << headings.str() << std::endl;
|
||||
input_dat << data.str() << std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void cxxSystem::ORCH_components(void)
|
||||
{
|
||||
// translate from H, O, charge to H+tot, e-tot, and H2Otot
|
||||
cxxNameDouble::iterator it;
|
||||
cxxNameDouble temp_totals;
|
||||
//
|
||||
// Set names in orch_totals to master species names
|
||||
//
|
||||
this->orch_totals.clear();
|
||||
temp_totals = this->totals;
|
||||
temp_totals.erase("H");
|
||||
temp_totals.erase("O");
|
||||
temp_totals.erase("Charge");
|
||||
//temp_totals.dump_raw(std::cerr, 1);
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
assert(elt_ptr != NULL);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
assert(master_ptr != NULL);
|
||||
double coef = master_ptr->coef;
|
||||
if (master_ptr->coef == 0)
|
||||
{
|
||||
coef = 1;
|
||||
}
|
||||
this->orch_totals[master_ptr->s->name] = it->second / coef;
|
||||
}
|
||||
//
|
||||
// Calculate h2otot
|
||||
//
|
||||
it = this->totals.find("O");
|
||||
assert (it != this->totals.end());
|
||||
double h2otot = it->second;
|
||||
// subtract O in master species
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
h2otot -= it->second * master_ptr->s->o;
|
||||
}
|
||||
//
|
||||
// Calculate htot
|
||||
//
|
||||
it = this->totals.find("H");
|
||||
assert (it != this->totals.end());
|
||||
double htot = it->second - 2*h2otot;
|
||||
// subtract O in master species
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
htot -= it->second * master_ptr->s->h;
|
||||
}
|
||||
//
|
||||
// Calculate etot
|
||||
//
|
||||
it = this->totals.find("Charge");
|
||||
assert (it != this->totals.end());
|
||||
double etot = -it->second + htot;
|
||||
// subtract O in master species
|
||||
for (it = temp_totals.begin(); it != temp_totals.end(); it++)
|
||||
{
|
||||
struct element *elt_ptr;
|
||||
elt_ptr = element_store(it->first);
|
||||
struct master *master_ptr;
|
||||
master_ptr = elt_ptr->primary;
|
||||
etot += it->second * master_ptr->s->z;
|
||||
}
|
||||
//
|
||||
// store h2otot, htot, etot in orch_totals
|
||||
//
|
||||
this->orch_totals["H2O"] = h2otot;
|
||||
this->orch_totals["H+"] = htot;
|
||||
this->orch_totals["e-"] = etot;
|
||||
this->orch_totals.dump_raw(std::cerr, 1);
|
||||
}
|
||||
void cxxSystem::ORCH_write_output_vars(std::ostream &outstream)
|
||||
{
|
||||
outstream << "\tnr_iter";
|
||||
//
|
||||
// Serialize solution
|
||||
//
|
||||
outstream << "\tstart_solution";
|
||||
//tc
|
||||
outstream << "\ttempc";
|
||||
//pH
|
||||
outstream << "\tpH";
|
||||
//pe
|
||||
outstream << "\tpe";
|
||||
//mu
|
||||
outstream << "\tI";
|
||||
//ah2o
|
||||
outstream << "\tH2O.act";
|
||||
//total_h;
|
||||
outstream << "\ttotal_hydrogen";
|
||||
//total_o;
|
||||
outstream << "\ttotal_oxygen";
|
||||
//cb
|
||||
outstream << "\tchargebalance";
|
||||
//mass_water;
|
||||
outstream << "\tH2O.con";
|
||||
//total_alkalinity;
|
||||
outstream << "\tAlkalinity";
|
||||
//orchestra master variables
|
||||
outstream << "\tH+.diss";
|
||||
outstream << "\te-.diss";
|
||||
outstream << "\tH2O.diss";
|
||||
//
|
||||
// Write totals
|
||||
for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++)
|
||||
{
|
||||
if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue;
|
||||
outstream << "\t" << it->first << ".diss";
|
||||
}
|
||||
outstream << "\tend_totals";
|
||||
for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++)
|
||||
{
|
||||
if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue;
|
||||
outstream << "\t" << it->first << ".act";
|
||||
}
|
||||
outstream << "\tend_master_activities";
|
||||
//
|
||||
// Write all species activities and concentrations
|
||||
//
|
||||
int i;
|
||||
for (i = 0; i < count_s_x; i++) {
|
||||
std::string name(s_x[i]->name);
|
||||
std::replace(name.begin(), name.end(), '(', '[');
|
||||
std::replace(name.begin(), name.end(), ')', ']');
|
||||
outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con";
|
||||
}
|
||||
outstream << "\tend_species";
|
||||
}
|
||||
#endif
|
||||
#endif /*
*/
|
||||
|
||||
422
Temperature.cxx
422
Temperature.cxx
@ -2,57 +2,62 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "Temperature.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxTemperature::cxxTemperature()
|
||||
//
|
||||
// default constructor for cxxTemperature
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxTemperature
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
countTemps = 0;
|
||||
equalIncrements = false;
|
||||
countTemps = 0;
|
||||
equalIncrements = false;
|
||||
}
|
||||
|
||||
cxxTemperature::cxxTemperature(struct temperature *temperature_ptr)
|
||||
//
|
||||
// constructor for cxxTemperature from struct temperature
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxTemperature from struct temperature
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
this->set_description(temperature_ptr->description);
|
||||
this->n_user = temperature_ptr->n_user;
|
||||
this->n_user_end = temperature_ptr->n_user_end;
|
||||
this->set_description(temperature_ptr->description);
|
||||
this->n_user = temperature_ptr->n_user;
|
||||
this->n_user_end = temperature_ptr->n_user_end;
|
||||
// temps
|
||||
if (temperature_ptr->count_t < 0) {
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (temperature_ptr->count_t < 0)
|
||||
{
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
this->temps.push_back(temperature_ptr->t[i]);
|
||||
}
|
||||
this->countTemps = -temperature_ptr->count_t;
|
||||
this->equalIncrements = true;
|
||||
} else {
|
||||
for (i = 0; i < temperature_ptr->count_t; i++) {
|
||||
this->countTemps = -temperature_ptr->count_t;
|
||||
this->equalIncrements = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < temperature_ptr->count_t; i++)
|
||||
{
|
||||
this->temps.push_back(temperature_ptr->t[i]);
|
||||
}
|
||||
this->countTemps = temperature_ptr->count_t;
|
||||
this->equalIncrements = false;
|
||||
this->countTemps = temperature_ptr->count_t;
|
||||
this->equalIncrements = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,201 +66,250 @@ cxxTemperature::~cxxTemperature()
|
||||
}
|
||||
|
||||
|
||||
struct temperature *cxxTemperature::cxxTemperature2temperature()
|
||||
//
|
||||
// Builds a temperature structure from instance of cxxTemperature
|
||||
//
|
||||
struct temperature *
|
||||
cxxTemperature::cxxTemperature2temperature()
|
||||
//
|
||||
// Builds a temperature structure from instance of cxxTemperature
|
||||
//
|
||||
{
|
||||
struct temperature *temperature_ptr;
|
||||
temperature_ptr = (struct temperature *) PHRQ_malloc(sizeof (struct temperature));
|
||||
if (temperature_ptr == NULL) malloc_error();
|
||||
struct temperature *temperature_ptr;
|
||||
temperature_ptr =
|
||||
(struct temperature *) PHRQ_malloc(sizeof(struct temperature));
|
||||
if (temperature_ptr == NULL)
|
||||
malloc_error();
|
||||
|
||||
temperature_ptr->description = this->get_description();
|
||||
temperature_ptr->n_user = this->n_user;
|
||||
temperature_ptr->n_user_end = this->n_user_end;
|
||||
temperature_ptr->description = this->get_description();
|
||||
temperature_ptr->n_user = this->n_user;
|
||||
temperature_ptr->n_user_end = this->n_user_end;
|
||||
|
||||
// temps
|
||||
temperature_ptr->t = NULL;
|
||||
if (this->temps.size() > 0) {
|
||||
temperature_ptr->t = (double *) PHRQ_malloc((size_t) (this->temps.size() * sizeof(double)));
|
||||
if (temperature_ptr->t == NULL) malloc_error();
|
||||
std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t);
|
||||
}
|
||||
if (this->equalIncrements) {
|
||||
temperature_ptr->count_t = - (int) this->countTemps;
|
||||
} else {
|
||||
temperature_ptr->count_t = (int) this->temps.size();
|
||||
if (this->temps.size() > 0)
|
||||
{
|
||||
temperature_ptr->t =
|
||||
(double *)
|
||||
PHRQ_malloc((size_t) (this->temps.size() * sizeof(double)));
|
||||
if (temperature_ptr->t == NULL)
|
||||
malloc_error();
|
||||
std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t);
|
||||
}
|
||||
return(temperature_ptr);
|
||||
if (this->equalIncrements)
|
||||
{
|
||||
temperature_ptr->count_t = -(int) this->countTemps;
|
||||
}
|
||||
else
|
||||
{
|
||||
temperature_ptr->count_t = (int) this->temps.size();
|
||||
}
|
||||
return (temperature_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxTemperature::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Temperature element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<temperature " << std::endl;
|
||||
// Temperature element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<temperature " << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_temperature_gammas=\"" << this->pitzer_temperature_gammas << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_temperature_gammas=\"" << this->
|
||||
pitzer_temperature_gammas << "\"" << std::endl;
|
||||
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list<cxxTemperatureComp>::const_iterator it = temperatureComps.begin(); it != temperatureComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list < cxxTemperatureComp >::const_iterator it =
|
||||
temperatureComps.begin(); it != temperatureComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxTemperature::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Temperature element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "REACTION_TEMPERATURE_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
// Temperature element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "REACTION_TEMPERATURE_RAW " << this->
|
||||
n_user << " " << this->description << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-temps " << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent2;
|
||||
for (std::vector<double>::const_iterator it = this->temps.begin(); it != this->temps.end(); it++) {
|
||||
if (i++ == 5) {
|
||||
s_oss << std::endl;
|
||||
s_oss << indent2;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
s_oss << indent1;
|
||||
s_oss << "-temps " << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent2;
|
||||
for (std::vector < double >::const_iterator it = this->temps.begin();
|
||||
it != this->temps.end(); it++)
|
||||
{
|
||||
if (i++ == 5)
|
||||
{
|
||||
s_oss << std::endl;
|
||||
s_oss << indent2;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-equal_increments " << this->equalIncrements << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-equal_increments " << this->equalIncrements << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-count_temps " << this->countTemps << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-count_temps " << this->countTemps << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void cxxTemperature::read_raw(CParser& parser)
|
||||
void
|
||||
cxxTemperature::read_raw(CParser & parser)
|
||||
{
|
||||
|
||||
double d;
|
||||
double d;
|
||||
CParser::TOKEN_TYPE k;
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("temps"); //0
|
||||
vopts.push_back("equal_increments"); //1
|
||||
vopts.push_back("count_temps"); //2
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("temps"); //0
|
||||
vopts.push_back("equal_increments"); //1
|
||||
vopts.push_back("count_temps"); //2
|
||||
}
|
||||
|
||||
// Read temperature number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool equalIncrements_defined(false);
|
||||
bool countTemps_defined(false);
|
||||
// Read temperature number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in TEMPERATURE_COMP_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool equalIncrements_defined(false);
|
||||
bool countTemps_defined(false);
|
||||
|
||||
case 0: // temps
|
||||
while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) {
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in TEMPERATURE_COMP_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 0: // temps
|
||||
while ((k =
|
||||
parser.copy_token(token, next_char)) == CParser::TT_DIGIT)
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
if (!(iss >> d)) {
|
||||
if (!(iss >> d))
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for temps.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
parser.error_msg("Expected numeric value for temps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->temps.push_back(d);
|
||||
}
|
||||
}
|
||||
opt_save = 0;
|
||||
useLastLine = false;
|
||||
break;
|
||||
}
|
||||
opt_save = 0;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 1: // equal_increments
|
||||
if (!(parser.get_iss() >> this->equalIncrements))
|
||||
{
|
||||
this->equalIncrements = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
equalIncrements_defined = true;
|
||||
break;
|
||||
case 1: // equal_increments
|
||||
if (!(parser.get_iss() >> this->equalIncrements))
|
||||
{
|
||||
this->equalIncrements = 0;
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg("Expected boolean value for equalIncrements.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
equalIncrements_defined = true;
|
||||
break;
|
||||
|
||||
case 2: // countTemps
|
||||
if (!(parser.get_iss() >> this->countTemps))
|
||||
{
|
||||
this->countTemps = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for countTemps.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
countTemps_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (equalIncrements_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (countTemps_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
case 2: // countTemps
|
||||
if (!(parser.get_iss() >> this->countTemps))
|
||||
{
|
||||
this->countTemps = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for countTemps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
countTemps_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (equalIncrements_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (countTemps_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Count_temps not defined for REACTION_TEMPERATURE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
97
Utils.cxx
97
Utils.cxx
@ -1,79 +1,94 @@
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
#include <stdlib.h> // ::tolower
|
||||
#include <ctype.h> // ::tolower
|
||||
#include <algorithm> //std::transform
|
||||
#include <iostream> // std::cout std::cerr
|
||||
#include <stdlib.h> // ::tolower
|
||||
#include <ctype.h> // ::tolower
|
||||
#include <algorithm> //std::transform
|
||||
#include <iostream> // std::cout std::cerr
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Parser.h"
|
||||
#include "output.h"
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
int Utilities::strcmp_nocase_arg1(const char *str1, const char *str2)
|
||||
int
|
||||
Utilities::strcmp_nocase_arg1(const char *str1, const char *str2)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
//
|
||||
// Compare two strings disregarding case
|
||||
//
|
||||
int c1, c2;
|
||||
while ((c1 = ::tolower(*str1++)) == (c2 = *str2++)) {
|
||||
if (c1 == '\0') return(0);
|
||||
}
|
||||
if (c1 < c2) return(-1);
|
||||
return(1);
|
||||
//
|
||||
// Compare two strings disregarding case
|
||||
//
|
||||
int c1, c2;
|
||||
while ((c1 =::tolower(*str1++)) == (c2 = *str2++))
|
||||
{
|
||||
if (c1 == '\0')
|
||||
return (0);
|
||||
}
|
||||
if (c1 < c2)
|
||||
return (-1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
int Utilities::strcmp_nocase(const char *str1, const char *str2)
|
||||
int
|
||||
Utilities::strcmp_nocase(const char *str1, const char *str2)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
//
|
||||
// Compare two strings disregarding case
|
||||
//
|
||||
int c1, c2;
|
||||
while ((c1 = ::tolower(*str1++)) == (c2 = ::tolower(*str2++))) {
|
||||
if (c1 == '\0') return(0);
|
||||
}
|
||||
if (c1 < c2) return(-1);
|
||||
return(1);
|
||||
//
|
||||
// Compare two strings disregarding case
|
||||
//
|
||||
int c1, c2;
|
||||
while ((c1 =::tolower(*str1++)) == (c2 =::tolower(*str2++)))
|
||||
{
|
||||
if (c1 == '\0')
|
||||
return (0);
|
||||
}
|
||||
if (c1 < c2)
|
||||
return (-1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void Utilities::str_tolower(std::string& str)
|
||||
void
|
||||
Utilities::str_tolower(std::string & str)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
std::transform(str.begin(), str.end(), str.begin(), tolower);
|
||||
std::transform(str.begin(), str.end(), str.begin(), tolower);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
bool Utilities::replace(const char* str1, const char* str2, std::string& str)
|
||||
bool
|
||||
Utilities::replace(const char *str1, const char *str2, std::string & str)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
std::string::size_type n = str.find(str1, 0);
|
||||
if (n == std::string::npos) return false;
|
||||
std::string::size_type n = str.find(str1, 0);
|
||||
if (n == std::string::npos)
|
||||
return false;
|
||||
|
||||
str.replace(n, ::strlen(str1), str2);
|
||||
return true;
|
||||
str.replace(n,::strlen(str1), str2);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void Utilities::squeeze_white(std::string& s_l)
|
||||
void
|
||||
Utilities::squeeze_white(std::string & s_l)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
std::string str;
|
||||
std::string::iterator beg = s_l.begin();
|
||||
std::string::iterator end = s_l.end();
|
||||
CParser::copy_token(str, beg, end);
|
||||
s_l = str;
|
||||
std::string str;
|
||||
std::string::iterator beg = s_l.begin();
|
||||
std::string::iterator end = s_l.end();
|
||||
CParser::copy_token(str, beg, end);
|
||||
s_l = str;
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void Utilities::error_msg (const std::string& err_str, const int stop)
|
||||
void
|
||||
Utilities::error_msg(const std::string & err_str, const int stop)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
//std::cerr << err_str << std::endl;
|
||||
output_message(OUTPUT_ERROR, err_str, stop, "", args);
|
||||
//std::cerr << err_str << std::endl;
|
||||
output_message(OUTPUT_ERROR, err_str, stop, "", args);
|
||||
}
|
||||
#endif
|
||||
|
||||
840
cxxKinetics.cxx
840
cxxKinetics.cxx
@ -2,433 +2,504 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "cxxKinetics.h"
|
||||
#include "KineticsComp.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxKinetics::cxxKinetics()
|
||||
//
|
||||
// default constructor for cxxKinetics
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxKinetics
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
step_divide = 1.0;
|
||||
rk = 3;
|
||||
bad_step_max = 500;
|
||||
use_cvode = false;
|
||||
cvode_steps = 100;
|
||||
cvode_order = 5;
|
||||
totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
step_divide = 1.0;
|
||||
rk = 3;
|
||||
bad_step_max = 500;
|
||||
use_cvode = false;
|
||||
cvode_steps = 100;
|
||||
cvode_order = 5;
|
||||
totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr)
|
||||
//
|
||||
// constructor for cxxKinetics from struct kinetics
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxKinetics from struct kinetics
|
||||
//
|
||||
:
|
||||
cxxNumKeyword(),
|
||||
totals(kinetics_ptr->totals)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
this->set_description(kinetics_ptr->description);
|
||||
n_user = kinetics_ptr->n_user;
|
||||
n_user_end = kinetics_ptr->n_user_end;
|
||||
step_divide = kinetics_ptr->step_divide;
|
||||
rk = kinetics_ptr->rk;
|
||||
bad_step_max = kinetics_ptr->bad_step_max;
|
||||
use_cvode = (kinetics_ptr->use_cvode == TRUE);
|
||||
cvode_steps = kinetics_ptr->cvode_steps;
|
||||
cvode_order = kinetics_ptr->cvode_order;
|
||||
this->set_description(kinetics_ptr->description);
|
||||
n_user = kinetics_ptr->n_user;
|
||||
n_user_end = kinetics_ptr->n_user_end;
|
||||
step_divide = kinetics_ptr->step_divide;
|
||||
rk = kinetics_ptr->rk;
|
||||
bad_step_max = kinetics_ptr->bad_step_max;
|
||||
use_cvode = (kinetics_ptr->use_cvode == TRUE);
|
||||
cvode_steps = kinetics_ptr->cvode_steps;
|
||||
cvode_order = kinetics_ptr->cvode_order;
|
||||
|
||||
// kinetics components
|
||||
for (i = 0; i < kinetics_ptr->count_comps; i++) {
|
||||
cxxKineticsComp ec(&(kinetics_ptr->comps[i]));
|
||||
this->kineticsComps.push_back(ec);
|
||||
}
|
||||
// kinetics components
|
||||
for (i = 0; i < kinetics_ptr->count_comps; i++)
|
||||
{
|
||||
cxxKineticsComp ec(&(kinetics_ptr->comps[i]));
|
||||
this->kineticsComps.push_back(ec);
|
||||
}
|
||||
|
||||
// steps
|
||||
for (i = 0; i < kinetics_ptr->count_steps; i++) {
|
||||
this->steps.push_back(kinetics_ptr->steps[i]);
|
||||
}
|
||||
// steps
|
||||
for (i = 0; i < kinetics_ptr->count_steps; i++)
|
||||
{
|
||||
this->steps.push_back(kinetics_ptr->steps[i]);
|
||||
}
|
||||
}
|
||||
cxxKinetics::cxxKinetics(const std::map<int, cxxKinetics> &entities, cxxMix &mix, int n_user)
|
||||
:
|
||||
cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities,
|
||||
cxxMix & mix, int n_user):
|
||||
cxxNumKeyword()
|
||||
{
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
step_divide = 1.0;
|
||||
rk = 3;
|
||||
bad_step_max = 500;
|
||||
use_cvode = false;
|
||||
cvode_steps = 100;
|
||||
cvode_order = 5;
|
||||
totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
this->n_user = this->n_user_end = n_user;
|
||||
step_divide = 1.0;
|
||||
rk = 3;
|
||||
bad_step_max = 500;
|
||||
use_cvode = false;
|
||||
cvode_steps = 100;
|
||||
cvode_order = 5;
|
||||
totals.type = cxxNameDouble::ND_ELT_MOLES;
|
||||
//
|
||||
// Mix
|
||||
//
|
||||
std::map<int, double> *mixcomps = mix.comps();
|
||||
std::map<int, double>::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxKinetics *entity_ptr = &(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
}
|
||||
}
|
||||
std::map < int, double >*mixcomps = mix.comps();
|
||||
std::map < int, double >::const_iterator it;
|
||||
for (it = mixcomps->begin(); it != mixcomps->end(); it++)
|
||||
{
|
||||
if (entities.find(it->first) != entities.end())
|
||||
{
|
||||
const cxxKinetics *entity_ptr =
|
||||
&(entities.find(it->first)->second);
|
||||
this->add(*entity_ptr, it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxKinetics::~cxxKinetics()
|
||||
{
|
||||
}
|
||||
|
||||
struct kinetics *cxxKinetics::cxxKinetics2kinetics()
|
||||
//
|
||||
// Builds a kinetics structure from instance of cxxKinetics
|
||||
//
|
||||
struct kinetics *
|
||||
cxxKinetics::cxxKinetics2kinetics()
|
||||
//
|
||||
// Builds a kinetics structure from instance of cxxKinetics
|
||||
//
|
||||
{
|
||||
struct kinetics *kinetics_ptr = kinetics_alloc();
|
||||
|
||||
kinetics_ptr->description = this->get_description();
|
||||
kinetics_ptr->n_user = this->n_user;
|
||||
kinetics_ptr->n_user_end = this->n_user_end;
|
||||
kinetics_ptr->step_divide = this->step_divide;
|
||||
kinetics_ptr->rk = this->rk;
|
||||
kinetics_ptr->bad_step_max = this->bad_step_max;
|
||||
kinetics_ptr->use_cvode = (int) this->use_cvode;
|
||||
kinetics_ptr->cvode_steps = this->cvode_steps;
|
||||
kinetics_ptr->cvode_order = this->cvode_order;
|
||||
struct kinetics *kinetics_ptr = kinetics_alloc();
|
||||
|
||||
// totals
|
||||
kinetics_ptr->totals = this->totals.elt_list();
|
||||
kinetics_ptr->description = this->get_description();
|
||||
kinetics_ptr->n_user = this->n_user;
|
||||
kinetics_ptr->n_user_end = this->n_user_end;
|
||||
kinetics_ptr->step_divide = this->step_divide;
|
||||
kinetics_ptr->rk = this->rk;
|
||||
kinetics_ptr->bad_step_max = this->bad_step_max;
|
||||
kinetics_ptr->use_cvode = (int) this->use_cvode;
|
||||
kinetics_ptr->cvode_steps = this->cvode_steps;
|
||||
kinetics_ptr->cvode_order = this->cvode_order;
|
||||
|
||||
// comps
|
||||
kinetics_ptr->count_comps = (int) this->kineticsComps.size();
|
||||
kinetics_ptr->comps = (struct kinetics_comp *) free_check_null(kinetics_ptr->comps);
|
||||
kinetics_ptr->comps = cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps);
|
||||
// totals
|
||||
kinetics_ptr->totals = this->totals.elt_list();
|
||||
|
||||
// steps
|
||||
kinetics_ptr->count_steps = (int) this->steps.size();
|
||||
kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps);
|
||||
if (this->steps.size() > 0) {
|
||||
kinetics_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double)));
|
||||
if (kinetics_ptr->steps == NULL) malloc_error();
|
||||
std::copy(this->steps.begin(), this->steps.end(), kinetics_ptr->steps);
|
||||
/*
|
||||
int i = 0;
|
||||
for (std::vector<double>::iterator it = this->steps.begin(); it != this->steps.end(); it++) {
|
||||
kinetics_ptr->steps[i] = *it;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return(kinetics_ptr);
|
||||
// comps
|
||||
kinetics_ptr->count_comps = (int) this->kineticsComps.size();
|
||||
kinetics_ptr->comps =
|
||||
(struct kinetics_comp *) free_check_null(kinetics_ptr->comps);
|
||||
kinetics_ptr->comps =
|
||||
cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps);
|
||||
|
||||
// steps
|
||||
kinetics_ptr->count_steps = (int) this->steps.size();
|
||||
kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps);
|
||||
if (this->steps.size() > 0)
|
||||
{
|
||||
kinetics_ptr->steps =
|
||||
(double *)
|
||||
PHRQ_malloc((size_t) (this->steps.size() * sizeof(double)));
|
||||
if (kinetics_ptr->steps == NULL)
|
||||
malloc_error();
|
||||
std::copy(this->steps.begin(), this->steps.end(),
|
||||
kinetics_ptr->steps);
|
||||
/*
|
||||
int i = 0;
|
||||
for (std::vector<double>::iterator it = this->steps.begin(); it != this->steps.end(); it++) {
|
||||
kinetics_ptr->steps[i] = *it;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return (kinetics_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxKinetics::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Kinetics element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<kinetics " << std::endl;
|
||||
// Kinetics element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<kinetics " << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_kinetics_gammas=\"" << this->pitzer_kinetics_gammas << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_kinetics_gammas=\"" << this->
|
||||
pitzer_kinetics_gammas << "\"" << std::endl;
|
||||
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list<cxxKineticsComp>::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list < cxxKineticsComp >::const_iterator it =
|
||||
kineticsComps.begin(); it != kineticsComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxKinetics::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Kinetics element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "KINETICS_RAW " << this->n_user << " " << this->description << std::endl;
|
||||
// Kinetics element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "KINETICS_RAW " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-step_divide " << this->step_divide << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-step_divide " << this->step_divide << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-rk " << this->rk << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-rk " << this->rk << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-bad_step_max " << this->bad_step_max << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-bad_step_max " << this->bad_step_max << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-use_cvode " << this->use_cvode << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-use_cvode " << this->use_cvode << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-cvode_steps " << this->cvode_steps << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-cvode_steps " << this->cvode_steps << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "-cvode_order " << this->cvode_order << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "-cvode_order " << this->cvode_order << std::endl;
|
||||
|
||||
// kineticsComps structures
|
||||
for (std::list<cxxKineticsComp>::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) {
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
for (std::list < cxxKineticsComp >::const_iterator it =
|
||||
kineticsComps.begin(); it != kineticsComps.end(); ++it)
|
||||
{
|
||||
s_oss << indent1;
|
||||
s_oss << "-component" << std::endl;
|
||||
it->dump_raw(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
// totals
|
||||
s_oss << indent1;
|
||||
s_oss << "-totals " << std::endl;
|
||||
this->totals.dump_raw(s_oss, indent + 2);
|
||||
// totals
|
||||
s_oss << indent1;
|
||||
s_oss << "-totals " << std::endl;
|
||||
this->totals.dump_raw(s_oss, indent + 2);
|
||||
|
||||
// steps
|
||||
s_oss << indent1;
|
||||
s_oss << "-steps " << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent2;
|
||||
for (std::vector<double>::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) {
|
||||
if (i++ == 5) {
|
||||
s_oss << std::endl;
|
||||
s_oss << indent2;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
return;
|
||||
// steps
|
||||
s_oss << indent1;
|
||||
s_oss << "-steps " << std::endl;
|
||||
{
|
||||
int i = 0;
|
||||
s_oss << indent2;
|
||||
for (std::vector < double >::const_iterator it = this->steps.begin();
|
||||
it != this->steps.end(); it++)
|
||||
{
|
||||
if (i++ == 5)
|
||||
{
|
||||
s_oss << std::endl;
|
||||
s_oss << indent2;
|
||||
i = 0;
|
||||
}
|
||||
s_oss << *it << " ";
|
||||
}
|
||||
s_oss << std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cxxKinetics::read_raw(CParser& parser)
|
||||
void
|
||||
cxxKinetics::read_raw(CParser & parser)
|
||||
{
|
||||
|
||||
double d;
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("step_divide");
|
||||
vopts.push_back("rk");
|
||||
vopts.push_back("bad_step_max");
|
||||
vopts.push_back("use_cvode");
|
||||
vopts.push_back("component");
|
||||
vopts.push_back("totals");
|
||||
vopts.push_back("steps");
|
||||
vopts.push_back("cvode_steps");
|
||||
vopts.push_back("cvode_order");
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
double d;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
vopts.push_back("step_divide");
|
||||
vopts.push_back("rk");
|
||||
vopts.push_back("bad_step_max");
|
||||
vopts.push_back("use_cvode");
|
||||
vopts.push_back("component");
|
||||
vopts.push_back("totals");
|
||||
vopts.push_back("steps");
|
||||
vopts.push_back("cvode_steps");
|
||||
vopts.push_back("cvode_order");
|
||||
}
|
||||
|
||||
// Read kinetics number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool step_divide_defined(false);
|
||||
bool rk_defined(false);
|
||||
bool bad_step_max_defined(false);
|
||||
bool use_cvode_defined(false);
|
||||
bool cvode_steps_defined(false);
|
||||
bool cvode_order_defined(false);
|
||||
// Read kinetics number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in KINETICS_COMP_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool step_divide_defined(false);
|
||||
bool rk_defined(false);
|
||||
bool bad_step_max_defined(false);
|
||||
bool use_cvode_defined(false);
|
||||
bool cvode_steps_defined(false);
|
||||
bool cvode_order_defined(false);
|
||||
|
||||
case 0: // step_divide
|
||||
if (!(parser.get_iss() >> this->step_divide))
|
||||
{
|
||||
this->step_divide = 1.0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for step_divide.", CParser::OT_CONTINUE);
|
||||
}
|
||||
step_divide_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 1: // rk
|
||||
if (!(parser.get_iss() >> this->rk))
|
||||
{
|
||||
this->rk = 3;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for rk.", CParser::OT_CONTINUE);
|
||||
}
|
||||
rk_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 2: // bad_step_max
|
||||
if (!(parser.get_iss() >> this->bad_step_max))
|
||||
{
|
||||
this->bad_step_max = 500;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for bad_step_max.", CParser::OT_CONTINUE);
|
||||
}
|
||||
bad_step_max_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 3: // use_cvode
|
||||
if (!(parser.get_iss() >> this->use_cvode))
|
||||
{
|
||||
this->use_cvode = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for use_cvode.", CParser::OT_CONTINUE);
|
||||
}
|
||||
use_cvode_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 4: // component
|
||||
{
|
||||
cxxKineticsComp kc;
|
||||
kc.read_raw(parser);
|
||||
this->kineticsComps.push_back(kc);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
|
||||
case 5: // totals
|
||||
if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected element name and molality for KineticsComp totals.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 5;
|
||||
useLastLine = false;
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in KINETICS_COMP_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 6: // steps
|
||||
while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) {
|
||||
//sscanf(token.c_str(), "%lf", &d);
|
||||
//this->steps.push_back(d);
|
||||
case 0: // step_divide
|
||||
if (!(parser.get_iss() >> this->step_divide))
|
||||
{
|
||||
this->step_divide = 1.0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for step_divide.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
step_divide_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 1: // rk
|
||||
if (!(parser.get_iss() >> this->rk))
|
||||
{
|
||||
this->rk = 3;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for rk.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
rk_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 2: // bad_step_max
|
||||
if (!(parser.get_iss() >> this->bad_step_max))
|
||||
{
|
||||
this->bad_step_max = 500;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for bad_step_max.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
bad_step_max_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 3: // use_cvode
|
||||
if (!(parser.get_iss() >> this->use_cvode))
|
||||
{
|
||||
this->use_cvode = false;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for use_cvode.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
use_cvode_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 4: // component
|
||||
{
|
||||
cxxKineticsComp kc;
|
||||
kc.read_raw(parser);
|
||||
this->kineticsComps.push_back(kc);
|
||||
}
|
||||
useLastLine = true;
|
||||
break;
|
||||
|
||||
case 5: // totals
|
||||
if (this->totals.read_raw(parser, next_char) !=
|
||||
CParser::PARSER_OK)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected element name and molality for KineticsComp totals.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = 5;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 6: // steps
|
||||
while (parser.copy_token(token, next_char) == CParser::TT_DIGIT)
|
||||
{
|
||||
//sscanf(token.c_str(), "%lf", &d);
|
||||
//this->steps.push_back(d);
|
||||
std::istringstream iss(token);
|
||||
if (!(iss >> d)) {
|
||||
if (!(iss >> d))
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for steps.", CParser::OT_CONTINUE);
|
||||
} else {
|
||||
parser.error_msg("Expected numeric value for steps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->steps.push_back(d);
|
||||
}
|
||||
}
|
||||
opt_save = 6;
|
||||
useLastLine = false;
|
||||
}
|
||||
opt_save = 6;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 7: // cvode_steps
|
||||
if (!(parser.get_iss() >> this->cvode_steps))
|
||||
{
|
||||
this->cvode_steps = 100;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for cvode_steps.", CParser::OT_CONTINUE);
|
||||
}
|
||||
cvode_steps_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 7: // cvode_steps
|
||||
if (!(parser.get_iss() >> this->cvode_steps))
|
||||
{
|
||||
this->cvode_steps = 100;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for cvode_steps.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
cvode_steps_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 8: // cvode_order
|
||||
if (!(parser.get_iss() >> this->cvode_order))
|
||||
{
|
||||
this->cvode_order = 5;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for cvode_order.", CParser::OT_CONTINUE);
|
||||
}
|
||||
cvode_order_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
case 8: // cvode_order
|
||||
if (!(parser.get_iss() >> this->cvode_order))
|
||||
{
|
||||
this->cvode_order = 5;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for cvode_order.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
cvode_order_defined = true;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (step_divide_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Step_divide not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (rk_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Rk not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (bad_step_max_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (use_cvode_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (cvode_steps_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
if (cvode_order_defined == false) {
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (step_divide_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Step_divide not defined for KINETICS_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (rk_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Rk not defined for KINETICS_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (bad_step_max_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (use_cvode_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Use_cvode not defined for KINETICS_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (cvode_steps_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (cvode_order_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Cvode_order not defined for KINETICS_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MPI
|
||||
void cxxKinetics::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
void
|
||||
cxxKinetics::mpi_pack(std::vector < int >&ints,
|
||||
std::vector < double >&doubles)
|
||||
{
|
||||
ints.push_back(this->n_user);
|
||||
ints.push_back((int) this->kineticsComps.size());
|
||||
for (std::list<cxxKineticsComp>::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) {
|
||||
for (std::list < cxxKineticsComp >::iterator it =
|
||||
this->kineticsComps.begin(); it != this->kineticsComps.end(); it++)
|
||||
{
|
||||
it->mpi_pack(ints, doubles);
|
||||
}
|
||||
ints.push_back((int) this->steps.size());
|
||||
for (std::vector<double>::iterator it = this->steps.begin(); it != this->steps.end(); it++) {
|
||||
for (std::vector < double >::iterator it = this->steps.begin();
|
||||
it != this->steps.end(); it++)
|
||||
{
|
||||
doubles.push_back(*it);
|
||||
}
|
||||
doubles.push_back(this->step_divide);
|
||||
@ -438,7 +509,9 @@ void cxxKinetics::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
|
||||
ints.push_back(this->cvode_steps);
|
||||
ints.push_back(this->cvode_order);
|
||||
}
|
||||
void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
void
|
||||
cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
{
|
||||
int i = *ii;
|
||||
int d = *dd;
|
||||
@ -448,14 +521,16 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
|
||||
int n = ints[i++];
|
||||
this->kineticsComps.clear();
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cxxKineticsComp kc;
|
||||
kc.mpi_unpack(ints, &i, doubles, &d);
|
||||
this->kineticsComps.push_back(kc);
|
||||
}
|
||||
n = ints[i++];
|
||||
this->steps.clear();
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
this->steps.push_back(doubles[d++]);
|
||||
}
|
||||
this->step_divide = doubles[d++];
|
||||
@ -468,42 +543,49 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
|
||||
*dd = d;
|
||||
}
|
||||
#endif
|
||||
void cxxKinetics::add(const cxxKinetics &addee, double extensive)
|
||||
//
|
||||
// Add to existing ppassemblage to "this" ppassemblage
|
||||
//
|
||||
void
|
||||
cxxKinetics::add(const cxxKinetics & addee, double extensive)
|
||||
//
|
||||
// Add to existing ppassemblage to "this" ppassemblage
|
||||
//
|
||||
{
|
||||
if (extensive == 0.0) return;
|
||||
//std::list<cxxKineticsComp> kineticsComps;
|
||||
for (std::list<cxxKineticsComp>::const_iterator itadd = addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); ++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list<cxxKineticsComp>::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); ++it)
|
||||
{
|
||||
if (it->get_rate_name() == itadd->get_rate_name())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
cxxKineticsComp entity = *itadd;
|
||||
entity.multiply(extensive);
|
||||
this->kineticsComps.push_back(entity);
|
||||
}
|
||||
}
|
||||
//std::vector<double> steps;
|
||||
this->steps = addee.steps;
|
||||
//cxxNameDouble totals;
|
||||
//double step_divide;
|
||||
this->step_divide = addee.step_divide;
|
||||
//int rk;
|
||||
this->rk = addee.rk;
|
||||
//int bad_step_max;
|
||||
this->bad_step_max = addee.bad_step_max;
|
||||
//bool use_cvode;
|
||||
this->use_cvode = addee.use_cvode;
|
||||
this->cvode_steps = addee.cvode_steps;
|
||||
this->cvode_order = addee.cvode_order;
|
||||
if (extensive == 0.0)
|
||||
return;
|
||||
//std::list<cxxKineticsComp> kineticsComps;
|
||||
for (std::list < cxxKineticsComp >::const_iterator itadd =
|
||||
addee.kineticsComps.begin(); itadd != addee.kineticsComps.end();
|
||||
++itadd)
|
||||
{
|
||||
bool found = false;
|
||||
for (std::list < cxxKineticsComp >::iterator it =
|
||||
this->kineticsComps.begin(); it != this->kineticsComps.end();
|
||||
++it)
|
||||
{
|
||||
if (it->get_rate_name() == itadd->get_rate_name())
|
||||
{
|
||||
it->add((*itadd), extensive);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
cxxKineticsComp entity = *itadd;
|
||||
entity.multiply(extensive);
|
||||
this->kineticsComps.push_back(entity);
|
||||
}
|
||||
}
|
||||
//std::vector<double> steps;
|
||||
this->steps = addee.steps;
|
||||
//cxxNameDouble totals;
|
||||
//double step_divide;
|
||||
this->step_divide = addee.step_divide;
|
||||
//int rk;
|
||||
this->rk = addee.rk;
|
||||
//int bad_step_max;
|
||||
this->bad_step_max = addee.bad_step_max;
|
||||
//bool use_cvode;
|
||||
this->use_cvode = addee.use_cvode;
|
||||
this->cvode_steps = addee.cvode_steps;
|
||||
this->cvode_order = addee.cvode_order;
|
||||
}
|
||||
|
||||
288
cxxMix.cxx
288
cxxMix.cxx
@ -2,48 +2,51 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#ifdef _DEBUG
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
|
||||
#endif
|
||||
|
||||
#include "Utils.h" // define first
|
||||
#include "Utils.h" // define first
|
||||
#include "cxxMix.h"
|
||||
#define EXTERNAL extern
|
||||
#include "global.h"
|
||||
#include "phqalloc.h"
|
||||
#include "phrqproto.h"
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
#include <cassert> // assert
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
cxxMix::cxxMix()
|
||||
//
|
||||
// default constructor for cxxMix
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
//
|
||||
// default constructor for cxxMix
|
||||
//
|
||||
: cxxNumKeyword()
|
||||
{
|
||||
}
|
||||
|
||||
cxxMix::cxxMix(struct mix *mix_ptr)
|
||||
//
|
||||
// constructor for cxxMix from struct mix
|
||||
//
|
||||
:
|
||||
//
|
||||
// constructor for cxxMix from struct mix
|
||||
//
|
||||
:
|
||||
cxxNumKeyword()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
this->set_description(mix_ptr->description);
|
||||
this->n_user = mix_ptr->n_user;
|
||||
this->n_user_end = mix_ptr->n_user_end;
|
||||
this->set_description(mix_ptr->description);
|
||||
this->n_user = mix_ptr->n_user;
|
||||
this->n_user_end = mix_ptr->n_user_end;
|
||||
// comps
|
||||
if (mix_ptr->count_comps > 0) {
|
||||
for (i = 0; i < mix_ptr->count_comps; i++) {
|
||||
this->mixComps[mix_ptr->comps[i].n_solution] = mix_ptr->comps[i].fraction;
|
||||
if (mix_ptr->count_comps > 0)
|
||||
{
|
||||
for (i = 0; i < mix_ptr->count_comps; i++)
|
||||
{
|
||||
this->mixComps[mix_ptr->comps[i].n_solution] =
|
||||
mix_ptr->comps[i].fraction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cxxMix::~cxxMix()
|
||||
@ -51,150 +54,187 @@ cxxMix::~cxxMix()
|
||||
}
|
||||
|
||||
|
||||
struct mix *cxxMix::cxxMix2mix()
|
||||
//
|
||||
// Builds a mix structure from instance of cxxMix
|
||||
//
|
||||
struct mix *
|
||||
cxxMix::cxxMix2mix()
|
||||
//
|
||||
// Builds a mix structure from instance of cxxMix
|
||||
//
|
||||
{
|
||||
struct mix *mix_ptr;
|
||||
mix_ptr = (struct mix *) PHRQ_malloc(sizeof (struct mix));
|
||||
if (mix_ptr == NULL) malloc_error();
|
||||
struct mix *mix_ptr;
|
||||
mix_ptr = (struct mix *) PHRQ_malloc(sizeof(struct mix));
|
||||
if (mix_ptr == NULL)
|
||||
malloc_error();
|
||||
|
||||
mix_ptr->description = this->get_description();
|
||||
mix_ptr->n_user = this->n_user;
|
||||
mix_ptr->n_user_end = this->n_user_end;
|
||||
mix_ptr->description = this->get_description();
|
||||
mix_ptr->n_user = this->n_user;
|
||||
mix_ptr->n_user_end = this->n_user_end;
|
||||
|
||||
// comps
|
||||
mix_ptr->comps = NULL;
|
||||
if (this->mixComps.size() > 0) {
|
||||
if (this->mixComps.size() > 0)
|
||||
{
|
||||
int i = 0;
|
||||
mix_ptr->comps = (struct mix_comp *) PHRQ_malloc((size_t) (this->mixComps.size() * sizeof(struct mix_comp)));
|
||||
if (mix_ptr->comps == NULL) malloc_error();
|
||||
for (std::map<int, double>::iterator it = mixComps.begin(); it != mixComps.end(); it++) {
|
||||
mix_ptr->comps =
|
||||
(struct mix_comp *)
|
||||
PHRQ_malloc((size_t)
|
||||
(this->mixComps.size() * sizeof(struct mix_comp)));
|
||||
if (mix_ptr->comps == NULL)
|
||||
malloc_error();
|
||||
for (std::map < int, double >::iterator it = mixComps.begin();
|
||||
it != mixComps.end(); it++)
|
||||
{
|
||||
mix_ptr->comps[i].n_solution = it->first;
|
||||
mix_ptr->comps[i].fraction = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
mix_ptr->count_comps = (int) this->mixComps.size();
|
||||
return(mix_ptr);
|
||||
return (mix_ptr);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
void cxxMix::dump_xml(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Mix element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<mix " << std::endl;
|
||||
// Mix element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "<mix " << std::endl;
|
||||
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_mix_gammas=\"" << this->pitzer_mix_gammas << "\"" << std::endl;
|
||||
s_oss << indent1;
|
||||
s_oss << "pitzer_mix_gammas=\"" << this->
|
||||
pitzer_mix_gammas << "\"" << std::endl;
|
||||
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list<cxxMixComp>::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) {
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
// components
|
||||
s_oss << indent1;
|
||||
s_oss << "<component " << std::endl;
|
||||
for (std::list < cxxMixComp >::const_iterator it = mixComps.begin();
|
||||
it != mixComps.end(); ++it)
|
||||
{
|
||||
it->dump_xml(s_oss, indent + 2);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cxxMix::dump_raw(std::ostream& s_oss, unsigned int indent)const
|
||||
void
|
||||
cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent) const const
|
||||
{
|
||||
//const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT);
|
||||
for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT);
|
||||
//const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n";
|
||||
unsigned int i;
|
||||
s_oss.precision(DBL_DIG - 1);
|
||||
std::string indent0(""), indent1(""), indent2("");
|
||||
for (i = 0; i < indent; ++i)
|
||||
indent0.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 1; ++i)
|
||||
indent1.append(Utilities::INDENT);
|
||||
for (i = 0; i < indent + 2; ++i)
|
||||
indent2.append(Utilities::INDENT);
|
||||
|
||||
// Mix element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "MIX " << this->n_user << " " << this->description << std::endl;
|
||||
// Mix element and attributes
|
||||
s_oss << indent0;
|
||||
s_oss << "MIX " << this->n_user << " " << this->
|
||||
description << std::endl;
|
||||
|
||||
for (std::map<int, double>::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) {
|
||||
for (std::map < int, double >::const_iterator it = this->mixComps.begin();
|
||||
it != this->mixComps.end(); it++)
|
||||
{
|
||||
s_oss << indent1 << it->first << " " << it->second << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void cxxMix::read_raw(CParser& parser)
|
||||
void
|
||||
cxxMix::read_raw(CParser & parser)
|
||||
{
|
||||
|
||||
int i;
|
||||
double d;
|
||||
static std::vector<std::string> vopts;
|
||||
if (vopts.empty()) {
|
||||
vopts.reserve(15);
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
double d;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(15);
|
||||
}
|
||||
|
||||
// Read mix number and description
|
||||
this->read_number_description(parser);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
// Read mix number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false) {
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
} else {
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in MIX_COMP_RAW keyword.", CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
|
||||
case CParser::OPT_DEFAULT: // solution number, mix fraction
|
||||
if (parser.copy_token(token, next_char) != CParser::TT_EMPTY) {
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in MIX_COMP_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case CParser::OPT_DEFAULT: // solution number, mix fraction
|
||||
if (parser.copy_token(token, next_char) != CParser::TT_EMPTY)
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
if (!(iss >> i))
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for solution number.", CParser::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected integer value for solution number.",
|
||||
CParser::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
if (!(parser.get_iss() >> d))
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for solution fraction.", CParser::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.
|
||||
error_msg
|
||||
("Expected numeric value for solution fraction.",
|
||||
CParser::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
this->mixComps[i] = d;
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
|
||||
}
|
||||
// members that must be defined
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user