
: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/burner_flame.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_burner_flame.m>`
        to download the full example code.

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

.. _sphx_glr_examples_matlab_burner_flame.m:

Burner-stabilized flat flame
============================


This script simulates a burner-stabilized lean hydrogen-oxygen flame
at low pressure. This example is equivalent to the Python
:doc:`burner_flame.py <../python/onedim/burner_flame>` example.

Requires: cantera >= 3.2.0

.. tags:: Matlab, combustion, 1D flow, burner-stabilized flame, plotting

.. GENERATED FROM PYTHON SOURCE LINES 10-12

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

.. GENERATED FROM PYTHON SOURCE LINES 15-19

.. code-block:: Matlab

    tic
    help burner_flame

    t0 = cputime;  % record the starting time

.. GENERATED FROM PYTHON SOURCE LINES 20-21

**Set parameter values**

.. GENERATED FROM PYTHON SOURCE LINES 23-36

.. code-block:: Matlab

    p = 0.05 * ct.OneAtm;  % pressure
    Tburner = 373.0;  % burner temperature
    mdot = 0.06;  % kg/m^2/s

    rxnmech = 'h2o2.yaml';  % reaction mechanism file
    comp = 'H2:1.5, O2:1, AR:7';  % premixed gas composition

    width = 0.5;
    nz = 11;

    logLevel = 1;  % amount of diagnostic output (0 to 5)
    refineGrid = 1;  % 1 to enable refinement, 0 to disable
    maxJacobianAge = [5, 10];

.. GENERATED FROM PYTHON SOURCE LINES 37-41

**Create the gas object**

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

.. GENERATED FROM PYTHON SOURCE LINES 43-54

.. code-block:: Matlab

    gas = ct.Solution(rxnmech, 'ohmech', 'mixture-averaged');

    % set its state to that of the unburned gas at the burner
    gas.TPX = {Tburner, p, comp};
    rhoIn = gas.massDensity;
    Yin = gas.Y;

    gas.equilibrate('HP');
    rhoOut = gas.massDensity;
    Yout = gas.Y;
    Tad = gas.T;

.. GENERATED FROM PYTHON SOURCE LINES 55-56

**Create the flow object**

.. GENERATED FROM PYTHON SOURCE LINES 58-62

.. code-block:: Matlab

    flow = ct.oneD.UnstrainedFlow(gas, 'flow');
    flow.P = p;
    flow.setupUniformGrid(nz, width, 0.0);
    flow.energyEnabled = false;

.. GENERATED FROM PYTHON SOURCE LINES 63-67

**Create the burner**

The burner is an ``Inlet`` object. The temperature, mass flux,
and composition (relative molar) may be specified.

.. GENERATED FROM PYTHON SOURCE LINES 69-74

.. code-block:: Matlab

    burner = ct.oneD.Inlet(gas, 'burner');
    burner.T = Tburner;
    burner.X = comp;
    burner.massFlux = mdot;
    uIn = mdot / rhoIn;

.. GENERATED FROM PYTHON SOURCE LINES 75-81

**Create the outlet**

The type of flame is determined by the object that terminates
the domain. An ``Outlet`` object imposes zero gradient boundary
conditions for the temperature and mass fractions, and zero
radial velocity and radial pressure gradient.

.. GENERATED FROM PYTHON SOURCE LINES 83-85

.. code-block:: Matlab

    out = ct.oneD.Outlet(gas, 'out');
    uOut = mdot / rhoOut;

.. GENERATED FROM PYTHON SOURCE LINES 86-90

**Create the flame object**

Once the component parts have been created, they can be assembled
to create the flame object.

.. GENERATED FROM PYTHON SOURCE LINES 91-103

.. code-block:: Matlab

    fl = ct.oneD.Sim1D({burner, flow, out});
    fl.setMaxJacAge(maxJacobianAge(1), maxJacobianAge(2));

    % Supply initial guess
    locs = [0.0, 0.2, 1.0];
    flow.setProfile('velocity', locs, [uIn, uOut, uOut]);
    flow.setProfile('T', locs, [Tburner, Tad, Tad]);

    names = gas.speciesNames;
    for i = 1:gas.nSpecies
        flow.setProfile(names{i}, locs, [Yin(i), Yout(i), Yout(i)]);
    end

.. GENERATED FROM PYTHON SOURCE LINES 104-108

Solution
--------

Start with energy equation disabled

.. GENERATED FROM PYTHON SOURCE LINES 110-111

.. code-block:: Matlab

    fl.solve(logLevel, refineGrid);

.. GENERATED FROM PYTHON SOURCE LINES 112-117

**Enable the energy equation**

The energy equation will now be solved to compute the
temperature profile. We also tighten the grid refinement
criteria to get an accurate final solution.

.. GENERATED FROM PYTHON SOURCE LINES 119-122

.. code-block:: Matlab

    flow.energyEnabled = true;
    flow.setRefineCriteria(3.0, 0.05, 0.1);
    fl.solve(logLevel, refineGrid);

.. GENERATED FROM PYTHON SOURCE LINES 123-126

**Show statistics and display results**

Show statistics

.. GENERATED FROM PYTHON SOURCE LINES 128-147

.. code-block:: Matlab

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

    toc

    %%
    % Plot results

    clf;
    subplot(2, 2, 1);
    plotSolution(flow, 'T', 'Temperature [K]');
    subplot(2, 2, 2);
    plotSolution(flow, 'velocity', 'Axial Velocity [m/s]');
    subplot(2, 2, 3);
    plotSolution(flow, 'H2O', 'H2O Mass Fraction');
    subplot(2, 2, 4);
    plotSolution(flow, 'O2', 'O2 Mass Fraction');

.. GENERATED FROM PYTHON SOURCE LINES 148-152

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

Local helper function to create plots

.. GENERATED FROM PYTHON SOURCE LINES 153-161

.. 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_burner_flame.m:

.. only:: html

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

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

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

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

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


.. only:: html

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

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