
:html_theme.sidebar_secondary.remove:

.. py:currentmodule:: cantera


.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/matlab/catalytic_combustion.m"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_matlab_catalytic_combustion.m>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_matlab_catalytic_combustion.m:

Catalytic combustion of a stagnation flow on a platinum surface
===============================================================


This script solves a catalytic combustion problem. This example is equivalent to the
Python :doc:`catalytic_combustion.py <../python/onedim/catalytic_combustion>` example.

A stagnation flow is set up, with a gas inlet 10 cm from a platinum surface at 900 K.
The lean, premixed methane/air mixture enters at ~ 6 cm/s (0.06 kg/m2/s), and burns
catalytically on the platinum surface. Gas-phase chemistry is included too, and has
some effect very near the surface.

The catalytic combustion mechanism is from Deutschmann et al., 26th
Symp. (Intl.) on Combustion,1996 pp. 1747-1754

Requires: cantera >= 3.2.0

.. tags:: Matlab, combustion, catalysis, 1D flow, surface chemistry

.. GENERATED FROM PYTHON SOURCE LINES 17-19

Problem Definition
------------------

.. GENERATED FROM PYTHON SOURCE LINES 21-24

.. code-block:: Matlab

    help catalytic_combustion;

    t0 = cputime;  % record the starting time

.. GENERATED FROM PYTHON SOURCE LINES 25-26

**Set parameter values**

.. GENERATED FROM PYTHON SOURCE LINES 28-33

.. code-block:: Matlab

    p = ct.OneAtm;  % pressure
    tinlet = 300.0;  % inlet temperature
    tsurf = 900.0;  % surface temperature
    mdot = 0.06;  % kg/m^2/s
    transport = 'mixture-averaged';  % transport model

.. GENERATED FROM PYTHON SOURCE LINES 34-36

Solve first for a hydrogen/air case for use as the initial estimate for
the methane/air case.

.. GENERATED FROM PYTHON SOURCE LINES 38-54

.. code-block:: Matlab

    % composition of the inlet premixed gas for the hydrogen/air case
    comp1 = 'H2:0.05, O2:0.21, N2:0.78, AR:0.01';

    % composition of the inlet premixed gas for the methane/air case
    comp2 = 'CH4:0.095, O2:0.21, N2:0.78, AR:0.01';

    % the initial grid, in meters. The inlet/surface separation is 10 cm.
    initial_grid = [0.0, 0.02, 0.04, 0.06, 0.08, 0.1];  % m

    % numerical parameters
    tol_ss = {1.0e-8 1.0e-14};  % {rtol atol} for steady-state problem
    tol_ts = {1.0e-4 1.0e-9};  % {rtol atol} for time stepping

    loglevel = 1;  % amount of diagnostic output (0 to 5)

    refine_grid = 1;  % 1 to enable refinement, 0 to disable

.. GENERATED FROM PYTHON SOURCE LINES 55-63

**Create the gas object**

This object will be used to evaluate all thermodynamic, kinetic,
and transport properties

The gas phase will be taken from the definition of phase ``gas`` in
input file ``ptcombust.yaml``, which is a stripped-down version of
GRI-Mech 3.0.

.. GENERATED FROM PYTHON SOURCE LINES 65-67

.. code-block:: Matlab

    gas = ct.Solution('ptcombust.yaml', 'gas', transport);
    gas.TPX = {tinlet, p, comp1};

.. GENERATED FROM PYTHON SOURCE LINES 68-75

**Create the interface object**

This object will be used to evaluate all surface chemical production
rates. It will be created from the interface definition ``Pt_surf``
in input file ``ptcombust.yaml``, which implements the reaction
mechanism of Deutschmann et al., 1995 for catalytic combustion on
platinum.

.. GENERATED FROM PYTHON SOURCE LINES 77-79

.. code-block:: Matlab

    surf_phase = ct.Interface('ptcombust.yaml', 'Pt_surf', gas);
    surf_phase.TP = {tsurf, surf_phase.P};

.. GENERATED FROM PYTHON SOURCE LINES 80-83

