forked from FDYdarmstadt/MomentFitting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
surfaceTest.m
66 lines (50 loc) · 1.67 KB
/
surfaceTest.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
function tests = surfaceTest
tests = functiontests(localfunctions);
end
function testStraightVertical(~)
phi = @(x,y)x;
gradPhi = {@(x,y)1 @(x,y)0};
exactLength = 2;
[~, w] = getSurfaceRule(phi, gradPhi, 2);
error = abs(sum(w) - exactLength);
assert(error < 1e-14);
end
function testStraightHorizontal(~)
phi = @(x,y)y;
gradPhi = {@(x,y)0 @(x,y)1};
exactLength = 2;
[~, w] = getSurfaceRule(phi, gradPhi, 2);
error = abs(sum(w) - exactLength);
assert(error < 1e-14);
end
function testStraightVerticalShifted(~)
phi = @(x,y)x - 0.5;
gradPhi = {@(x,y)1 @(x,y)0};
exactLength = 2;
[~, w] = getSurfaceRule(phi, gradPhi, 2);
error = abs(sum(w) - exactLength);
assert(error < 1e-14);
end
function testStraightDiagonal(~)
phi = @(x,y)x+y;
gradPhi = {@(x,y)1 @(x,y)1};
exactLength = 2 * sqrt(2);
[~, w] = getSurfaceRule(phi, gradPhi, 2);
error = abs(sum(w) - exactLength);
assert(error < 1e-14);
end
function testCircleSection(~)
phi = @(x,y)(x-1.5).^2 + (y-1.5).^2 - 5/2;
gradPhi = {@(x,y)2*(x-1.5) @(x,y)2*(y-1.5)};
exactLength = 1.46618247613376;
errors = zeros(1, 5);
for i=1:5
[~, w] = getSurfaceRule(phi, gradPhi, i);
errors(i) = abs(sum(w) - exactLength);
end
thresholds = [ 0.2 0.06 0.02 0.005 0.0002 ];
assert(all(errors < thresholds));
% For reference: Errors obtained with divergence-free basis based on an
% orthonormal basis, Gauss nodes and complete orthogonal factorization:
% optimizedResults = [ 0.01091 0.00359 0.00065 0.00061 0.00025 ];
end