[Thermo] Make IonsFromNeutralVPSSTP::neutralMoleculePhase_ a shared_ptr

Also make it non-public and add getters and setters
This commit is contained in:
Ray Speth 2017-07-31 23:27:10 -04:00
parent 338b21694f
commit 4856d1328b
5 changed files with 34 additions and 76 deletions

View file

@ -85,17 +85,9 @@ public:
* to set up the object
* @param id ID of the phase in the input file. Defaults to the
* empty string.
* @param neutralPhase The object takes a neutralPhase ThermoPhase object
* as input. It can either take a pointer to an existing object in the
* parameter list, in which case it does not own the object, or it can
* construct a neutral Phase as a slave object, in which case, it does
* own the slave object, for purposes of who gets to destroy the object.
* If this parameter is zero, then a slave neutral phase object is
* created and used.
*/
IonsFromNeutralVPSSTP(const std::string& inputFile,
const std::string& id = "",
ThermoPhase* neutralPhase = 0);
const std::string& id = "");
//! Construct and initialize an IonsFromNeutralVPSSTP object
//! directly from an XML database
@ -103,18 +95,8 @@ public:
* @param phaseRoot XML phase node containing the description of the phase
* @param id id attribute containing the name of the phase.
* (default is the empty string)
* @param neutralPhase The object takes a neutralPhase ThermoPhase object
* as input. It can either take a pointer to an existing object in the
* parameter list, in which case it does not own the object, or it can
* construct a neutral Phase as a slave object, in which case, it does
* own the slave object, for purposes of who gets to destroy the object.
* If this parameter is zero, then a slave neutral phase object is
* created and used.
*/
IonsFromNeutralVPSSTP(XML_Node& phaseRoot, const std::string& id = "",
ThermoPhase* neutralPhase = 0);
virtual ~IonsFromNeutralVPSSTP();
IonsFromNeutralVPSSTP(XML_Node& phaseRoot, const std::string& id = "");
// @}
//! @name Utilities
@ -289,6 +271,9 @@ public:
//@}
void setNeutralMoleculePhase(shared_ptr<ThermoPhase> neutral);
shared_ptr<ThermoPhase> getNeutralMoleculePhase();
virtual void initThermo();
virtual void initThermoXML(XML_Node& phaseNode, const std::string& id);
virtual void setParametersFromXML(const XML_Node& thermoNode);
@ -420,13 +405,8 @@ protected:
//! neutralMoleculePhase ThermoPhase. These have neutral charges.
std::vector<size_t> passThroughList_;
public:
//! This is a pointer to the neutral Molecule Phase
/*!
* If the variable, IOwnNThermoPhase_ is true, then we own
* the pointer. If not, then this is considered a shallow pointer.
*/
ThermoPhase* neutralMoleculePhase_;
shared_ptr<ThermoPhase> neutralMoleculePhase_;
private:
GibbsExcessVPSSTP* geThermo;
@ -437,13 +417,6 @@ private:
mutable vector_fp dX_NeutralMolecule_;
mutable vector_fp m_work; // length m_kk
//! If true then we own the underlying neutral Molecule Phase
/*!
* If this is false, then the neutral molecule phase is considered
* as a shallow pointer.
*/
bool IOwnNThermoPhase_;
//! Temporary mole fraction vector
mutable vector_fp moleFractionsTmp_;

View file

@ -96,10 +96,7 @@ public:
protected:
//! Pointer to the Neutral Molecule ThermoPhase object
/*!
* This is a shallow pointer.
*/
const ThermoPhase* neutralMoleculePhase_;
shared_ptr<ThermoPhase> neutralMoleculePhase_;
std::map<std::string, double> neutralSpeciesMultipliers_;

View file

