@@ -79,7 +79,9 @@ function distmesh(fdist::Function,
79
79
end
80
80
81
81
# Result struct for holding points, simplices, and iteration statistics
82
- result = DistMeshResult (p, GeometryBasics. SimplexFace{4 ,Int32}[], DistMeshStatistics ())
82
+ result = DistMeshResult (p,
83
+ GeometryBasics. SimplexFace{4 ,Int32}[],
84
+ stats ? DistMeshStatistics () : nothing )
83
85
84
86
# initialize arrays
85
87
pair_set = Set {Tuple{Int32,Int32}} () # set used for ensure we have a unique set of edges
@@ -103,14 +105,8 @@ function distmesh(fdist::Function,
103
105
# if large move, retriangulation
104
106
if maxmove> setup. ttol* h
105
107
106
- # use hilbert sort to improve cache locality of points
107
- if setup. sort && iszero (triangulationcount % setup. sort_interval)
108
- hilbertsort! (p)
109
- end
110
-
111
108
# compute a new delaunay triangulation
112
- # we use the default random insertion method
113
- delaunayn! (fdist, result, geps, false )
109
+ retriangulate! (fdist, result, geps, setup, triangulationcount)
114
110
115
111
tet_to_edges! (pair, pair_set, result. tetrahedra) # Describe each edge by a unique pair of nodes
116
112
@@ -192,3 +188,32 @@ function distmesh(fdist::Function,
192
188
end
193
189
end
194
190
end
191
+
192
+ function retriangulate! (fdist, result:: DistMeshResult , geps, setup, triangulationcount)
193
+ # use hilbert sort to improve cache locality of points
194
+ if setup. sort && iszero (triangulationcount % setup. sort_interval)
195
+ hilbertsort! (result. points)
196
+ end
197
+
198
+ t = result. tetrahedra
199
+ p = result. points
200
+ triangulation = delaunayn (p)
201
+ t_d = triangulation. tetrahedra
202
+ resize! (t, length (t_d))
203
+ copyto! (t, t_d) # we need to copy since we have a shared reference with tetgen
204
+
205
+ # average points to get mid point of each tetrahedra
206
+ # if the mid point of the tetrahedra is outside of
207
+ # the boundary we remove it.
208
+ # TODO : this is an inlined filter call. Would be good to revert
209
+ # TODO : can we use the point distance array to pass boundary points to
210
+ # tetgen so this call is no longer required?
211
+ j = firstindex (t)
212
+ for ai in t
213
+ t[j] = ai
214
+ pm = (p[ai[1 ]]. + p[ai[2 ]]. + p[ai[3 ]]. + p[ai[4 ]]). / 4
215
+ j = ifelse (fdist (pm) <= - geps, nextind (t, j), j)
216
+ end
217
+ j <= lastindex (t) && resize! (t, j- 1 )
218
+ nothing
219
+ end
0 commit comments