-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefineHexMesh.m
70 lines (52 loc) · 1.62 KB
/
refineHexMesh.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function m = refineHexMesh(m,r,Lm,hardM)
% m - Mesh in the given direction
% r - Required ratio
% Lm - Maximal sub-division size allowed
% hardM - Hard mesh points
% First go from left to right
% Start from left to right
while true;
D = diff(m(:));
% This has limited accuracy, check within 5 per-cent
binDivRatio = D(2:end)./D(1:(end - 1)) > r*1.05;
% fprintf(1,'Number of anomalies %d\n',sum(binDivRatio(:)));
% pause(0.1);
if ~max(binDivRatio)
break;
end
% Start from left to right
i1 = find(binDivRatio,1);
% Find first hard mesh point that might brake the smoothing
mHard = hardM(find(hardM > m(i1 + 1),1));
iHard = find(m == mHard);
% Take segment to smooth
cM = [m(i1) m(i1 + 1) m(iHard)];
i3 = iHard;
cD = cM(2:end) - cM(1:(end-1));
cR = cD(2:end)./cD(1:(end-1));
% Refine this bit of mesh
nM = AutoSmoothMeshLines(cM,Lm,r,'symmetric',0,'homogeneous',0);
nD = nM(2:end) - nM(1:(end-1));
nR = nD(2:end)./nD(1:(end-1));
% figure('position',[1747 223 1420 811]);
% subplot(2,1,1);
% plot(cM,ones(size(cM)),'.r','markersize',14);
% hold on;
% plot(m,ones(size(m)),'.b','markersize',10);
% hold off;
% axis([(min(m(:))-5) (max(m(:))+5) 0.5 1.5]);
%
% subplot(2,1,2);
% plot(cM,ones(size(cM)),'.b','markersize',20);
% hold on;
% plot(nM,ones(size(nM)),'.r','markersize',10);
% hold off
% axis([(min(cM)-5) (max(cM)+5) 0.5 1.5]);
%
% close(gcf);
% Stick this snippet in
m1 = m(1:(i1 - 1));
m3 = m((i3 + 1):end);
m = [m1 nM m3];
end
end