8 import Cube hiding (i, j, k)
10 import FunctionValues (value_at)
14 import ThreeDimensional
17 -- | Check the value of c0030 for tetrahedron0 belonging to the
18 -- cube centered on (1,1,1) with a grid constructed from the
19 -- trilinear values. See example one in the paper.
20 test_trilinear_c0030 :: Assertion
21 test_trilinear_c0030 =
22 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
24 g = make_grid 1 trilinear
25 cube = cube_at g 1 1 1
29 -- | Check the value of c0003 for tetrahedron0 belonging to the
30 -- cube centered on (1,1,1) with a grid constructed from the
31 -- trilinear values. See example one in the paper.
32 test_trilinear_c0003 :: Assertion
33 test_trilinear_c0003 =
34 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
36 g = make_grid 1 trilinear
37 cube = cube_at g 1 1 1
41 -- | Check the value of c0021 for tetrahedron0 belonging to the
42 -- cube centered on (1,1,1) with a grid constructed from the
43 -- trilinear values. See example one in the paper.
44 test_trilinear_c0021 :: Assertion
45 test_trilinear_c0021 =
46 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
48 g = make_grid 1 trilinear
49 cube = cube_at g 1 1 1
53 -- | Check the value of c0012 for tetrahedron0 belonging to the
54 -- cube centered on (1,1,1) with a grid constructed from the
55 -- trilinear values. See example one in the paper.
56 test_trilinear_c0012 :: Assertion
57 test_trilinear_c0012 =
58 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
60 g = make_grid 1 trilinear
61 cube = cube_at g 1 1 1
65 -- | Check the value of c0120 for tetrahedron0 belonging to the
66 -- cube centered on (1,1,1) with a grid constructed from the
67 -- trilinear values. See example one in the paper.
68 test_trilinear_c0120 :: Assertion
69 test_trilinear_c0120 =
70 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
72 g = make_grid 1 trilinear
73 cube = cube_at g 1 1 1
77 -- | Check the value of c0102 for tetrahedron0 belonging to the
78 -- cube centered on (1,1,1) with a grid constructed from the
79 -- trilinear values. See example one in the paper.
80 test_trilinear_c0102 :: Assertion
81 test_trilinear_c0102 =
82 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
84 g = make_grid 1 trilinear
85 cube = cube_at g 1 1 1
89 -- | Check the value of c0111 for tetrahedron0 belonging to the
90 -- cube centered on (1,1,1) with a grid constructed from the
91 -- trilinear values. See example one in the paper.
92 test_trilinear_c0111 :: Assertion
93 test_trilinear_c0111 =
94 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
96 g = make_grid 1 trilinear
97 cube = cube_at g 1 1 1
101 -- | Check the value of c0210 for tetrahedron0 belonging to the
102 -- cube centered on (1,1,1) with a grid constructed from the
103 -- trilinear values. See example one in the paper.
104 test_trilinear_c0210 :: Assertion
105 test_trilinear_c0210 =
106 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
108 g = make_grid 1 trilinear
109 cube = cube_at g 1 1 1
110 t = tetrahedron0 cube
113 -- | Check the value of c0201 for tetrahedron0 belonging to the
114 -- cube centered on (1,1,1) with a grid constructed from the
115 -- trilinear values. See example one in the paper.
116 test_trilinear_c0201 :: Assertion
117 test_trilinear_c0201 =
118 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
120 g = make_grid 1 trilinear
121 cube = cube_at g 1 1 1
122 t = tetrahedron0 cube
125 -- | Check the value of c0300 for tetrahedron0 belonging to the
126 -- cube centered on (1,1,1) with a grid constructed from the
127 -- trilinear values. See example one in the paper.
128 test_trilinear_c0300 :: Assertion
129 test_trilinear_c0300 =
130 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
132 g = make_grid 1 trilinear
133 cube = cube_at g 1 1 1
134 t = tetrahedron0 cube
137 -- | Check the value of c1020 for tetrahedron0 belonging to the
138 -- cube centered on (1,1,1) with a grid constructed from the
139 -- trilinear values. See example one in the paper.
140 test_trilinear_c1020 :: Assertion
141 test_trilinear_c1020 =
142 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
144 g = make_grid 1 trilinear
145 cube = cube_at g 1 1 1
146 t = tetrahedron0 cube
149 -- | Check the value of c1002 for tetrahedron0 belonging to the
150 -- cube centered on (1,1,1) with a grid constructed from the
151 -- trilinear values. See example one in the paper.
152 test_trilinear_c1002 :: Assertion
153 test_trilinear_c1002 =
154 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
156 g = make_grid 1 trilinear
157 cube = cube_at g 1 1 1
158 t = tetrahedron0 cube
161 -- | Check the value of c1011 for tetrahedron0 belonging to the
162 -- cube centered on (1,1,1) with a grid constructed from the
163 -- trilinear values. See example one in the paper.
164 test_trilinear_c1011 :: Assertion
165 test_trilinear_c1011 =
166 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
168 g = make_grid 1 trilinear
169 cube = cube_at g 1 1 1
170 t = tetrahedron0 cube
173 -- | Check the value of c1110 for tetrahedron0 belonging to the
174 -- cube centered on (1,1,1) with a grid constructed from the
175 -- trilinear values. See example one in the paper.
176 test_trilinear_c1110 :: Assertion
177 test_trilinear_c1110 =
178 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
180 g = make_grid 1 trilinear
181 cube = cube_at g 1 1 1
182 t = tetrahedron0 cube
185 -- | Check the value of c1101 for tetrahedron0 belonging to the
186 -- cube centered on (1,1,1) with a grid constructed from the
187 -- trilinear values. See example one in the paper.
188 test_trilinear_c1101 :: Assertion
189 test_trilinear_c1101 =
190 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
192 g = make_grid 1 trilinear
193 cube = cube_at g 1 1 1
194 t = tetrahedron0 cube
197 -- | Check the value of c1200 for tetrahedron0 belonging to the
198 -- cube centered on (1,1,1) with a grid constructed from the
199 -- trilinear values. See example one in the paper.
200 test_trilinear_c1200 :: Assertion
201 test_trilinear_c1200 =
202 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
204 g = make_grid 1 trilinear
205 cube = cube_at g 1 1 1
206 t = tetrahedron0 cube
209 -- | Check the value of c2010 for tetrahedron0 belonging to the
210 -- cube centered on (1,1,1) with a grid constructed from the
211 -- trilinear values. See example one in the paper.
212 test_trilinear_c2010 :: Assertion
213 test_trilinear_c2010 =
214 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
216 g = make_grid 1 trilinear
217 cube = cube_at g 1 1 1
218 t = tetrahedron0 cube
221 -- | Check the value of c2001 for tetrahedron0 belonging to the
222 -- cube centered on (1,1,1) with a grid constructed from the
223 -- trilinear values. See example one in the paper.
224 test_trilinear_c2001 :: Assertion
225 test_trilinear_c2001 =
226 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
228 g = make_grid 1 trilinear
229 cube = cube_at g 1 1 1
230 t = tetrahedron0 cube
233 -- | Check the value of c2100 for tetrahedron0 belonging to the
234 -- cube centered on (1,1,1) with a grid constructed from the
235 -- trilinear values. See example one in the paper.
236 test_trilinear_c2100 :: Assertion
237 test_trilinear_c2100 =
238 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
240 g = make_grid 1 trilinear
241 cube = cube_at g 1 1 1
242 t = tetrahedron0 cube
245 -- | Check the value of c3000 for tetrahedron0 belonging to the
246 -- cube centered on (1,1,1) with a grid constructed from the
247 -- trilinear values. See example one in the paper.
248 test_trilinear_c3000 :: Assertion
249 test_trilinear_c3000 =
250 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
252 g = make_grid 1 trilinear
253 cube = cube_at g 1 1 1
254 t = tetrahedron0 cube
257 -- | Make sure that v0 of tetrahedron0 belonging to the cube centered
258 -- on (1,1,1) with a grid constructed from the trilinear values
259 -- winds up in the right place. See example one in the paper.
260 test_trilinear_f0_t0_v0 :: Assertion
261 test_trilinear_f0_t0_v0 =
262 assertEqual "v0 is correct" (v0 t) (1, 1, 1)
264 g = make_grid 1 trilinear
265 cube = cube_at g 1 1 1
266 t = tetrahedron0 cube
269 -- | Make sure that v1 of tetrahedron0 belonging to the cube centered
270 -- on (1,1,1) with a grid constructed from the trilinear values
271 -- winds up in the right place. See example one in the paper.
272 test_trilinear_f0_t0_v1 :: Assertion
273 test_trilinear_f0_t0_v1 =
274 assertEqual "v1 is correct" (v1 t) (0.5, 1, 1)
276 g = make_grid 1 trilinear
277 cube = cube_at g 1 1 1
278 t = tetrahedron0 cube
281 -- | Make sure that v2 of tetrahedron0 belonging to the cube centered
282 -- on (1,1,1) with a grid constructed from the trilinear values
283 -- winds up in the right place. See example one in the paper.
284 test_trilinear_f0_t0_v2 :: Assertion
285 test_trilinear_f0_t0_v2 =
286 assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
288 g = make_grid 1 trilinear
289 cube = cube_at g 1 1 1
290 t = tetrahedron0 cube
293 -- | Make sure that v3 of tetrahedron0 belonging to the cube centered
294 -- on (1,1,1) with a grid constructed from the trilinear values
295 -- winds up in the right place. See example one in the paper.
296 test_trilinear_f0_t0_v3 :: Assertion
297 test_trilinear_f0_t0_v3 =
298 assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
300 g = make_grid 1 trilinear
301 cube = cube_at g 1 1 1
302 t = tetrahedron0 cube
305 test_trilinear_reproduced :: Assertion
306 test_trilinear_reproduced =
307 assertTrue "trilinears are reproduced correctly" $
308 and [p (i', j', k') ~= value_at trilinear i j k
313 let p = polynomial t,
314 let i' = fromIntegral i,
315 let j' = fromIntegral j,
316 let k' = fromIntegral k]
318 g = make_grid 1 trilinear
322 test_zeros_reproduced :: Assertion
323 test_zeros_reproduced =
324 assertTrue "the zero function is reproduced correctly" $
325 and [p (i', j', k') ~= value_at zeros i j k
329 let i' = fromIntegral i,
330 let j' = fromIntegral j,
331 let k' = fromIntegral k]
333 g = make_grid 1 zeros
339 -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one.
340 test_trilinear9x9x9_reproduced :: Assertion
341 test_trilinear9x9x9_reproduced =
342 assertTrue "trilinear 9x9x9 is reproduced correctly" $
343 and [p (i', j', k') ~= value_at trilinear9x9x9 i j k
348 let p = polynomial t,
349 let i' = (fromIntegral i) * 0.5,
350 let j' = (fromIntegral j) * 0.5,
351 let k' = (fromIntegral k) * 0.5]
353 g = make_grid 1 trilinear
357 -- | The point 'p' in this test lies on the boundary of tetrahedra 12 and 15.
358 -- However, the 'contains_point' test fails due to some numerical innacuracy.
359 -- This bug should have been fixed by setting a positive tolerance level.
361 -- Example from before the fix:
363 -- > b0 (tetrahedron15 c) p
364 -- -3.4694469519536365e-18
366 test_tetrahedra_collision_sensitivity :: Assertion
367 test_tetrahedra_collision_sensitivity =
368 assertTrue "tetrahedron collision tests isn't too sensitive" $
371 g = make_grid 1 naturals_1d
373 p = (0, 16.75, 0.5) :: Point
374 t15 = tetrahedron15 c