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