class SimpleOctreeOperatorTests(unittest.TestCase): def setUp(self): h1 = np.random.rand(5) h2 = np.random.rand(7) h3 = np.random.rand(3) self.tM = TensorMesh([h1,h2,h3]) self.oM = TreeMesh([h1,h2,h3]) self.tM2 = TensorMesh([h1,h2]) self.oM2 = TreeMesh([h1,h2]) def test_faceDiv(self): self.assertAlmostEqual((self.tM.faceDiv - self.oM.faceDiv).toarray().sum(), 0) self.assertAlmostEqual((self.tM2.faceDiv - self.oM2.faceDiv).toarray().sum(), 0) def test_nodalGrad(self): self.assertAlmostEqual((self.tM.nodalGrad - self.oM.nodalGrad).toarray().sum(), 0) self.assertAlmostEqual((self.tM2.nodalGrad - self.oM2.nodalGrad).toarray().sum(), 0) def test_edgeCurl(self): self.assertAlmostEqual((self.tM.edgeCurl - self.oM.edgeCurl).toarray().sum(), 0) # self.assertAlmostEqual((self.tM2.edgeCurl - self.oM2.edgeCurl).toarray().sum(), 0) def test_InnerProducts(self): self.assertAlmostEqual((self.tM.getFaceInnerProduct() - self.oM.getFaceInnerProduct()).toarray().sum(), 0) self.assertAlmostEqual((self.tM2.getFaceInnerProduct() - self.oM2.getFaceInnerProduct()).toarray().sum(), 0) self.assertAlmostEqual((self.tM2.getEdgeInnerProduct() - self.oM2.getEdgeInnerProduct()).toarray().sum(), 0) self.assertAlmostEqual((self.tM.getEdgeInnerProduct() - self.oM.getEdgeInnerProduct()).toarray().sum(), 0)
def dotest(MYSOLVER, multi=False, A=None, **solverOpts): if A is None: h1 = np.ones(10)*100. h2 = np.ones(10)*100. h3 = np.ones(10)*100. h = [h1,h2,h3] M = TensorMesh(h) D = M.faceDiv G = -M.faceDiv.T Msig = M.getFaceInnerProduct() A = D*Msig*G A[-1,-1] *= 1/M.vol[-1] # remove the constant null space from the matrix else: M = Mesh.TensorMesh([A.shape[0]]) Ainv = MYSOLVER(A, **solverOpts) if multi: e = np.ones(M.nC) else: e = np.ones((M.nC, numRHS)) rhs = A * e x = Ainv * rhs Ainv.clean() return np.linalg.norm(e-x,np.inf)
def dotest(MYSOLVER, multi=False, A=None, **solverOpts): if A is None: h1 = np.ones(10) * 100. h2 = np.ones(10) * 100. h3 = np.ones(10) * 100. h = [h1, h2, h3] M = TensorMesh(h) D = M.faceDiv G = -M.faceDiv.T Msig = M.getFaceInnerProduct() A = D * Msig * G A[-1, -1] *= 1 / M.vol[ -1] # remove the constant null space from the matrix else: M = Mesh.TensorMesh([A.shape[0]]) Ainv = MYSOLVER(A, **solverOpts) if multi: e = np.ones(M.nC) else: e = np.ones((M.nC, numRHS)) rhs = A * e x = Ainv * rhs Ainv.clean() return np.linalg.norm(e - x, np.inf)
if __name__ == '__main__': from SimPEG.Mesh import TensorMesh from time import time h1 = np.ones(20) * 100. h2 = np.ones(20) * 100. h3 = np.ones(20) * 100. h = [h1, h2, h3] M = TensorMesh(h) D = M.faceDiv G = M.cellGrad Msig = M.getFaceInnerProduct() A = D * Msig * G A[0, 0] *= 10 # remove the constant null space from the matrix e = np.ones(M.nC) rhs = A.dot(e) tic = time() solve = Solver(A, options={'factorize': True}) x = solve.solve(rhs) print 'Factorized', time() - tic print np.linalg.norm(e - x, np.inf) tic = time() solve = Solver(A, options={'factorize': False}) x = solve.solve(rhs) print 'spsolve', time() - tic
if __name__ == '__main__': from SimPEG.Mesh import TensorMesh from time import time h1 = np.ones(20)*100. h2 = np.ones(20)*100. h3 = np.ones(20)*100. h = [h1,h2,h3] M = TensorMesh(h) D = M.faceDiv G = M.cellGrad Msig = M.getFaceInnerProduct() A = D*Msig*G A[0,0] *= 10 # remove the constant null space from the matrix e = np.ones(M.nC) rhs = A.dot(e) tic = time() solve = Solver(A, options={'factorize':True}) x = solve.solve(rhs) print 'Factorized', time() - tic print np.linalg.norm(e-x,np.inf) tic = time() solve = Solver(A, options={'factorize':False}) x = solve.solve(rhs) print 'spsolve', time() - tic