@ -32,50 +32,30 @@ IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP() :
indexSpecialSpecies_(npos),
indexSecondSpecialSpecies_(npos),
neutralMoleculePhase_(0),
geThermo(0),
IOwnNThermoPhase_(true)
geThermo(0)
{
}
IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(const std::string& inputFile,
const std::string& id_,
ThermoPhase* neutralPhase) :
const std::string& id_) :
ionSolnType_(cIonSolnType_SINGLEANION),
numNeutralMoleculeSpecies_(0),
indexSpecialSpecies_(npos),
indexSecondSpecialSpecies_(npos),
neutralMoleculePhase_(neutralPhase),
IOwnNThermoPhase_(true)
indexSecondSpecialSpecies_(npos)
{
if (neutralPhase) {
IOwnNThermoPhase_ = false;
}
initThermoFile(inputFile, id_);
}
IonsFromNeutralVPSSTP::IonsFromNeutralVPSSTP(XML_Node& phaseRoot,
const std::string& id_, ThermoPhase* neutralPhase) :
const std::string& id_) :
ionSolnType_(cIonSolnType_SINGLEANION),
numNeutralMoleculeSpecies_(0),
indexSpecialSpecies_(npos),
indexSecondSpecialSpecies_(npos),
neutralMoleculePhase_(neutralPhase),
IOwnNThermoPhase_(true)
indexSecondSpecialSpecies_(npos)
{
if (neutralPhase) {
IOwnNThermoPhase_ = false;
}
importPhase(phaseRoot, this);
}
IonsFromNeutralVPSSTP::~IonsFromNeutralVPSSTP()
{
if (IOwnNThermoPhase_) {
delete neutralMoleculePhase_;
neutralMoleculePhase_ = 0;
}
}
// ------------ Molar Thermodynamic Properties ----------------------
doublereal IonsFromNeutralVPSSTP::enthalpy_mole() const
@ -474,20 +454,15 @@ void IonsFromNeutralVPSSTP::initThermo()
{
initLengths();
GibbsExcessVPSSTP::initThermo();
geThermo = dynamic_cast<GibbsExcessVPSSTP*>(neutralMoleculePhase_);
}
void IonsFromNeutralVPSSTP::initLengths()
void IonsFromNeutralVPSSTP::setNeutralMoleculePhase(shared_ptr<ThermoPhase> neutral)
{
neutralMoleculePhase_ = neutral;
geThermo = dynamic_cast<GibbsExcessVPSSTP*>(neutralMoleculePhase_.get());
numNeutralMoleculeSpecies_ = neutralMoleculePhase_->nSpecies();
moleFractions_.resize(m_kk);
fm_neutralMolec_ions_.resize(numNeutralMoleculeSpecies_ * m_kk);
fm_invert_ionForNeutral.resize(m_kk);
NeutralMolecMoleFractions_.resize(numNeutralMoleculeSpecies_);
cationList_.resize(m_kk);
anionList_.resize(m_kk);
passThroughList_.resize(m_kk);
moleFractionsTmp_.resize(m_kk);
muNeutralMolecule_.resize(numNeutralMoleculeSpecies_);
lnActCoeff_NeutralMolecule_.resize(numNeutralMoleculeSpecies_);
dlnActCoeffdT_NeutralMolecule_.resize(numNeutralMoleculeSpecies_);
@ -497,6 +472,22 @@ void IonsFromNeutralVPSSTP::initLengths()
y_.resize(numNeutralMoleculeSpecies_, 0.0);
dlnActCoeff_NeutralMolecule_.resize(numNeutralMoleculeSpecies_, 0.0);
dX_NeutralMolecule_.resize(numNeutralMoleculeSpecies_, 0.0);
}
shared_ptr<ThermoPhase> IonsFromNeutralVPSSTP::getNeutralMoleculePhase()
{
return neutralMoleculePhase_;
}
void IonsFromNeutralVPSSTP::initLengths()
{
moleFractions_.resize(m_kk);
fm_neutralMolec_ions_.resize(numNeutralMoleculeSpecies_ * m_kk);
fm_invert_ionForNeutral.resize(m_kk);
cationList_.resize(m_kk);
anionList_.resize(m_kk);
passThroughList_.resize(m_kk);
moleFractionsTmp_.resize(m_kk);
m_work.resize(m_kk);
}
@ -549,10 +540,7 @@ void IonsFromNeutralVPSSTP::setParametersFromXML(const XML_Node& thermoNode)
"neut_ptr = 0");
}
// Create the neutralMolecule ThermoPhase if we haven't already
if (!neutralMoleculePhase_) {
neutralMoleculePhase_ = newPhase(*neut_ptr);
}
setNeutralMoleculePhase(shared_ptr<ThermoPhase>(newPhase(*neut_ptr)));
}
void IonsFromNeutralVPSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)

View file

@ -27,7 +27,7 @@ PDSS_IonsFromNeutral::PDSS_IonsFromNeutral()
void PDSS_IonsFromNeutral::setParent(VPStandardStateTP* phase, size_t k)
{
neutralMoleculePhase_ = dynamic_cast<IonsFromNeutralVPSSTP&>(*phase).neutralMoleculePhase_;
neutralMoleculePhase_ = dynamic_cast<IonsFromNeutralVPSSTP&>(*phase).getNeutralMoleculePhase();
}
void PDSS_IonsFromNeutral::setParametersFromXML(const XML_Node& speciesNode)

View file

@ -517,7 +517,7 @@ void LTI_StefanMaxwell_PPN::getMatrixTransProp(DenseMatrix& mat, doublereal* spe
}
m_ionCondMix = m_ionCondMixModel->getMixTransProp(m_ionCondSpecies);
MargulesVPSSTP* marg_thermo = dynamic_cast<MargulesVPSSTP*>(ions_thermo->neutralMoleculePhase_);
MargulesVPSSTP* marg_thermo = dynamic_cast<MargulesVPSSTP*>(ions_thermo->getNeutralMoleculePhase().get());
doublereal vol = m_thermo->molarVolume();
size_t k = 0;