Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
0cb057a
[Kinetics] Remove 'experimental' warnings for new classes
ischoegl Mar 19, 2021
12543ad
[Kinetics] Create ElementaryReaction2 class
ischoegl Mar 19, 2021
dc609bc
[Kinetics] Implement Reaction constructors for AnyMap
ischoegl Mar 20, 2021
5428206
[Kinetics] Separate ReactionFactory for AnyMap and XML
ischoegl Mar 20, 2021
aeb47a1
[Kinetics] Return boolean from Reaction2::setParameters
ischoegl Mar 20, 2021
d8e56de
[Kinetics] Ensure integration works
ischoegl Mar 20, 2021
54589fd
[CI] Create test/kinetics/kineticsFromScratch2.cpp
ischoegl Mar 19, 2021
1798508
[Kinetics] Expose ElementaryReaction2 to Python
ischoegl Mar 20, 2021
1d532c8
[CI] Update Python tests
ischoegl Mar 20, 2021
45b9067
[CI] Accommodate new names in conversion tests
ischoegl Mar 20, 2021
ec98014
[Kinetics] Rename Reaction2 to Reaction3 to reflect Cantera version
ischoegl Mar 20, 2021
fea207e
[Kinetics] Fix shadowed member variable
ischoegl Mar 21, 2021
6a2157e
[Kinetics] Add setParameters to ElementaryReaction3
ischoegl Apr 25, 2021
cedceab
[Kinetics] Create ThreeBodyReaction3
ischoegl Mar 21, 2021
79bd243
[Kinetics] Expose ThreeBodyReaction3 to Python
ischoegl Mar 21, 2021
c302278
[Kinetics] Add getParameters to ThreeBodyReaction3
ischoegl Apr 25, 2021
5beeae1
[Kinetics] Implement ThirdBody handling for ThreeBodyReaction3
ischoegl Mar 21, 2021
9190de7
[Kinetics] Update cython interface
ischoegl Mar 21, 2021
f9ce6f0
[CI] Add unit tests for ThreeBodyReaction3
ischoegl Mar 21, 2021
dbaae56
[Kinetics] Switch ThreeBodyReaction to ThreeBodyReaction3
ischoegl Mar 21, 2021
d750f95
[Kinetics] Simplify Python constructors
ischoegl Mar 22, 2021
62e55b9
[CI] Add unit tests for conversion from YAML
ischoegl Mar 22, 2021
4800843
[Kinetics] Prepare for unified handling of third-body concentrations
ischoegl Mar 22, 2021
504a02a
[CI] Switch test_reaction.py to kineticsfromscratch.yaml
ischoegl Mar 22, 2021
cab1687
[Kinetics] Add __init__ to PlogReaction and ChebyshevReaction
ischoegl Mar 22, 2021
88b34b0
[Kinetics] Switch ArrheniusRate to customary activation energy units
ischoegl Mar 22, 2021
0255e6d
[samples] Add XML benchmark to custom_reaction.py
ischoegl Mar 22, 2021
b2ced6d
[Kinetics] Implement PlogRate
ischoegl Mar 23, 2021
f5a31e2
[Kinetics] Implement PlogReaction3
ischoegl Mar 23, 2021
7df04c3
[Kinetics] Streamline MultiRate update mechanism
ischoegl Mar 23, 2021
08ba915
[Kinetics] Expose PlogRate and PlogReaction3 to Python
ischoegl Mar 23, 2021
012d9de
[Kinetics] Make PlogReaction3 default for YAML import
ischoegl Mar 23, 2021
358b454
[Kinetics] Introduce ReactionRate::validate
ischoegl Mar 23, 2021
28bbee2
[Kinetics] Simplify validation checks
ischoegl Mar 23, 2021
220c1fc
[Kinetics] Simplify setParameters
ischoegl Mar 24, 2021
5f94dcd
[CI] Update unit tests
ischoegl Mar 24, 2021
394697d
[Kinetics] Implement ChebyshevRate3 wrapper for ChebyshevRate
ischoegl Mar 24, 2021
4c5d1a8
[Kinetics] Implement ChebyshevReaction3
ischoegl Mar 24, 2021
985a52d
[Kinetics] Expose ChebyshevReaction3 to Python
ischoegl Mar 24, 2021
275144c
[Kinetics] Make ChebyshevReaction3 default for YAML import
ischoegl Mar 24, 2021
fde3b41
[Kinetics] Implement getParameters for ChebyshevReaction3
ischoegl Apr 26, 2021
fbcec15
[Kinetics] Deprecate ChebyshevRate in favor of Chebyshev
ischoegl Mar 24, 2021
de57371
[Kinetics] Construct ArrheniusRate from Arrhenius
ischoegl Mar 25, 2021
81a7938
[Kinetics] Remove unused and mark deprecated Python methods
ischoegl Mar 25, 2021
4e98794
[Kinetics] Update documentation for Reaction3 classes
ischoegl Mar 25, 2021
e169f87
[CI] Add unit tests for Python ReactionRate objects
ischoegl Mar 25, 2021
3a0f32f
[Kinetics] Organize new code sections
ischoegl Apr 27, 2021
357ad68
[Kinetics] Streamline setParameters
ischoegl Apr 27, 2021
97a31c5
[Kinetics] Update docstrings
ischoegl Apr 27, 2021
c6473f4
[Kinetics] Tweak performance of MultiRate
ischoegl Apr 27, 2021
ddaf2a3
[Kinetics] Complete serialization of ReactionRate
ischoegl Apr 27, 2021
c920ccd
[Kinetics] Create ReactionRate objects from Python input_data
ischoegl Apr 27, 2021
a26f834
[CI] Add checks for serialization of new ReactionRate objects
ischoegl Apr 27, 2021
fef7407
[CI] Fix kineticsFromScratch3
ischoegl Apr 27, 2021
26ee443
[Kinetics] Revert to dynamic_cast in MultiRate.h
ischoegl May 8, 2021
e9ce2ae
[Kinetics] Add transitional deprecated Reaction3 properties
ischoegl May 8, 2021
febce88
[Kinetics] Update Plog3 instantiation
ischoegl May 9, 2021
5925fff
[Kinetics] Fix logic for modifyReaction exception
ischoegl May 10, 2021
8457214
[Tests] Add tests for deprecated reaction properties
ischoegl May 8, 2021
52cf2cb
[Kinetics] Save input node within ReactionRate.h
ischoegl May 13, 2021
7a0e8d5
[Kinetics] Add Reaction3::undeclaredThirdBodies
ischoegl May 13, 2021
1413fc5
[Kinetics] Non-configured reaction rates return SNAN
ischoegl May 13, 2021
9cf96d7
[Kinetics] Update serialization of unconfigured reaction rates
ischoegl May 13, 2021
45e4e48
[Tests] Remove deprecation warnings and update unit tests
ischoegl May 10, 2021
e04fa18
Update definition for NaN
ischoegl May 13, 2021
5e2b6ab
[Kinetics] Remove non-void ReactionData constructors & simplify code
ischoegl May 17, 2021
65fd6d1
[Kinetics] Fix Python docstrings
ischoegl May 17, 2021
1ee6add
[Tests] Simplify test_reaction.py
ischoegl May 17, 2021
18c616d
[Kinetics] Use suffix -legacy rather than -old for reaction type names
ischoegl May 17, 2021
57d604a
[Kinetics] Implement *Reaction2 in conjunction with C++ preprocessor
ischoegl May 18, 2021
3773f6a
[Kinetics] Use numbered *Reaction2 labels for old Python framework
ischoegl May 18, 2021
18c906e
[Kinetics] Allow setting of ElementaryReaction.rate using legacy Arrh…
ischoegl May 18, 2021
73a5661
[Kinetics] Clarify Reaction3 docstring
ischoegl May 26, 2021
26ea903
[Kinetics] Prepare ReactionData for holding species information
ischoegl May 31, 2021
bd4f00d
[Kinetics] Always reference underlying C++ type in Python reaction type
ischoegl Jun 2, 2021
c539b0b
[Kinetics] Introduce Python Reaction.uses_legacy flag
ischoegl Jun 2, 2021
18f807d
[Kinetics] Make Python PlogReaction agnostic of framework
ischoegl Jun 2, 2021
1b9faf9
[Kinetics] Make Python ChebyshevReaction agnostic of framework
ischoegl Jun 2, 2021
2af12d0
[Kinetics] Make remaining Python reactions agnostic of framework
ischoegl Jun 2, 2021
9d2db3a
[Kinetics] Simplify handling of legacy methods in Python reactions
ischoegl Jun 2, 2021
bd9d20b
[Kinetics] Streamline code based on review comments
ischoegl Jun 6, 2021
85fa600
[Kinetics] Remove transitional Reaction3 object
ischoegl Jun 6, 2021
bed7982
[Kinetics] Make rate constructor keyword consistent
ischoegl Jun 6, 2021
952d113
[Kinetics] Introduce Reaction.from_dict in Python
ischoegl Jun 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions include/cantera/kinetics/BulkKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

