
: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/python/reactors/surf_pfr.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_examples_python_reactors_surf_pfr.py>`
        to download the full example code.

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

.. _sphx_glr_examples_python_reactors_surf_pfr.py:


Plug flow reactor with surface chemistry
========================================

This example simulates the partial oxidation of methane over a platinum catalyst in a
packed bed reactor. This example solves the DAE system directly, using the `FlowReactor`
class and the SUNDIALS IDA solver, in contrast to the approximation as a chain of
steady-state WSRs used in :doc:`surf_pfr_chain.py <surf_pfr_chain>`.

Requires: cantera >= 3.2.0

.. tags:: Python, catalysis, reactor network, surface chemistry, plug flow reactor,
          packed bed reactor

.. GENERATED FROM PYTHON SOURCE LINES 15-24

.. code-block:: Python


    import csv

    import cantera as ct

    # unit conversion factors to SI
    cm = 0.01
    minute = 60.0








.. GENERATED FROM PYTHON SOURCE LINES 25-27

Input Parameters
######################################################################

.. GENERATED FROM PYTHON SOURCE LINES 27-40

.. code-block:: Python


    tc = 800.0  # Temperature in Celsius
    length = 0.3 * cm  # Catalyst bed length
    area = 1.0 * cm**2  # Catalyst bed area
    cat_area_per_vol = 1000.0 / cm  # Catalyst particle surface area per unit volume
    velocity = 40.0 * cm / minute  # gas velocity
    porosity = 0.3  # Catalyst bed porosity

    # input file containing the surface reaction mechanism
    yaml_file = 'methane_pox_on_pt.yaml'

    output_filename = 'surf_pfr2_output.csv'








.. GENERATED FROM PYTHON SOURCE LINES 41-93

.. code-block:: Python


    t = tc + 273.15  # convert to Kelvin

    # import the model and set the initial conditions
    surf = ct.Interface(yaml_file, 'Pt_surf')
    surf.TP = t, ct.one_atm
    gas = surf.adjacent['gas']
    gas.TPX = t, ct.one_atm, 'CH4:1, O2:1.5, AR:0.1'

    mass_flow_rate = velocity * gas.density * area * porosity

    # create a new reactor
    r = ct.FlowReactor(gas, clone=True)
    r.area = area
    r.surface_area_to_volume_ratio = cat_area_per_vol * porosity
    r.mass_flow_rate = mass_flow_rate
    r.energy_enabled = False

    # Add the reacting surface to the reactor
    rsurf = ct.ReactorSurface(surf, r, clone=True)

    sim = ct.ReactorNet([r])

    output_data = []
    n = 0
    print('    distance       X_CH4        X_H2        X_CO')
    print('  {:10f}  {:10f}  {:10f}  {:10f}'.format(
          0, *r.phase['CH4', 'H2', 'CO'].X))

    while sim.distance < length:
        dist = sim.distance * 1e3  # convert to mm
        sim.step()

        if n % 100 == 0 or (dist > 1 and n % 10 == 0):
            print('  {:10f}  {:10f}  {:10f}  {:10f}'.format(
                  dist, *r.phase['CH4', 'H2', 'CO'].X))
        n += 1

        # write the gas mole fractions and surface coverages vs. distance
        output_data.append(
            [dist, r.T - 273.15, r.phase.P / ct.one_atm]
            + list(r.phase.X)  # use r.phase.X not gas.X
            + list(rsurf.phase.coverages)  # use rsurf.phase.coverages not surf.coverages
        )

    with open(output_filename, 'w', newline="") as outfile:
        writer = csv.writer(outfile)
        writer.writerow(['Distance (mm)', 'T (C)', 'P (atm)'] +
                        gas.species_names + surf.species_names)
        writer.writerows(output_data)

    print("Results saved to '{0}'".format(output_filename))




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

        distance       X_CH4        X_H2        X_CO
        0.000000    0.384615    0.000000    0.000000
        0.000000    0.384615    0.000000    0.000000
        0.000001    0.381811    0.001809    0.001708
        0.000003    0.375915    0.004803    0.004775
        0.000007    0.354587    0.011053    0.011992
        0.000014    0.318578    0.013978    0.016563
        0.000024    0.272890    0.012369    0.016270
        0.000041    0.215859    0.008179    0.011959
        0.000067    0.158552    0.004720    0.008029
        0.000079    0.137463    0.003822    0.007769
        0.000082    0.132861    0.003713    0.008126
        0.000083    0.131850    0.003723    0.008286
        0.000083    0.131553    0.003737    0.008353
        0.000083    0.131269    0.003762    0.008432
        0.000083    0.130834    0.003803    0.008566
        0.000083    0.129963    0.003872    0.008841
        0.000084    0.128728    0.003922    0.009225
        0.000084    0.127265    0.003915    0.009652
        0.000086    0.123776    0.003688    0.010528
        0.000088    0.120554    0.003344    0.011147
        0.000091    0.114869    0.002665    0.011834
        0.000097    0.108814    0.001975    0.012107
        0.000103    0.103455    0.001421    0.012050
        0.000110    0.099844    0.001086    0.011893
        0.000127    0.095060    0.000726    0.011574
        0.000141    0.093649    0.000683    0.011461
        0.000158    0.092915    0.000758    0.011402
        0.000177    0.092606    0.000929    0.011379
        0.000194    0.092468    0.001132    0.011370
        0.000221    0.092340    0.001457    0.011366
        0.000240    0.092263    0.001699    0.011364
        0.000286    0.092097    0.002248    0.011362
        0.000334    0.091935    0.002791    0.011362
        0.000428    0.091637    0.003788    0.011366
        0.000809    0.090581    0.007281    0.011414
        0.001343    0.089314    0.011413    0.011532
        0.003009    0.086188    0.021394    0.012040
        0.006861    0.080822    0.038026    0.013409
        0.020458    0.069323    0.072594    0.017420
        0.044848    0.058730    0.103787    0.021764
        0.102974    0.047161    0.136965    0.027399
        0.236365    0.035815    0.168473    0.033956
        0.382695    0.029595    0.185404    0.037891
        1.039072    0.017584    0.217547    0.046043
        1.178389    0.016250    0.221076    0.046989
        1.291850    0.015322    0.223525    0.047652
        1.370825    0.014721    0.225110    0.048083
        1.436127    0.014252    0.226347    0.048422
        1.517728    0.013665    0.227890    0.048845
        1.618259    0.013040    0.229535    0.049299
        1.710643    0.012507    0.230934    0.049686
        1.789502    0.012082    0.232051    0.049997
        1.866647    0.011685    0.233092    0.050287
        1.954358    0.011238    0.234263    0.050615
        2.071138    0.010712    0.235642    0.051002
        2.190362    0.010176    0.237044    0.051397
        2.413907    0.009347    0.239211    0.052011
        2.637452    0.008622    0.241104    0.052551
        2.981574    0.007638    0.243669    0.053286
    Results saved to 'surf_pfr2_output.csv'





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.539 seconds)


.. _sphx_glr_download_examples_python_reactors_surf_pfr.py:

.. only:: html

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

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: surf_pfr.ipynb <surf_pfr.ipynb>`

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

      :download:`Download Python source code: surf_pfr.py <surf_pfr.py>`

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

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


.. only:: html

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

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