@@ -103,7 +103,7 @@ def create_mesh(
103103 edge_length_r : float = 0.015 ,
104104 skip_simplify : bool = False ,
105105 coarsen : bool = True ,
106- stop_quality : int = 8 ,
106+ stop_quality : int = 10 ,
107107 max_its : int = 30 ,
108108 loglevel : int = 10 ,
109109 disable_filtering : bool = False ,
@@ -129,41 +129,73 @@ def create_mesh(
129129 }
130130 logger .info (pprint .pformat (params ))
131131
132- import wildmeshing as wm
132+ try :
133+ import wildmeshing as wm
134+
135+ HAS_WILDMESHING = True
136+ except ImportError :
137+ HAS_WILDMESHING = False
138+
139+ try :
140+ from pytetwild import PyfTetWildWrapper
141+
142+ HAS_PYTETWILD = True
143+ except ImportError :
144+ HAS_PYTETWILD = False
145+
133146 import meshio
134147 import pyvista as pv
135148
136149 outdir = Path (outdir )
137150 outdir .mkdir (parents = True , exist_ok = True )
138151 (outdir / "mesh_params.json" ).write_text (json .dumps (params , indent = 2 ))
139152
140- tetra = wm .Tetrahedralizer (
141- epsilon = epsilon ,
142- edge_length_r = edge_length_r ,
143- coarsen = coarsen ,
144- stop_quality = stop_quality ,
145- max_its = max_its ,
146- skip_simplify = skip_simplify ,
147- )
148- tetra .set_log_level (loglevel )
149-
150- tetra .load_csg_tree (json .dumps (csg_tree ))
151- tetra .tetrahedralize ()
152- point_array , cell_array , marker = tetra .get_tet_mesh (
153- all_mesh = disable_filtering ,
154- smooth_open_boundary = smooth_open_boundary ,
155- floodfill = use_floodfill ,
156- manifold_surface = manifold_surface ,
157- correct_surface_orientation = True ,
158- )
153+ if HAS_WILDMESHING :
154+ tetra = wm .Tetrahedralizer (
155+ epsilon = epsilon ,
156+ edge_length_r = edge_length_r ,
157+ coarsen = coarsen ,
158+ stop_quality = stop_quality ,
159+ max_its = max_its ,
160+ skip_simplify = skip_simplify ,
161+ )
162+ tetra .set_log_level (loglevel )
163+
164+ tetra .load_csg_tree (json .dumps (csg_tree ))
165+ tetra .tetrahedralize ()
166+ point_array , cell_array , marker = tetra .get_tet_mesh (
167+ all_mesh = disable_filtering ,
168+ smooth_open_boundary = smooth_open_boundary ,
169+ floodfill = use_floodfill ,
170+ manifold_surface = manifold_surface ,
171+ correct_surface_orientation = True ,
172+ )
173+
174+ else :
175+ assert HAS_PYTETWILD , "Either wildmeshing or pytetwild must be installed"
176+
177+ csg_tree_path = outdir / "csg_tree.json"
178+ csg_tree_path .write_text (json .dumps (csg_tree ))
179+ num_threads = 0
180+ coarsen = True
181+ vtk_ordering = True
182+ point_array , cell_array , marker = PyfTetWildWrapper .tetrahedralize_csg (
183+ str (csg_tree_path ),
184+ epsilon ,
185+ edge_length_r ,
186+ stop_quality ,
187+ coarsen ,
188+ num_threads ,
189+ loglevel ,
190+ vtk_ordering ,
191+ )
159192
160193 tetra_mesh = meshio .Mesh (
161194 point_array , [("tetra" , cell_array )], cell_data = {"cell_tags" : [marker .ravel ()]}
162195 )
163196
164197 tetra_mesh_pv = pv .from_meshio (tetra_mesh )
165198 pv .save_meshio (outdir / "tetra_mesh.xdmf" , tetra_mesh_pv )
166-
167199 np .save (outdir / "point_array.npy" , point_array )
168200 np .save (outdir / "cell_array.npy" , cell_array )
169201 np .save (outdir / "marker.npy" , marker )
0 commit comments