Plotter#
This module contains the DPF plotter class.
Contains classes used to plot a mesh and a fields container using PyVista.
- class ansys.dpf.core.plotter.DpfPlotter(**kwargs)#
DpfPlotter class. Can be used in order to plot results over a mesh.
The current DpfPlotter is a PyVista based object.
That means that PyVista must be installed, and that it supports kwargs as parameter (the argument must be supported by the installed PyVista version). More information about the available arguments are available at
pyvista.Plotter
.- property labels#
Return a list of labels.
- Returns:
List of Label(s). Each list member or member group will share same properties.
- Return type:
list
- add_node_labels(nodes: ansys.dpf.core.nodes.Nodes | List[ansys.dpf.core.nodes.Node] | List[int], meshed_region: ansys.dpf.core.meshed_region.MeshedRegion, labels: List[str] | None = None, **kwargs)#
Add labels at nodal locations.
- Parameters:
nodes (
Union
[Nodes
,List
[Node
],List
[int
]]) – Nodes where the labels should be added.meshed_region (
MeshedRegion
) – MeshedRegion to plot.labels (
Optional
[List
[str
]], default:None
) – The labels to use. A node for which the label is not defined or None will show the scalar value of the currently active field at that node, or, if no field is active, its node ID.kwargs – Keyword arguments controlling label properties. See
pyvista.Plotter.add_point_labels()
.
- add_mesh(meshed_region, deform_by=None, scale_factor=1.0, **kwargs)#
Add a mesh to plot.
- Parameters:
meshed_region (MeshedRegion) – MeshedRegion to plot.
deform_by (Field, Result, Operator, optional) – Used to deform the plotted mesh. Must output a 3D vector field. Defaults to None.
scale_factor (float, optional) – Scaling factor to apply when warping the mesh. Defaults to 1.0.
**kwargs (optional) – Additional keyword arguments for the plotter. More information are available at
pyvista.plot()
.
Examples
>>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> from ansys.dpf.core.plotter import DpfPlotter >>> pl = DpfPlotter() >>> pl.add_mesh(mesh)
- add_streamlines(streamlines, source=None, radius=0.1, **kwargs)#
Add a streamline to the plotter.
The current add_streamlines method adds streamline as a PyVista based object. For more information about arguments, see
pyvista.DataSetFilters.streamlines()
.- Parameters:
streamlines (helpers.streamlines.Streamlines) – Object containing computed streamlines data, computed using helpers.streamlines.compute_streamlines function.
source (helpers.streamlines.StreamlinesSource, optional) – Object containing computed streamines source data, computed using helpers.streamlines.compute_streamlines function.
**kwargs (optional) – Additional keyword arguments for the plotter. More information is available at
pyvista.plot()
. The “permissive” (boolean, default being True) can be used to avoid throwing if computed streamlines are empty. SeeExamples
section for more information.
Examples
>>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> from ansys.dpf.core.helpers.streamlines import compute_streamlines >>> # Get model and meshed region >>> files = examples.download_fluent_mixing_elbow_steady_state() >>> ds = dpf.DataSources() >>> ds.set_result_file_path(files["cas"][0], "cas") >>> ds.add_file_path(files["dat"][1], "dat") >>> model = dpf.Model(ds) >>> mesh = model.metadata.meshed_region >>> # Get velocity data >>> velocity_op = model.results.velocity() >>> fc = velocity_op.outputs.fields_container() >>> op = dpf.operators.averaging.to_nodal_fc(fields_container=fc) >>> field = op.outputs.fields_container()[0] >>> # Plot >>> from ansys.dpf.core.plotter import DpfPlotter >>> pl = DpfPlotter() >>> pl.add_mesh(meshed_region=mesh, opacity=0.15, color="g") >>> streamline_obj = compute_streamlines( ... meshed_region=mesh, ... field=field, ... source_center=(0.55, 0.55, 0.), ... n_points=10, ... source_radius=0.08, ... max_time=10.0 ... ) >>> pl.add_streamlines( ... streamlines=streamline_obj, ... radius=0.001, ... ) >>> pl.show_figure(show_axes=True)
- add_field(field, meshed_region=None, show_max=False, show_min=False, label_text_size=30, label_point_size=20, deform_by=None, scale_factor=1.0, **kwargs)#
Add a field containing data to the plotter.
A meshed_region to plot on can be added. If no
meshed_region
is specified, the field support will be used. Ensure that the field support is ameshed_region
.- Parameters:
field (Field) – Field data to plot
meshed_region (MeshedRegion, optional) –
MeshedRegion
to plot the field on.show_max (bool, optional) – Label the point with the maximum value.
show_min (bool, optional) – Label the point with the minimum value.
deform_by (Field, Result, Operator, optional) – Used to deform the plotted mesh. Must output a 3D vector field. Defaults to None.
scale_factor (float, optional) – Scaling factor to apply when warping the mesh. Defaults to 1.0.
**kwargs (optional) – Additional keyword arguments for the plotter. More information are available at
pyvista.plot()
.
Examples
>>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> field = model.results.displacement().outputs.fields_container()[0] >>> from ansys.dpf.core.plotter import DpfPlotter >>> pl = DpfPlotter() >>> pl.add_field(field, mesh)
- show_figure(**kwargs)#
Plot the figure built by the plotter object.
- Parameters:
**kwargs (optional) – Additional keyword arguments for the plotter. More information are available at
pyvista.plot()
.
Examples
>>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> field = model.results.displacement().outputs.fields_container()[0] >>> from ansys.dpf.core.plotter import DpfPlotter >>> pl = DpfPlotter() >>> pl.add_field(field, mesh) >>> pl.show_figure()
- ansys.dpf.core.plotter.plot_chart(fields_container, off_screen=False, screenshot=None)#
Plot the minimum/maximum result values over time.
This is a valid method if
time_freq_support
contains several time_steps, such as in a transient analysis.- Parameters:
fields_container (dpf.core.FieldsContainer) – Fields container that must contains a result for each time step of
time_freq_support
.off_screen (bool, optional) – Whether to render the image off-screen. Useful for batch workflows. The default is
False
.screenshot (path-like, optional) – A file path to which the figure should be saved. The format is inferred from the file extension in the path (defaults to “.png”). The default is
None
.
Examples
>>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.find_transient_therm()) >>> t = model.results.temperature.on_all_time_freqs() >>> fc = t.outputs.fields_container() >>> plotter = dpf.plotter.plot_chart(fc)
- class ansys.dpf.core.plotter.Plotter(mesh, **kwargs)#
Plots fields and meshed regions in DPF-Core.
- Parameters:
mesh (str) – Name of the mesh.
- plot_mesh(**kwargs)#
Plot the mesh using PyVista.
- Parameters:
notebook (bool, optional) – When
None
(default) plot a static image within an iPython notebook if available. WhenFalse
, plot external to the notebook with an interactive window. WhenTrue
, always plot within a notebook.**kwargs (optional) – Additional keyword arguments for the plotter. For more information, ee
help(pyvista.plot)
.
- static plot_chart(fields_container, off_screen=False, screenshot=None)#
Plot the minimum/maximum result values over time.
This is a valid method if
time_freq_support
contains several time steps, such as in a transient analysis.- Parameters:
fields_container (dpf.core.FieldsContainer) – Fields container that must contain a result for each time step of
time_freq_support
.off_screen (bool, optional) – Used to prevent the figure from showing in a pop-up, useful for batch image generation. Defaults to False.
screenshot (str, os.pathLike, optional) – Path to save the figure to. Defaults to None. If no extension is given, defaults to .png format. See
help(matplotlib.pyplot.savefig)
for more information on supported formats.
Examples
>>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.find_simple_bar()) >>> disp = model.results.displacement() >>> scoping = dpf.Scoping() >>> scoping.ids = range(1, len(model.metadata.time_freq_support.time_frequencies) + 1) >>> disp.inputs.time_scoping.connect(scoping) >>> fc = disp.outputs.fields_container() >>> plotter = dpf.plotter.Plotter(model.metadata.meshed_region) >>> pl = plotter.plot_chart(fc)
- plot_contour(field_or_fields_container, shell_layers=None, meshed_region=None, deform_by=None, scale_factor=1.0, **kwargs)#
Plot the contour result on its mesh support.
You cannot plot a fields container containing results at several time steps.
- Parameters:
field_or_fields_container (dpf.core.Field or dpf.core.FieldsContainer) – Field or field container that contains the result to plot.
shell_layers (core.shell_layers, optional) – Enum used to set the shell layers if the model to plot contains shell elements.
deform_by (Field, Result, Operator, optional) – Used to deform the plotted mesh. Must output a 3D vector field. Defaults to None.
scale_factor (float, optional) – Scaling factor to apply when warping the mesh. Defaults to 1.0.
**kwargs (optional) – Additional keyword arguments for the plotter. For more information, see
help(pyvista.plot)
.