Skip to content

Commit

Permalink
Disable balance check for photolysis reactions (#6)
Browse files Browse the repository at this point in the history
- Disable balance check for photolysis reactions when there are more than one products
- Any photolysis product must have a unit stoichiometric coefficient
  • Loading branch information
chengcli committed Apr 26, 2024
1 parent a598366 commit c0040ef
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/cantera/kinetics/Kinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ class Kinetics
virtual void modifyProductStoichCoeff(size_t i, Composition const& comp);

virtual bool isPhotolysis(size_t i) const {
throw NotImplementedError("Kinetics::isPhotolysis");
return false;
}

//! @}
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/kinetics/StoichManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,10 @@ class StoichManagerN
* expression involving the species vector.
* @param stoich This is used to handle fractional stoichiometric
* coefficients on the product side of irreversible reactions.
* @param frac Specify that the reaction is a fractional reaction (photolysis).
*/
void add(size_t rxn, const vector<size_t>& k, const vector<double>& order,
const vector<double>& stoich) {
const vector<double>& stoich, bool frac = false) {
if (order.size() != k.size()) {
throw CanteraError(
"StoichManagerN::add()", "size of order and species arrays differ");
Expand All @@ -680,7 +681,6 @@ class StoichManagerN
throw CanteraError(
"StoichManagerN::add()", "size of stoich and species arrays differ");
}
bool frac = false;
for (size_t n = 0; n < stoich.size(); n++) {
m_coeffList.emplace_back(
static_cast<int>(k[n]), static_cast<int>(rxn), stoich[n]);
Expand Down
3 changes: 2 additions & 1 deletion src/kinetics/Kinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ bool Kinetics::addReaction(shared_ptr<Reaction> r, bool resize)

m_reactantStoich.add(irxn, rk, rorder, rstoich);
// product orders = product stoichiometric coefficients
m_productStoich.add(irxn, pk, pstoich, pstoich);
bool frac = isPhotolysis(irxn) && r->products.size() > 1;
m_productStoich.add(irxn, pk, pstoich, pstoich, frac);
if (r->reversible) {
m_revProductStoich.add(irxn, pk, pstoich, pstoich);
}
Expand Down
12 changes: 12 additions & 0 deletions src/kinetics/Reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,18 @@ void Reaction::checkBalance(const Kinetics& kin) const
{
Composition balr, balp;

// disable balance check for photolysis reactions with more than one product
if (products.size() > 1 && type() == "Photolysis") {
for (const auto& [name, stoich] : products) {
if (stoich != 1.0) {
throw InputFileError("Reaction::checkBalance", input,
"Every product of a photolysis reaction '{}' must have "
"a unit stoichiometric coefficient", equation());
}
}
return;
}

// iterate over products and reactants
for (const auto& [name, stoich] : products) {
const ThermoPhase& ph = kin.speciesPhase(name);
Expand Down
12 changes: 6 additions & 6 deletions test/data/ch4_photolysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ species:
model: constant-cp

reactions:
- equation: CH4 => 0.2 CH4 + 0.2 CH3 + 0.2 (1)CH2 + 0.2 (3)CH2 + 0.2 CH + 0.4 H2 + 0.8 H
- equation: CH4 => CH4 + CH3 + (1)CH2 + (3)CH2 + CH + H2 + H
type: photolysis
branches:
- name: b1 # 0.2
- name: b1
product: "CH4:1"
- name: b2 # 0.2
- name: b2
product: "CH3:1 H:1"
- name: b3 # 0.2
- name: b3
product: "(1)CH2:1 H2:1"
- name: b4 # 0.2
- name: b4
product: "(3)CH2:1 H:2"
- name: b5 # 0.2
- name: b5
product: "CH:1 H2:1 H:1"
cross-section:
- format: KINETICS7
Expand Down

0 comments on commit c0040ef

Please sign in to comment.