Ignition Batch Jobs

YAML Defaults

# default parameters for the `ignition` module
initial:
  T: 1000. kelvin # temperature
  P: 1. atmosphere # pressure
  phi: 1. # equivalence ratio
  fuel: H2
  oxidizer: O2:1.,AR:3.76
chemistry:
  mechanism: h2o2.yaml
settings:
  delta_t: 1.e-5
  max_time_step: 1.e-5
  n_points: 500
  atol: 1.e-15
  rtol: 1.e-12

Simulation Module

"""Simulation module running ignition test

Code is based on stock Cantera example `reactor1.py
<https://cantera.org/examples/python/reactors/reactor1.py.html>`_,
where differences are:

* Parameter values are passed using a :any:`Parser` object
* Content is broken down into methods ``defaults`` and ``run``
"""
import warnings

from ctwrap import Parser


# pylint: disable=no-member
try:
    import cantera as ct
except ImportError as err:
    ct = ImportError('Method requires a working cantera installation.')


def defaults():
    """Returns Parser object containing default configuration"""
    return Parser.from_yaml('ignition.yaml', defaults=True)


def run(chemistry=None, initial=None, settings=None):
    """Function handling reactor simulation.

    The function uses the class 'ctwrap.Parser' in conjunction with 'pint.Quantity'
    for handling and conversion of units.

    Arguments:
        chemistry  (Parser): overloads 'defaults.chemistry'
        initial    (Parser): overloads 'defaults.initial'
        settings (Parser): overloads 'defaults.settings'

    Returns:
        Cantera SolutionArray
    """

    # initialize gas object
    gas = ct.Solution(chemistry.mechanism)

    # set temperature, pressure, and composition
    T = initial.T.m_as('kelvin')
    P = initial.P.m_as('pascal')
    gas.TP = T, P
    phi = initial['phi']
    gas.set_equivalence_ratio(phi, initial['fuel'], initial['oxidizer'])

    # define a reactor network
    reactor = ct.IdealGasConstPressureReactor(gas)
    sim = ct.ReactorNet([reactor])

    delta_T_max = 20.
    reactor.set_advance_limit('temperature', delta_T_max)

    # set simulation parameters
    sim.atol = settings['atol']
    sim.rtol = settings['rtol']
    sim.max_time_step = settings['max_time_step']
    delta_t = settings['delta_t']
    n_points = settings['n_points']

    # define SolutionArray and run simulation
    states = ct.SolutionArray(gas, extra=['t'])
    time = sim.time

    for _ in range(n_points):

        time += delta_t
        sim.advance(time)
        states.append(reactor.thermo.state, t=time)

    return states


if __name__ == "__main__":
    """ Main function """
    config = defaults()
    out = run(**config)

Running a Batch Simulation

An example for a batch simulation is given by the YAML configuration

# YAML file example for the `ignition` module
# file specifes a parameter variation of the equivalence ratio
strategy:
  sequence:
    initial.phi: [0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8]
defaults:
  initial:
    T: 1000. kelvin # temperature
    P: 101325. pascal # pressure
    phi: 1. # equivalence ratio
    fuel: H2
    oxidizer: O2:1,AR:5
  chemistry:
    mechanism: h2o2.yaml
  settings:
    delta_t: .5e-6
    max_time_step: .2e-9
    n_points: 1000
    atol: 1.e-18
    rtol: 1.e-15
output:
  format: h5
  force: True
ctwrap: 0.3.0

A parallel batch job for ignition calculations using the configuration and the simulation module above can be run as:

$ ctwrap run ignition ignition.yaml --parallel

Results are written to a single file ignition.h5.