.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/simple_pdes/pde_brusselator_expression.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_simple_pdes_pde_brusselator_expression.py: Brusselator - Using the `PDE` class =================================== This example uses the :class:`~pde.pdes.pde.PDE` class to implement the `Brusselator `_ with spatial coupling, .. math:: \partial_t u &= D_0 \nabla^2 u + a - (1 + b) u + v u^2 \\ \partial_t v &= D_1 \nabla^2 v + b u - v u^2 Here, :math:`D_0` and :math:`D_1` are the respective diffusivity and the parameters :math:`a` and :math:`b` are related to reaction rates. Note that the same result can also be achieved with a :doc:`full implementation of a custom class <../advanced_pdes/pde_brusselator_class>`, which allows for more flexibility at the cost of code complexity. .. GENERATED FROM PYTHON SOURCE LINES 21-43 .. image-sg:: /examples_gallery/simple_pdes/images/sphx_glr_pde_brusselator_expression_001.png :alt: Time: 20, Field $u$, Field $v$ :srcset: /examples_gallery/simple_pdes/images/sphx_glr_pde_brusselator_expression_001.png :class: sphx-glr-single-img .. code-block:: Python from pde import PDE, FieldCollection, PlotTracker, ScalarField, UnitGrid # define the PDE a, b = 1, 3 d0, d1 = 1, 0.1 eq = PDE( { "u": f"{d0} * laplace(u) + {a} - ({b} + 1) * u + u**2 * v", "v": f"{d1} * laplace(v) + {b} * u - u**2 * v", } ) # initialize state grid = UnitGrid([64, 64]) u = ScalarField(grid, a, label="Field $u$") v = b / a + 0.1 * ScalarField.random_normal(grid, label="Field $v$") state = FieldCollection([u, v]) # simulate the pde tracker = PlotTracker(interrupts=1, plot_args={"vmin": 0, "vmax": 5}) sol = eq.solve(state, t_range=20, dt=1e-3, tracker=tracker) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.694 seconds) .. _sphx_glr_download_examples_gallery_simple_pdes_pde_brusselator_expression.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pde_brusselator_expression.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pde_brusselator_expression.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pde_brusselator_expression.zip `