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.plotter(*args: Function | List[Function], **kwargs) Plotter[source]

A generic function to plot 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>
update_scalars(*all_scalars, **kwargs)[source]

Calls pyvista.Plotter.update_scalars for all subplots

live_plotter_start()[source]
live_plotter_stop()[source]
live_plotter_update_function(i: int, vec: Vec) None[source]
add_time_browser(update_fields_function: Callable, timesteps: ndarray, **kwargs_slider)[source]
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>
update_vectors(*all_vectors, render: bool = True) None[source]

Calls pyvista.Plotter.update_coordinates and .update_scalars for all subplots

Parameters:

all_vectors – tuple of np.ndarray, e.g. all_vectors = (u1.x, u2.x, …) where u1, u2 are dolfinx.fem.Function

live_plotter_start()[source]
live_plotter_stop()[source]
live_plotter_update_function(i: int, vec: Vec) None[source]
add_time_browser(update_fields_function: Callable, timesteps: ndarray, **kwargs_slider) None[source]
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.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: Function | List[Function], **kwargs) Plotter[source]

A generic function to plot 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[pyvista.UnstructuredGrid]
update_scalars(*all_scalars, **kwargs)[source]

Calls pyvista.Plotter.update_scalars for all subplots

live_plotter_start()[source]
live_plotter_stop()[source]
live_plotter_update_function(i: int, vec: Vec) None[source]
add_time_browser(update_fields_function: Callable, timesteps: ndarray, **kwargs_slider)[source]
mapper: _BaseMapper | None
volume: Volume | None
text: CornerAnnotation | Text | None
iren: RenderWindowInteractor | None
mwriter: imageio.plugins.ffmpeg.Writer | None
mesh: MultiBlock | DataSet | None
last_image_depth: pyvista.pyvista_ndarray | None
last_image: pyvista.pyvista_ndarray | None
last_vtksz: str | Path | None
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[pyvista.UnstructuredGrid]
mapper: _BaseMapper | None
volume: Volume | None
text: CornerAnnotation | Text | None
iren: RenderWindowInteractor | None
mwriter: imageio.plugins.ffmpeg.Writer | None
mesh: MultiBlock | DataSet | None
last_image_depth: pyvista.pyvista_ndarray | None
last_image: pyvista.pyvista_ndarray | None
last_vtksz: str | Path | None
update_vectors(*all_vectors, render: bool = True) None[source]

Calls pyvista.Plotter.update_coordinates and .update_scalars for all subplots

Parameters:

all_vectors – tuple of np.ndarray, e.g. all_vectors = (u1.x, u2.x, …) where u1, u2 are dolfinx.fem.Function

live_plotter_start()[source]
live_plotter_stop()[source]
live_plotter_update_function(i: int, vec: Vec) None[source]
add_time_browser(update_fields_function: Callable, timesteps: ndarray, **kwargs_slider) None[source]
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