コード例 #1
0
    def test_triangle_domain(self):
        for dimension, order, element_type, meshfile in [
            (Caribou._2D, Caribou.Linear, 'triangle',
             '2D_triangle_linear.vtk'),
            (Caribou._3D, Caribou.Linear, 'triangle',
             '3D_triangle_linear.vtk'),
            (Caribou._2D, Caribou.Quadratic, 'triangle6',
             '2D_triangle_quadratic.vtk'),
            (Caribou._3D, Caribou.Quadratic, 'triangle6',
             '3D_triangle_quadratic.vtk'),
        ]:
            m = meshio.read(
                os.path.join(os.path.dirname(__file__), '..', 'meshes',
                             meshfile))
            if dimension == Caribou._2D:
                mesh = Mesh(m.points[:, 0:2])
            else:
                mesh = Mesh(m.points)

            if type(m.cells) == dict:
                cells = m.cells[element_type]
            else:
                cells = m.cells_dict[element_type]

            domain = mesh.add_domain("triangles", Triangle(dimension, order),
                                     cells)
            self.assertEqual(domain.number_of_elements(), 32)
            self.assertMatrixEqual(domain.element_indices(0), cells[0])
            self.assertMatrixEqual(domain.element_indices(31), cells[-1])

        m = meshio.read(
            os.path.join(os.path.dirname(__file__), '..', 'meshes',
                         '2D_triangle_quadratic.vtk'))
        mesh = Mesh(m.points[:, 0:2])

        if type(m.cells) == dict:
            cells = m.cells[element_type]
        else:
            cells = m.cells_dict[element_type]

        self.assertMatrixAlmostEqual(mesh.position(0), m.points[0][0:2])
        self.assertMatrixAlmostEqual(mesh.position(len(m.points) - 1),
                                     m.points[-1][0:2])
        mesh.add_domain("triangles", Triangle(Caribou._2D, Caribou.Quadratic),
                        cells)
        domain = mesh.domain("triangles")
        numerical_solution = 0.
        for element_id in range(domain.number_of_elements()):
            element = domain.element(element_id)
            for gauss_node in element.gauss_nodes():
                x = gauss_node.position
                w = gauss_node.weight
                J = element.jacobian(x)
                detJ = np.abs(np.linalg.det(J))
                numerical_solution += w * detJ

        analytic_solution = 100
        self.assertAlmostEqual(numerical_solution,
                               analytic_solution,
                               delta=1e-10)
コード例 #2
0
    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)
コード例 #3
0
    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())