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

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

.. _sphx_glr_examples_matlab_diamond_cvd.m:

Simulating growth of a diamond film by CVD
==========================================


This example computes the growth rate of a diamond film according to a
simplified version of a particular published growth mechanism (see file
``diamond.yaml`` for details). Only the surface coverage equations are solved
here; the gas composition is fixed. (For an example of coupled gas-phase
and surface, see :doc:`catalytic_combustion.m <catalytic_combustion>`).

Atomic hydrogen plays an important role in diamond CVD, and this example computes the
growth rate and surface coverages as a function of [H] at the surface for
fixed temperature and [CH3].

Requires: cantera >= 3.2.0

.. tags:: Matlab, surface chemistry, kinetics

.. GENERATED FROM PYTHON SOURCE LINES 16-18

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

.. GENERATED FROM PYTHON SOURCE LINES 20-22

.. code-block:: Matlab

    help diamond_cvd
    t0 = cputime; % record the starting time

.. GENERATED FROM PYTHON SOURCE LINES 23-24

**Set parameter values**

.. GENERATED FROM PYTHON SOURCE LINES 26-28

.. code-block:: Matlab

    t = 1200.0; % surface temperature
    p = 20.0 * ct.OneAtm / 760.0; % pressure

.. GENERATED FROM PYTHON SOURCE LINES 29-33

**Create the gas object**

The gas phase will be taken from the definition of phase 'gas' in
input file 'diamond.yaml'.

.. GENERATED FROM PYTHON SOURCE LINES 35-40

.. code-block:: Matlab

    gas = ct.Solution('diamond.yaml', 'gas');
    gas.TP = {t, p};
    x = gas.X;
    ih = gas.speciesIndex('H');
    xh0 = x(ih);

.. GENERATED FROM PYTHON SOURCE LINES 41-45

**Create the bulk diamond object**

The bulk phase will be taken from the definition of phase 'diamond' in
input file 'diamond.yaml'.

.. GENERATED FROM PYTHON SOURCE LINES 47-49

.. code-block:: Matlab

    dbulk = ct.Solution('diamond.yaml', 'diamond');
    mw = dbulk.molecularWeights;

.. GENERATED FROM PYTHON SOURCE LINES 50-55

**Create the interface object**

This object will be used to evaluate all surface chemical production
rates. It will be created from the interface definition 'diamond_100'
in input file 'diamond.yaml'.

.. GENERATED FROM PYTHON SOURCE LINES 57-58

.. code-block:: Matlab

    surf_phase = ct.Interface('diamond.yaml', 'diamond_100', gas, dbulk);

.. GENERATED FROM PYTHON SOURCE LINES 59-63

Solution
--------

Advance Coverages

.. GENERATED FROM PYTHON SOURCE LINES 65-83

.. code-block:: Matlab

    iC = surf_phase.kineticsSpeciesIndex('C(d)');

    xx = [];
    rr = [];
    cov = [];

    for i = 1:20
        x(ih) = x(ih) / 1.4;
        gas.TPX = {t, p, x};
        surf_phase.advanceCoverages(10.0);
        r = surf_phase.netProdRates;
        carbon_dot = r(iC);
        mdot = mw * carbon_dot;
        rate = mdot / dbulk.massDensity;
        xx = [xx; x(ih)];
        rr = [rr; rate * 1.0e6 * 3600.0];
        cov = [cov; surf_phase.coverages];
    end

.. GENERATED FROM PYTHON SOURCE LINES 84-85

**Plot Results**

.. GENERATED FROM PYTHON SOURCE LINES 86-98

.. code-block:: Matlab

    clf;

    subplot(1, 2, 1);
    plot(xx, rr);
    xlabel('H Mole Fraction');
    ylabel('Growth Rate (microns/hr)');
    title('Growth Rate');

    subplot(1, 2, 2);
    plot(xx, cov);
    xlabel('H Mole Fraction');
    ylabel('Coverage');
    title('Coverages');

.. _sphx_glr_download_examples_matlab_diamond_cvd.m:

.. only:: html

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

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

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

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

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


.. only:: html

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

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