def test_assemblePatchBoundaryMatrix1d(self): NPatch = np.array([4]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) CComputed = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter) CCorrect = np.array([[4, -4, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, -4, 4]]) self.assertTrue(np.allclose(CComputed.todense(), CCorrect)) NPatch = np.array([4]) aPatch = np.array([2, 10, 10, 3]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) CComputed = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter, aPatch) CCorrect = np.array([[8, -8, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, -12, 12]]) self.assertTrue(np.allclose(CComputed.todense(), CCorrect))
def test_boundaryNormalDerivativeMatrixProperties(self): # BoundaryNormalDerivative bilinear form should map constants to 0 NPatch = np.array([3, 4, 5]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) C = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter) constant = np.ones(np.prod(NPatch + 1)) self.assertTrue(np.isclose(np.linalg.norm(C * constant), 0)) # BoundaryNormalDerivative bilinear form (a=constant) should map planes to 0 NPatch = np.array([3, 4, 5, 6]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) C = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter) p = util.pCoordinates(NPatch) pSum = np.sum(p, axis=1) ones = np.ones(np.prod(NPatch + 1)) self.assertTrue(np.isclose(np.linalg.norm(np.dot(ones, C * pSum)), 0)) # A function f with df/dx_k = 1 at x_k = 0 and df/dx_k = 0 at # x_k = 1 should give 1'*C*f = -d NPatch = np.array([5, 4, 3, 7]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) C = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter) p = util.pCoordinates(NPatch) p = np.minimum(p, 0.5) pSum = np.sum(p, axis=1) ones = np.ones(np.prod(NPatch + 1)) self.assertTrue(np.isclose(np.dot(ones, C * pSum), -4)) # Same test as above, but with a coefficient a NPatch = np.array([5, 4, 3, 7]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) p = util.pCoordinates(NPatch) p0 = p[:, 0] pElement = util.pCoordinates(NPatch, NPatch=NPatch - 1) pElement0 = pElement[:, 0] aPatch = 1. * (pElement0 < 0.5) + 10. * (pElement0 >= 0.5) C = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter, aPatch) ones = np.ones(np.prod(NPatch + 1)) self.assertTrue(np.isclose(np.dot(ones, C * p0), 10 - 1))
def test_assemblePatchBoundaryNormalDerivativeMatrix2d(self): NPatch = np.array([1, 2]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) CComputed = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter) CCorrect = 1. / 12 * np.array( [[10, 2, 1, -1, 0, 0], [2, 10, -1, 1, 0, 0], [-7, -5, 4, -4, -7, -5], [-5, -7, -4, 4, -5, -7], [0, 0, 1, -1, 10, 2], [0, 0, -1, 1, 2, 10]]).T self.assertTrue(np.allclose(CComputed.todense(), CCorrect)) NPatch = np.array([1, 2]) aPatch = np.array([1, 10]) CLocGetter = fem.localBoundaryNormalDerivativeMatrixGetter(NPatch) CComputed = fem.assemblePatchBoundaryMatrix(NPatch, CLocGetter, aPatch) CCorrect = 1. / 12 * np.array( [[10, 2, 1, -1, 0, 0], [2, 10, -1, 1, 0, 0], [-7, -5, 22, -22, -70, -50], [-5, -7, -22, 22, -50, -70], [0, 0, 10, -10, 100, 20], [0, 0, -10, 10, 20, 100]]).T self.assertTrue(np.allclose(CComputed.todense(), CCorrect))