@@ -35,6 +35,13 @@ function distmesh(fdist::Function,
35
35
distmesh (fdist, fh, h, setup, o, w, fp, Val (stats), VT)
36
36
end
37
37
38
+
39
+ struct DistMeshResult{PT, TT, STATS}
40
+ points:: Vector{PT}
41
+ tetrahedra:: Vector{TT}
42
+ stats:: STATS
43
+ end
44
+
38
45
function distmesh (fdist:: Function ,
39
46
fh,
40
47
h:: Number ,
@@ -71,14 +78,16 @@ function distmesh(fdist::Function,
71
78
facecenteredcubic! (fdist, p, pt_dists, h, setup. iso, origin, widths, VertType)
72
79
end
73
80
81
+ # Result struct for holding points, simplices, and iteration statistics
82
+ result = DistMeshResult (p, GeometryBasics. SimplexFace{4 ,Int32}[], DistMeshStatistics ())
83
+
74
84
# initialize arrays
75
85
pair_set = Set {Tuple{Int32,Int32}} () # set used for ensure we have a unique set of edges
76
86
pair = Tuple{Int32,Int32}[] # edge indices (Int32 since we use Tetgen)
77
87
dp = zeros (VertType, length (p)) # displacement at each node
78
88
bars = VertType[] # the vector of each edge
79
89
L = eltype (VertType)[] # vector length of each edge
80
90
L0 = non_uniform ? eltype (VertType)[] : nothing # desired edge length computed by dh (edge length function)
81
- t = GeometryBasics. SimplexFace{4 ,Int32}[] # tetrahedra indices from delaunay triangulation
82
91
maxmove = typemax (eltype (VertType)) # stores an iteration max movement for retriangulation
83
92
84
93
# arrays for tracking quality metrics
@@ -87,7 +96,6 @@ function distmesh(fdist::Function,
87
96
qualities = eltype (VertType)[]
88
97
89
98
# information on each iteration
90
- statsdata = DistMeshStatistics ()
91
99
lcount = 0 # iteration counter
92
100
triangulationcount = 0 # triangulation counter
93
101
@@ -102,9 +110,9 @@ function distmesh(fdist::Function,
102
110
103
111
# compute a new delaunay triangulation
104
112
# we use the default random insertion method
105
- delaunayn! (fdist, p, t , geps, false )
113
+ delaunayn! (fdist, result , geps, false )
106
114
107
- tet_to_edges! (pair, pair_set, t ) # Describe each edge by a unique pair of nodes
115
+ tet_to_edges! (pair, pair_set, result . tetrahedra ) # Describe each edge by a unique pair of nodes
108
116
109
117
# resize arrays for new pair counts
110
118
resize! (bars, length (pair))
@@ -114,14 +122,14 @@ function distmesh(fdist::Function,
114
122
# if the points were sorted we need to update the distance cache
115
123
if setup. sort && iszero (triangulationcount % setup. sort_interval)
116
124
for i in eachindex (p)
117
- pt_dists[i] = fdist (p [i])
125
+ pt_dists[i] = fdist (result . points [i])
118
126
end
119
127
end
120
128
triangulationcount += 1
121
- stats && push! (statsdata . retriangulations, lcount)
129
+ stats && push! (result . stats . retriangulations, lcount)
122
130
end
123
131
124
- compute_displacements! (fh, dp, pair, L, L0, bars, p , setup, VertType)
132
+ compute_displacements! (fh, dp, pair, L, L0, bars, result . points , setup, VertType)
125
133
126
134
# Zero out forces on fix points
127
135
if have_fixed
@@ -144,7 +152,7 @@ function distmesh(fdist::Function,
144
152
# complex distance functions and large node counts
145
153
move = sqrt (sum ((p[i]- p0). ^ 2 )) # compute movement from the displacement
146
154
d_est = pt_dists[i] + move # apply the movement to our cache point
147
- d = d_est < - geps ? d_est : fdist (p [i]) # determine if we need correct or approximate distance
155
+ d = d_est < - geps ? d_est : fdist (result . points [i]) # determine if we need correct or approximate distance
148
156
pt_dists[i] = d # store distance
149
157
150
158
if d < - geps
@@ -167,20 +175,20 @@ function distmesh(fdist::Function,
167
175
168
176
# save iteration stats
169
177
if stats
170
- push! (statsdata . maxmove,maxmove)
171
- push! (statsdata . maxdp,maxdp)
172
- triangle_qualities! (tris,triset,qualities,p,t )
178
+ push! (result . stats . maxmove,maxmove)
179
+ push! (result . stats . maxdp,maxdp)
180
+ triangle_qualities! (tris,triset,qualities,result . points,result . tetrahedra )
173
181
sort! (qualities) # sort for median calc and robust summation
174
182
mine, maxe = extrema (qualities)
175
- push! (statsdata . average_qual, sum (qualities)/ length (qualities))
176
- push! (statsdata . median_qual, qualities[round (Int,length (qualities)/ 2 )])
177
- push! (statsdata . minimum_qual, mine)
178
- push! (statsdata . maximum_qual, maxe)
183
+ push! (result . stats . average_qual, sum (qualities)/ length (qualities))
184
+ push! (result . stats . median_qual, qualities[round (Int,length (qualities)/ 2 )])
185
+ push! (result . stats . minimum_qual, mine)
186
+ push! (result . stats . maximum_qual, maxe)
179
187
end
180
188
181
189
# Termination criterion
182
190
if maxdp< setup. ptol* h
183
- return p, t, statsdata
191
+ return result
184
192
end
185
193
end
186
194
end
0 commit comments