Skip to content

Commit f03bb68

Browse files
committed
wip
1 parent 6453242 commit f03bb68

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/decompositions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ end
4646
Decompose tets to edges, using a pre-allocated array and set.
4747
Set ensures uniqueness, and result will be sorted.
4848
"""
49-
function tet_to_edges!(pair::Vector, pair_set::Set, t)
49+
function tet_to_edges!(pair::Vector, pair_set::Set, t, num_tets)
5050
empty!(pair_set)
51-
length(pair) < length(t)*6 && resize!(pair, length(t)*6)
51+
length(pair) < num_tets*6 && resize!(pair, num_tets*6)
5252
num_pair = 1
53-
@inbounds for i in eachindex(t)
53+
@inbounds for i in 1:num_tets
5454
for ep in 1:6
5555
p1 = t[i][tetpairs[ep][1]]
5656
p2 = t[i][tetpairs[ep][2]]

src/distmeshnd.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ function distmesh(fdist::Function,
9696
lcount = 0 # iteration counter
9797
triangulationcount = 0 # triangulation counter
9898
num_pairs = 0
99+
num_tets = 0
99100

100101
@inbounds while true
101102
# if large move, retriangulation
102103
if maxmove>setup.ttol*h
103104

104105
# 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)
106107

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
108109

109110
# resize arrays for new pair count
110111
length(bars) < num_pairs && resize!(bars, num_pairs)
@@ -170,6 +171,7 @@ function distmesh(fdist::Function,
170171

171172
# Termination criterion
172173
if maxdp<setup.ptol*h
174+
resize!(result.tetrahedra, num_tets)
173175
return result
174176
end
175177
end
@@ -195,23 +197,23 @@ function retriangulate!(fdist, result::DistMeshResult, geps, setup, triangulatio
195197
p = result.points
196198
triangulation = delaunayn(p)
197199
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))
200201

201202
# average points to get mid point of each tetrahedra
202203
# if the mid point of the tetrahedra is outside of
203204
# the boundary we remove it.
204205
# TODO: this is an inlined filter call. Would be good to revert
205206
# TODO: can we use the point distance array to pass boundary points to
206207
# 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
209210
t[j] = ai
210211
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)
212213
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)
215217
end
216218

217219

0 commit comments

Comments
 (0)