コード例 #1
0
    def test_segment_domain(self):
        for order, element_type, meshfile in [
            (Caribou.Linear, 'line', '1D_linear.vtk'),
            (Caribou.Quadratic, 'line3', '1D_quadratic.vtk')
        ]:
            m = meshio.read(
                os.path.join(os.path.dirname(__file__), '..', 'meshes',
                             meshfile))
            mesh = Mesh(m.points[:, 0])

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

            # Creation with name
            domain = mesh.add_domain("segments", Segment(Caribou._1D, order),
                                     cells)
            self.assertEqual(domain.number_of_elements(), 10)
            self.assertMatrixEqual(domain.element_indices(0), cells[0])
            self.assertMatrixEqual(domain.element_indices(9), cells[9])

            # Creation without name
            domain = mesh.add_domain(Segment(Caribou._1D, order), cells)
            self.assertEqual(domain.number_of_elements(), 10)
            self.assertMatrixEqual(domain.element_indices(0), cells[0])
            self.assertMatrixEqual(domain.element_indices(9), cells[9])
コード例 #2
0
    def test_constructor_quadratic(self):
        s = Segment(Caribou.Quadratic)
        self.assertTrue((s.nodes() == np.array([-1., 1., 0.])).all())

        # 1D
        s = Segment(-5, 5, 0)
        self.assertTrue((s.nodes() == np.array([-5., 5., 0])).all())

        s = Segment([-5, 5, 0])
        self.assertTrue((s.nodes() == np.array([-5., 5., 0])).all())

        s = Segment([[-5], [5], [0]])
        self.assertTrue((s.nodes() == np.array([-5., 5., 0])).all())

        # 2D
        s = Segment([-5, 5], [5, -5], [0, 0])
        self.assertTrue((s.nodes() == np.array([[-5, 5], [5, -5], [0,
                                                                   0]])).all())

        s = Segment([[-5, 5], [5, -5], [0, 0]])
        self.assertTrue((s.nodes() == np.array([[-5, 5], [5, -5], [0,
                                                                   0]])).all())

        # 3D
        s = Segment([-5, 4, 1], [5, -4, 1], [0, 0, 1])
        self.assertTrue((s.nodes() == np.array([[-5, 4, 1], [5, -4, 1],
                                                [0, 0, 1]])).all())

        s = Segment([[-5, 4, 1], [5, -4, 1], [0, 0, 1]])
        self.assertTrue((s.nodes() == np.array([[-5, 4, 1], [5, -4, 1],
                                                [0, 0, 1]])).all())
コード例 #3
0
    def test_constructor_linear(self):
        s = Segment()
        self.assertTrue((s.nodes() == np.array([-1., 1.])).all())

        # 1D
        s = Segment(-5, 5)
        self.assertTrue((s.nodes() == np.array([-5., 5.])).all())

        s = Segment([-5, 5])
        self.assertTrue((s.nodes() == np.array([-5., 5.])).all())

        s = Segment([[-5], [5]])
        self.assertTrue((s.nodes() == np.array([-5., 5.])).all())

        # 2D
        s = Segment([-5, 4], [5, -4])
        self.assertTrue((s.nodes() == np.array([[-5, 4], [5, -4]])).all())

        s = Segment([[-5, 4], [5, -4]])
        self.assertTrue((s.nodes() == np.array([[-5, 4], [5, -4]])).all())

        # 3D
        s = Segment([-5, 4, 1], [5, -4, 1])
        self.assertTrue((s.nodes() == np.array([[-5, 4, 1], [5, -4,
                                                             1]])).all())

        s = Segment([[-5, 4, 1], [5, -4, 1]])
        self.assertTrue((s.nodes() == np.array([[-5, 4, 1], [5, -4,
                                                             1]])).all())
コード例 #4
0
    def test_linear_1D(self):
        # Shape functions
        s = Segment()
        self.assertTrue((s.nodes() == np.array([-1., 1.])).all())
        self.assertTrue((s.L([-1]) == [1, 0]).all())
        self.assertTrue((s.L([+1]) == [0, 1]).all())

        s = Segment(-5.5, 1.1)

        # Center
        self.assertEqual(s.center()[0], -2.2)

        # Inverse transformation
        for gauss_node in s.gauss_nodes():
            self.assertMatrixEqual(
                gauss_node.position,
                s.local_coordinates(s.world_coordinates(gauss_node.position)))

        # Contains point
        s.contains_local(s.local_coordinates(s.center()))

        # Integration
        numerical_solution = 0.
        for gauss_node in s.gauss_nodes():
            x = gauss_node.position
            w = gauss_node.weight
            detJ = s.jacobian(x)[0]
            numerical_solution += p1(s.world_coordinates(x)) * w * detJ
        analytic_solution = (5 * 1.1 + (1.1 * 1.1)) - (-5.5 * 5 + (-5.5) *
                                                       (-5.5))
        self.assertAlmostEqual(numerical_solution,
                               analytic_solution,
                               delta=1e-10)