Changed the conventions on specifying the element E.

Now it is optional to specify E in the atomArray. The value is
calculated from the species Charge automatically. E is still in the
element list for the phase.

  Now, you don't have to put E explicitly in the element list for
the phase. It's automatically included if it's needed.
This commit is contained in:
Harry Moffat 2008-09-26 23:13:05 +00:00
parent db3c4a592d
commit d23fb00c52
3 changed files with 45 additions and 12 deletions

View file

@ -156,9 +156,10 @@ namespace Cantera {
* -> Passthrough to the Element lvl.
*/
void Constituents::
addUniqueElement(const std::string& symbol, doublereal weight)
addUniqueElement(const std::string& symbol, doublereal weight,
int atomicNumber, doublereal entropy298)
{
m_Elements->addUniqueElement(symbol, weight);
m_Elements->addUniqueElement(symbol, weight, atomicNumber, entropy298);
}
void Constituents::
@ -290,12 +291,13 @@ namespace Cantera {
* and it need not be supplied on the command line.
*/
void Constituents::
addSpecies(const std::string& name, const doublereal* comp,
addSpecies(const std::string& name, doublereal* comp,
doublereal charge, doublereal size) {
m_Elements->freezeElements();
m_speciesNames.push_back(name);
m_speciesCharge.push_back(charge);
m_speciesSize.push_back(size);
vector_fp compNew;;
double wt = 0.0;
int m_mm = m_Elements->nElements();
const vector_fp &aw = m_Elements->atomicWeights();
@ -304,12 +306,40 @@ namespace Cantera {
if (eindex >= 0) {
doublereal ecomp = comp[eindex];
if (fabs (charge + ecomp) > 0.001) {
throw CanteraError("Constituents::addSpecies",
"Input charge and element E compositions differ for species " + name);
if (ecomp != 0.0) {
throw CanteraError("Constituents::addSpecies",
"Input charge and element E compositions differ for species " + name);
} else {
// Just fix up the element E composition based on the input species charge
comp[eindex] = -charge;
}
}
} else {
throw CanteraError("Constituents::addSpecies",
"Input charge and element E compositions differ for species " + name);
m_Elements->m_elementsFrozen = false;
addUniqueElement("E", 0.000545, 0, 0.0);
m_Elements->m_elementsFrozen = true;
m_mm = m_Elements->nElements();
if (m_kk > 0) {
vector_fp old(m_speciesComp);
m_speciesComp.resize(m_kk*m_mm, 0.0);
for (int k = 0; k < m_kk; k++) {
int m_old = m_mm - 1;
for (int m = 0; m < m_old; m++) {
m_speciesComp[k * m_mm + m] = old[k * (m_old) + m];
}
m_speciesComp[k * (m_mm) + (m_mm-1)] = 0.0;
}
}
eindex = m_Elements->elementIndex("E");
compNew.resize(m_mm);
for (int m = 0; m < m_mm-1; m++) {
compNew[m] = comp[m];
}
compNew[m_mm-1] = - charge;
comp = DATA_PTR(compNew);
//comp[eindex] = -charge;
// throw CanteraError("Constituents::addSpecies",
// "Element List doesn't include E, yet this species has charge:" + name);
}
}
for (int m = 0; m < m_mm; m++) {
@ -330,7 +360,7 @@ namespace Cantera {
* existing species in the phase.
*/
void Constituents::
addUniqueSpecies(const std::string& name, const doublereal* comp,
addUniqueSpecies(const std::string& name, doublereal* comp,
doublereal charge, doublereal size) {
vector<string>::const_iterator it = m_speciesNames.begin();
for (int k = 0; k < m_kk; k++) {

View file

@ -18,12 +18,12 @@
#include "ct_defs.h"
//using namespace std;
#include "SpeciesThermo.h"
#include "ctexceptions.h"
#include "stringUtils.h"
#include "xml.h"
#include "Elements.h"
namespace Cantera {
@ -187,7 +187,9 @@ namespace Cantera {
* @param symbol String symbol of the element
* @param weight Atomic weight of the element (kg kmol-1).
*/
void addUniqueElement(const std::string& symbol, doublereal weight);
void addUniqueElement(const std::string& symbol, doublereal weight,
int atomicNumber = 0,
doublereal entropy298 = ENTROPY298_UNKNOWN);
//! Adde an element, checking for uniqueness
/*!
@ -256,7 +258,7 @@ namespace Cantera {
* They are not usually called by user programs.
*/
//@{
void addSpecies(const std::string& name, const doublereal* comp,
void addSpecies(const std::string& name, doublereal* comp,
doublereal charge = 0.0, doublereal size = 1.0);
//! Add a species to the phase, checking for uniqueness of the name
@ -270,7 +272,7 @@ namespace Cantera {
* @param charge Charge of the species. Defaults to zero.
* @param size Size of the species (meters). Defaults to 1 meter.
*/
void addUniqueSpecies(const std::string& name, const doublereal* comp,
void addUniqueSpecies(const std::string& name, doublereal* comp,
doublereal charge = 0.0,
doublereal size = 1.0);

View file

@ -278,6 +278,7 @@ namespace Cantera {
*/
static std::vector<Elements *> Global_Elements_List;
friend class Constituents;
};
} // namespace