#include "Kinetics.h"
#include "RateCoeffMgr.h"
#include "ThirdBodyCalc.h"
#include "cantera/kinetics/MultiRate.h"

namespace Cantera
{

class ElementaryReaction;
class ElementaryReaction2;

//! Partial specialization of Kinetics for chemistry in a single bulk phase
class BulkKinetics : public Kinetics
Expand Down Expand Up @@ -45,9 +46,11 @@ class BulkKinetics : public Kinetics
virtual void setMultiplier(size_t i, double f);
virtual void invalidateCache();

void addThirdBody(shared_ptr<Reaction> r);

protected:
virtual void addElementaryReaction(ElementaryReaction& r);
virtual void modifyElementaryReaction(size_t i, ElementaryReaction& rNew);
virtual void addElementaryReaction(ElementaryReaction2& r);
virtual void modifyElementaryReaction(size_t i, ElementaryReaction2& rNew);

//! Vector of rate handlers
std::vector<unique_ptr<MultiRateBase>> m_bulk_rates;
Expand All @@ -62,12 +65,19 @@ class BulkKinetics : public Kinetics
//! valued stoichiometries.
vector_fp m_dn;

//! Activity concentrations, as calculated by
//! ThermoPhase::getActivityConcentrations
ThirdBodyCalc m_multi_concm; //!< used with MultiRate evaluator
vector_fp concm_multi_values; //!< concentrations of third-body collision partners
std::vector<size_t> m_multi_indices; //!< reaction indices

//! Third body concentrations
vector_fp m_concm;

//! Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations
vector_fp m_act_conc;

//! Physical concentrations, as calculated by ThermoPhase::getConcentrations
vector_fp m_phys_conc;

vector_fp m_grt;

bool m_ROP_ok;
Expand Down
24 changes: 16 additions & 8 deletions include/cantera/kinetics/GasKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define CT_GASKINETICS_H

#include "BulkKinetics.h"
#include "ThirdBodyCalc.h"
#include "FalloffMgr.h"
#include "Reaction.h"

Expand Down Expand Up @@ -87,7 +86,7 @@ class GasKinetics : public BulkKinetics
ThirdBodyCalc m_falloff_concm;

Rate1<Plog> m_plog_rates;
Rate1<ChebyshevRate> m_cheb_rates;
Rate1<Chebyshev> m_cheb_rates;
Rate1<BlowersMasel> m_blowersmasel_rates;

//! @name Reaction rate data
Expand All @@ -107,16 +106,25 @@ class GasKinetics : public BulkKinetics

void processFalloffReactions();

void addThreeBodyReaction(ThreeBodyReaction& r);
// functions marked as deprecated below are only used for XML import and
// transitional reaction types are marked as '-legacy'

//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void addThreeBodyReaction(ThreeBodyReaction2& r);
void addFalloffReaction(FalloffReaction& r);
void addPlogReaction(PlogReaction& r);
void addChebyshevReaction(ChebyshevReaction& r);
//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void addPlogReaction(PlogReaction2& r);
//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void addChebyshevReaction(ChebyshevReaction2& r);
void addBlowersMaselReaction(BlowersMaselReaction& r);

void modifyThreeBodyReaction(size_t i, ThreeBodyReaction& r);
//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void modifyThreeBodyReaction(size_t i, ThreeBodyReaction2& r);
void modifyFalloffReaction(size_t i, FalloffReaction& r);
void modifyPlogReaction(size_t i, PlogReaction& r);
void modifyChebyshevReaction(size_t i, ChebyshevReaction& r);
//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void modifyPlogReaction(size_t i, PlogReaction2& r);
//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void modifyChebyshevReaction(size_t i, ChebyshevReaction2& r);
void modifyBlowersMaselReaction(size_t i, BlowersMaselReaction& r);

//! Update the equilibrium constants in molar units.
Expand Down
62 changes: 33 additions & 29 deletions include/cantera/kinetics/MultiRate.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/**
* @file MultiRate.h
*
* @warning This file is an experimental part of the %Cantera API and
* may be changed or removed without notice.
*/

// This file is part of Cantera. See License.txt in the top-level directory or
Expand All @@ -26,9 +23,6 @@ namespace Cantera
* which can be updated using information of a single `ThermoPhase`.
* `InterfaceKinetics` will require access to an entire `Kinetics` object
* or the underlying `vector<ThermoPhase*>` vector (e.g. `m_thermo`).
*
* @warning This class is an experimental part of the %Cantera API and
* may be changed or removed without notice.
*/
class MultiRateBase
{
Expand All @@ -47,77 +41,87 @@ class MultiRateBase
virtual bool replace(const size_t rxn_index,
ReactionRateBase& rate) = 0;

//! Update number of species
//! @param n_species number of species
virtual void resizeSpecies(size_t n_species) = 0;

//! Evaluate all rate constants handled by the evaluator
//! @param bulk object representing bulk phase
//! @param kf array of rate constants
virtual void getRateConstants(const ThermoPhase& bulk,
double* kf) const = 0;
double* kf, double* concm) const = 0;
Comment thread
ischoegl marked this conversation as resolved.

//! Update data common to reaction rates of a specific type
//! @param bulk object representing bulk phase
virtual void update(const ThermoPhase& bulk) = 0;
//! @param concm effective third-body concentrations
//! @TODO enable more generic handling of non-trivial concentration dependencies
virtual void update(const ThermoPhase& bulk, double* concm) = 0;
};


