Mercurial > repos > public > sbplib
annotate diracDiscrTest.m @ 1331:60c875c18de3 feature/D2_boundary_opt
Merge with feature/poroelastic for Elastic schemes
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 10 Mar 2022 16:54:26 +0100 |
parents | 25efceb0c392 43a1c3ac07b1 |
children |
rev | line source |
---|---|
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
1 function tests = diracDiscrTest() |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
2 tests = functiontests(localfunctions); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
3 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
4 |
1243
4e0b88f3def1
Use rng(1) to set seed in diracDiscrTest because hex-speak crashed.
Martin Almquist <malmquist@stanford.edu>
parents:
1234
diff
changeset
|
5 %TODO: |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
6 % 1. Test discretizing with smoothness conditions. |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
7 % Only discretization with moment conditions currently tested. |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
8 % 2. Test using other types of grids. Only equidistant grids currently used. |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
9 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
10 function testLeftRandom(testCase) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
11 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
12 orders = [2, 4, 6]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
13 mom_conds = orders; |
1243
4e0b88f3def1
Use rng(1) to set seed in diracDiscrTest because hex-speak crashed.
Martin Almquist <malmquist@stanford.edu>
parents:
1234
diff
changeset
|
14 rng(1) % Set seed |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
15 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
16 for o = 1:length(orders) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
17 order = orders(o); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
18 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
19 [g, H, fs] = setup1D(order, mom_cond); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
20 xl = g.lim{1}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
21 h = g.scaling(); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
22 x = g.x{1}; |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
23 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
24 % Test random points near left boundary |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
25 x0s = xl + 2*h*rand(1,10); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
26 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
27 for j = 1:length(fs) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
28 f = fs{j}; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
29 fx = f(x); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
30 for i = 1:length(x0s) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
31 x0 = x0s(i); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
32 delta = diracDiscr(g, x0, mom_cond, 0, H); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
33 integral = delta'*H*fx; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
34 err = abs(integral - f(x0)); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
35 testCase.verifyLessThan(err, 1e-12); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
36 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
37 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
38 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
39 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
40 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
41 function testRightRandom(testCase) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
42 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
43 orders = [2, 4, 6]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
44 mom_conds = orders; |
1243
4e0b88f3def1
Use rng(1) to set seed in diracDiscrTest because hex-speak crashed.
Martin Almquist <malmquist@stanford.edu>
parents:
1234
diff
changeset
|
45 rng(1) % Set seed |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
46 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
47 for o = 1:length(orders) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
48 order = orders(o); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
49 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
50 [g, H, fs] = setup1D(order, mom_cond); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
51 xr = g.lim{1}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
52 h = g.scaling(); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
53 x = g.x{1}; |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
54 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
55 % Test random points near right boundary |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
56 x0s = xr - 2*h*rand(1,10); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
57 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
58 for j = 1:length(fs) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
59 f = fs{j}; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
60 fx = f(x); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
61 for i = 1:length(x0s) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
62 x0 = x0s(i); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
63 delta = diracDiscr(g, x0, mom_cond, 0, H); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
64 integral = delta'*H*fx; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
65 err = abs(integral - f(x0)); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
66 testCase.verifyLessThan(err, 1e-12); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
67 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
68 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
69 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
70 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
71 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
72 function testInteriorRandom(testCase) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
73 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
74 orders = [2, 4, 6]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
75 mom_conds = orders; |
1243
4e0b88f3def1
Use rng(1) to set seed in diracDiscrTest because hex-speak crashed.
Martin Almquist <malmquist@stanford.edu>
parents:
1234
diff
changeset
|
76 rng(1) % Set seed |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
77 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
78 for o = 1:length(orders) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
79 order = orders(o); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
80 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
81 [g, H, fs] = setup1D(order, mom_cond); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
82 xl = g.lim{1}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
83 xr = g.lim{1}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
84 h = g.scaling(); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
85 x = g.x{1}; |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
86 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
87 % Test random points in interior |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
88 x0s = (xl+2*h) + (xr-xl-4*h)*rand(1,20); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
89 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
90 for j = 1:length(fs) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
91 f = fs{j}; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
92 fx = f(x); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
93 for i = 1:length(x0s) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
94 x0 = x0s(i); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
95 delta = diracDiscr(g, x0, mom_cond, 0, H); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
96 integral = delta'*H*fx; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
97 err = abs(integral - f(x0)); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
98 testCase.verifyLessThan(err, 1e-12); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
99 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
100 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
101 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
102 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
103 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
104 % x0 outside grid should yield 0 integral! |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
105 function testX0OutsideGrid(testCase) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
106 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
107 orders = [2, 4, 6]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
108 mom_conds = orders; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
109 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
110 for o = 1:length(orders) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
111 order = orders(o); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
112 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
113 [g, H, fs] = setup1D(order, mom_cond); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
114 xl = g.lim{1}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
115 xr = g.lim{1}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
116 h = g.scaling(); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
117 x = g.x{1}; |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
118 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
119 % Test points outisde grid |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
120 x0s = [xl-1.1*h, xr+1.1*h]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
121 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
122 for j = 1:length(fs) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
123 f = fs{j}; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
124 fx = f(x); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
125 for i = 1:length(x0s) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
126 x0 = x0s(i); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
127 delta = diracDiscr(g, x0, mom_cond, 0, H); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
128 integral = delta'*H*fx; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
129 err = abs(integral - 0); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
130 testCase.verifyLessThan(err, 1e-12); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
131 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
132 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
133 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
134 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
135 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
136 function testAllGP(testCase) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
137 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
138 orders = [2, 4, 6]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
139 mom_conds = orders; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
140 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
141 for o = 1:length(orders) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
142 order = orders(o); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
143 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
144 [g, H, fs] = setup1D(order, mom_cond); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
145 x = g.x{1}; |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
146 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
147 % Test all grid points |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
148 x0s = x; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
149 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
150 for j = 1:length(fs) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
151 f = fs{j}; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
152 fx = f(x); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
153 for i = 1:length(x0s) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
154 x0 = x0s(i); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
155 delta = diracDiscr(g, x0, mom_cond, 0, H); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
156 integral = delta'*H*fx; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
157 err = abs(integral - f(x0)); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
158 testCase.verifyLessThan(err, 1e-12); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
159 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
160 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
161 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
162 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
163 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
164 function testHalfGP(testCase) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
165 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
166 orders = [2, 4, 6]; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
167 mom_conds = orders; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
168 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
169 for o = 1:length(orders) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
170 order = orders(o); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
171 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
172 [g, H, fs] = setup1D(order, mom_cond); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
173 x = g.x{1}; |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
174 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
175 % Test halfway between all grid points |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
176 x0s = 1/2*(x(2:end)+x(1:end-1)); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
177 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
178 for j = 1:length(fs) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
179 f = fs{j}; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
180 fx = f(x); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
181 for i = 1:length(x0s) |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
182 x0 = x0s(i); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
183 delta = diracDiscr(g, x0, mom_cond, 0, H); |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
184 integral = delta'*H*fx; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
185 err = abs(integral - f(x0)); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
186 testCase.verifyLessThan(err, 1e-12); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
187 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
188 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
189 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
190 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
191 |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
192 %=============== 2D tests ============================== |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
193 function testAllGP2D(testCase) |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
194 |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
195 orders = [2, 4, 6]; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
196 mom_conds = orders; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
197 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
198 for o = 1:length(orders) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
199 order = orders(o); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
200 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
201 [g, H, fs] = setup2D(order, mom_cond); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
202 H_global = kron(H{1}, H{2}); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
203 X = g.points(); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
204 % Test all grid points |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
205 x0s = X; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
206 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
207 for j = 1:length(fs) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
208 f = fs{j}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
209 fx = f(X(:,1), X(:,2)); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
210 for i = 1:length(x0s) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
211 x0 = x0s(i,:); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
212 delta = diracDiscr(g, x0, mom_cond, 0, H); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
213 integral = delta'*H_global*fx; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
214 err = abs(integral - f(x0(1), x0(2))); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
215 testCase.verifyLessThan(err, 1e-12); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
216 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
217 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
218 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
219 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
220 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
221 function testAllRandom2D(testCase) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
222 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
223 orders = [2, 4, 6]; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
224 mom_conds = orders; |
1243
4e0b88f3def1
Use rng(1) to set seed in diracDiscrTest because hex-speak crashed.
Martin Almquist <malmquist@stanford.edu>
parents:
1234
diff
changeset
|
225 rng(1) % Set seed |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
226 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
227 for o = 1:length(orders) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
228 order = orders(o); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
229 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
230 [g, H, fs] = setup2D(order, mom_cond); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
231 H_global = kron(H{1}, H{2}); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
232 X = g.points(); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
233 xl = g.lim{1}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
234 xr = g.lim{1}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
235 yl = g.lim{2}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
236 yr = g.lim{2}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
237 h = g.scaling(); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
238 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
239 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
240 % Test random points, even outside grid |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
241 Npoints = 100; |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
242 x0s = [(xl-3*h(1)) + (xr-xl+6*h(1))*rand(Npoints,1), ... |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
243 (yl-3*h(2)) + (yr-yl+6*h(2))*rand(Npoints,1) ]; |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
244 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
245 for j = 1:length(fs) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
246 f = fs{j}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
247 fx = f(X(:,1), X(:,2)); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
248 for i = 1:length(x0s) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
249 x0 = x0s(i,:); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
250 delta = diracDiscr(g, x0, mom_cond, 0, H); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
251 integral = delta'*H_global*fx; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
252 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
253 % Integral should be 0 if point is outside grid |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
254 if x0(1) < xl || x0(1) > xr || x0(2) < yl || x0(2) > yr |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
255 err = abs(integral - 0); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
256 else |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
257 err = abs(integral - f(x0(1), x0(2))); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
258 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
259 testCase.verifyLessThan(err, 1e-12); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
260 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
261 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
262 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
263 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
264 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
265 %=============== 3D tests ============================== |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
266 function testAllGP3D(testCase) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
267 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
268 orders = [2, 4, 6]; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
269 mom_conds = orders; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
270 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
271 for o = 1:length(orders) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
272 order = orders(o); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
273 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
274 [g, H, fs] = setup3D(order, mom_cond); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
275 H_global = kron(kron(H{1}, H{2}), H{3}); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
276 X = g.points(); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
277 % Test all grid points |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
278 x0s = X; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
279 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
280 for j = 1:length(fs) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
281 f = fs{j}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
282 fx = f(X(:,1), X(:,2), X(:,3)); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
283 for i = 1:length(x0s) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
284 x0 = x0s(i,:); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
285 delta = diracDiscr(g, x0, mom_cond, 0, H); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
286 integral = delta'*H_global*fx; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
287 err = abs(integral - f(x0(1), x0(2), x0(3))); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
288 testCase.verifyLessThan(err, 1e-12); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
289 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
290 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
291 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
292 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
293 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
294 function testAllRandom3D(testCase) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
295 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
296 orders = [2, 4, 6]; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
297 mom_conds = orders; |
1243
4e0b88f3def1
Use rng(1) to set seed in diracDiscrTest because hex-speak crashed.
Martin Almquist <malmquist@stanford.edu>
parents:
1234
diff
changeset
|
298 rng(1) % Set seed |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
299 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
300 for o = 1:length(orders) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
301 order = orders(o); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
302 mom_cond = mom_conds(o); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
303 [g, H, fs] = setup3D(order, mom_cond); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
304 H_global = kron(kron(H{1}, H{2}), H{3}); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
305 X = g.points(); |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
306 xl = g.lim{1}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
307 xr = g.lim{1}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
308 yl = g.lim{2}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
309 yr = g.lim{2}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
310 zl = g.lim{3}{1}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
311 zr = g.lim{3}{2}; |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
312 h = g.scaling(); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
313 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
314 % Test random points, even outside grid |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
315 Npoints = 200; |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
316 x0s = [(xl-3*h(1)) + (xr-xl+6*h(1))*rand(Npoints,1), ... |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
317 (yl-3*h(2)) + (yr-yl+6*h(2))*rand(Npoints,1), ... |
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
318 (zl-3*h(3)) + (zr-zl+6*h(3))*rand(Npoints,1) ]; |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
319 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
320 for j = 1:length(fs) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
321 f = fs{j}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
322 fx = f(X(:,1), X(:,2), X(:,3)); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
323 for i = 1:length(x0s) |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
324 x0 = x0s(i,:); |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
325 delta = diracDiscr(g, x0, mom_cond, 0, H); |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
326 integral = delta'*H_global*fx; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
327 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
328 % Integral should be 0 if point is outside grid |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
329 if x0(1) < xl || x0(1) > xr || x0(2) < yl || x0(2) > yr || x0(3) < zl || x0(3) > zr |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
330 err = abs(integral - 0); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
331 else |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
332 err = abs(integral - f(x0(1), x0(2), x0(3))); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
333 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
334 testCase.verifyLessThan(err, 1e-12); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
335 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
336 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
337 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
338 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
339 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
340 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
341 % ====================================================== |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
342 % ============== Setup functions ======================= |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
343 % ====================================================== |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
344 function [g, H, fs] = setup1D(order, mom_cond) |
836
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
345 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
346 % Grid |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
347 xl = -3; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
348 xr = 900; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
349 L = xr-xl; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
350 m = 101; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
351 g = grid.equidistant(m, {xl, xr}); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
352 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
353 % Quadrature |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
354 ops = sbp.D2Standard(m, {xl, xr}, order); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
355 H = ops.H; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
356 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
357 % Moment conditions |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
358 fs = cell(mom_cond,1); |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
359 for p = 0:mom_cond-1 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
360 fs{p+1} = @(x) (x/L).^p; |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
361 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
362 |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
363 end |
049e4c6fa630
Add dirac delta function, with corresponding test. Commented out tests for staggered grid because they do not yet exist on this branch.
Martin Almquist <malmquist@stanford.edu>
parents:
diff
changeset
|
364 |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
365 function [g, H, fs] = setup2D(order, mom_cond) |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
366 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
367 % Grid |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
368 xlims = {-3, 20}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
369 ylims = {-11,5}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
370 Lx = xlims{2} - xlims{1}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
371 Ly = ylims{2} - ylims{1}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
372 m = [15, 16]; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
373 g = grid.equidistant(m, xlims, ylims); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
374 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
375 % Quadrature |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
376 opsx = sbp.D2Standard(m(1), xlims, order); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
377 opsy = sbp.D2Standard(m(2), ylims, order); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
378 Hx = opsx.H; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
379 Hy = opsy.H; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
380 H = {Hx, Hy}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
381 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
382 % Moment conditions |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
383 fs = cell(mom_cond,1); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
384 for p = 0:mom_cond-1 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
385 fs{p+1} = @(x,y) (x/Lx + y/Ly).^p; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
386 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
387 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
388 |
1234
f1806475498b
- Pass grids to diracDiscr and adjust tests.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1232
diff
changeset
|
389 function [g, H, fs] = setup3D(order, mom_cond) |
837
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
390 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
391 % Grid |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
392 xlims = {-3, 20}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
393 ylims = {-11,5}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
394 zlims = {2,4}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
395 Lx = xlims{2} - xlims{1}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
396 Ly = ylims{2} - ylims{1}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
397 Lz = zlims{2} - zlims{1}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
398 m = [13, 14, 15]; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
399 g = grid.equidistant(m, xlims, ylims, zlims); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
400 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
401 % Quadrature |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
402 opsx = sbp.D2Standard(m(1), xlims, order); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
403 opsy = sbp.D2Standard(m(2), ylims, order); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
404 opsz = sbp.D2Standard(m(3), zlims, order); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
405 Hx = opsx.H; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
406 Hy = opsy.H; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
407 Hz = opsz.H; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
408 H = {Hx, Hy, Hz}; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
409 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
410 % Moment conditions |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
411 fs = cell(mom_cond,1); |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
412 for p = 0:mom_cond-1 |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
413 fs{p+1} = @(x,y,z) (x/Lx + y/Ly + z/Lz).^p; |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
414 end |
43a1c3ac07b1
Make diracDiscr work for n dimensions. Add tests up to 3D.
Martin Almquist <malmquist@stanford.edu>
parents:
836
diff
changeset
|
415 end |