Integrate the coverage equations in time for 1 s, holding the gas
composition fixed to generate a good starting estimate for the
coverages.

.. GENERATED FROM PYTHON SOURCE LINES 85-87

.. code-block:: Matlab

    surf_phase.coverages = 'PT(S): 0.5, O(S): 0.5'
    surf_phase.advanceCoverages(1.0);

.. GENERATED FROM PYTHON SOURCE LINES 88-93

The two objects we just created are independent of the problem
type -- they are useful in zero-D simulations, 1-D simulations,
etc. Now we turn to creating the objects that are specifically
for 1-D simulations. These will be 'stacked' together to create
the complete simulation.

.. GENERATED FROM PYTHON SOURCE LINES 95-100

**Create the inlet**

The temperature, mass flux, and composition (relative molar) may be
specified. This object provides the inlet boundary conditions for
the flow equations.

.. GENERATED FROM PYTHON SOURCE LINES 102-108

.. code-block:: Matlab

    inlt = ct.oneD.Inlet(gas, 'inlet');

    % set the inlet parameters. Start with comp1 (hydrogen/air)
    inlt.T = tinlet;
    inlt.X = comp1;
    inlt.massFlux = mdot;

.. GENERATED FROM PYTHON SOURCE LINES 109-114

**Create the flow object**

The flow object is responsible for evaluating the 1D governing
equations for the flow. We will initialize it with the gas
object, and assign it the name ``flow``.

.. GENERATED FROM PYTHON SOURCE LINES 116-123

.. code-block:: Matlab

    flow = ct.oneD.AxisymmetricFlow(gas, 'flow');

    % set some parameters for the flow
    flow.P = p;
    flow.grid = initial_grid;
    flow.setSteadyTolerances(tol_ss{:});
    flow.setTransientTolerances(tol_ts{:});

.. GENERATED FROM PYTHON SOURCE LINES 124-131

**Create the surface**

This object provides the surface boundary conditions for the flow
equations. By supplying object ``surface_phase`` as an argument, the
coverage equations for its surface species will be added to the
equation set, and used to compute the surface production rates of
the gas-phase species.

.. GENERATED FROM PYTHON SOURCE LINES 133-135

.. code-block:: Matlab

    surf = ct.oneD.ReactingSurface(surf_phase, 'surface');
    surf.T = tsurf;

.. GENERATED FROM PYTHON SOURCE LINES 136-140

**Create the stack**

Once the component parts have been created, they can be assembled
to create the 1D simulation.

.. GENERATED FROM PYTHON SOURCE LINES 142-160

.. code-block:: Matlab

    stack = ct.oneD.Sim1D({inlt, flow, surf});

    % set the initial profiles.
    flow.setProfile('velocity', [0.0, 1.0], [0.06, 0.0]);
    flow.setFlatProfile('spreadRate', 0.0)
    flow.setProfile('T', [0.0, 1.0], [tinlet, tsurf]);
    names = gas.speciesNames;

    for k = 1:gas.nSpecies
        y = inlt.massFraction(k);
        flow.setProfile(names{k}, [0. 1.], [y y]);
    end

    fprintf("Profile used for initial guess:\n\n")
    flow.info()

    stack.setTimeStep(1.0e-5, [1, 3, 6, 12]);
    stack.setMaxJacAge(4, 5);

.. GENERATED FROM PYTHON SOURCE LINES 161-165

Solution
--------

Start with the energy equation on

.. GENERATED FROM PYTHON SOURCE LINES 166-167

.. code-block:: Matlab

    flow.energyEnabled = true;

.. GENERATED FROM PYTHON SOURCE LINES 168-170

Disable the surface coverage equations, and turn off all gas and
surface chemistry

.. GENERATED FROM PYTHON SOURCE LINES 172-175

.. code-block:: Matlab

    surf.coverageEnabled = false;
    surf_phase.setMultiplier(0.0);
    gas.setMultiplier(0.0);

.. GENERATED FROM PYTHON SOURCE LINES 176-177

Solve the problem, refining the grid if needed

.. GENERATED FROM PYTHON SOURCE LINES 178-179

