Skip to content

Commit

Permalink
[Kinetics] Remove NAN sentinel from ChebyshevRate
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jul 12, 2022
1 parent 91c0e34 commit 4f6b759
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions include/cantera/kinetics/ChebyshevRate.h
Expand Up @@ -228,6 +228,10 @@ class ChebyshevRate final : public ReactionRate
//! Set the Chebyshev coefficients as 2-dimensional array.
void setData(const Array2D& coeffs);

virtual bool ready() const override {
return m_ready;
}

protected:
double m_log10P; //!< value detecting updates
double Tmin_, Tmax_; //!< valid temperature range
Expand All @@ -239,6 +243,7 @@ class ChebyshevRate final : public ReactionRate
vector_fp dotProd_; //!< dot product of coeffs with the reduced pressure polynomial

Units m_rate_units; //!< Reaction rate units
bool m_ready = false; //!< Flag indicating object status
};

}
Expand Down
10 changes: 6 additions & 4 deletions src/kinetics/ChebyshevRate.cpp
Expand Up @@ -83,14 +83,15 @@ void ChebyshevRate::setParameters(const AnyMap& node, const UnitStack& rate_unit
unit_system.convert(P_range[0], "Pa"),
unit_system.convert(P_range[1], "Pa")
);
setData(coeffs);
} else {
// ensure that reaction rate can be evaluated (but returns NaN)
coeffs = Array2D(1, 1);
coeffs(0, 0) = NAN;
setLimits(290., 3000., 1.e-7, 1.e14);
setData(coeffs);
m_ready = false;
}

setData(coeffs);
}

void ChebyshevRate::setLimits(double Tmin, double Tmax, double Pmin, double Pmax)
Expand All @@ -115,12 +116,13 @@ void ChebyshevRate::setData(const Array2D& coeffs)
{
m_coeffs = coeffs;
dotProd_.resize(coeffs.nRows());
m_ready = m_coeffs.data().size();
}

void ChebyshevRate::getParameters(AnyMap& rateNode) const
{
rateNode["type"] = type();
if (!m_coeffs.data().size() || std::isnan(m_coeffs(0, 0))) {
if (!ready()) {
// object not fully set up
return;
}
Expand Down Expand Up @@ -154,7 +156,7 @@ void ChebyshevRate::getParameters(AnyMap& rateNode) const

void ChebyshevRate::validate(const std::string& equation, const Kinetics& kin)
{
if (m_coeffs.data().empty() || isnan(m_coeffs(0, 0))) {
if (!ready()) {
throw InputFileError("ChebyshevRate::validate", m_input,
"Rate object for reaction '{}' is not configured.", equation);
}
Expand Down

0 comments on commit 4f6b759

Please sign in to comment.