@@ -78,7 +78,7 @@ function distmesh(fdist::Function,
78
78
dp = zeros (VertType, length (p)) # displacement at each node
79
79
bars = VertType[] # the vector of each edge
80
80
L = eltype (VertType)[] # vector length of each edge
81
- non_uniform && ( L0 = eltype (VertType)[]) # desired edge length computed by dh (edge length function)
81
+ L0 = non_uniform ? eltype (VertType)[] : nothing # desired edge length computed by dh (edge length function)
82
82
t = GeometryBasics. SimplexFace{4 ,Int32}[] # tetrahedra indices from delaunay triangulation
83
83
maxmove = typemax (eltype (VertType)) # stores an iteration max movement for retriangulation
84
84
@@ -107,46 +107,7 @@ function distmesh(fdist::Function,
107
107
stats && push! (statsdata. retriangulations, lcount)
108
108
end
109
109
110
- # compute edge lengths (L) and adaptive edge lengths (L0)
111
- # Lp norm (p=3) is partially computed here
112
- Lsum = zero (eltype (L))
113
- L0sum = non_uniform ? zero (eltype (L0)) : length (pair)
114
- for i in eachindex (pair)
115
- pb = pair[i]
116
- b1 = p[pb[1 ]]
117
- b2 = p[pb[2 ]]
118
- barvec = b1 - b2 # bar vector
119
- bars[i] = barvec
120
- L[i] = sqrt (sum (barvec.^ 2 )) # length
121
- non_uniform && (L0[i] = fh ((b1+ b2). / 2 ))
122
- Lsum = Lsum + L[i]. ^ 3
123
- non_uniform && (L0sum = L0sum + L0[i]. ^ 3 )
124
- end
125
-
126
- # zero out force at each node
127
- for i in eachindex (dp)
128
- dp[i] = zero (VertType)
129
- end
130
-
131
- # this is not hoisted correctly in the loop so we initialize here
132
- # finish computing the Lp norm (p=3)
133
- lscbrt = (1 + (0.4 / 2 ^ 2 ))* cbrt (Lsum/ L0sum)
134
-
135
- # Move mesh points based on edge lengths L and forces F
136
- for i in eachindex (pair)
137
- L0_f = non_uniform ? L0[i]. * lscbrt : lscbrt
138
- # compute force vectors
139
- F = L0_f- L[i]
140
- # edges are not allowed to pull, only repel
141
- if F > zero (eltype (L))
142
- FBar = bars[i]. * F./ L[i]
143
- # add the force vector to the node
144
- b1 = pair[i][1 ]
145
- b2 = pair[i][2 ]
146
- dp[b1] = dp[b1] .+ FBar
147
- dp[b2] = dp[b2] .- FBar
148
- end
149
- end
110
+ compute_displacements! (fh, dp, pair, L, L0, bars, p, setup, VertType)
150
111
151
112
# Zero out forces on fix points
152
113
if have_fixed
@@ -281,46 +242,7 @@ function distmesh(fdist::Function,
281
242
stats && push! (statsdata. retriangulations, lcount)
282
243
end
283
244
284
- # compute edge lengths (L) and adaptive edge lengths (L0)
285
- # Lp norm (p=3) is partially computed here
286
- Lsum = zero (eltype (L))
287
- L0sum = non_uniform ? zero (eltype (L0)) : length (pair)
288
- for i in eachindex (pair)
289
- pb = pair[i]
290
- b1 = p[pb[1 ]]
291
- b2 = p[pb[2 ]]
292
- barvec = b1 - b2 # bar vector
293
- bars[i] = barvec
294
- L[i] = sqrt (sum (barvec.^ 2 )) # length
295
- non_uniform && (L0[i] = fh ((b1+ b2). / 2 ))
296
- Lsum = Lsum + L[i]. ^ 3
297
- non_uniform && (L0sum = L0sum + L0[i]. ^ 3 )
298
- end
299
-
300
- # zero out force at each node
301
- for i in eachindex (dp)
302
- dp[i] = zero (VertType)
303
- end
304
-
305
- # this is not hoisted correctly in the loop so we initialize here
306
- # finish computing the Lp norm (p=3)
307
- lscbrt = (1 + (0.4 / 2 ^ 2 ))* cbrt (Lsum/ L0sum)
308
-
309
- # Move mesh points based on edge lengths L and forces F
310
- for i in eachindex (pair)
311
- if non_uniform && L[i] < L0[i] || L[i] < lscbrt
312
- L0_f = non_uniform ? L0[i]. * lscbrt : lscbrt
313
- # compute force vectors
314
- F = L0_f- L[i]
315
- # edges are not allowed to pull, only repel
316
- FBar = bars[i]. * F./ L[i]
317
- # add the force vector to the node
318
- b1 = pair[i][1 ]
319
- b2 = pair[i][2 ]
320
- dp[b1] = dp[b1] .+ FBar
321
- dp[b2] = dp[b2] .- FBar
322
- end
323
- end
245
+ compute_displacements! (fh, dp, pair, L, L0, bars, p, setup, VertType)
324
246
325
247
# Zero out forces on fix points
326
248
if have_fixed
0 commit comments