.. code-block:: Matlab

    stack.solve(1, refine_grid);

.. GENERATED FROM PYTHON SOURCE LINES 180-182

Now turn on the surface coverage equations, and turn the
chemistry on slowly

.. GENERATED FROM PYTHON SOURCE LINES 184-192

.. code-block:: Matlab

    surf.coverageEnabled = true;

    for iter = 1:6
        mult = 10.0^(iter - 6);
        surf_phase.setMultiplier(mult);
        gas.setMultiplier(mult);
        stack.solve(1, refine_grid);
    end

.. GENERATED FROM PYTHON SOURCE LINES 193-195

At this point, we should have the solution for the hydrogen/air
problem. Now switch the inlet to the methane/air composition.

.. GENERATED FROM PYTHON SOURCE LINES 196-197

.. code-block:: Matlab

    inlt.X = comp2;

.. GENERATED FROM PYTHON SOURCE LINES 198-199

Set more stringent grid refinement criteria

.. GENERATED FROM PYTHON SOURCE LINES 200-201

.. code-block:: Matlab

    flow.setRefineCriteria(100.0, 0.15, 0.2);

.. GENERATED FROM PYTHON SOURCE LINES 202-203

Solve the problem for the final time

.. GENERATED FROM PYTHON SOURCE LINES 204-205

.. code-block:: Matlab

    stack.solve(loglevel, refine_grid);

.. GENERATED FROM PYTHON SOURCE LINES 206-209

**Show statistics and display results**

Show statistics

.. GENERATED FROM PYTHON SOURCE LINES 211-215

.. code-block:: Matlab

    stack.writeStats;
    elapsed = cputime - t0;
    e = sprintf('Elapsed CPU time: %10.4g', elapsed);
    disp(e);

.. GENERATED FROM PYTHON SOURCE LINES 216-217

Display solution

.. GENERATED FROM PYTHON SOURCE LINES 219-227

.. code-block:: Matlab

    fprintf("\nFlow domain profile after final solution step:\n\n")
    flow.info()

    fprintf("Surface domain after final solution step:\n\n")
    surf.info()

    fprintf("Surface phase coverages after final solution step:\n\n")
    disp(surf_phase.coverages())

.. GENERATED FROM PYTHON SOURCE LINES 228-229

Make plots

.. GENERATED FROM PYTHON SOURCE LINES 231-259

.. code-block:: Matlab

    clf;

    subplot(3, 3, 1);
    plotSolution(flow, 'T', 'Temperature [K]');

    subplot(3, 3, 2);
    plotSolution(flow, 'velocity', 'Axial Velocity [m/s]');

    subplot(3, 3, 3);
    plotSolution(flow, 'spreadRate', 'Radial Velocity / Radius [1/s]');

    subplot(3, 3, 4);
    plotSolution(flow, 'CH4', 'CH4 Mass Fraction');

    subplot(3, 3, 5);
    plotSolution(flow, 'O2', 'O2 Mass Fraction');

    subplot(3, 3, 6);
    plotSolution(flow, 'CO', 'CO Mass Fraction');

    subplot(3, 3, 7);
    plotSolution(flow, 'CO2', 'CO2 Mass Fraction');

    subplot(3, 3, 8);
    plotSolution(flow, 'H2O', 'H2O Mass Fraction');

    subplot(3, 3, 9);
    plotSolution(flow, 'H2', 'H2 Mass Fraction');

.. GENERATED FROM PYTHON SOURCE LINES 260-262

Plotting Utility
----------------

.. GENERATED FROM PYTHON SOURCE LINES 263-271

.. code-block:: Matlab

    function plotSolution(domain, component, titleStr)
        % Utility for plotting a specific solution component
        z = domain.grid;
        x = domain.values(component);
        plot(z, x);
        xlabel('z (m)');
        ylabel(component);
        title(titleStr)
    end

.. _sphx_glr_download_examples_matlab_catalytic_combustion.m:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Matlab source code: catalytic_combustion.m <catalytic_combustion.m>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: catalytic_combustion.zip <catalytic_combustion.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
