examples.cfd package

Submodules

examples.cfd.example_diffusion module

NOTE: This is a legacy example. For more up-to-date examples please see the tutorials under examples/cfd/.

This example encodes multiple ways to solve the 2D diffusion equations using an explicit finite difference scheme with fixed boundary values and a given initial value for the density. The example also includes demo implementations using more traditional methods, including pure Python, vectorized NumPy and a vectorized symbolic implementation using SymPy’s lambdify() functionality. For a visual demonstration and comparison between pure Python and NumPy, for example, run:

python example_diffusion.py run -m python numpy –show

examples.cfd.example_diffusion.animate(field)[source]

Animate solution field

examples.cfd.example_diffusion.execute_devito(ui, spacing=0.01, a=0.5, timesteps=500)[source]

Execute diffusion stencil using the devito Operator API.

examples.cfd.example_diffusion.execute_lambdify(ui, spacing=0.01, a=0.5, timesteps=500)[source]

Execute diffusion stencil using vectorised numpy array accesses.

examples.cfd.example_diffusion.execute_numpy(ui, spacing=0.01, a=0.5, timesteps=500)[source]

Execute diffusion stencil using vectorised numpy array accesses.

examples.cfd.example_diffusion.execute_python(ui, spacing=0.01, a=0.5, timesteps=500)[source]

Execute diffusion stencil using pure Python list indexing.

examples.cfd.example_diffusion.ring_initial(spacing=0.01)[source]

Initialise grid with initial condition (“ring”)

examples.cfd.example_diffusion.test_diffusion2d(spacing=0.01, timesteps=1000)[source]

examples.cfd.tools module

examples.cfd.tools.fin_bump(x)[source]
examples.cfd.tools.gaussian(x, mu, sig)[source]
examples.cfd.tools.init_hat(field, dx, dy, value=2.0, bgvalue=1.0)[source]

Set “hat function” initial condition on an array:

u(.5<=x<=1 && .5<=y<=1 ) is 2

Parameters:
  • field – Numpy array with field data to plot
  • dx – Spacing in the x-dimension
  • dy – Spacing in the y-dimension
  • value – Value of the top part of the function, default=2.
  • bgvalue – Background value for the bottom of the function, default=1.
examples.cfd.tools.init_smooth(field, dx, dy)[source]
examples.cfd.tools.plot_field(field, xmax=2.0, ymax=2.0, zmax=None, view=None, linewidth=0)[source]

Utility plotting routine for 2D data

Parameters:
  • field – Numpy array with field data to plot
  • xmax – (Optional) Length of the x-axis
  • ymax – (Optional) Length of the y-axis
  • view – (Optional) View point to intialise

Module contents