Skip to content

Instantly share code, notes, and snippets.

@jiweiqi
Last active February 23, 2021 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiweiqi/21b8d149bd95b97d9ae948ab92e446df to your computer and use it in GitHub Desktop.
Save jiweiqi/21b8d149bd95b97d9ae948ab92e446df to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiweiqi
Copy link
Author

jiweiqi commented Feb 23, 2021

mechanism interpreter, disable Troe

import cantera as ct
import torch
import numpy as np

import reactorch as rt

import json

mech_yaml = 'chem.yaml'

sol = rt.Solution(mech_yaml=mech_yaml, device=torch.device('cpu'),
                  vectorize=True,
                  is_clip=False, is_norm=False, is_wdot_vec=False)

gas = sol.gas

gas.TPY = 1200, ct.one_atm, np.ones(gas.n_species)/gas.n_species

molecular_weights = gas.molecular_weights.tolist()
reactant_stoich_coeffs = gas.reactant_stoich_coeffs()
product_stoich_coeffs = gas.product_stoich_coeffs()
Arrhenius_coeffs = sol.Arrhenius_coeffs
efficiencies_coeffs = sol.efficiencies_coeffs

np.savez(mech_yaml,
         molecular_weights=molecular_weights,
         reactant_stoich_coeffs=reactant_stoich_coeffs,
         product_stoich_coeffs=product_stoich_coeffs,
         reactant_orders=sol.reactant_orders,
         is_reversible=sol.is_reversible,
         Arrhenius_coeffs=Arrhenius_coeffs,
         efficiencies_coeffs=efficiencies_coeffs,
         # Arrhenius_A0=sol.Arrhenius_A0,
         # Arrhenius_b0=sol.Arrhenius_b0,
         # Arrhenius_Ea0=sol.Arrhenius_Ea0,
         # Troe_A=sol.Troe_A,
         # Troe_T1=sol.Troe_T1,
         # Troe_T2=sol.Troe_T2,
         # Troe_T3=sol.Troe_T3
         )

@jiweiqi
Copy link
Author

jiweiqi commented Feb 23, 2021

chem.yaml

generator: cti2yaml
cantera-version: 2.5.0a4
date: Tue, 23 Feb 2021 11:08:23 -0500
input-files: [chem.cti]

units: {length: cm, quantity: mol, activation-energy: cal/mol}

phases:
- name: gas
  thermo: ideal-gas
  elements: [N, H, O, C]
  species: [H2, O2, N2, H, O, OH, HO2, H2O2, H2O]
  kinetics: gas
  reactions: all
  state:
    T: 300.0
    P: 1.01325e+05

species:
- name: H2
  composition: {H: 2}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [2.34433112, 7.98052075e-03, -1.9478151e-05, 2.01572094e-08, -7.37611761e-12,
      -917.935173, 0.683010238]
    - [3.3372792, -4.94024731e-05, 4.99456778e-07, -1.79566394e-10, 2.00255376e-14,
      -950.158922, -3.20502331]
  note: '000000'
- name: O2
  composition: {O: 2}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [3.78245636, -2.99673416e-03, 9.84730201e-06, -9.68129509e-09, 3.24372837e-12,
      -1063.94356, 3.65767573]
    - [3.28253784, 1.48308754e-03, -7.57966669e-07, 2.09470555e-10, -2.16717794e-14,
      -1088.45772, 5.45323129]
  note: '000000'
- name: N2
  composition: {N: 2}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [3.298677, 1.4082404e-03, -3.963222e-06, 5.641515e-09, -2.444854e-12,
      -1020.8999, 3.950372]
    - [2.92664, 1.4879768e-03, -5.68476e-07, 1.0097038e-10, -6.753351e-15,
      -922.7977, 5.980528]
  note: '000000'
- name: H
  composition: {H: 1}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [2.5, 7.05332819e-13, -1.99591964e-15, 2.30081632e-18, -9.27732332e-22,
      2.54736599e+04, -0.446682853]
    - [2.50000001, -2.30842973e-11, 1.61561948e-14, -4.73515235e-18, 4.98197357e-22,
      2.54736599e+04, -0.446682914]
  note: '000000'
- name: O
  composition: {O: 1}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [3.1682671, -3.27931884e-03, 6.64306396e-06, -6.12806624e-09, 2.11265971e-12,
      2.91222592e+04, 2.05193346]
    - [2.56942078, -8.59741137e-05, 4.19484589e-08, -1.00177799e-11, 1.22833691e-15,
      2.92175791e+04, 4.78433864]
  note: '000000'
- name: OH
  composition: {H: 1, O: 1}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [4.12530561, -3.22544939e-03, 6.52764691e-06, -5.79853643e-09, 2.06237379e-12,
      3381.53812, -0.69043296]
    - [2.86472886, 1.05650448e-03, -2.59082758e-07, 3.05218674e-11, -1.33195876e-15,
      3718.85774, 5.70164073]
  note: '000000'
- name: HO2
  composition: {H: 1, O: 2}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [4.30179801, -4.74912051e-03, 2.11582891e-05, -2.42763894e-08, 9.29225124e-12,
      294.80804, 3.71666245]
    - [4.0172109, 2.23982013e-03, -6.3365815e-07, 1.1424637e-10, -1.07908535e-14,
      111.856713, 3.78510215]
  note: '000000'
