Skip to content

Commit 91c123b

Browse files
committed
start to implement API for switching sort
1 parent 32e77ee commit 91c123b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/DistMesh.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,32 @@ abstract type AbstractDistMeshAlgorithm end
1515
1616
iso (default: 0): Value of which to extract the iso surface, inside negative
1717
deltat (default: 0.1): the fraction of edge displacement to apply each iteration
18+
sort (default:false):
1819
"""
1920
struct DistMeshSetup{T} <: AbstractDistMeshAlgorithm
2021
iso::T
2122
deltat::T
2223
ttol::T
2324
ptol::T
25+
sort::Bool # use hilbert sort to cache-localize points
26+
sort_interval::Int # retriangulations before resorting
2427
distribution::Symbol # intial point distribution
2528
end
2629

2730
function DistMeshSetup(;iso=0,
2831
ptol=.001,
2932
deltat=0.05,
3033
ttol=0.02,
34+
sort=false,
35+
sort_interval=20,
3136
distribution=:regular)
3237
T = promote_type(typeof(iso),typeof(ptol),typeof(deltat), typeof(ttol))
3338
DistMeshSetup{T}(iso,
3439
deltat,
3540
ttol,
3641
ptol,
42+
sort,
43+
sort_interval,
3744
distribution)
3845
end
3946

src/distmeshnd.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ function distmesh(fdist::Function,
7171
facecenteredcubic!(fdist, p, pt_dists, h, setup.iso, origin, widths, VertType)
7272
end
7373

74-
# use nearest neighbors kd tree to spatially sort points if point set is large
75-
sort_pts = !have_fixed
76-
7774
# initialize arrays
7875
pair_set = Set{Tuple{Int32,Int32}}() # set used for ensure we have a unique set of edges
7976
pair = Tuple{Int32,Int32}[] # edge indices (Int32 since we use Tetgen)
@@ -93,17 +90,17 @@ function distmesh(fdist::Function,
9390
statsdata = DistMeshStatistics()
9491
lcount = 0 # iteration counter
9592
triangulationcount = 0 # triangulation counter
96-
resortinterval = 10
9793

9894
@inbounds while true
9995
# if large move, retriangulation
10096
if maxmove>setup.ttol*h
10197

10298
# use hilbert sort to improve cache locality of points
103-
if sort_pts && iszero(triangulationcount%resortinterval)
99+
if setup.sort && iszero(triangulationcount % setup.sort_interval)
104100
hilbertsort!(p)
105101
end
106-
delaunayn!(fdist, p, t, geps, sort_pts) # compute a new delaunay triangulation
102+
103+
delaunayn!(fdist, p, t, geps, false) # compute a new delaunay triangulation
107104

108105
tet_to_edges!(pair, pair_set, t) # Describe each edge by a unique pair of nodes
109106

@@ -113,7 +110,7 @@ function distmesh(fdist::Function,
113110
non_uniform && resize!(L0, length(pair))
114111

115112
# if the points were sorted we need to update the distance cache
116-
if sort_pts && iszero(triangulationcount%resortinterval)
113+
if setup.sort && iszero(triangulationcount % setup.sort_interval)
117114
for i in eachindex(p)
118115
pt_dists[i] = fdist(p[i])
119116
end

0 commit comments

Comments
 (0)