.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/advanced_pdes/post_step_hook.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_advanced_pdes_post_step_hook.py: Post-step hook function ======================= Demonstrate the simple hook function in :class:`~pde.pdes.PDE`, which is called after each time step and may modify the state and abort the simulation. .. GENERATED FROM PYTHON SOURCE LINES 8-24 .. image-sg:: /examples_gallery/advanced_pdes/images/sphx_glr_post_step_hook_001.png :alt: post step hook :srcset: /examples_gallery/advanced_pdes/images/sphx_glr_post_step_hook_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/10000.0 [00:00 1e3: raise StopIteration # abort simulation at given time eq = PDE({"c": "laplace(c)"}, post_step_hook=post_step_hook) state = ScalarField(UnitGrid([64, 64])) result = eq.solve(state, dt=0.1, t_range=1e4) result.plot() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 27.400 seconds) .. _sphx_glr_download_examples_gallery_advanced_pdes_post_step_hook.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: post_step_hook.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: post_step_hook.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: post_step_hook.zip `