Skip to content

Commit c42e749

Browse files
committed
initial pass at volume-edge ratio quality metric
1 parent b117d92 commit c42e749

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/quality.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,34 @@ function min_dihedral_angles(p,t)
8585
end
8686
a
8787
end
88+
89+
"""
90+
Computes the volume and edge-length ratio from four given points
91+
"""
92+
function volume_edge_ratio(a,b,c,d)
93+
t = a - d
94+
u = b - d
95+
v = c - d
96+
volume = dot(t,cross(u,v))/6
97+
edges = (t,u,v,a-b,b-c,a-c)
98+
lengths = norm.(edges)
99+
l_rms = sqrt(sum(lengths.^2)/6)
100+
return 6*volume/(sqrt(2)*l_rms^3)
101+
end
102+
103+
"""
104+
105+
update a pre-allocated array with tetrahedra qualities
106+
"""
107+
function volume_edge_ratio(points::Vector{T},tets) where {T}
108+
n = length(tets)
109+
min_q = typemax(eltype(T))
110+
max_q = typemin(eltype(T))
111+
for i = 1:n
112+
tet = tets[i]
113+
q = volume_edge_ratio(points[tet[1]],points[tet[2]],points[tet[3]],points[tet[4]])
114+
min_q = min(q,min_q)
115+
max_q = max(q,max_q)
116+
end
117+
min_q, max_q
118+
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ end
3939
@test DistMesh.triqual([0,0,0],[2,0,0],[1,sqrt(3),0]) 1
4040
@test DistMesh.triqual([0,0,0],[1,sqrt(3),0],[2,0,0]) 1
4141
end
42+
@testset "volume-length" begin
43+
pts = ([1,0,-1/sqrt(2)], [-1,0,-1/sqrt(2)], [0,1,1/sqrt(2)], [0,-1,1/sqrt(2)])
44+
@show DistMesh.volume_edge_ratio(pts...)
45+
@show DistMesh.volume_edge_ratio((pts.*2)...)
4246

47+
48+
end
4349
end
4450

4551
@testset "decompositions" begin

0 commit comments

Comments
 (0)