.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/dimension_reduction/pod/DiffusionEquation.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_dimension_reduction_pod_DiffusionEquation.py: Diffusion Equation File ======================== .. GENERATED FROM PYTHON SOURCE LINES 8-38 .. code-block:: default import numpy as np def diffusion(w, h, dx, dy, D, Tcool, Thot, r, cx, cy, nsteps): nx, ny = int(w/dx), int(h/dy) dx2, dy2 = dx*dx, dy*dy dt = dx2 * dy2 / (2 * D * (dx2 + dy2)) u0 = Tcool * np.ones((nx, ny)) u = u0.copy() r2 = r**2 for i in range(nx): for j in range(ny): p2 = (i*dx-cx)**2 + (j*dy-cy)**2 if p2 < r2: u0[i,j] = Thot def do_timestep(u0, u): # Propagate with forward-difference in time, central-difference in space u[1:-1, 1:-1] = u0[1:-1, 1:-1] + D * dt * ( (u0[2:, 1:-1] - 2*u0[1:-1, 1:-1] + u0[:-2, 1:-1])/dx2 + (u0[1:-1, 2:] - 2*u0[1:-1, 1:-1] + u0[1:-1, :-2])/dy2 ) u0 = u.copy() return u0, u u_f = [] for m in range(nsteps): u0, u = do_timestep(u0, u) u_f.append(u0) return u_f .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_dimension_reduction_pod_DiffusionEquation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/SURGroup/UQpy/master?urlpath=lab/tree/notebooks/auto_examples/dimension_reduction/pod/DiffusionEquation.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: DiffusionEquation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: DiffusionEquation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_