- name: H2O2
  composition: {H: 2, O: 2}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [4.27611269, -5.42822417e-04, 1.67335701e-05, -2.15770813e-08, 8.62454363e-12,
      -1.77025821e+04, 3.43505074]
    - [4.16500285, 4.90831694e-03, -1.90139225e-06, 3.71185986e-10, -2.87908305e-14,
      -1.78617877e+04, 2.91615662]
  note: '000000'
- name: H2O
  composition: {H: 2, O: 1}
  thermo:
    model: NASA7
    temperature-ranges: [300.0, 1000.0, 5000.0]
    data:
    - [4.19864056, -2.0364341e-03, 6.52040211e-06, -5.48797062e-09, 1.77197817e-12,
      -3.02937267e+04, -0.849032208]
    - [3.03399249, 2.17691804e-03, -1.64072518e-07, -9.7041987e-11, 1.68200992e-14,
      -3.00042971e+04, 4.9667701]
  note: '000000'

reactions:
- equation: H + O2 <=> OH + O  # Reaction 1
  rate-constant: {A: 3.52e+16, b: -0.7, Ea: 1.706979e+04}
- equation: H2 + O <=> OH + H  # Reaction 2
  rate-constant: {A: 5.06e+04, b: 2.67, Ea: 6290.63}
- equation: H2 + OH <=> H2O + H  # Reaction 3
  rate-constant: {A: 1.17e+09, b: 1.3, Ea: 3635.28}
- equation: H2O + O <=> OH + OH  # Reaction 4
  rate-constant: {A: 7.0e+05, b: 2.33, Ea: 1.454828e+04}
- equation: H + H + M <=> H2 + M  # Reaction 5
  type: three-body
  rate-constant: {A: 1.3e+18, b: -1.0, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 12.0}
- equation: H + OH + M <=> H2O + M  # Reaction 6
  type: three-body
  rate-constant: {A: 4.0e+22, b: -2.0, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 12.0}
- equation: O + O + M <=> O2 + M  # Reaction 7
  type: three-body
  rate-constant: {A: 6.17e+15, b: -0.5, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 12.0}
- equation: H + O + M <=> OH + M  # Reaction 8
  type: three-body
  rate-constant: {A: 4.71e+18, b: -1.0, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 12.0}
- equation: O + OH + M <=> HO2 + M  # Reaction 9
  type: three-body
  rate-constant: {A: 8.0e+15, b: 0.0, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 12.0}
- equation: H + O2 + M <=> HO2 + M  # Reaction 10
  type: three-body
  rate-constant: {A: 4.65e+12, b: 0.44, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 16.0}
- equation: HO2 + H <=> OH + OH  # Reaction 11
  rate-constant: {A: 7.08e+13, b: 0.0, Ea: 294.93}
- equation: HO2 + H <=> H2 + O2  # Reaction 12
  rate-constant: {A: 1.66e+13, b: 0.0, Ea: 822.9}
- equation: HO2 + H <=> H2O + O  # Reaction 13
  rate-constant: {A: 3.1e+13, b: 0.0, Ea: 1720.84}
- equation: HO2 + O <=> OH + O2  # Reaction 14
  rate-constant: {A: 2.0e+13, b: 0.0, Ea: 0.0}
- equation: HO2 + OH <=> H2O + O2  # Reaction 15
  rate-constant: {A: 7.0e+12, b: 0.0, Ea: -1094.65}
  duplicate: true
- equation: HO2 + OH <=> H2O + O2  # Reaction 16
  rate-constant: {A: 4.5e+14, b: 0.0, Ea: 1.092973e+04}
  duplicate: true
- equation: OH + OH + M <=> H2O2 + M  # Reaction 17
  type: three-body
  rate-constant: {A: 9.55e+13, b: -0.27, Ea: 0.0}
  efficiencies: {H2: 2.5, H2O: 6.0, H2O2: 6.0}
- equation: HO2 + HO2 <=> H2O2 + O2  # Reaction 18
  rate-constant: {A: 1.03e+14, b: 0.0, Ea: 1.104207e+04}
  duplicate: true
- equation: HO2 + HO2 <=> H2O2 + O2  # Reaction 19
  rate-constant: {A: 1.94e+11, b: 0.0, Ea: -1408.94}
  duplicate: true
- equation: H2O2 + H <=> HO2 + H2  # Reaction 20
  rate-constant: {A: 2.3e+13, b: 0.0, Ea: 7950.05}
- equation: H2O2 + H <=> H2O + OH  # Reaction 21
  rate-constant: {A: 1.0e+13, b: 0.0, Ea: 3585.09}
- equation: H2O2 + OH <=> H2O + HO2  # Reaction 22
  rate-constant: {A: 1.74e+12, b: 0.0, Ea: 1434.03}
  duplicate: true
- equation: H2O2 + OH <=> H2O + HO2  # Reaction 23
  rate-constant: {A: 7.59e+13, b: 0.0, Ea: 7272.94}
  duplicate: true
- equation: H2O2 + O <=> HO2 + OH  # Reaction 24
  rate-constant: {A: 9.63e+06, b: 2.0, Ea: 3991.4}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment