-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathmeshquality.m
50 lines (48 loc) · 1.43 KB
/
meshquality.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function quality = meshquality(node, elem, maxnode)
%
% quality=meshquality(node,elem)
%
% compute the Joe-Liu mesh quality measure of an N-D mesh (N<=3)
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2011/02/26
%
% input:
% node: node coordinates of the mesh (nn x 3)
% elem: element table of an N-D mesh (ne x (N+1))
%
% output:
% quality: a vector of the same length as size(elem,1), with
% each element being the Joe-Liu mesh quality metric (0-1) of
% the corresponding element. A value close to 1 represents
% higher mesh quality (1 means equilateral tetrahedron);
% a value close to 0 means nearly degenerated element.
%
% reference:
% A. Liu, B. Joe, Relationship between tetrahedron shape measures,
% BIT 34 (2) (1994) 268-287.
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
if (nargin < 3)
maxnode = 4;
end
if (size(elem, 2) > maxnode)
elem = elem(:, 1:maxnode);
end
enum = size(elem, 1);
vol = elemvolume(node, elem);
edges = meshedge(elem);
ed = node(edges(:, 1), :) - node(edges(:, 2), :);
ed = sum((ed .* ed)');
ed = sum(reshape(ed, [enum length(ed) / enum])')';
dim = size(elem, 2) - 1;
coeff = 10 / 9; % for tetrahedral
if (dim == 2)
coeff = 1;
end
quality = coeff * dim * 2^(2 * (1 - 1 ./ dim)) * 3^((dim - 1) / 2) * vol.^(2 / dim) ./ ed;
maxquality = max(quality);
if (maxquality > 1)
quality = quality ./ maxquality;
end