elastodynamicsx.plot
Module contents
The plot module contains convenience tools for plotting
- elastodynamicsx.plot.live_plotter(u: Function, refresh_step: int = 1, **kwargs) Plotter [source]
Convenience function to initialize a plotter for live-plotting within a time- or frequency-domain computation
- Parameters:
u – The FEM function to be live-plotted
refresh_step – Refresh each # step
- Keyword Arguments:
kwargs – passed to plotter
Example
Time-domain problems:
tStepper = TimeStepper.build(...) u_res = tStepper.timescheme.u # The solution p = live_plotter(u_res, refresh_step=10) tStepper.solve(..., live_plotter=p)
Frequency-domain problems:
fdsolver = FrequencyDomainSolver(...) u_res = fem.Function(V, name='solution') p = live_plotter(u_res) fdsolver.solve(omega=omegas, out=u_res.x.petsc_vec, callbacks=[], live_plotter=p)
- elastodynamicsx.plot.plot_mesh(mesh: Mesh, cell_tags: MeshTags | None = None, **kwargs) Plotter [source]
Plot the mesh with colored subdomains
- Parameters:
mesh – a dolfinx mesh
cell_tags – (optional) a dolfinx MeshTag instance
- Returns:
The pyvista.Plotter
Example
from mpi4py import MPI from dolfinx.mesh import create_unit_square from elastodynamicsx.utils import make_tags domain = create_unit_square(MPI.COMM_WORLD, 10, 10) Omegas = [(1, lambda x: x[1] <= 0.5), (2, lambda x: x[1] >= 0.5)] cell_tags = make_tags(domain, Omegas, 'domains') p = plot_mesh(domain, cell_tags=cell_tags) p.show()
- elastodynamicsx.plot.plotter(*args: List[Function] | Mesh, **kwargs) Plotter [source]
A generic function to plot a mesh or one/several fields
- Parameters:
*args – FEM functions to be plotted, sharing the same underlying function space
- Keyword Arguments:
**kwargs – passed to either CustomScalarPlotter or CustomVectorPlotter
Example
u1 = fem.Function(V) u2 = fem.Function(V) p = plotter(u1, u2, labels=['first', 'second']) p.show()
- class elastodynamicsx.plot.CustomScalarPlotter(*args, **kwargs)[source]
Bases:
Plotter
Not intended to be instanciated by user; better use the plotter function
- Parameters:
u1 – fem.Function; the underlying function space is a scalar function space
u2 – fem.Function; the underlying function space is a scalar function space
... – fem.Function; the underlying function space is a scalar function space
- Keyword Arguments:
refresh_step – (default=1) The refresh step, if used for live-plotting
sleep – (default=0.01) The sleep time after refresh, if used for live-plotting
complex – (default=’real’) The way complex functions are plotted. Possible options: ‘real’, ‘imag’, ‘abs’, ‘angle’
labels – list of labels
**kwargs – any valid kwarg for pyvista.Plotter and pyvista.Plotter.add_mesh
- default_cmap = <matplotlib.colors.LinearSegmentedColormap object>
- class elastodynamicsx.plot.CustomVectorPlotter(*args, **kwargs)[source]
Bases:
Plotter
- Parameters:
u1 – fem.Function; the underlying function space is a scalar function space
u2 – fem.Function; the underlying function space is a scalar function space
... – fem.Function; the underlying function space is a scalar function space
- Keyword Arguments:
refresh_step – (default=1) The refresh step, if used for live-plotting
sleep – (default=0.01) The sleep time after refresh, if used for live-plotting
complex – (default=’real’) The way complex functions are plotted. Possible options: ‘real’, ‘imag’, ‘abs’, ‘angle’
labels – list of labels
warp_factor – (default=1 or 0.5/max(clim) if provided) Factor for plotting mesh deformation
ref_mesh – (default=False) Whether to show the undeformed mesh
**kwargs – any valid kwarg for pyvista.Plotter and pyvista.Plotter.add_mesh
- default_cmap = <matplotlib.colors.ListedColormap object>
- elastodynamicsx.plot.spy_petscMatrix(Z: Mat, *args, **kwargs) AxesImage [source]
matplotlib.pyplot.spy with Z being a petsc4py.PETSc.Mat object
- Parameters:
Z – The array to be plotted, of type petsc4py.PETSc.Mat
args – Passed to matplotlib.pyplot.spy (see doc)
- Keyword Arguments:
kwargs – Passed to matplotlib.pyplot.spy (see doc)
- Returns:
See doc of matplotlib.pyplot.spy
elastodynamicsx.plot.plot
- elastodynamicsx.plot.plot.plot_mesh(mesh: Mesh, cell_tags: MeshTags | None = None, **kwargs) Plotter [source]
Plot the mesh with colored subdomains
- Parameters:
mesh – a dolfinx mesh
cell_tags – (optional) a dolfinx MeshTag instance
- Returns:
The pyvista.Plotter
Example
from mpi4py import MPI from dolfinx.mesh import create_unit_square from elastodynamicsx.utils import make_tags domain = create_unit_square(MPI.COMM_WORLD, 10, 10) Omegas = [(1, lambda x: x[1] <= 0.5), (2, lambda x: x[1] >= 0.5)] cell_tags = make_tags(domain, Omegas, 'domains') p = plot_mesh(domain, cell_tags=cell_tags) p.show()
- elastodynamicsx.plot.plot.live_plotter(u: Function, refresh_step: int = 1, **kwargs) Plotter [source]
Convenience function to initialize a plotter for live-plotting within a time- or frequency-domain computation
- Parameters:
u – The FEM function to be live-plotted
refresh_step – Refresh each # step
- Keyword Arguments:
kwargs – passed to plotter
Example
Time-domain problems:
tStepper = TimeStepper.build(...) u_res = tStepper.timescheme.u # The solution p = live_plotter(u_res, refresh_step=10) tStepper.solve(..., live_plotter=p)
Frequency-domain problems:
fdsolver = FrequencyDomainSolver(...) u_res = fem.Function(V, name='solution') p = live_plotter(u_res) fdsolver.solve(omega=omegas, out=u_res.x.petsc_vec, callbacks=[], live_plotter=p)
- elastodynamicsx.plot.plot.plotter(*args: List[Function] | Mesh, **kwargs) Plotter [source]
A generic function to plot a mesh or one/several fields
- Parameters:
*args – FEM functions to be plotted, sharing the same underlying function space
- Keyword Arguments:
**kwargs – passed to either CustomScalarPlotter or CustomVectorPlotter
Example
u1 = fem.Function(V) u2 = fem.Function(V) p = plotter(u1, u2, labels=['first', 'second']) p.show()
- class elastodynamicsx.plot.plot.CustomScalarPlotter(*args, **kwargs)[source]
Bases:
Plotter
Not intended to be instanciated by user; better use the plotter function
- Parameters:
u1 – fem.Function; the underlying function space is a scalar function space
u2 – fem.Function; the underlying function space is a scalar function space
... – fem.Function; the underlying function space is a scalar function space
- Keyword Arguments:
refresh_step – (default=1) The refresh step, if used for live-plotting
sleep – (default=0.01) The sleep time after refresh, if used for live-plotting
complex – (default=’real’) The way complex functions are plotted. Possible options: ‘real’, ‘imag’, ‘abs’, ‘angle’
labels – list of labels
**kwargs – any valid kwarg for pyvista.Plotter and pyvista.Plotter.add_mesh
- default_cmap = <matplotlib.colors.LinearSegmentedColormap object>
- grids: List[UnstructuredGrid]
- class elastodynamicsx.plot.plot.CustomVectorPlotter(*args, **kwargs)[source]
Bases:
Plotter
- Parameters:
u1 – fem.Function; the underlying function space is a scalar function space
u2 – fem.Function; the underlying function space is a scalar function space
... – fem.Function; the underlying function space is a scalar function space
- Keyword Arguments:
refresh_step – (default=1) The refresh step, if used for live-plotting
sleep – (default=0.01) The sleep time after refresh, if used for live-plotting
complex – (default=’real’) The way complex functions are plotted. Possible options: ‘real’, ‘imag’, ‘abs’, ‘angle’
labels – list of labels
warp_factor – (default=1 or 0.5/max(clim) if provided) Factor for plotting mesh deformation
ref_mesh – (default=False) Whether to show the undeformed mesh
**kwargs – any valid kwarg for pyvista.Plotter and pyvista.Plotter.add_mesh
- default_cmap = <matplotlib.colors.ListedColormap object>
- grids: List[UnstructuredGrid]
- elastodynamicsx.plot.plot.spy_petscMatrix(Z: Mat, *args, **kwargs) AxesImage [source]
matplotlib.pyplot.spy with Z being a petsc4py.PETSc.Mat object
- Parameters:
Z – The array to be plotted, of type petsc4py.PETSc.Mat
args – Passed to matplotlib.pyplot.spy (see doc)
- Keyword Arguments:
kwargs – Passed to matplotlib.pyplot.spy (see doc)
- Returns:
See doc of matplotlib.pyplot.spy