2010-04-29 22:29:35 -07:00
|
|
|
#!/usr/bin/env python
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2011-01-29 13:59:32 -08:00
|
|
|
from interp.baker import run_baker
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2011-01-29 13:59:32 -08:00
|
|
|
from interp.grid.DD import grid
|
|
|
|
from interp.grid.simplex import contains
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
def exact_func(X):
|
|
|
|
x = X[0]
|
|
|
|
y = X[0]
|
2011-02-03 08:45:11 -08:00
|
|
|
return 1 - x*x + y*y
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2011-02-15 10:27:45 -08:00
|
|
|
class Test(unittest.TestCase):
|
2010-03-20 16:10:02 -07:00
|
|
|
def setUp(self):
|
|
|
|
self.points = [
|
|
|
|
[ 0.25, 0.40], # 0
|
|
|
|
[ 0.60, 0.80], # 1
|
|
|
|
[ 0.65, 0.28], # 2
|
|
|
|
[ 0.28, 0.65], # 3
|
|
|
|
[ 1.00, 0.75], # 4
|
|
|
|
[ 0.30, 0.95], # 5
|
|
|
|
[ 0.80, 0.50], # 6
|
|
|
|
[ 0.35, 0.15], # 7
|
|
|
|
]
|
|
|
|
self.q = [exact_func(p) for p in self.points]
|
|
|
|
|
|
|
|
self.X = [0.25, 0.4001]
|
2010-03-20 19:09:46 -07:00
|
|
|
self.X = [0.55, 0.45]
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
self.g = grid(self.points, self.q)
|
|
|
|
self.R = self.g.create_mesh(range(3))
|
|
|
|
|
|
|
|
self.exact = exact_func(self.X)
|
|
|
|
|
|
|
|
|
|
|
|
self.accuracy = 8
|
|
|
|
|
|
|
|
def test_R_contains_X(self):
|
2011-01-29 13:59:32 -08:00
|
|
|
self.assertTrue(contains(self.X, self.R.verts))
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
def test_RunBaker_1_extra_point(self, extra=1):
|
|
|
|
S = self.g.create_mesh(range(3, 3 + extra))
|
|
|
|
answer = run_baker(self.X, self.R, S)
|
|
|
|
lin_err = abs(self.exact - answer['qlin'])
|
|
|
|
final_err = abs(self.exact - answer['final'])
|
2011-01-29 13:59:32 -08:00
|
|
|
|
|
|
|
# I expect this one to be bad:
|
|
|
|
# self.assertTrue(lin_err >= final_err)
|
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
def test_RunBaker_2_extra_point(self, extra=2):
|
|
|
|
S = self.g.create_mesh(range(3, 3 + extra))
|
|
|
|
answer = run_baker(self.X, self.R, S)
|
|
|
|
lin_err = abs(self.exact - answer['qlin'])
|
|
|
|
final_err = abs(self.exact - answer['final'])
|
|
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
def test_RunBaker_3_extra_point(self, extra=3):
|
|
|
|
S = self.g.create_mesh(range(3, 3 + extra))
|
|
|
|
answer = run_baker(self.X, self.R, S)
|
|
|
|
lin_err = abs(self.exact - answer['qlin'])
|
|
|
|
final_err = abs(self.exact - answer['final'])
|
|
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
def test_RunBaker_4_extra_point(self, extra=4):
|
|
|
|
S = self.g.create_mesh(range(3, 3 + extra))
|
|
|
|
answer = run_baker(self.X, self.R, S)
|
|
|
|
lin_err = abs(self.exact - answer['qlin'])
|
|
|
|
final_err = abs(self.exact - answer['final'])
|
|
|
|
self.assertTrue(lin_err >= final_err)
|
|
|
|
def test_RunBaker_5_extra_point(self, extra=5):
|
|
|
|
S = self.g.create_mesh(range(3, 3 + extra))
|
|
|
|
answer = run_baker(self.X, self.R, S)
|
|
|
|
lin_err = abs(self.exact - answer['qlin'])
|
|
|
|
final_err = abs(self.exact - answer['final'])
|
|
|
|
self.assertTrue(lin_err >= final_err)
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-02-15 10:27:45 -08:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
|
2010-03-20 16:10:02 -07:00
|
|
|
unittest.TextTestRunner(verbosity=3).run(suite)
|