[Kinetics] Used shared pointers in Kinetics::addPhase

This commit is contained in:
Ingmar Schoegl
2023-03-03 11:52:32 -06:00
parent 12e6ca225b
commit 6f8b151e72
6 changed files with 61 additions and 3 deletions

View File

@@ -49,9 +49,9 @@ public:
virtual void setTransport(shared_ptr<Transport> transport);
//! Set the Transport object by name
//! @param model name of transport model
//! @param model name of transport model; if omitted, the default model is used
//! @since New in Cantera 3.0
void setTransportModel(const std::string& model);
void setTransportModel(const std::string& model="");
//! Accessor for the ThermoPhase pointer
shared_ptr<ThermoPhase> thermo() {

View File

@@ -142,6 +142,9 @@ public:
*
* @param thermo Reference to the ThermoPhase to be added.
*/
virtual void addPhase(shared_ptr<ThermoPhase> thermo);
//! @see InterfaceKinetics::addPhase(shared_ptr<ThermoPhase>)
virtual void addPhase(ThermoPhase& thermo);
virtual void init();

View File

@@ -219,6 +219,12 @@ public:
return m_rxnphase;
}
/**
* Return pointer to phase where the reactions occur.
* @since New in Cantera 3.0
*/
shared_ptr<ThermoPhase> reactionPhase() const;
/**
* This method returns a reference to the nth ThermoPhase object defined
* in this kinetics mechanism. It is typically used so that member
@@ -1098,7 +1104,13 @@ public:
* kinetics manager object as the value.
*
* @param thermo Reference to the ThermoPhase to be added.
* @since Changed in Cantera 3.0. Replaces version using reference.
*/
virtual void addPhase(shared_ptr<ThermoPhase> thermo);
//! @see Kinetics::addPhase(shared_ptr<ThermoPhase>)
//! @deprecated To be removed after Cantera 3.0. Replaced by version using shared
//! pointer.
virtual void addPhase(ThermoPhase& thermo);
/**
@@ -1320,6 +1332,10 @@ protected:
*/
std::vector<ThermoPhase*> m_thermo;
//! vector of shared pointers, @see m_thermo
//! @todo replace m_thermo with shared version after Cantera 3.0
vector<shared_ptr<ThermoPhase>> m_sharedThermo;
/**
* m_start is a vector of integers specifying the beginning position for the
* species vector for the n'th phase in the kinetics class.

View File

@@ -487,6 +487,13 @@ void InterfaceKinetics::setIOFlag(int ioFlag)
}
}
void InterfaceKinetics::addPhase(shared_ptr<ThermoPhase> thermo)
{
Kinetics::addPhase(thermo);
m_phaseExists.push_back(true);
m_phaseIsStable.push_back(true);
}
void InterfaceKinetics::addPhase(ThermoPhase& thermo)
{
Kinetics::addPhase(thermo);

View File

@@ -93,6 +93,16 @@ size_t Kinetics::surfacePhaseIndex() const
return m_surfphase;
}
shared_ptr<ThermoPhase> Kinetics::reactionPhase() const
{
if (!m_sharedThermo.size()) {
// @todo remove after Cantera 3.0
throw CanteraError("Kinetics::reactionPhase",
"Cannot access phases that were not added using smart pointers.");
}
return m_sharedThermo[m_rxnphase];
}
void Kinetics::checkSpeciesIndex(size_t k) const
{
if (k >= m_kk) {
@@ -561,8 +571,30 @@ Eigen::SparseMatrix<double> Kinetics::netProductionRates_ddX()
return m_stoichMatrix * netRatesOfProgress_ddX();
}
void Kinetics::addPhase(shared_ptr<ThermoPhase> thermo)
{
// the phase with lowest dimensionality is assumed to be the
// phase/interface at which reactions take place
if (thermo->nDim() <= m_mindim) {
m_mindim = thermo->nDim();
m_rxnphase = nPhases();
}
// there should only be one surface phase
if (thermo->type() == kineticsType()) {
m_surfphase = nPhases();
}
m_thermo.push_back(thermo.get());
m_sharedThermo.push_back(thermo);
m_phaseindex[m_thermo.back()->name()] = nPhases();
resizeSpecies();
}
void Kinetics::addPhase(ThermoPhase& thermo)
{
warn_deprecated("Kinetics::addPhase",
"To be removed after Cantera 3.0. Use version with shared pointer instead.");
// the phase with lowest dimensionality is assumed to be the
// phase/interface at which reactions take place
if (thermo.nDim() <= m_mindim) {

View File

@@ -89,7 +89,7 @@ shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
shared_ptr<Kinetics> kin(KineticsFactory::factory()->newKinetics(kinType));
for (auto& phase : phases) {
kin->addPhase(*phase);
kin->addPhase(phase);
}
kin->init();
addReactions(*kin, phaseNode, rootNode);