gridFIT3D module

class wakis.gridFIT3D.GridFIT3D(xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, Nx=None, Ny=None, Nz=None, x=None, y=None, z=None, use_mpi=False, use_mesh_refinement=False, refinement_method='insert', refinement_tol=1e-8, snap_points=None, snap_tol=1e-5, snap_solids=None, stl_solids=None, stl_materials=None, stl_rotate=[0.0, 0.0, 0.0], stl_translate=[0.0, 0.0, 0.0], stl_scale=1.0, stl_colors=None, stl_tol=1e-3, load_from_h5=None, verbose=1)[source]

Bases: object

Class holding the grid information and stl importing handling using PyVista

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

load_from_h5(filename)[source]

Load grid axis arrays and STL metadata from an HDF5 file.

The function restores axis arrays, recomputes grid metrics and fills self.grid cell_data with imported STL masks saved previously by save_to_h5.

Parameters

filename (str) – HDF5 filename to read. The β€˜.h5’ suffix is appended if missing.

mpi_gather_asGrid()[source]

Gather the global grid from all MPI subdomains and return a new GridFIT3D.

Returns

_grid – The global grid object (only on rank 0).

Return type

GridFIT3D 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_colors when available.

  • Solids labeled β€˜vacuum’ are rendered with reduced opacity by default.

plot_stl_mask(stl_solid, cmap='viridis', bounding_box=True, show_grid=True, add_stl='all', stl_opacity=0.0, stl_colors=None, xmax=None, ymax=None, zmax=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 ({'all', str, list[str]}, optional) – STL geometries to add. Default β€˜all’.

  • 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.

read_stl(key)[source]

Read and transform an STL solid by key.

Parameters

key (str) – Key of the STL solid to read.

Returns

surf – The transformed STL surface.

Return type

pyvista.PolyData

refine_axis(xmin, xmax, Nx, x_snaps, method='insert', tol=1e-12)[source]

Refine a grid axis using snap points and a chosen method.

Parameters
  • xmin (float) – Axis bounds.

  • xmax (float) – Axis bounds.

  • Nx (int) – Number of grid points.

  • x_snaps (array_like) – Snap points to include in the axis.

  • method (str, optional) – Refinement algorithm (β€˜insert’, β€˜neighbor’, β€˜subdivision’).

  • tol (float, optional) – Convergence tolerance for optimization.

Returns

x – Refined axis array.

Return type

ndarray

save_to_h5(filename='grid.h5')[source]

Save the generated grid and STL metadata to an HDF5 file.

The file contains axis arrays, STL masks suitable for grid.cell_data, and all stl_ related variables (materials, colors, transforms).

Parameters

filename (str, optional) – Output filename for the HDF5 file. Default β€˜grid.h5’.

update_logger(attrs)[source]

Copy selected Grid attributes into the internal Logger.

Parameters

attrs (iterable of str) – Names of attributes to copy into self.logger.grid.