Skip to content

Commit 497fe5e

Browse files
committed
feature: add function to extract the surface of a given STL mask using a gradient based boundary detection
1 parent ff498bf commit 497fe5e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

wakis/gridFIT3D.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class GridFIT3D:
5757
- if dict, it must contain the same keys as `stl_solids`
5858
use_mpi: bool, default False
5959
Enable MPI domain decomposition in the z direction.
60+
use_SIBC: bool, default True
61+
Enable SIBC (Leontovich boundary condition) to model high-conductive
62+
materials. Applied when material conductivity > 1e3 S/m
6063
use_mesh_refinement: bool, default False
6164
[!] WIP -- Enable mesh refinement based on snap points
6265
extracted from the stl solids
@@ -76,6 +79,7 @@ def __init__(self, xmin=None, xmax=None,
7679
Nx=None, Ny=None, Nz=None,
7780
x=None, y=None, z=None,
7881
use_mpi=False,
82+
use_SIBC=True,
7983
use_mesh_refinement=False, refinement_method='insert', refinement_tol=1e-8,
8084
snap_points=None, snap_tol=1e-5, snap_solids=None,
8185
stl_solids=None, stl_materials=None,
@@ -137,6 +141,7 @@ def __init__(self, xmin=None, xmax=None,
137141
self.update_logger(['xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax'])
138142

139143
# stl info
144+
self.use_SIBC = use_SIBC
140145
self.stl_solids = stl_solids
141146
self.stl_materials = stl_materials
142147
self.stl_rotate = stl_rotate
@@ -199,6 +204,8 @@ def __init__(self, xmin=None, xmax=None,
199204
self.stl_tol = stl_tol
200205
if stl_solids is not None:
201206
self._mark_cells_in_stl()
207+
if use_SIBC:
208+
self._mark_cells_in_surface()
202209

203210
if verbose:
204211
print(f'Total grid initialization time: {time.time() - t0} s')
@@ -395,6 +402,7 @@ def _mark_cells_in_stl(self):
395402
if self.verbose > 1:
396403
print(f'[!] Warning: stl solid {key} may have issues with closed surfaces. Consider checking the STL file.')
397404

405+
# TODO: adapt for subpixel smoothing
398406
self.grid[key] = select.point_data_to_cell_data()['SelectedPoints'] > stl_tolerance
399407

400408
if self.verbose and np.sum(self.grid[key]) == 0:
@@ -403,6 +411,16 @@ def _mark_cells_in_stl(self):
403411
if self.verbose > 1:
404412
print(f' * STL solid {key}: {np.sum(self.grid[key])} cells marked inside the solid.')
405413

414+
def _mark_cells_in_surface(self):
415+
# Modify the STL mask to account only for the surface
416+
# Needed for the SIBC boundary condition when conductivity > 1e3 S/m
417+
for key in self.stl_solids.keys():
418+
if len(self.stl_materials[key]) == 3 and self.stl_materials[key][2] > 1e3:
419+
grad = np.array(self.grid.compute_derivative(scalars=key, gradient='gradient')['gradient'])
420+
grad = np.sqrt(grad[:, 0]**2 + grad[:, 1]**2 + grad[:, 2]**2)
421+
#TODO: adapt for subpixel smoothing
422+
self.grid[key] = grad.astype(bool)
423+
406424
def read_stl(self, key):
407425
# import stl
408426
surf = pv.read(self.stl_solids[key])

0 commit comments

Comments
 (0)