Pyvista4dolfinx

Library link: FEniCSx4Flow / pyvista4dolfinx · GitLab
Documentation: Pyvista for dolfinx — pyvista for dolfinx documentation
Version: PyPi
CI-status: test status

Installation instructions

pip install pyvista4dolfinx

Description

This package reintroduces simple plot and show functionality to FEniCSx, capable of plotting most common data-structures during both serial and parallel execution.

At a prototyping stage one often desires quick-and-dirty visualization with a simple interface. Yet, quite a bit of boiler-plate code is required to interface dolfinx and pyvista. To mitigate this, pyvista4dolfinx provides a single plot function that can be used to plot most of dolfinx’s visualizable data-structures; scalar- and vector-valued Function, Mesh, FacetMarker, and even integration Measure.

The plot function returns a pyvista.Plotter instance, such that the user still has full access to pyvista’s full range of capabilities.

Examples

Demo 1

A minimal example would be:

from dolfinx import fem,mesh
from mpi4py import MPI
import numpy as np
from pyvista4dolfinx import plot

domain = mesh.create_unit_square(MPI.COMM_WORLD,10,10)
V = fem.functionspace(domain, ("Lagrange", 2))
u = fem.Function(V, name='my_function')
u.interpolate(lambda x: np.sin(x[0]*np.pi)*np.sin(x[1]*np.pi))

# This is the single required plotting call:
plot(u, warp=True, show=True)

Which outputs:

Demo 2

A demo that illustrates a broader range of functionality can be found at:

Feedback

I’ll happily take feedback through responses to this post, PMs, or issues created on the gitlab page. In particular, I have only been able to perform limited across platforms, so I’d still be curious to learn how robust the package is.

1 Like

For comparison, libraries with similar goals are febug (cc @nate) and viskex (cc myself).

2 Likes

Release v0.10.2

Feature-set now includes (boldface specific to new release):

  • MPI stable; plot(plottable) shows the same irrespective of mpirun.
  • Plotting scalarfields and vectorfields from all element types.
  • Plotting element and facet MeshTags.
  • Plotting integration Measures.
  • Plotting meshes of lower and higher order.
  • Easy scalar warp plotting or warp by a supplied vectorfield, possible with higher-order functions without rendering as coarse linear triangles.
  • Plotting of numpy arrays of data representing facet indices or element indices or degrees of freedom.
  • Plotting of mesh partitioning with mpirun

Below a is a short gallery from the four demos on Demos — pyvista for dolfinx documentation .

plotter = Plotter(shape=(1, 3))
plot(linear_mesh, plotter=plotter, subplot=(0, 0), color="lightgray")
plot(curved_mesh, plotter=plotter, subplot=(0, 0), color="black")
plot(u, show_mesh=True, plotter=plotter, subplot=(0, 1), cmap="viridis")
plot(v, factor=0.5, show_mesh=True, glyph_resolution=4, plotter=plotter, subplot=(0, 2), cmap="plasma")
show()

plot(domain, show_partitioning=True)
show()

plot(element_tags, domain, name="Element tags", cmap="cool", \
                    scalar_bar_args={"vertical": True,"position_x": 0.85,"position_y": 0.25})
plot(facet_tags, domain, name="Facet tags", \
                    scalar_bar_args={"position_x": 0.21,"position_y": 0.05})
show()

plot(dx(3), domain, name="Volume measure", cmap="cool", \
                    scalar_bar_args={"vertical": True,"position_x": 0.85,"position_y": 0.25})
plot(ds(2), domain, name="Surface measure",  \
                    scalar_bar_args={"position_x": 0.21,"position_y": 0.05})
show()

plotter = Plotter(shape=(1, 2))
plot(uh, factor=0.5, show_mesh=False, plotter=plotter, subplot=(0,0))
plot(stresses, warp=uh, show_mesh=False, subplot=(0,1))
show()

plotter = Plotter(shape=(1, 3))
plot(facets_top, mesh=msh, entity_type="facets", plotter=plotter, subplot=(0, 0))
plot(cells_left, mesh=msh, entity_type="cells", plotter=plotter, subplot=(0, 1))
plot(dofs_top, function_space=V, entity_type="dofs", plotter=plotter, subplot=(0, 2))
show()

plot(u, warp=True, show=True)

3 Likes