Graphics windows manager#

The GraphicsWindowsManager class provides for managing and directly interacting with PyVista windows. By registering these methods with EventsManager, you can update graphics during run time and create animations.

The following example updates window-1 during solution initialization and whenever data is read. During the calculation, it also updates window-1 at the end of every time step and creates an animation.

Note

The animation is saved when the window is closed.

from ansys.fluent.visualization import Graphics
from ansys.fluent.visualization.graphics import graphics_windows_manager

graphics_session = Graphics(session)

#Create contour.
contour1 = graphics_session.Contours["contour-1"]
contour1.field = "velocity-magnitude"
contour1.surfaces = ['symmetry']

#Display contour on window-1.
contour1.display("window-1")

#Create callback that refreshes window-1.
def auto_refresh_contour(session_id, event_info):
    graphics_windows_manager.refresh_windows(session_id, ["window-1"])

#Register this callback with server events.
cb_init_id = session.events_manager.register_callback('InitializedEvent', auto_refresh_contour)
cb_data_read_id = session.events_manager.register_callback('DataReadEvent', auto_refresh_contour)
cb_time_step_ended_id = session.events_manager.register_callback('TimestepEndedEvent', auto_refresh_contour)

#Create animation for window-1.
graphics_windows_manager.animate_windows(session.id, ["window-1"])
class ansys.fluent.visualization.graphics.graphics_windows_manager.GraphicsWindowsManager(*args, **kwargs)#

Provides for managing Graphics windows.

add_graphics(object, window_id=None, fetch_data=False, overlay=False, position=(0, 0), opacity=1)#

Draw a plot.

Parameters:
object: GraphicsDefn

Object to plot.

window_idstr

Window ID for the plot.

fetch_databool, optional

Whether to fetch data. The default is False.

overlaybool, optional

Whether to overlay graphics over existing graphics. The default is False.

position: tuple, optional

Position of the sub-plot.

opacity: float, optional

Transparency of the sub-plot.

Raises
——
RuntimeError

If the window does not support the object.

Return type:

None

animate_windows(session_id='', windows_id=[])#

Animate windows.

Parameters:
session_idstr, optional

Session ID for animating the windows that belong only to this session. The default is "", in which case the windows in all sessions are animated.

windows_idList[str], optional

List of IDs for the windows to animate. The default is [], in which case all windows are animated.

Raises:
NotImplementedError

If not implemented.

Return type:

None

close_windows(session_id='', windows_id=[])#

Close windows.

Parameters:
session_idstr, optional

Session ID for closing the windows that belong only to this session. The default is "", in which case the windows in all sessions are closed.

windows_idList[str], optional

List of IDs for the windows to close. The default is [], in which all windows are closed.

Return type:

None

get_plotter(window_id)#

Get the PyVista plotter.

Parameters:
window_idstr

Window ID for the plotter.

Returns:
Union[BackgroundPlotter, pv.Plotter]

PyVista plotter.

Return type:

Union[BackgroundPlotter, Plotter]

get_window(window_id)#

Get the Graphics window.

Parameters:
window_idstr

Window ID.

Returns:
GraphicsWindow

Graphics window.

Return type:

GraphicsWindow

open_window(window_id=None, grid=(1, 1))#

Open a new window.

Parameters:
window_idstr, optional

ID for the new window. The default is None, in which case a unique ID is automatically assigned.

grid: tuple, optional

Layout or arrangement of the graphics window. The default is (1, 1).

Returns:
str

ID for the new window.

Return type:

str

plot(object, window_id=None, fetch_data=False, overlay=False)#

Draw a plot.

Parameters:
object: GraphicsDefn

Object to plot.

window_idstr, optional

Window ID for the plot. The default is None, in which case a unique ID is assigned.

fetch_databool, optional

Whether to fetch data. The default is False.

overlaybool, optional

Whether to overlay graphics over existing graphics. The default is False.

Raises
——
RuntimeError

If the window does not support the object.

Return type:

None

refresh_windows(session_id='', windows_id=[], overlay=False)#

Refresh windows.

Parameters:
session_idstr, optional

Session ID for refreshing the windows that belong only to this session. The default is "", in which case the windows in all sessions are refreshed.

windows_idList[str], optional

IDs of the windows to refresh. The default is [], in which case all windows are refreshed.

overlaybool, Optional

Overlay graphics over existing graphics.

Return type:

None

save_graphic(window_id, format)#

Save a graphics.

Parameters:
window_idstr

Window ID for the graphics to save.

formatstr

Graphic file format. Supported formats are SVG, EPS, PS, PDF, and TEX.

Raises:
ValueError

If the window does not support the specified format.

Return type:

None

set_object_for_window(object, window_id)#

Associate a visualization object with a running window instance.

Parameters:
objectGraphicsDefn

Post object to associate with a running window instance.

window_idstr

Window ID for the association.

Raises:
RuntimeError

If the window does not support the object.

Return type:

None

show_graphics(window_id)#

Display the graphics window.