[Thermo] Store sub-lattices as shared_ptr in LatticeSolidPhase

Also eliminates undefined behavior associated with unchecked cast to
LatticePhase*, since, at least in the Li7Si3_ls.xml example file, the
sub-lattices can be represented as other ThermoPhase types,
e.g. StoichSubstance.
This commit is contained in:
Ray Speth 2017-06-18 19:58:23 -04:00
parent d744bd9fb8
commit 04f10972c8
2 changed files with 3 additions and 14 deletions

View file

@ -12,7 +12,6 @@
#define CT_LATTICESOLID_H
#include "ThermoPhase.h"
#include "LatticePhase.h"
namespace Cantera
{
@ -107,7 +106,6 @@ class LatticeSolidPhase : public ThermoPhase
public:
//! Base empty constructor
LatticeSolidPhase();
virtual ~LatticeSolidPhase();
virtual std::string type() const {
return "LatticeSolid";
@ -431,7 +429,7 @@ protected:
doublereal m_molar_density;
//! Vector of sublattic ThermoPhase objects
std::vector<LatticePhase*> m_lattice;
std::vector<shared_ptr<ThermoPhase>> m_lattice;
//! Vector of mole fractions
/*!

View file

@ -27,15 +27,6 @@ LatticeSolidPhase::LatticeSolidPhase() :
{
}
LatticeSolidPhase::~LatticeSolidPhase()
{
// We own the sublattices. So we have to delete the sublattices
for (size_t n = 0; n < m_lattice.size(); n++) {
delete m_lattice[n];
m_lattice[n] = 0;
}
}
doublereal LatticeSolidPhase::minTemp(size_t k) const
{
if (k != npos) {
@ -303,7 +294,7 @@ void LatticeSolidPhase::initThermo()
size_t loc = 0;
for (size_t n = 0; n < m_lattice.size(); n++) {
LatticePhase* lp = m_lattice[n];
shared_ptr<ThermoPhase>& lp = m_lattice[n];
vector_fp constArr(lp->nElements());
const vector_fp& aws = lp->atomicWeights();
for (size_t es = 0; es < lp->nElements(); es++) {
@ -390,7 +381,7 @@ void LatticeSolidPhase::setParametersFromXML(const XML_Node& eosdata)
XML_Node& la = eosdata.child("LatticeArray");
std::vector<XML_Node*> lattices = la.getChildren("phase");
for (size_t n = 0; n < lattices.size(); n++) {
m_lattice.push_back((LatticePhase*)newPhase(*lattices[n]));
m_lattice.emplace_back(newPhase(*lattices[n]));
}
std::vector<string> pnam;
std::vector<string> pval;