Testing N and CC as well. Updates to TestOrder

This commit is contained in:
Rowan Cockett
2013-11-04 16:25:57 -08:00
parent 592490844d
commit 967eb1216f
2 changed files with 26 additions and 5 deletions
+6 -4
View File
@@ -67,8 +67,7 @@ class OrderTest(unittest.TestCase):
name = "Order Test"
expectedOrders = 2. # This can be a list of orders, must be the same length as meshTypes
_expectedOrder = 2.
tolerance = 0.85
tolerance = 0.85 # This can also be a list, must be the same length as meshTypes
meshSizes = [4, 8, 16, 32]
meshTypes = ['uniformTensorMesh']
_meshType = meshTypes[0]
@@ -124,6 +123,8 @@ class OrderTest(unittest.TestCase):
"""
assert type(self.meshTypes) == list, 'meshTypes must be a list'
if type(self.tolerance) is not list:
self.tolerance = np.ones(len(self.meshTypes))*self.tolerance
# if we just provide one expected order, repeat it for each mesh type
if type(self.expectedOrders) == float or type(self.expectedOrders) == int:
@@ -134,6 +135,7 @@ class OrderTest(unittest.TestCase):
for ii_meshType, meshType in enumerate(self.meshTypes):
self._meshType = meshType
self._tolerance = self.tolerance[ii_meshType]
self._expectedOrder = self.expectedOrders[ii_meshType]
order = []
@@ -144,7 +146,7 @@ class OrderTest(unittest.TestCase):
err = self.getError()
if ii == 0:
print ''
print 'Testing convergence on ' + self.M._meshType + ' of: ' + self.name
print self._meshType + ': ' + self.name
print '_____________________________________________'
print ' h | error | e(i-1)/e(i) | order'
print '~~~~~~|~~~~~~~~~~~~~|~~~~~~~~~~~~~|~~~~~~~~~~'
@@ -155,7 +157,7 @@ class OrderTest(unittest.TestCase):
err_old = err
max_h_old = max_h
print '---------------------------------------------'
passTest = np.mean(np.array(order)) > self.tolerance*self._expectedOrder
passTest = np.mean(np.array(order)) > self._tolerance*self._expectedOrder
if passTest:
print ['The test be workin!', 'You get a gold star!', 'Yay passed!', 'Happy little convergence test!', 'That was easy!'][np.random.randint(5)]
else:
+20 -1
View File
@@ -2,7 +2,8 @@ import numpy as np
import unittest
from TestUtils import OrderTest
MESHTYPES = ['uniformTensorMesh']
MESHTYPES = ['uniformTensorMesh', 'randomTensorMesh']
TOLERANCES = [0.9, 0.6]
call2 = lambda fun, xyz: fun(xyz[:, 0], xyz[:, 1])
call3 = lambda fun, xyz: fun(xyz[:, 0], xyz[:, 1], xyz[:, 2])
cart_row2 = lambda g, xfun, yfun: np.c_[call2(xfun, g), call2(yfun, g)]
@@ -18,7 +19,9 @@ LOCS = np.random.rand(50,3)*0.6+0.2
class TestInterpolation(OrderTest):
name = "Interpolation"
meshTypes = MESHTYPES
tolerance = TOLERANCES
meshDimension = 3
meshSizes = [8, 16, 32]
def getError(self):
funX = lambda x, y, z: np.cos(2*np.pi*y)
@@ -31,6 +34,8 @@ class TestInterpolation(OrderTest):
anal = call3(funY, LOCS)
elif 'z' in self.type:
anal = call3(funZ, LOCS)
else:
anal = call3(funX, LOCS)
if 'F' in self.type:
Fc = cartF3(self.M, funX, funY, funZ)
@@ -38,12 +43,26 @@ class TestInterpolation(OrderTest):
elif 'E' in self.type:
Ec = cartE3(self.M, funX, funY, funZ)
grid = self.M.projectEdgeVector(Ec)
elif 'CC' == self.type:
grid = call3(funX, self.M.gridCC)
elif 'N' == self.type:
grid = call3(funX, self.M.gridN)
comp = self.M.getInterpolationMat(LOCS, self.type)*grid
err = np.linalg.norm((comp - anal), np.inf)
return err
def test_orderCC(self):
self.type = 'CC'
self.name = 'Interpolation CC'
self.orderTest()
def test_orderN(self):
self.type = 'N'
self.name = 'Interpolation N'
self.orderTest()
def test_orderFx(self):
self.type = 'Fx'
self.name = 'Interpolation Fx'