[Thermo] Use shared_ptr<Species> in ThermoPhase
This commit is contained in:
parent
8f36e524fe
commit
43952b30fc
9 changed files with 72 additions and 62 deletions
|
|
@ -761,7 +761,7 @@ public:
|
|||
//! Add a Species to this Phase. Returns `true` if the species was
|
||||
//! successfully added, or `false` if the species was ignored.
|
||||
//! @see ignoreUndefinedElements addUndefinedElements throwUndefinedElements
|
||||
virtual bool addSpecies(const Species& spec);
|
||||
virtual bool addSpecies(shared_ptr<Species>& spec);
|
||||
|
||||
void addSpecies(const std::string& name, const doublereal* comp,
|
||||
doublereal charge = 0.0, doublereal size = 1.0);
|
||||
|
|
@ -779,7 +779,7 @@ public:
|
|||
doublereal size = 1.0);
|
||||
|
||||
//! Return the Species object for the named species.
|
||||
const Species& species(const std::string& name) const;
|
||||
shared_ptr<Species> species(const std::string& name) const;
|
||||
|
||||
//! Set behavior when adding a species containing undefined elements to just
|
||||
//! skip the species.
|
||||
|
|
@ -843,7 +843,7 @@ protected:
|
|||
|
||||
vector_fp m_speciesCharge; //!< Vector of species charges. length m_kk.
|
||||
|
||||
std::map<std::string, Species> m_species;
|
||||
std::map<std::string, shared_ptr<Species> > m_species;
|
||||
|
||||
//! Flag determining behavior when adding species with an undefined element
|
||||
UndefElement::behavior m_undefinedElementBehavior;
|
||||
|
|
|
|||
|
|
@ -1310,7 +1310,7 @@ public:
|
|||
//@{
|
||||
|
||||
using Phase::addSpecies;
|
||||
virtual bool addSpecies(const Species& spec);
|
||||
virtual bool addSpecies(shared_ptr<Species>& spec);
|
||||
|
||||
//! Store a reference pointer to the XML tree containing the species data
|
||||
//! for this phase.
|
||||
|
|
|
|||
|
|
@ -839,11 +839,11 @@ size_t Phase::addUniqueElementAfterFreeze(const std::string& symbol,
|
|||
return addElement(symbol, weight, atomicNumber, entropy298, elem_type);
|
||||
}
|
||||
|
||||
bool Phase::addSpecies(const Species& spec) {
|
||||
m_species[spec.name] = spec;
|
||||
bool Phase::addSpecies(shared_ptr<Species>& spec) {
|
||||
m_species[spec->name] = spec;
|
||||
vector_fp comp(nElements());
|
||||
for (map<string, double>::const_iterator iter = spec.composition.begin();
|
||||
iter != spec.composition.end();
|
||||
for (map<string, double>::const_iterator iter = spec->composition.begin();
|
||||
iter != spec->composition.end();
|
||||
iter++) {
|
||||
size_t m = elementIndex(iter->first);
|
||||
if (m == npos) { // Element doesn't exist in this phase
|
||||
|
|
@ -860,33 +860,33 @@ bool Phase::addSpecies(const Species& spec) {
|
|||
case UndefElement::error:
|
||||
default:
|
||||
throw CanteraError("Phase::addSpecies",
|
||||
"Species '" + spec.name + "' contains an "
|
||||
"Species '" + spec->name + "' contains an "
|
||||
"undefined element '" + iter->first + "'.");
|
||||
}
|
||||
}
|
||||
comp[m] = iter->second;
|
||||
}
|
||||
|
||||
m_speciesNames.push_back(spec.name);
|
||||
m_speciesCharge.push_back(spec.charge);
|
||||
m_speciesSize.push_back(spec.size);
|
||||
m_speciesNames.push_back(spec->name);
|
||||
m_speciesCharge.push_back(spec->charge);
|
||||
m_speciesSize.push_back(spec->size);
|
||||
size_t ne = nElements();
|
||||
|
||||
double wt = 0.0;
|
||||
const vector_fp& aw = atomicWeights();
|
||||
if (spec.charge != 0.0) {
|
||||
if (spec->charge != 0.0) {
|
||||
size_t eindex = elementIndex("E");
|
||||
if (eindex != npos) {
|
||||
doublereal ecomp = comp[eindex];
|
||||
if (fabs(spec.charge + ecomp) > 0.001) {
|
||||
if (fabs(spec->charge + ecomp) > 0.001) {
|
||||
if (ecomp != 0.0) {
|
||||
throw CanteraError("Phase::addSpecies",
|
||||
"Input charge and element E compositions differ "
|
||||
"for species " + spec.name);
|
||||
"for species " + spec->name);
|
||||
} else {
|
||||
// Just fix up the element E composition based on the input
|
||||
// species charge
|
||||
comp[eindex] = -spec.charge;
|
||||
comp[eindex] = -spec->charge;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -894,7 +894,7 @@ bool Phase::addSpecies(const Species& spec) {
|
|||
ne = nElements();
|
||||
eindex = elementIndex("E");
|
||||
comp.resize(ne);
|
||||
comp[ne - 1] = - spec.charge;
|
||||
comp[ne - 1] = - spec->charge;
|
||||
}
|
||||
}
|
||||
for (size_t m = 0; m < ne; m++) {
|
||||
|
|
@ -933,7 +933,8 @@ void Phase::addSpecies(const std::string& name_, const doublereal* comp,
|
|||
cmap[elementName(i)] = comp[i];
|
||||
}
|
||||
}
|
||||
Phase::addSpecies(Species(name_, cmap, 0, charge_, size_));
|
||||
shared_ptr<Species> sp(new Species(name_, cmap, 0, charge_, size_));
|
||||
Phase::addSpecies(sp);
|
||||
}
|
||||
|
||||
void Phase::addUniqueSpecies(const std::string& name_, const doublereal* comp,
|
||||
|
|
@ -965,7 +966,7 @@ void Phase::addUniqueSpecies(const std::string& name_, const doublereal* comp,
|
|||
addSpecies(name_, comp, charge_, size_);
|
||||
}
|
||||
|
||||
const Species& Phase::species(const std::string& name) const
|
||||
shared_ptr<Species> Phase::species(const std::string& name) const
|
||||
{
|
||||
return getValue(m_species, name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -621,7 +621,7 @@ bool installSpecies(size_t k, const XML_Node& s, thermo_t& th,
|
|||
vp_ptr->createInstallPDSS(k, s, phaseNode_ptr);
|
||||
} else {
|
||||
SpeciesThermoInterpType* st = newSpeciesThermoInterpType(s);
|
||||
Species sp(s["name"], comp_map, st, chrg, sz);
|
||||
shared_ptr<Species> sp(new Species(s["name"], comp_map, st, chrg, sz));
|
||||
|
||||
// Read gas-phase transport data, if provided
|
||||
if (s.hasChild("transport") &&
|
||||
|
|
@ -646,10 +646,10 @@ bool installSpecies(size_t k, const XML_Node& s, thermo_t& th,
|
|||
getOptionalFloat(tr, "acentric_factor", acentric);
|
||||
|
||||
GasTransportData* gastran = new GasTransportData;
|
||||
gastran->setCustomaryUnits(sp.name, geometry, diam, welldepth,
|
||||
gastran->setCustomaryUnits(sp->name, geometry, diam, welldepth,
|
||||
dipole, polar, rot, acentric);
|
||||
sp.transport.reset(gastran);
|
||||
gastran->validate(sp);
|
||||
sp->transport.reset(gastran);
|
||||
gastran->validate(*sp);
|
||||
}
|
||||
th.addSpecies(sp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -694,13 +694,12 @@ void ThermoPhase::installSlavePhases(Cantera::XML_Node* phaseNode)
|
|||
{
|
||||
}
|
||||
|
||||
bool ThermoPhase::addSpecies(const Species& spec)
|
||||
bool ThermoPhase::addSpecies(shared_ptr<Species>& spec)
|
||||
{
|
||||
bool added = Phase::addSpecies(spec);
|
||||
if (added) {
|
||||
Species& s = m_species[spec.name];
|
||||
s.thermo->validate(spec.name);
|
||||
m_spthermo->install_STIT(m_kk-1, s.thermo);
|
||||
spec->thermo->validate(spec->name);
|
||||
m_spthermo->install_STIT(m_kk-1, spec->thermo);
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -464,9 +464,9 @@ void GasTransport::setupMM()
|
|||
void GasTransport::getTransportData()
|
||||
{
|
||||
for (size_t k = 0; k < m_thermo->nSpecies(); k++) {
|
||||
const Species& s = m_thermo->species(m_thermo->speciesName(k));
|
||||
shared_ptr<Species> s = m_thermo->species(m_thermo->speciesName(k));
|
||||
const GasTransportData& sptran =
|
||||
dynamic_cast<GasTransportData&>(*s.transport.get());
|
||||
dynamic_cast<GasTransportData&>(*s->transport.get());
|
||||
if (sptran.geometry == "atom") {
|
||||
m_crot[k] = 0.0;
|
||||
} else if (sptran.geometry == "linear") {
|
||||
|
|
|
|||
|
|
@ -105,23 +105,23 @@ class ConstructFromScratch : public testing::Test
|
|||
{
|
||||
public:
|
||||
ConstructFromScratch()
|
||||
: sH2O("H2O", parseCompString("H:2 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs))
|
||||
, sH2("H2", parseCompString("H:2"),
|
||||
new NasaPoly2(200, 3500, 101325, h2_nasa_coeffs))
|
||||
, sO2("O2", parseCompString("O:2"),
|
||||
new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs))
|
||||
, sOH("OH", parseCompString("H:1 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, oh_nasa_coeffs))
|
||||
, sCO("CO", parseCompString("C:1 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs))
|
||||
, sCO2("CO2", parseCompString("C:1 O:2"),
|
||||
new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs))
|
||||
: sH2O(new Species("H2O", parseCompString("H:2 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs)))
|
||||
, sH2(new Species("H2", parseCompString("H:2"),
|
||||
new NasaPoly2(200, 3500, 101325, h2_nasa_coeffs)))
|
||||
, sO2(new Species("O2", parseCompString("O:2"),
|
||||
new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs)))
|
||||
, sOH(new Species("OH", parseCompString("H:1 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, oh_nasa_coeffs)))
|
||||
, sCO(new Species("CO", parseCompString("C:1 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs)))
|
||||
, sCO2(new Species("CO2", parseCompString("C:1 O:2"),
|
||||
new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs)))
|
||||
{
|
||||
}
|
||||
|
||||
IdealGasPhase p;
|
||||
Species sH2O, sH2, sO2, sOH, sCO, sCO2;
|
||||
shared_ptr<Species> sH2O, sH2, sO2, sOH, sCO, sCO2;
|
||||
};
|
||||
|
||||
TEST_F(ConstructFromScratch, AddElements)
|
||||
|
|
|
|||
|
|
@ -35,9 +35,12 @@ TEST_F(SpeciesThermoInterpTypeTest, install_const_cp)
|
|||
SpeciesThermoInterpType* stit_o2 = new ConstCpPoly(200, 5000, 101325, c_o2);
|
||||
SpeciesThermoInterpType* stit_h2 = new ConstCpPoly(200, 5000, 101325, c_h2);
|
||||
SpeciesThermoInterpType* stit_h2o = new ConstCpPoly(200, 5000, 101325, c_h2o);
|
||||
p.addSpecies(Species("O2", parseCompString("O:2"), stit_o2));
|
||||
p.addSpecies(Species("H2", parseCompString("H:2"), stit_h2));
|
||||
p.addSpecies(Species("H2O", parseCompString("H:2 O:1"), stit_h2o));
|
||||
shared_ptr<Species> sO2(new Species("O2", parseCompString("O:2"), stit_o2));
|
||||
shared_ptr<Species> sH2(new Species("H2", parseCompString("H:2"), stit_h2));
|
||||
shared_ptr<Species> sH2O(new Species("H2O", parseCompString("H:2 O:1"), stit_h2o));
|
||||
p.addSpecies(sO2);
|
||||
p.addSpecies(sH2);
|
||||
p.addSpecies(sH2O);
|
||||
p.initThermo();
|
||||
p2.setState_TPX(298.15, 101325, "H2:0.2, O2:0.7, H2O:0.1");
|
||||
p.setState_TPX(298.15, 101325, "H2:0.2, O2:0.7, H2O:0.1");
|
||||
|
|
@ -53,9 +56,11 @@ TEST_F(SpeciesThermoInterpTypeTest, DISABLED_install_bad_pref)
|
|||
// pressure consistency.
|
||||
SpeciesThermoInterpType* stit_o2 = new ConstCpPoly(200, 5000, 101325, c_o2);
|
||||
SpeciesThermoInterpType* stit_h2 = new ConstCpPoly(200, 5000, 100000, c_h2);
|
||||
p.addSpecies(Species("O2", parseCompString("O:2"), stit_o2));
|
||||
shared_ptr<Species> sO2(new Species("O2", parseCompString("O:2"), stit_o2));
|
||||
shared_ptr<Species> sH2(new Species("H2", parseCompString("H:2"), stit_h2));
|
||||
p.addSpecies(sO2);
|
||||
// Pref does not match
|
||||
ASSERT_THROW(p.addSpecies(Species("H2", parseCompString("H:2"), stit_h2)), CanteraError);
|
||||
ASSERT_THROW(p.addSpecies(sH2), CanteraError);
|
||||
delete stit_h2;
|
||||
}
|
||||
|
||||
|
|
@ -66,9 +71,12 @@ TEST_F(SpeciesThermoInterpTypeTest, install_nasa)
|
|||
SpeciesThermoInterpType* stit_o2 = new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs);
|
||||
SpeciesThermoInterpType* stit_h2 = new NasaPoly2(200, 3500, 101325, h2_nasa_coeffs);
|
||||
SpeciesThermoInterpType* stit_h2o = new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs);
|
||||
p.addSpecies(Species("O2", parseCompString("O:2"), stit_o2));
|
||||
p.addSpecies(Species("H2", parseCompString("H:2"), stit_h2));
|
||||
p.addSpecies(Species("H2O", parseCompString("H:2 O:1"), stit_h2o));
|
||||
shared_ptr<Species> sO2(new Species("O2", parseCompString("O:2"), stit_o2));
|
||||
shared_ptr<Species> sH2(new Species("H2", parseCompString("H:2"), stit_h2));
|
||||
shared_ptr<Species> sH2O(new Species("H2O", parseCompString("H:2 O:1"), stit_h2o));
|
||||
p.addSpecies(sO2);
|
||||
p.addSpecies(sH2);
|
||||
p.addSpecies(sH2O);
|
||||
p.initThermo();
|
||||
p2.setState_TPX(900, 101325, "H2:0.2, O2:0.7, H2O:0.1");
|
||||
p.setState_TPX(900, 101325, "H2:0.2, O2:0.7, H2O:0.1");
|
||||
|
|
@ -84,8 +92,10 @@ TEST_F(SpeciesThermoInterpTypeTest, install_shomate)
|
|||
IdealGasPhase p2("../data/simplephases.cti", "shomate1");
|
||||
SpeciesThermoInterpType* stit_co = new ShomatePoly2(200, 6000, 101325, co_shomate_coeffs);
|
||||
SpeciesThermoInterpType* stit_co2 = new ShomatePoly2(200, 6000, 101325, co2_shomate_coeffs);
|
||||
p.addSpecies(Species("CO", parseCompString("C:1 O:1"), stit_co));
|
||||
p.addSpecies(Species("CO2", parseCompString("C:1 O:2"), stit_co2));
|
||||
shared_ptr<Species> sCO(new Species("CO", parseCompString("C:1 O:1"), stit_co));
|
||||
shared_ptr<Species> sCO2(new Species("CO2", parseCompString("C:1 O:2"), stit_co2));
|
||||
p.addSpecies(sCO);
|
||||
p.addSpecies(sCO2);
|
||||
p.initThermo();
|
||||
p2.setState_TPX(900, 101325, "CO:0.2, CO2:0.8");
|
||||
p.setState_TPX(900, 101325, "CO:0.2, CO2:0.8");
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ class TransportFromScratch : public testing::Test
|
|||
{
|
||||
public:
|
||||
TransportFromScratch()
|
||||
: sH2("H2", parseCompString("H:2"),
|
||||
new NasaPoly2(200, 3500, 101325, h2_nasa_coeffs))
|
||||
, sO2("O2", parseCompString("O:2"),
|
||||
new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs))
|
||||
, sH2O("H2O", parseCompString("H:2 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs))
|
||||
: sH2(new Species("H2", parseCompString("H:2"),
|
||||
new NasaPoly2(200, 3500, 101325, h2_nasa_coeffs)))
|
||||
, sO2(new Species("O2", parseCompString("O:2"),
|
||||
new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs)))
|
||||
, sH2O(new Species("H2O", parseCompString("H:2 O:1"),
|
||||
new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs)))
|
||||
, tH2(new GasTransportData())
|
||||
, tO2(new GasTransportData())
|
||||
, tH2O(new GasTransportData())
|
||||
|
|
@ -32,9 +32,9 @@ public:
|
|||
tO2->setCustomaryUnits("O2", "linear", 3.46, 107.40, 0.0, 1.60, 3.80);
|
||||
tH2O->setCustomaryUnits("H2O", "nonlinear", 2.60, 572.4, 1.84, 0.0, 4.00);
|
||||
|
||||
sH2.transport = tH2;
|
||||
sO2.transport = tO2;
|
||||
sH2O.transport = tH2O;
|
||||
sH2->transport = tH2;
|
||||
sO2->transport = tO2;
|
||||
sH2O->transport = tH2O;
|
||||
|
||||
std::string phase_def = "ideal_gas(name='test', elements='O H',"
|
||||
"species='gri30: H2 O2 H2O')";
|
||||
|
|
@ -54,7 +54,7 @@ public:
|
|||
test->setState_TPX(400, 5e5, "H2:0.5, O2:0.3, H2O:0.2");
|
||||
}
|
||||
|
||||
Species sH2, sO2, sH2O;
|
||||
shared_ptr<Species> sH2, sO2, sH2O;
|
||||
shared_ptr<GasTransportData> tH2, tO2, tH2O;
|
||||
shared_ptr<ThermoPhase> ref;
|
||||
shared_ptr<ThermoPhase> test;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue