Skip to content

Commit

Permalink
[Kinetics] Used shared pointers in Kinetics::addPhase
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Mar 7, 2023
1 parent 12e6ca2 commit 6f8b151
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/cantera/base/Solution.h
Expand Up @@ -49,9 +49,9 @@ class Solution : public std::enable_shared_from_this<Solution>
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() {
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/kinetics/InterfaceKinetics.h
Expand Up @@ -142,6 +142,9 @@ class InterfaceKinetics : public Kinetics
*
* @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();
Expand Down
16 changes: 16 additions & 0 deletions include/cantera/kinetics/Kinetics.h
Expand Up @@ -219,6 +219,12 @@ class Kinetics
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
Expand Down Expand Up @@ -1098,7 +1104,13 @@ class Kinetics
* 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);

/**
Expand Down Expand Up @@ -1320,6 +1332,10 @@ class Kinetics
*/
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.
Expand Down
7 changes: 7 additions & 0 deletions src/kinetics/InterfaceKinetics.cpp
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions src/kinetics/Kinetics.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/kinetics/KineticsFactory.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 6f8b151

Please sign in to comment.