def test_quadratic_3D(self): t = Triangle([50, 50, 5], [60, 50, 5], [55, 55, 5], Caribou.Quadratic) self.assertEqual(t.number_of_boundary_elements(), 3) self.assertEqual(t.number_of_nodes(), 6) # Center self.assertMatrixAlmostEqual(t.center(), (t.node(0) + t.node(1) + t.node(2)) / 3.) # Inverse transformation for gauss_node in t.gauss_nodes(): self.assertMatrixAlmostEqual( gauss_node.position, t.local_coordinates(t.world_coordinates(gauss_node.position))) for node in t.nodes(): self.assertMatrixAlmostEqual( node, t.world_coordinates(t.local_coordinates(node))) # Contains point self.assertTrue(t.contains_local(t.local_coordinates(t.center()))) # Integration numerical_solution = 0. for gauss_node in t.gauss_nodes(): x = gauss_node.position w = gauss_node.weight J = t.jacobian(x) detJ = np.sqrt(np.linalg.det(J.T.dot(J))) numerical_solution += p2(t.world_coordinates(x)) * w * detJ analytic_solution = 164083.3333333333 self.assertAlmostEqual(numerical_solution, analytic_solution, delta=1e-10)
def test_constructor_linear(self): t = Triangle() self.assertTrue((t.nodes() == np.array([[0, 0], [1, 0], [0, 1]])).all()) # 2D t = Triangle([50, 50], [60, 50], [55, 55]) self.assertTrue((t.nodes() == np.array([[50, 50], [60, 50], [55, 55]])).all()) t = Triangle([[50, 50], [60, 50], [55, 55]]) self.assertTrue((t.nodes() == np.array([[50, 50], [60, 50], [55, 55]])).all()) # 3D t = Triangle([50, 50, 5], [60, 50, 5], [55, 55, 5]) self.assertTrue((t.nodes() == np.array([[50, 50, 5], [60, 50, 5], [55, 55, 5]])).all()) t = Triangle([[50, 50, 5], [60, 50, 5], [55, 55, 5]]) self.assertTrue((t.nodes() == np.array([[50, 50, 5], [60, 50, 5], [55, 55, 5]])).all())