//! A class template handling all reaction rates specific to `BulkKinetics`.
/**
* @warning This class is an experimental part of the %Cantera API and
* may be changed or removed without notice.
*/
template <class RateType, class DataType>
class MultiBulkRates final : public MultiRateBase
{
public:
virtual void add(const size_t rxn_index,
ReactionRateBase& rate) override {
m_indices[rxn_index] = m_rates.size();
m_rates.push_back(dynamic_cast<RateType&>(rate));
m_rxn.push_back(rxn_index);
ReactionRateBase& rate) override
{
m_indices[rxn_index] = m_rxn_rates.size();
m_rxn_rates.emplace_back(rxn_index, dynamic_cast<RateType&>(rate));
}

virtual bool replace(const size_t rxn_index,
ReactionRateBase& rate) override {
if (!m_rates.size()) {
ReactionRateBase& rate) override
{
if (!m_rxn_rates.size()) {
throw CanteraError("MultiBulkRate::replace",
"Invalid operation: cannot replace rate object "
"in empty rate handler.");
} else if (typeid(rate) != typeid(RateType)) {
throw CanteraError("MultiBulkRate::replace",
"Invalid operation: cannot replace rate object of type '{}' "
"with a new rate of type '{}'.",
m_rates[0].type(), rate.type());
m_rxn_rates.at(0).second.type(), rate.type());
}
if (m_indices.find(rxn_index) != m_indices.end()) {
size_t j = m_indices[rxn_index];
m_rates[j] = dynamic_cast<RateType&>(rate);
m_rxn_rates.at(j).second = dynamic_cast<RateType&>(rate);
return true;
}
return false;
}

virtual void resizeSpecies(size_t n_species)
{
m_shared.resizeSpecies(n_species);
}

virtual void getRateConstants(const ThermoPhase& bulk,
double* kf) const override {
for (size_t i = 0; i < m_rates.size(); i++) {
kf[m_rxn[i]] = m_rates[i].eval(m_shared);
double* kf, double* concm) const override
{
for (const auto& rxn : m_rxn_rates) {
kf[rxn.first] = rxn.second.eval(m_shared, concm[rxn.first]);
}
}

virtual void update(const ThermoPhase& bulk) override {
virtual void update(const ThermoPhase& bulk, double* concm) override
{
// update common data once for each reaction type
m_shared.update(bulk);
if (RateType::uses_update()) {
if (RateType::usesUpdate()) {
// update reaction-specific data for each reaction. This loop
// is efficient as all function calls are de-virtualized, and
// all of the rate objects are contiguous in memory
for (auto& rate : m_rates) {
rate.update(m_shared, bulk);
for (auto& rxn : m_rxn_rates) {
rxn.second.update(m_shared, concm[rxn.first]);
}
}
}

protected:
std::vector<RateType> m_rates; //! Reaction rate objects
std::vector<size_t> m_rxn; //! Index within overall rate vector
//! Vector of pairs of reaction rates indices and reaction rates
std::vector<std::pair<size_t, RateType>> m_rxn_rates;
std::map<size_t, size_t> m_indices; //! Mapping of indices
DataType m_shared;
};
Expand Down
Loading