@@ -96,16 +96,15 @@ function distmesh(fdist::Function,
96
96
lcount = 0 # iteration counter
97
97
triangulationcount = 0 # triangulation counter
98
98
num_pairs = 0
99
- num_tets = 0
100
99
101
100
@inbounds while true
102
101
# if large move, retriangulation
103
102
if maxmove> setup. ttol* h
104
103
105
104
# compute a new delaunay triangulation
106
- num_tets = retriangulate! (fdist, result, geps, setup, triangulationcount, pt_dists)
105
+ retriangulate! (fdist, result, geps, setup, triangulationcount, pt_dists)
107
106
108
- num_pairs = tet_to_edges! (pair, pair_set, result. tetrahedra, num_tets ) # Describe each edge by a unique pair of nodes
107
+ num_pairs = tet_to_edges! (pair, pair_set, result. tetrahedra) # Describe each edge by a unique pair of nodes
109
108
110
109
# resize arrays for new pair count
111
110
length (bars) < num_pairs && resize! (bars, num_pairs)
@@ -171,7 +170,6 @@ function distmesh(fdist::Function,
171
170
172
171
# Termination criterion
173
172
if maxdp< setup. ptol* h
174
- resize! (result. tetrahedra, num_tets)
175
173
return result
176
174
end
177
175
end
@@ -197,23 +195,23 @@ function retriangulate!(fdist, result::DistMeshResult, geps, setup, triangulatio
197
195
p = result. points
198
196
triangulation = delaunayn (p)
199
197
t_d = triangulation. tetrahedra
200
- length (t) < length (t_d) && resize! (t, length (t_d))
198
+ resize! (t, length (t_d))
199
+ copyto! (t, t_d) # we need to copy since we have a shared reference with tetgen
201
200
202
201
# average points to get mid point of each tetrahedra
203
202
# if the mid point of the tetrahedra is outside of
204
203
# the boundary we remove it.
205
204
# TODO : this is an inlined filter call. Would be good to revert
206
205
# TODO : can we use the point distance array to pass boundary points to
207
206
# tetgen so this call is no longer required?
208
- j = 1
209
- for ai in t_d
207
+ j = firstindex (t)
208
+ for ai in t
210
209
t[j] = ai
211
210
pm = (p[ai[1 ]]. + p[ai[2 ]]. + p[ai[3 ]]. + p[ai[4 ]]). / 4
212
- j = ifelse (fdist (pm) <= - geps, j + 1 , j)
211
+ j = ifelse (fdist (pm) <= - geps, nextind (t, j) , j)
213
212
end
214
- # j <= lastindex(t) && resize!(t, j-1)
215
- j <= length (t_d) && return j- 1
216
- return length (t_d)
213
+ j <= lastindex (t) && resize! (t, j- 1 )
214
+ nothing
217
215
end
218
216
219
217
0 commit comments