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:
objectClass 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.gridcell_data with imported STL masks saved previously bysave_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_colorswhen 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 allstl_related variables (materials, colors, transforms).- Parameters
filename (str, optional) β Output filename for the HDF5 file. Default βgrid.h5β.