def test_rt0_2d_iso_simplex_surf(self): g = pp.simplex.StructuredTriangleGrid([1, 1], [1, 1]) R = cg.rot(-np.pi / 4., [1, 1, -1]) g.nodes = np.dot(R, g.nodes) g.compute_geometry() kxx = np.ones(g.num_cells) perm = pp.SecondOrderTensor(3, kxx=kxx, kyy=kxx, kzz=1) perm.rotate(R) bf = g.get_boundary_faces() bc = pp.BoundaryCondition(g, bf, bf.size * ["dir"]) solver = pp.RT0(physics="flow") param = pp.Parameters(g) param.set_tensor(solver, perm) param.set_bc(solver, bc) M = solver.matrix(g, {"param": param}).todense() # Matrix computed with an already validated code M_known = np.matrix( [ [0.33333333, 0., 0., -0.16666667, 0., -1., 0.], [0., 0.33333333, 0., 0., -0.16666667, 0., -1.], [0., 0., 0.33333333, 0., 0., -1., 1.], [-0.16666667, 0., 0., 0.33333333, 0., -1., 0.], [0., -0.16666667, 0., 0., 0.33333333, 0., -1.], [-1., 0., -1., -1., 0., 0., 0.], [0., -1., 1., 0., -1., 0., 0.], ] ) self.assertTrue(np.allclose(M, M.T)) # We test only the mass-Hdiv part self.assertTrue(np.allclose(M, M_known))
def test_dual_rt0_1d_iso_line(self): g = pp.structured.CartGrid(3, 1) R = cg.rot(np.pi / 6., [0, 0, 1]) g.nodes = np.dot(R, g.nodes) g.compute_geometry() kxx = np.ones(g.num_cells) perm = pp.SecondOrderTensor(3, kxx, kyy=1, kzz=1) perm.rotate(R) bf = g.get_boundary_faces() bc = pp.BoundaryCondition(g, bf, bf.size * ["dir"]) solver = pp.RT0(physics="flow") param = pp.Parameters(g) param.set_tensor(solver, perm) param.set_bc(solver, bc) M = solver.matrix(g, {"param": param}).todense() # Matrix computed with an already validated code M_known = np.matrix( [ [0.11111111, 0.05555556, 0., 0., 1., 0., 0.], [0.05555556, 0.22222222, 0.05555556, 0., -1., 1., 0.], [0., 0.05555556, 0.22222222, 0.05555556, 0., -1., 1.], [0., 0., 0.05555556, 0.11111111, 0., 0., -1.], [1., -1., 0., 0., 0., 0., 0.], [0., 1., -1., 0., 0., 0., 0.], [0., 0., 1., -1., 0., 0., 0.], ] ) self.assertTrue(np.allclose(M, M.T)) self.assertTrue(np.allclose(M, M_known))
def test_p1_2d_ani_simplex_surf(self): g = pp.simplex.StructuredTriangleGrid([1, 1], [1, 1]) g.compute_geometry() kxx = np.square(g.cell_centers[1, :]) + 1 kyy = np.square(g.cell_centers[0, :]) + 1 kxy = -np.multiply(g.cell_centers[0, :], g.cell_centers[1, :]) perm = pp.SecondOrderTensor(3, kxx=kxx, kyy=kyy, kxy=kxy, kzz=1) R = cg.rot(np.pi / 3., [1, 1, 0]) perm.rotate(R) g.nodes = np.dot(R, g.nodes) g.compute_geometry() bn = g.get_boundary_nodes() bc = pp.BoundaryConditionNode(g, bn, bn.size * ["neu"]) solver = pp.P1(physics="flow") param = pp.Parameters(g) param.set_tensor(solver, perm) param.set_bc(solver, bc) M = solver.matrix(g, {"param": param}).todense() # Matrix computed with an already validated code M_known = np.matrix( [ [1.11111111, -0.66666667, -0.66666667, 0.22222222], [-0.66666667, 1.5, 0., -0.83333333], [-0.66666667, 0., 1.5, -0.83333333], [0.22222222, -0.83333333, -0.83333333, 1.44444444], ] ) self.assertTrue(np.allclose(M, M.T)) self.assertTrue(np.allclose(M, M_known))
def test_p1_2d_iso_simplex_surf(self): g = pp.simplex.StructuredTriangleGrid([1, 1], [1, 1]) R = cg.rot(-np.pi / 4., [1, 1, -1]) g.nodes = np.dot(R, g.nodes) g.compute_geometry() kxx = np.ones(g.num_cells) perm = pp.SecondOrderTensor(3, kxx=kxx, kyy=kxx, kzz=1) perm.rotate(R) bn = g.get_boundary_nodes() bc = pp.BoundaryConditionNode(g, bn, bn.size * ["neu"]) solver = pp.P1(physics="flow") param = pp.Parameters(g) param.set_tensor(solver, perm) param.set_bc(solver, bc) M = solver.matrix(g, {"param": param}).todense() # Matrix computed with an already validated code M_known = np.matrix( [ [1., -0.5, -0.5, 0.], [-0.5, 1., 0., -0.5], [-0.5, 0., 1., -0.5], [0., -0.5, -0.5, 1.], ] ) self.assertTrue(np.allclose(M, M.T)) self.assertTrue(np.allclose(M, M_known)) solver = pp.P1MassMatrix(physics="flow") M = solver.matrix(g, {"param": param}).todense() M_known = ( np.matrix( [ [1., 0.25, 0.25, 0.5], [0.25, 0.5, 0., 0.25], [0.25, 0., 0.5, 0.25], [0.5, 0.25, 0.25, 1.], ] ) / 6. ) self.assertTrue(np.allclose(M, M_known))
def test_p1_1d_iso_line(self): g = pp.structured.CartGrid(3, 1) R = cg.rot(np.pi / 6., [0, 0, 1]) g.nodes = np.dot(R, g.nodes) g.compute_geometry() kxx = np.ones(g.num_cells) perm = pp.SecondOrderTensor(3, kxx, kyy=1, kzz=1) perm.rotate(R) bn = g.get_boundary_nodes() bc = pp.BoundaryConditionNode(g, bn, ["dir", "neu"]) solver = pp.P1(physics="flow") param = pp.Parameters(g) param.set_tensor(solver, perm) param.set_bc(solver, bc) M = solver.matrix(g, {"param": param}).todense() # Matrix computed with an already validated code M_known = np.matrix( [ [1., 0., 0., 0.], [-3., 6., -3., 0.], [0., -3., 6., -3.], [0., 0., -3., 3.], ] ) self.assertTrue(np.allclose(M, M_known)) solver = pp.P1MassMatrix(physics="flow") M = solver.matrix(g, {"param": param}).todense() M_known = ( np.matrix( [[0., 0., 0., 0.], [1., 4., 1., 0.], [0., 1., 4., 1.], [0., 0., 1., 2.]] ) / 18. ) self.assertTrue(np.allclose(M, M_known))
def test_rt0_2d_ani_simplex_surf(self): g = pp.simplex.StructuredTriangleGrid([1, 1], [1, 1]) g.compute_geometry() al = np.square(g.cell_centers[1, :]) + np.square(g.cell_centers[0, :]) + 1 kxx = (np.square(g.cell_centers[0, :]) + 1) / al kyy = (np.square(g.cell_centers[1, :]) + 1) / al kxy = np.multiply(g.cell_centers[0, :], g.cell_centers[1, :]) / al perm = pp.SecondOrderTensor(3, kxx=kxx, kyy=kyy, kxy=kxy, kzz=1) R = cg.rot(np.pi / 3., [1, 1, 0]) perm.rotate(R) g.nodes = np.dot(R, g.nodes) g.compute_geometry() bf = g.get_boundary_faces() bc = pp.BoundaryCondition(g, bf, bf.size * ["dir"]) solver = pp.RT0(physics="flow") param = pp.Parameters(g) param.set_tensor(solver, perm) param.set_bc(solver, bc) M = solver.matrix(g, {"param": param}).todense() # Matrix computed with an already validated code M_known = np.matrix( [ [0.39814815, 0., -0.0462963, -0.15740741, 0., -1., 0.], [0., 0.39814815, 0.0462963, 0., -0.15740741, 0., -1.], [-0.0462963, 0.0462963, 0.46296296, 0.00925926, -0.00925926, -1., 1.], [-0.15740741, 0., 0.00925926, 0.34259259, 0., -1., 0.], [0., -0.15740741, -0.00925926, 0., 0.34259259, 0., -1.], [-1., 0., -1., -1., 0., 0., 0.], [0., -1., 1., 0., -1., 0., 0.], ] ) self.assertTrue(np.allclose(M, M.T)) # We test only the mass-Hdiv part self.assertTrue(np.allclose(M, M_known))