Skip to content

Commit

Permalink
Prevent infinite recursion in Solution callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Mar 7, 2023
1 parent cc6489d commit 399e1cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/base/Solution.cpp
Expand Up @@ -48,6 +48,9 @@ void Solution::setThermo(shared_ptr<ThermoPhase> thermo) {
}

void Solution::setKinetics(shared_ptr<Kinetics> kinetics) {
if (kinetics == m_kinetics) {
return;
}
m_kinetics = kinetics;
if (m_kinetics) {
m_kinetics->setRoot(shared_from_this());
Expand All @@ -58,6 +61,9 @@ void Solution::setKinetics(shared_ptr<Kinetics> kinetics) {
}

void Solution::setTransport(shared_ptr<Transport> transport) {
if (transport == m_transport) {
return;
}
m_transport = transport;
for (const auto& [id, callback] : m_changeCallbacks) {
callback();
Expand Down
4 changes: 2 additions & 2 deletions src/oneD/IonFlow.cpp
Expand Up @@ -74,8 +74,8 @@ IonFlow::IonFlow(shared_ptr<Solution> sol, const std::string& id, size_t points)
setTransportModel("Ion");
}
m_solution->registerChangedCallback(this, [this]() {
setKinetics(*m_solution->kinetics());
setTransport(*m_solution->transport());
setKinetics(m_solution->kinetics());
setTransport(m_solution->transport());
});
}

Expand Down
14 changes: 6 additions & 8 deletions src/oneD/StFlow.cpp
Expand Up @@ -131,8 +131,8 @@ StFlow::StFlow(shared_ptr<Solution> sol, const std::string& id, size_t points)
setTransportModel("Mix");
}
m_solution->registerChangedCallback(this, [this]() {
setKinetics(*m_solution->kinetics());
setTransport(*m_solution->transport());
setKinetics(m_solution->kinetics());
setTransport(m_solution->transport());
});
}

Expand Down Expand Up @@ -161,9 +161,8 @@ void StFlow::setKinetics(shared_ptr<Kinetics> kin)

void StFlow::setKinetics(Kinetics& kin)
{
// @todo: resolve crash for updated m_solution->registerChangedCallback
// warn_deprecated("StFlow::setKinetics",
// "To be removed after Cantera 3.0. Replaced by Domain1D::setKinetics.");
warn_deprecated("StFlow::setKinetics(Kinetics&)", "To be removed after Cantera 3.0."
" Replaced by setKinetics(shared_ptr<Kinetics>).");
m_kin = &kin;
}

Expand Down Expand Up @@ -258,9 +257,8 @@ std::string StFlow::transportModel() const {

void StFlow::setTransport(Transport& trans)
{
// @todo: resolve crash for updated m_solution->registerChangedCallback
// warn_deprecated("StFlow::setTransport",
// "To be removed after Cantera 3.0. Replaced by Domain1D::setTransport.");
warn_deprecated("StFlow::setTransport(Transport&)", "To be removed after"
" Cantera 3.0. Replaced by setTransport(shared_ptr<Transport>).");
m_trans = &trans;
if (m_trans->transportModel() == "None") {
throw CanteraError("StFlow::setTransport",
Expand Down

0 comments on commit 399e1cb

Please sign in to comment.