2121from svv .simulation .mesh import GeneralMesh
2222from svv .simulation .fluid .fluid_equation import FluidEquation
2323from svv .simulation .utils .boundary_layer import BoundaryLayer
24-
24+ from svv . domain . routines . tetrahedralize import tetrahedralize
2525
2626# Defer 1D/0D ROM imports to their respective methods to avoid importing
2727# vtk-heavy modules during Simulation class import.
@@ -96,17 +96,20 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
9696 fluid_surface_mesh = self .synthetic_object .export_solid (watertight = True )
9797 print ("Finished Unioning water-tight model" )
9898 print ("Tetrahedralizing" )
99- tet_fluid = tetgen .TetGen (fluid_surface_mesh )
99+ # tet_fluid = tetgen.TetGen(fluid_surface_mesh)
100100 try :
101- tet_fluid .make_manifold (verbose = True )
101+ # tet_fluid.make_manifold(verbose=True)
102102 #tet_fluid.tetrahedralize(minratio=minratio, mindihedral=10.0, steinerleft=-1, order=order, nobisect=True, verbose=2, switches='M')
103- tet_fluid .tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
104- fluid_volume_mesh = tet_fluid .grid
103+ #tet_fluid.tetrahedralize(switches='pq{}/{}MVYSJ'.format(minratio, mindihedral))
104+ grid , node , elems = tetrahedralize (fluid_surface_mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
105+ fluid_volume_mesh = grid
105106 except :
106- tet_fluid .make_manifold (verbose = True )
107+ fix = pymeshfix .MeshFix (fluid_surface_mesh )
108+ fix .repair (verbose = True )
109+ #tet_fluid.make_manifold(verbose=True)
107110 #tet_fluid.tetrahedralize(minratio=minratio, mindihedral=10.0, steinerleft=-1, order=order, nobisect=True, verbose=2, switches='M')
108- tet_fluid . tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
109- fluid_volume_mesh = tet_fluid . grid
111+ grid , node , elems = tetrahedralize (fix . mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
112+ fluid_volume_mesh = grid
110113 if isinstance (fluid_volume_mesh , type (None )):
111114 print ("Failed to generate fluid volume mesh." )
112115 else :
@@ -176,7 +179,7 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
176179 # Extrude the root of the tree to ensure proper intersection with the tissue domain.
177180 if not fluid :
178181 root_extension = max (self .synthetic_object .data [0 , 21 ] * 4 , self .synthetic_object .data [0 , 20 ] * 0.5 )
179- self .synthetic_object .data [0 , 0 :3 ] - = root_extension * self .synthetic_object .data .get ('w_basis' , 0 )
182+ self .synthetic_object .data [0 , 0 :3 ] + = root_extension * self .synthetic_object .data .get ('w_basis' , 0 )
180183 # Should check to see that the extended point does not intersect with another fluid or tissue domain.
181184 fluid_surface_boolean_mesh = self .synthetic_object .export_solid (watertight = True )
182185 else :
@@ -186,7 +189,7 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
186189 fluid_surface_boolean_mesh = deepcopy (self .fluid_domain_wall_layers [- 1 ])
187190 hsize = fluid_surface_boolean_mesh .cell_data ["hsize" ][0 ]
188191 try :
189- tissue_domain = remesh_surface (self .synthetic_object .domain .boundary , hausd = hausd ) # Check if this should be remeshed
192+ tissue_domain = remesh_surface (self .synthetic_object .domain .boundary , hausd = hausd , verbosity = 0 ) # Check if this should be remeshed
190193 except :
191194 print ("REMESHING FAILS: CHECKING FOR TRIANGLE INTERSECTIONS" )
192195 tmp_boundary = pymeshfix .MeshFix (self .synthetic_object .domain .boundary )
@@ -200,23 +203,25 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
200203 hmin = ((4.0 * low_tri_area )/ 3.0 ** 0.5 ) ** (0.5 )
201204 upper_tri_area = area / lower_num_triangles
202205 hmax = ((4.0 * upper_tri_area )/ 3.0 ** 0.5 ) ** (0.5 )
203- tissue_domain = remesh_surface (tissue_domain , hausd = hausd )
206+ tissue_domain = remesh_surface (tissue_domain , hausd = hausd , verbosity = 0 )
204207 else :
205- tissue_domain = remesh_surface (tissue_domain , hausd = hausd )
206- tet_tissue = tetgen .TetGen (tissue_domain )
208+ tissue_domain = remesh_surface (tissue_domain , hausd = hausd , verbosity = 0 )
209+ # tet_tissue = tetgen.TetGen(tissue_domain)
207210 if not fluid :
208211 self .synthetic_object .data [0 , 0 :3 ] += root_extension * self .synthetic_object .data .get ('w_basis' , 0 )
209212 try :
210- tet_tissue . tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
213+ grid , nodes , elems = tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
211214 #tet_tissue.tetrahedralize(minratio=minratio, order=order)
212- tissue_volume_mesh = tet_tissue . grid
215+ tissue_volume_mesh = grid
213216 except :
214217 if fluid :
215218 print ('Mesh interface may be corrupted after mesh fixing for tetrahedralization.' )
216- tet_tissue .make_manifold (verbose = True )
219+ fix = pymeshfix .MeshFix (tissue_domain )
220+ fix .repair (verbose = True )
221+ #tet_tissue.make_manifold(verbose=True)
217222 #tet_tissue.tetrahedralize(minratio=minratio, order=order)
218- tet_tissue . tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
219- tissue_volume_mesh = tet_tissue . grid
223+ grid , nodes , elems = tetrahedralize (fix . mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
224+ tissue_volume_mesh = grid
220225 if isinstance (tissue_volume_mesh , type (None )):
221226 print ("Failed to generate tissue volume mesh." )
222227 else :
@@ -234,17 +239,19 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
234239 for tree in network :
235240 if fluid :
236241 fluid_surface_mesh = tree .export_solid (watertight = True )
237- tet_fluid = tetgen .TetGen (fluid_surface_mesh )
242+ # tet_fluid = tetgen.TetGen(fluid_surface_mesh)
238243 try :
239- tet_fluid .make_manifold (verbose = False )
244+ # tet_fluid.make_manifold(verbose=False)
240245 # Tetrahedralize the fluid domain (correct target object)
241- tet_fluid . tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
242- fluid_volume_mesh = tet_fluid . grid
246+ grid , nodes , elems = tetrahedralize (fluid_surface_mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
247+ fluid_volume_mesh = grid
243248 except :
244249 try :
245- tet_fluid .make_manifold (verbose = True )
246- tet_fluid .tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
247- fluid_volume_mesh = tet_fluid .grid
250+ #tet_fluid.make_manifold(verbose=True)
251+ fix = pymeshfix .MeshFix (fluid_surface_mesh )
252+ fix .repair (verbose = True )
253+ grid , nodes , elems = tetrahedralize (fix .mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
254+ fluid_volume_mesh = grid
248255 except :
249256 fluid_volume_mesh = None
250257 if isinstance (fluid_volume_mesh , type (None )):
@@ -259,34 +266,39 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
259266 if tissue :
260267 # Extrude the root of the tree to ensure proper intersection with the tissue domain.
261268 root_extension = max (tree .data [0 , 21 ] * 4 , tree .data [0 , 20 ] * 0.5 )
262- tree .data [0 , 0 :3 ] - = root_extension * tree .data .get ('w_basis' , 0 )
269+ tree .data [0 , 0 :3 ] + = root_extension * tree .data .get ('w_basis' , 0 )
263270 # Should check to see that the extended point does not intersect with another fluid or tissue domain.
264271 fluid_surface_boolean_mesh = tree .export_solid (watertight = True )
265272 if len (self .tissue_domain_surface_meshes ) > 0 :
266273 tissue_domain = self .tissue_domain_surface_meshes [- 1 ]
267274 else :
268275 tissue_domain = tree .domain .boundary
269276 tissue_domain = boolean (tissue_domain , fluid_surface_boolean_mesh , operation = 'difference' )
270- tissue_domain = remesh_surface (tissue_domain , hausd = hausd )
271- tet_tissue = tetgen .TetGen (tissue_domain )
272- tree .data [0 , 0 :3 ] += root_extension * tree .data .get ('w_basis' , 0 )
277+ tissue_domain = remesh_surface (tissue_domain , hausd = hausd , verbosity = 0 )
278+ # tet_tissue = tetgen.TetGen(tissue_domain)
279+ # tree.data[0, 0:3] += root_extension * tree.data.get('w_basis', 0)
273280 try :
274- tet_tissue .make_manifold (verbose = False )
275- tet_tissue .tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
276- tissue_volume_mesh = tet_tissue .grid
281+ # tet_tissue.make_manifold(verbose=False)
282+ # fix = pymeshfix.MeshFix(tissue_domain)
283+ # fix.repair(verbose=True)
284+ grid , nodes , elems = tetrahedralize (tissue_domain , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
285+ tissue_volume_mesh = grid
277286 except :
278287 try :
279- tet_tissue .make_manifold (verbose = True )
280- tet_tissue .tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
281- tissue_volume_mesh = tet_tissue .grid
288+ # tet_tissue.make_manifold(verbose=True)
289+ fix = pymeshfix .MeshFix (fix .mesh )
290+ fix .repair (verbose = True )
291+ grid , nodes , elems = tetrahedralize (fix .mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
292+ tissue_volume_mesh = grid
282293 except :
283294 tissue_volume_mesh = None
284295 if isinstance (tissue_volume_mesh , type (None )):
285296 print ("Failed to generate tissue volume mesh." )
286297 network_tissue_surface_meshes .append (None )
287298 network_tissue_volume_meshes .append (None )
288299 else :
289- tissue_volume_mesh = remesh_volume (tissue_volume_mesh , hausd = hausd )
300+ if remesh_vol :
301+ tissue_volume_mesh = remesh_volume (tissue_volume_mesh , hausd = hausd )
290302 tissue_domain = tissue_volume_mesh .extract_surface ()
291303 network_tissue_surface_meshes .append (tissue_domain )
292304 network_tissue_volume_meshes .append (tissue_volume_mesh )
@@ -302,14 +314,16 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
302314 network_solids , _ , _ = self .synthetic_object .connections .export_solid (extrude_roots = False )
303315 for i , fluid_surface in enumerate (network_solids ):
304316 if fluid :
305- tet_fluid = tetgen .TetGen (fluid_surface )
317+ # tet_fluid = tetgen.TetGen(fluid_surface)
306318 try :
307- tet_fluid . tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
308- fluid_volume = tet_fluid . grid
319+ grid , nodes , elems = tetrahedralize (fluid_surface , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
320+ fluid_volume = grid
309321 except :
310- tet_fluid .make_manifold (verbose = True )
311- tet_fluid .tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
312- fluid_volume = tet_fluid .grid
322+ #tet_fluid.make_manifold(verbose=True)
323+ fix = pymeshfix .MeshFix (fluid_surface )
324+ fix .repair (verbose = True )
325+ grid , nodes , elems = tetrahedralize (fix .mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
326+ fluid_volume = grid
313327 if isinstance (fluid_volume , type (None )):
314328 print ("Failed to generate fluid volume mesh." )
315329 self .fluid_domain_surface_meshes .append (fluid_surface )
@@ -386,7 +400,7 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
386400 radii .append (self .synthetic_object .networks [net ][tr ].data [0 , 21 ])
387401 hsize = min (radii ) * 2.0
388402 print ("Remeshing tissue domain with edge size {}." .format (hsize ))
389- tissue_domain = remesh_surface (tissue_domain , hsiz = hsize )
403+ tissue_domain = remesh_surface (tissue_domain , hsiz = hsize , verbosity = 0 )
390404 for i , fluid_surface in enumerate (self .fluid_domain_surface_meshes ):
391405 fluid_surface_normals = fluid_surface .compute_normals (auto_orient_normals = True )
392406 print ("Performing boolean operation with fluid surface mesh {}." .format (i ))
@@ -398,14 +412,16 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
398412 self .tissue_domain_surface_meshes .append (tissue_domain )
399413 #tissue_domain = remesh_surface(tissue_domain, hausd=hausd)
400414 print ("Tetrahedralizing tissue domain." )
401- tet_tissue = tetgen .TetGen (tissue_domain )
415+ # tet_tissue = tetgen.TetGen(tissue_domain)
402416 try :
403- tet_tissue . tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
404- tissue_volume_mesh = tet_tissue . grid
417+ grid , nodes , elems = tetrahedralize (tissue_domain , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
418+ tissue_volume_mesh = grid
405419 except :
406- tet_tissue .make_manifold (verbose = True )
407- tet_tissue .tetrahedralize (switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
408- tissue_volume_mesh = tet_tissue .grid
420+ #tet_tissue.make_manifold(verbose=True)
421+ fix = pymeshfix .MeshFix (tissue_domain )
422+ fix .repair (verbose = True )
423+ grid , nodes , elems = tetrahedralize (fix .mesh , switches = 'pq{}/{}MVYSJ' .format (minratio , mindihedral ))
424+ tissue_volume_mesh = grid
409425 if isinstance (tissue_volume_mesh , type (None )):
410426 print ("Failed to generate tissue volume mesh." )
411427 else :
0 commit comments