plotting moduleο
- class wakis.plotting.PlotMixinGrid[source]ο
Bases:
objectPlotting mixin providing 1D/2D/3D visualization helpers for GridFIT3D.
- inspect(add_stl=None, stl_opacity=0.5, stl_colors=None, anti_aliasing='ssaa', smooth_shading=True, off_screen=False)[source]ο
Interactive 3D inspector showing grid and STL geometries.
- Parameters
add_stl (str or list, optional) β Key or list of keys of STL solids to include. If None, all solids are shown.
stl_opacity (float, optional) β Opacity for STL surfaces (0 transparent, 1 opaque). Default 0.5.
stl_colors (str, list, or dict, optional) β Color specification for STL surfaces; defaults to
self.stl_colors.anti_aliasing (str or None, optional) β Anti-aliasing mode to enable in the plotter (default βssaaβ).
smooth_shading (bool, optional) β Enable smooth shading for surfaces (default True).
off_screen (bool, optional) β If True, return the off-screen plotter object instead of showing an interactive window.
- Returns
pl β The plotter object if off_screen is True, otherwise None.
- Return type
pyvista.Plotter or None
- plot_snap_points(snap_solids=None, snap_tol=1e-8)[source]ο
Plot snap points extracted from STL feature edges for mesh refinement.
- Parameters
snap_solids (list or None, optional) β STL solids to use for snap point extraction. Default is all.
snap_tol (float, optional) β Tolerance for snap point detection.
- plot_solids(bounding_box=False, show_grid=False, anti_aliasing=None, opacity=1.0, specular=0.5, smooth_shading=False, off_screen=False, **kwargs)[source]ο
Generate a 3D visualization of imported STL geometries using PyVista.
- Parameters
bounding_box (bool, optional) β If True, adds a bounding box around the plotted geometry (default False).
show_grid (bool, optional) β If True, overlays the grid wireframe on the scene (default False).
anti_aliasing (str or None, optional) β Anti-aliasing mode passed to PyVista (default: None).
opacity (float, optional) β Opacity for solids (1.0 opaque, 0.0 transparent). Default 1.0.
specular (float, optional) β Specular lighting strength, higher is shinier (default 0.5).
smooth_shading (bool, optional) β Enable smooth shading for surface rendering (default False).
off_screen (bool, optional) β If True, export to HTML instead of opening an interactive window.
**kwargs (dict) β Additional keyword args forwarded to
pyvista.add_mesh.
Notes
Colors come from
self.stl_colorswhen available.Solids labeled βvacuumβ are rendered with reduced opacity by default.
- plot_stl_mask(stl_solid, cmap='viridis', bounding_box=True, clip_plane='x', add_stl=True, stl_opacity=0.1, stl_colors=None, anti_aliasing='ssaa', smooth_shading=False, off_screen=False)[source]ο
Interactive 3D visualization of the structured grid mask and imported STL geometries.
This routine uses PyVista to display the grid scalar field corresponding to a chosen STL mask. It provides interactive slider widgets to clip the domain along the X, Y, and Z directions. At each slider position, the clipped scalar field is shown with a colormap while the grid structure is shown as a 2D slice in wireframe. Optionally, one or more STL geometries can be added to the scene, along with a bounding box of the simulation domain.
- Parameters
stl_solid (str) β Key name of the stl_solids dictionary to retrieve the mask for visualization (used as the scalar field).
cmap (str, optional) β Colormap used to visualize the clipped scalar values. Default βviridisβ.
bounding_box (bool, optional) β If True, add a static wireframe bounding box of the simulation domain.
show_grid (bool, optional) β If True, adds the computational grid overlay on the clipped slice.
add_stl ({True, 'all', str, list[str]}, optional) β
- STL geometries to add. Default True adds the STL solid corresponding to the mask.
If βallβ, add all STL solids. If a string, add the STL solid with that key. If a list of strings, add the STL solids with those keys. False or None will not add any STL solids.
stl_opacity (float, optional) β Opacity of the STL surfaces (0 = fully transparent, 1 = fully opaque).
stl_colors (str, list[str], dict, or None, optional) β Color(s) of the STL surfaces.
xmax (float, optional) β Initial clipping positions along each axis. If None, use the maximum domain extent.
ymax (float, optional) β Initial clipping positions along each axis. If None, use the maximum domain extent.
zmax (float, optional) β Initial clipping positions along each axis. If None, use the maximum domain extent.
anti_aliasing ({'ssaa', 'fxaa', None}, optional) β Anti-aliasing mode passed to pl.enable_anti_aliasing.
smooth_shading (bool, optional) β Enable smooth shading for STL surfaces. Default False.
off_screen (bool, optional) β If True, render off-screen and export the scene to HTML.
Notes
Three sliders (X, Y, Z) control clipping of the scalar field by a box.
STL solids can be visualized in transparent mode.
A static domain bounding box can be added for reference.
- plot_stl_mask_slice(stl_solid, plane='ZX', position=None, cmap='viridis', bounding_box=False, show_grid=True, add_stl=False, stl_opacity=0.1, stl_colors=None, smooth_shading=False, off_screen=False)[source]ο
Interactive 2D slice visualization of the structured grid STL mask.
Lighter alternative to
plot_stl_mask()for heavy grids (>10M cells). Instead of clipping the full 3D domain, only a single 2D slice is rendered at a time. A slider widget controls the slice position along the axis normal to the chosen plane.- Parameters
stl_solid (str) β Key name of the stl_solids dictionary to retrieve the mask for visualization (used as the scalar field).
plane ({'XY', 'YX', 'ZY', 'YZ', 'ZX', 'XZ'}, optional) β
Plane of the slice. Default βZXβ.
βXYβ / βYXβ β normal along Z, slider controls Z position.
βZYβ / βYZβ β normal along X, slider controls X position.
βZXβ / βXZβ β normal along Y, slider controls Y position.
position (float or None, optional) β Initial position of the slice along the normal axis. If None, uses the center of the domain along that axis.
cmap (str, optional) β Colormap used to visualize the scalar values. Default βviridisβ.
bounding_box (bool, optional) β If True, add a static wireframe bounding box of the simulation domain.
add_stl ({True, 'all', str, list[str]}, optional) β
- STL geometries to add. Default True adds the STL solid corresponding to the mask.
If βallβ, add all STL solids. If a string, add the STL solid with that key. If a list of strings, add the STL solids with those keys. False or None will not add any STL solids.
stl_opacity (float, optional) β Opacity of the STL surfaces (0 = fully transparent, 1 = fully opaque).
stl_colors (str, list[str], dict, or None, optional) β Color(s) of the STL surfaces.
smooth_shading (bool, optional) β Enable smooth shading for STL surfaces. Default False.
off_screen (bool, optional) β If True, render off-screen and return the plotter object.
Notes
Only a single 2D slice of the domain is rendered at a time, making this much lighter than
plot_stl_mask()for large grids.- The slider controls the slice position along the normal to the chosen plane.
- The selected
stl_solidintersection with the plane is overlaid as a contour line for easier visual alignment.
- The selected
- class wakis.plotting.PlotMixinSolver[source]ο
Bases:
objectPlotting mixin providing 1D/2D/3D visualization helpers for SolverFIT3D.
- inspect(wake=None, window_size=None, off_screen=False, opacity=1.0, inactive_opacity=0.1, add_silhouette=False, specular=0.5, smooth_shading=False)[source]ο
Interactive inspection of STL solids and optional wake geometry.
Provides a PyVista-based UI to toggle visibility and highlighting for the package STL solids. When a
wakeobject is provided the method also creates a beam and an integration-path actor and exposes check boxes to toggle them. A master checkbox toggles all solids at once.- Parameters
wake (object or None, optional) β Optional wake-like object (for example a
WakeSolverinstance) that providesxsource,ysource,xtestandytestattributes used to place a beam and an integration path. When provided the object is stored asself.wake. DefaultNone.window_size (sequence or None, optional) β Tuple
(width, height)passed topyvista.Plotterto set the window size. DefaultNone(use PyVista defaults).off_screen (bool, optional) β If True the plotter is not shown interactively and the method returns the created
pyvista.Plotterinstance for programmatic control and screenshot capture. DefaultFalse.opacity (float, optional) β Opacity applied to solids when they are active/highlighted (default 1.0).
inactive_opacity (float, optional) β Opacity applied to solids when inactive (default 0.1).
add_silhouette (bool, optional) β When True add a silhouette actor behind each solid for emphasis.
specular (float, optional) β Specular lighting value forwarded to
pyvista.Plotter.add_meshfor STL actors (default 0.5).smooth_shading (bool, optional) β Enable smooth shading for STL meshes (default False).
- Returns
Returns the created
pyvista.Plotterwhenoff_screenis True so the caller can save screenshots or control rendering programmatically. Otherwise shows the interactive window and returnsNone.- Return type
pyvista.Plotter or None
Notes
The method expects
self.stl_solidsandself.stl_colorsto be populated and usesself.grid.read_stl(key)to load surfaces.When running under MPI the method prints a warning and returns immediately (interactive plotting is not supported under MPI).
- plot1D(field='E', component='z', line='z', pos=[0.5], xscale='linear', yscale='linear', xlim=None, ylim=None, figsize=[8, 4], title=None, off_screen=False, n=None, colors=None, **kwargs)[source]ο
Built-in 1D plotting of a field line using matplotlib.
Plots 1D cuts along a grid line (x, y or z) for the selected field component. Supports plotting multiple positions and MPI gathering when running in parallel.
- Parameters
field (str, optional) β Field to plot: βEβ, βHβ, or βJβ. Two-letter values (e.g. βExβ) are accepted and override
component. Default βEβ.component (str, optional) β Component to plot (βxβ,βyβ,βzβ,βAbsβ). Default βzβ.
line (str or sequence, optional) β Line specification as βxβ,βyβ,βzβ or a sequence of three indices or slices (e.g. [0, slice(10,Ny-10), 0]). Default βzβ.
pos (float or sequence, optional) β Relative position(s) (0-1) used when
lineis a single-axis specifier. Default 0.5.xscale (str, optional) β Axis scaling passed to matplotlib (default βlinearβ).
yscale (str, optional) β Axis scaling passed to matplotlib (default βlinearβ).
xlim (sequence, optional) β Axis limits for the plot.
ylim (sequence, optional) β Axis limits for the plot.
figsize (sequence, optional) β Figure size for the matplotlib figure (default [8,4]).
title (str, optional) β Basename used to save screenshots when
off_screen=True.off_screen (bool, optional) β If True save the figure to disk instead of showing it interactively.
n (int, optional) β Timestep index appended to saved filenames.
colors (sequence, optional) β Colors used for each plotted line when multiple positions are requested.
**kwargs (dict) β Extra keyword arguments forwarded to
matplotlib.axes.Axes.plot.
- Return type
None
Notes
When running with MPI (use_mpi=True), only rank 0 will display or save the figure.
- plot2D(field='E', component='z', plane='ZY', pos=0.5, norm=None, vmin=None, vmax=None, figsize=[8, 4], cmap='jet', patch_alpha=0.1, patch_reverse=False, add_patch=False, title=None, off_screen=False, n=None, interpolation='antialiased', dpi=100, return_handles=False, backend='matplotlib')[source]ο
Built-in 2D plotting of a field slice.
Renders a 2D cut through the structured grid using either a matplotlib (
imshow) or PyVista (static slice) backend.- Parameters
field (str, optional) β Field to plot: βEβ, βHβ, or βJβ. Two-letter values (e.g. βExβ) are accepted and override
component. Default βEβ.component (str, optional) β Component to plot (βxβ,βyβ,βzβ,βAbsβ). Default βzβ.
plane (str or sequence, optional) β Cut plane specified as βXYβ, βZYβ, βZXβ or a sequence of slices and an integer index
[x,y,z]. Default βZYβ.pos (float, optional) β Relative position in the normal direction for the cut (0-1). Default 0.5 (center).
norm (str or None, optional) β Color normalization for
imshow(βlinearβ,βlogβ,βsymlogβ). Matplotlib backend only.vmin (scalar, optional) β Color limits for the plot.
vmax (scalar, optional) β Color limits for the plot.
figsize (sequence, optional) β Figure size for the matplotlib figure (default [8,4]).
cmap (str, optional) β Colormap for the field plot (default βjetβ).
patch_alpha (float, optional) β Alpha value for STL overlays (default 0.1).
patch_reverse (bool, optional) β If True, reverse the mask for the patch overlay. Matplotlib only.
add_patch (str or list, optional) β STL key or list of keys to overlay. Matplotlib: drawn as a filled mask patch. PyVista: drawn as STL contour lines on the slice.
title (str, optional) β Basename used to save screenshots when
off_screen=True.off_screen (bool, optional) β Matplotlib: save figure to disk. PyVista: return plotter object.
n (int, optional) β Timestep index appended to saved filenames. Matplotlib only.
interpolation (str, optional) β Interpolation method for
imshow(default βantialiasedβ). Matplotlib only.dpi (int, optional) β Dots per inch for the figure (default 100). Matplotlib only.
return_handles (bool, optional) β If True return the
(fig, ax)handles instead of showing. Matplotlib only.backend ({'matplotlib', 'pyvista'}, optional) β Visualization backend. Default βmatplotlibβ.
- Returns
(fig, ax)whenbackend='matplotlib'andreturn_handles=Trueoroff_screen=True.pyvista.Plotterwhenbackend='pyvista'andoff_screen=True.Noneotherwise.
- Return type
None or tuple or pyvista.Plotter
Notes
When running with MPI (use_mpi=True), only rank 0 will display or save the figure (matplotlib backend only).
STL patch overlays are not supported when running under MPI.
- plot3D(field='E', component='z', clim=None, hide_solids=None, show_solids=None, add_stl=None, stl_opacity=0.1, stl_colors='white', title=None, cmap='jet', clip_interactive=True, clip_normal='-y', clip_box=False, clip_bounds=None, off_screen=False, zoom=0.5, camera_position=None, nan_opacity=1.0, n=None)[source]ο
Built-in 3D plotting using PyVista.
Displays a cell-centered field (E, H or J) on the structured grid using PyVista. Optionally overlays STL solids, clipping widgets or a static clip box. When rendered off-screen the plot can be saved to a PNG file for later composition into animations.
- Parameters
field (str, optional) β 3D field magnitude to plot: βEβ, βHβ, or βJβ. A two-letter value (e.g., βExβ) is accepted to plot a single component; in that case
componentis overridden. Default βEβ.component (str, optional) β Component of the field to plot: βxβ, βyβ, βzβ, or βAbsβ. Default βzβ. Overridden when
fieldcontains a component.clim (sequence, optional) β Colorbar limits for the field plot as
[min, max].hide_solids (str, list, or None, optional) β If provided, mask values inside the named STL solids to
np.nan. NaNs are shown in grey due to a known PyVista opacity limitation.show_solids (str, list, or None, optional) β If provided, mask values outside the named STL solids to
np.nan.add_stl (str or list, optional) β STL solid key or list of keys to add to the scene via
pv.add_mesh.stl_opacity (float, optional) β Opacity for STL surfaces (0 transparent, 1 opaque). Default 0.1.
stl_colors (str or list, optional) β Color or list of colors for STL surfaces (default βwhiteβ).
title (str, optional) β Basename used to save screenshots when
off_screen=True.cmap (str, optional) β Colormap name for the field display (default βjetβ).
clip_interactive (bool, optional) β Enable an interactive clipping plane widget (default False).
clip_normal (str, optional) β Normal direction for the interactive clip plane (default β-yβ).
clip_box (bool, optional) β Enable a static box clipping of the domain (default False).
clip_bounds (sequence, optional) β Box bounds as
[xmin,xmax,ymin,ymax,zmin,zmax]whenclip_boxis active.off_screen (bool, optional) β Render off-screen and save screenshots instead of opening an interactive window (default False).
zoom (float, optional) β Camera zoom factor (default 0.5).
camera_position (str, sequence, or None, optional) β Camera position preset or coordinates (default None).
nan_opacity (float, optional) β Opacity for NaN values produced by masking (default 1.0).
n (int, optional) β Timestep index appended to saved screenshot filenames.
- Return type
None
Notes
When running with MPI (use_mpi=True), plotting is not supported.
The method modifies the PyVista plotter state and may save screenshots if off_screen=True.
- plot3DonSTL(field='E', component='z', clim=None, cmap='jet', log_scale=False, stl_with_field=None, field_opacity=1.0, tolerance=None, stl_transparent=None, stl_opacity=0.1, stl_colors='white', clip_plane=False, clip_interactive=False, clip_normal='-x', clip_origin=[0, 0, 0], clip_box=False, clip_bounds=None, title=None, off_screen=False, n=None, zoom=0.5, camera_position=None, **kwargs)[source]ο
Built-in 3D plotting sampling fields onto STL surfaces.
Samples a cell-centered field onto STL surfaces and visualizes the sampled field. Supports clipping with a plane or a static box and rendering the STL surfaces with or without sampled field data.
- Parameters
field (str, optional) β Field to sample and plot: βEβ, βHβ, or βJβ. Two-letter values like βExβ are accepted and override
component. Default βEβ.component (str, optional) β Component to plot (βxβ, βyβ, βzβ, βAbsβ). Default βzβ.
clim (sequence, optional) β Color limits for the plotted field.
cmap (str, Colormap, optional) β Colormap for field rendering (default βjetβ).
log_scale (bool, optional) β Use logarithmic color scaling when True (default False).
stl_with_field (str or list, optional) β STL key or list of keys whose surfaces will be sampled with the selected field.
field_opacity (float, optional) β Opacity for the sampled field rendering on STL surfaces.
tolerance (float, optional) β Sampling tolerance passed to
pyvista.PolyData.sample.stl_transparent (str or list, optional) β STL solids to add to the scene with transparent rendering.
stl_opacity (float, optional) β Opacity for non-sampled STL solids (default 0.1).
stl_colors (str or list, optional) β Colors used for STL solids (default βwhiteβ).
clip_interactive (bool, optional) β Enable an interactive clipping plane for sampled surfaces.
clip_plane (bool, optional) β Clip the STL surface with a plane and show the field on the plane.
clip_normal (str, optional) β Normal direction for clipping operations (default β-xβ).
clip_origin (sequence, optional) β Origin for planar clipping when
clip_planeis True.clip_box (bool, optional) β Clip sampled surfaces using a static box (default False).
clip_bounds (sequence, optional) β Bounds for the static clip box as
[xmin,xmax,ymin,ymax,zmin,zmax].title (str, optional) β Basename used to save screenshots when
off_screen=True.off_screen (bool, optional) β Render off-screen and save screenshots when True.
n (int, optional) β Timestep index appended to saved filenames.
zoom (float, optional) β Camera zoom factor (default 0.5).
camera_position (str, sequence, or None, optional) β Camera position preset or coordinates (default None).
**kwargs (dict) β Extra keyword arguments forwarded to
pyvista.Plotter.add_mesh.
- Return type
None
Notes
When running with MPI (use_mpi=True), plotting is not supported.
The method modifies the PyVista plotter state and may save screenshots if off_screen=True.