working on implementing the cubic interpolation. need to split that routine out of the run_baker method

This commit is contained in:
Stephen Mardson McQuay 2010-03-19 21:27:51 -06:00
parent f089848a1b
commit bd8f24d64f
4 changed files with 19 additions and 18 deletions

View File

@ -103,4 +103,4 @@ if __name__ == '__main__':
errors.append(cur_error) errors.append(cur_error)
print rms(errors) print rms(errors)
print "%s of %s won" % (success, len(mesh_dest.points)) print >>sys.stderr, "%s of %s won" % (success, len(mesh_dest.points))

View File

@ -27,7 +27,7 @@ exact = exact_func_3D(X)
print "exact solution: %0.6f" % exact print "exact solution: %0.6f" % exact
phis = get_phis_3D(X, R.points) phis = get_phis_3D(X, R.points)
print "phi values (should all be positive): ", phis print "phi values (should all be positive): ", phis, sum(phis)
if [i for i in phis if i < 0.0]: if [i for i in phis if i < 0.0]:
print "problems" print "problems"
sys.exit(1) sys.exit(1)

View File

@ -27,8 +27,8 @@ def get_phis(X, R):
]) ])
try: try:
phi = np.linalg.solve(A,b) phi = np.linalg.solve(A,b)
except: except LinAlgError as e:
print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system" print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system", e
raise smberror('get_phis') raise smberror('get_phis')
phi = np.dot(np.linalg.pinv(A), b) phi = np.dot(np.linalg.pinv(A), b)
@ -65,8 +65,8 @@ def get_phis_3D(X, r):
]) ])
try: try:
phi = np.linalg.solve(A,b) phi = np.linalg.solve(A,b)
except: except LinAlgError as e:
print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system" print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system", e
phi = np.dot(np.linalg.pinv(A), b) phi = np.dot(np.linalg.pinv(A), b)
return phi return phi
@ -152,8 +152,8 @@ def run_baker(X, R, S):
# baker solve eq 10 # baker solve eq 10
try: try:
(a, b, c) = np.linalg.solve(A,b) (a, b, c) = np.linalg.solve(A,b)
except: except LinAlgError as e:
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv" print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
(a, b, c) = np.dot(np.linalg.pinv(A), b) (a, b, c) = np.dot(np.linalg.pinv(A), b)
error_term = a * phi[0] * phi[1]\ error_term = a * phi[0] * phi[1]\
@ -230,8 +230,8 @@ def run_baker_3D(X, R, S):
# baker solve eq 10 # baker solve eq 10
try: try:
(a, b, c, d, e, f) = np.linalg.solve(A,b) (a, b, c, d, e, f) = np.linalg.solve(A,b)
except: except np.linalg.LinAlgError as e:
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv" print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
(a, b, c, d, e, f) = np.dot(np.linalg.pinv(A), b) (a, b, c, d, e, f) = np.dot(np.linalg.pinv(A), b)
error_term = a * phi[0] * phi[1]\ error_term = a * phi[0] * phi[1]\

View File

@ -23,6 +23,7 @@ class TestSequenceFunctions(unittest.TestCase):
] ]
self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0] self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
self.X = [1.5, 10.25] self.X = [1.5, 10.25]
self.accuracy = 8
def testImports(self): def testImports(self):
import numpy import numpy
@ -36,9 +37,9 @@ class TestSequenceFunctions(unittest.TestCase):
r = [[-1, -1], [0, 2], [1, -1]] r = [[-1, -1], [0, 2], [1, -1]]
result = baker.get_phis(X, r) result = baker.get_phis(X, r)
result = [round(i, 5) for i in result] result = [round(i, self.accuracy) for i in result]
right_answer = [round(i, 5) for i in [1/3.0, 1/3.0, 1/3.0]] right_answer = [round(i, self.accuracy) for i in [1/3.0, 1/3.0, 1/3.0]]
for a,b in zip(result, right_answer): for a,b in zip(result, right_answer):
self.assertEqual(a,b) self.assertEqual(a,b)
@ -77,13 +78,13 @@ class TestSequenceFunctions(unittest.TestCase):
self.q[size_of_simplex:size_of_simplex + extra_points]) self.q[size_of_simplex:size_of_simplex + extra_points])
answer = baker.run_baker(self.X, R, S) answer = baker.run_baker(self.X, R, S)
a = round(answer['a'], 5) a = round(answer['a'], self.accuracy)
b = round(answer['b'], 5) b = round(answer['b'], self.accuracy)
c = round(answer['c'], 5) c = round(answer['c'], self.accuracy)
self.assertEqual(a, c) self.assertEqual(a, c)
self.assertEqual(c, round(0.00 , 5)) self.assertEqual(c, round(0.00 , self.accuracy))
self.assertEqual(b, round(1/3.0, 5)) self.assertEqual(b, round(1/3.0, self.accuracy))
def testRunBaker_2(self): def testRunBaker_2(self):
size_of_simplex = 3 size_of_simplex = 3
@ -144,4 +145,4 @@ class TestSequenceFunctions(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions) suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=3).run(suite)