Skip to content

Commit

Permalink
[Kinetics] Implement InterfaceData
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 21, 2022
1 parent 56cff89 commit d068924
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/cantera/kinetics/MultiRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class MultiBulkRate final : public MultiRateBase
m_shared.update(T, extra);
}

virtual void update(double T, vector_fp extra) override {
m_shared.update(T, extra);
}

virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override {
return m_shared.update(bulk, kin);
}
Expand Down
6 changes: 6 additions & 0 deletions include/cantera/kinetics/MultiRateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class MultiRateBase
//! @param extra extra parameter (depends on parameterization)
virtual void update(double T, double extra) = 0;

//! Update common reaction rate data based on temperature and extra parameter.
//! Only used in conjunction with evalSingle and ReactionRate::eval
//! @param T temperature [K]
//! @param extra extra parameter (depends on parameterization)
virtual void update(double T, vector_fp extra) = 0;

//! Update data common to reaction rates of a specific type.
//! This update mechanism is used by Kinetics reaction rate evaluators.
//! @param bulk object representing bulk phase
Expand Down
57 changes: 57 additions & 0 deletions include/cantera/kinetics/ReactionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ struct ReactionData
*/
virtual void update(double T, double extra);

//! Update data container based on temperature *T* and an *extra* parameter
/**
* Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
* This method allows for testing of a reaction rate expression outside of
* Kinetics reaction rate evaluators.
*/
virtual void update(double T, vector_fp values);

//! Update data container based on *bulk* phase state
/**
* This update mechanism is used by Kinetics reaction rate evaluators.
Expand Down Expand Up @@ -110,6 +118,8 @@ struct TwoTempPlasmaData : public ReactionData

virtual void update(double T, double Te) override;

using ReactionData::update;

virtual void updateTe(double Te);

virtual void invalidateCache() override {
Expand Down Expand Up @@ -138,6 +148,8 @@ struct BlowersMaselData : public ReactionData

virtual void update(double T, double deltaH) override;

using ReactionData::update;

virtual void resize(size_t n_species, size_t n_reactions) override {
m_grt.resize(n_species, 0.);
dH.resize(n_reactions, 0.);
Expand Down Expand Up @@ -169,6 +181,8 @@ struct FalloffData : public ReactionData

virtual void update(double T, double M) override;

using ReactionData::update;

//! Perturb third-body concentration vector of data container
/**
* The method is used for the evaluation of numerical derivatives.
Expand Down Expand Up @@ -219,6 +233,8 @@ struct PlogData : public ReactionData

virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

using ReactionData::update;

//! Perturb pressure of data container
/**
* The method is used for the evaluation of numerical derivatives.
Expand Down Expand Up @@ -260,6 +276,8 @@ struct ChebyshevData : public ReactionData

virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

using ReactionData::update;

//! Perturb pressure of data container
/**
* The method is used for the evaluation of numerical derivatives.
Expand All @@ -281,6 +299,45 @@ struct ChebyshevData : public ReactionData
double m_pressure_buf; //!< buffered pressure
};


//! Data container holding shared data specific to InterfaceRate
/**
* The data container `InterfaceData` holds precalculated data common to
* all `InterfaceRate` objects.
*/
struct InterfaceData : public ReactionData
{
InterfaceData();

virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

virtual void update(double T) override;

virtual void update(double T, vector_fp values) override;

using ReactionData::update;

virtual void resize(size_t n_species, size_t n_reactions) override {
m_actConc.resize(n_species, 0.);
coverages.resize(n_species, 0.);
ready = true;
}

bool ready; //!< boolean indicating whether vectors are accessible
vector_fp coverages; //!< vector holding surface coverages

protected:
int m_state_mf_number; //!< integer that is incremented when composition changes

//! Array of activity concentrations for each surface species
/*!
* An array of activity concentrations \f$ Ca_k \f$ that are defined
* such that \f$ a_k = Ca_k / C^0_k, \f$ where \f$ C^0_k \f$ is a standard
* concentration.
*/
vector_fp m_actConc;
};

}

#endif
47 changes: 46 additions & 1 deletion src/kinetics/ReactionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "cantera/kinetics/ReactionData.h"
#include "cantera/kinetics/Kinetics.h"
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/thermo/SurfPhase.h"
#include "cantera/base/ctexceptions.h"

namespace Cantera
Expand All @@ -14,7 +15,13 @@ namespace Cantera
void ReactionData::update(double T, double extra)
{
throw NotImplementedError("ReactionData::update",
"ReactionData type does not use extra argument.");
"ReactionData type does not use extra scalar argument.");
}

void ReactionData::update(double T, vector_fp extra)
{
throw NotImplementedError("ReactionData::update",
"ReactionData type does not use extra vector argument.");
}

void ReactionData::perturbTemperature(double deltaT)
Expand Down Expand Up @@ -263,4 +270,42 @@ void ChebyshevData::restore()
m_pressure_buf = -1.;
}

InterfaceData::InterfaceData()
: ready(false)
, m_state_mf_number(-1)
{
coverages.resize(1, NAN);
}

void InterfaceData::update(double T)
{
throw CanteraError("InterfaceData::update",
"Missing state information: 'InterfaceData' requires species coverages.");
}

void InterfaceData::update(double T, vector_fp values)
{
ReactionData::update(T);
coverages = values;
}

bool InterfaceData::update(const ThermoPhase& bulk, const Kinetics& kin)
{
int mf = bulk.stateMFNumber();
double T = bulk.temperature();
bool changed = false;
if (T != temperature) {
ReactionData::update(T);
changed = true;
}
if (changed || mf != m_state_mf_number) {
bulk.getActivityConcentrations(coverages.data());
const auto& surf = dynamic_cast<const SurfPhase&>(bulk);
surf.getCoverages(coverages.data());
m_state_mf_number = mf;
changed = true;
}
return changed;
}

}

0 comments on commit d068924

Please sign in to comment.