Skip to content

Commit f781e62

Browse files
committed
minimal version of a single resize for bar vectors
1 parent fb3486d commit f781e62

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/decompositions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ function tet_to_edges!(pair::Vector, pair_set::Set, t)
6565

6666
# sort the edge pairs for better point lookup
6767
sort!(pair)
68-
end
68+
69+
return length(pair) # return the number of pairs
70+
end

src/distmeshnd.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function distmesh(fdist::Function,
9595
# information on each iteration
9696
lcount = 0 # iteration counter
9797
triangulationcount = 0 # triangulation counter
98+
num_pairs = 0
9899

99100
@inbounds while true
100101
# if large move, retriangulation
@@ -103,18 +104,20 @@ function distmesh(fdist::Function,
103104
# compute a new delaunay triangulation
104105
retriangulate!(fdist, result, geps, setup, triangulationcount, pt_dists)
105106

106-
tet_to_edges!(pair, pair_set, result.tetrahedra) # 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
107108

108109
# resize arrays for new pair counts
109-
resize!(bars, length(pair))
110-
resize!(L, length(pair))
110+
if triangulationcount == 0
111+
resize!(bars, length(result.tetrahedra)*6)
112+
resize!(L, length(result.tetrahedra)*6)
113+
end
111114
non_uniform && resize!(L0, length(pair))
112115

113116
triangulationcount += 1
114117
stats && push!(result.stats.retriangulations, lcount)
115118
end
116119

117-
compute_displacements!(fh, dp, pair, L, L0, bars, result.points, setup, VertType)
120+
compute_displacements!(fh, dp, pair, num_pairs, L, L0, bars, result.points, setup, VertType)
118121

119122
# Zero out forces on fix points
120123
if have_fixed
@@ -214,16 +217,17 @@ function retriangulate!(fdist, result::DistMeshResult, geps, setup, triangulatio
214217
end
215218

216219

217-
function compute_displacements!(fh, dp, pair, L, L0, bars, p, setup,
218-
::Type{VertType}) where {VertType}
220+
221+
function compute_displacements!(fh, dp, pair, num_pairs, L, L0, bars, p, setup,
222+
::Type{VertType}) where {VertType}
219223

220224
non_uniform = isa(typeof(L0), AbstractVector)
221225

222226
# compute edge lengths (L) and adaptive edge lengths (L0)
223227
# Lp norm (p=3) is partially computed here
224228
Lsum = zero(eltype(L))
225229
L0sum = non_uniform ? zero(eltype(L0)) : length(pair)
226-
for i in eachindex(pair)
230+
for i in 1:num_pairs
227231
pb = pair[i]
228232
b1 = p[pb[1]]
229233
b2 = p[pb[2]]
@@ -245,7 +249,7 @@ function compute_displacements!(fh, dp, pair, L, L0, bars, p, setup,
245249
lscbrt = (1+(0.4/2^2))*cbrt(Lsum/L0sum)
246250

247251
# Move mesh points based on edge lengths L and forces F
248-
for i in eachindex(pair)
252+
for i in 1:num_pairs
249253
if non_uniform && L[i] < L0[i]*lscbrt || L[i] < lscbrt
250254
L0_f = non_uniform ? L0[i].*lscbrt : lscbrt
251255
# compute force vectors

0 commit comments

Comments
 (0)