Skip to content

Commit 3e38796

Browse files
committed
some more cleanups
1 parent 5836af1 commit 3e38796

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/distmeshnd.jl

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ function distmesh(fdist::Function,
7979
end
8080

8181
# 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)
8385

8486
# initialize arrays
8587
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,
103105
# if large move, retriangulation
104106
if maxmove>setup.ttol*h
105107

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-
111108
# 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)
114110

115111
tet_to_edges!(pair, pair_set, result.tetrahedra) # Describe each edge by a unique pair of nodes
116112

@@ -192,3 +188,32 @@ function distmesh(fdist::Function,
192188
end
193189
end
194190
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

Comments
 (0)