Introduction to DOLFINx#

We start by importing DOLFINx, and check the version and git commit hash

import dolfinx
print(f"You have DOLFINx {dolfinx.__version__} installed, "
      "based on commit \nhttps://github.com/FEniCS/dolfinx/commit/"
      f"{dolfinx.common.git_commit_hash}")
You have DOLFINx 0.5.0 installed, based on commit 
https://github.com/FEniCS/dolfinx/commit/2aaf3b20dbaedcbd3925a9640c3859deec563e02

Using a ‘built-in’ mesh#

In DOLFINx, we do not use wildcard imports as we used to in legacy DOLFIN, ie

from dolfin import *

We instead import dolfinx.mesh as a module:

import dolfinx
from mpi4py import MPI
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)

Interface to external libraries#

We use external libraries, such as pyvista for plotting.

import dolfinx.plot
import pyvista
topology, cells, geometry = dolfinx.plot.create_vtk_mesh(mesh)
grid = pyvista.UnstructuredGrid(topology, cells, geometry)

We add settings for both static and interactive plotting

Hide code cell content
pyvista.start_xvfb(0.5)
pyvista.set_jupyter_backend("pythreejs")
plotter = pyvista.Plotter(window_size=(600, 600))
renderer = plotter.add_mesh(grid, show_edges=True)
Hide code cell content
# Settings for presentation mode
plotter.view_xy()
plotter.camera.zoom(1.35)
plotter.export_html("./mesh.html", backend="pythreejs")
2024-05-06 08:09:10.062 (   0.915s) [        6425C000]    vtkExtractEdges.cxx:435   INFO| Executing edge extractor: points are renumbered
2024-05-06 08:09:10.063 (   0.915s) [        6425C000]    vtkExtractEdges.cxx:551   INFO| Created 320 edges
2024-05-06 08:09:10.080 (   0.933s) [        6425C000]    vtkExtractEdges.cxx:435   INFO| Executing edge extractor: points are renumbered
2024-05-06 08:09:10.080 (   0.933s) [        6425C000]    vtkExtractEdges.cxx:551   INFO| Created 320 edges

Interactive plot#

We can get interactive plots in notebook by calling.

Hide code cell source
%%html
<iframe src='./mesh.html' width="610px" height="610px">></iframe>  <!--  # noqa, -->