示例#1
0
    def setUp(self):
        class DummyConstraint:
            def __init__(self):
                self.no_of_constrained_dofs = 2

            def unconstrain_u(self, u_constr):
                return np.array([0, 0, 0])

            def constrain_matrix(self, K_unconstr):
                return K_unconstr[0:2, 0:2]

        class DummyAssembly:
            def __init__(self):
                pass

            def assemble_k_and_f(self, u, t):
                K_unconstr = np.array([[10, -5, 0], [-5, 10, -5], [0, -5, 10]])
                f_unsonstr = np.array([2, 0, 0])
                return K_unconstr, f_unsonstr

        class DummyMesh:
            def __init__(self, dimension):
                self.dimension = dimension
                self.nodes = np.empty((0, dimension), dtype=float)
                self.connectivity = None
                self.el_df = pd.DataFrame(
                    columns=['shape', 'is_boundary', 'connectivity'])
                self.no_of_nodes = 0

            @property
            def no_of_elements(self):
                return 0

        class DummyLeaf:
            def __init__(self):
                pass

            def get_local_component_id(self, leaf_id, composite_layer):
                return leaf_id

        self.mesh = DummyMesh(2)
        self.assembly = DummyAssembly()
        self.constraints = DummyConstraint()
        self.leaf_paths = DummyLeaf()

        comp = StructuralComponent(self.mesh)
        comp._constraints = self.constraints
        comp._assembly = self.assembly

        self.TestComponent = comp
        self.CompComposite = ComponentComposite(self.TestComponent)
示例#2
0
    def test_map_dofs_local2global(self):
        d = {
            'partition_id': [3, 3, 3, 3, 3, 3],
            'global_nodeid': [3, 4, 6, 9, 10, 11],
            'local_nodeid': [15, 16, 17, 9, 10, 11]
        }
        nodes_mapping_df = pd.DataFrame(data=d)

        mesh, nodes_mapping = self.partitioner._separate_common_nodes_of_partitions(
            self.testcomponent._mesh)
        local_component = StructuralComponent(
            self.partitioner._get_submesh_by_partition_id(3, mesh))

        local_component.assign_material(DummyMaterial1(), [6, 8, 10], 'S',
                                        '_eleids')

        dofs_map_actual = self.partitioner._map_dofs_local2global(
            nodes_mapping_df, local_component._mapping,
            self.testcomponent._mapping, self.testcomponent.fields)

        dofs_map_desired = {
            0: 4,
            1: 5,
            2: 10,
            3: 11,
            8: 2,
            9: 3,
            4: 12,
            5: 13,
            6: 14,
            7: 15,
            10: 16,
            11: 17
        }

        assert_equal(dofs_map_desired, dofs_map_actual)
示例#3
0
 def setUp(self):
     mesh_input = amfe_dir('tests/meshes/gid_json_4_tets.json')
     mesh_reader = GidJsonMeshReader(mesh_input)
     converter = AmfeMeshConverter()
     mesh_reader.parse(converter)
     self.mesh = converter.return_mesh()
     self.amp = 1.0
     my_comp = StructuralComponent(self.mesh)
     my_material = KirchhoffMaterial()
     my_comp.assign_material(my_material, ['left', 'right'], 'S')
     neumann_bc = my_comp._neumann.create_fixed_direction_neumann((1, 0), lambda t: self.amp*t)
     my_comp.assign_neumann('Right force', neumann_bc, ['right_boundary'])
     self.my_comp = my_comp
示例#4
0
def create_structural_component(mesh):
    return StructuralComponent(mesh)
示例#5
0
    def setUp(self):
        self.testmesh = Mesh(dimension=2)
        '''
        Testmesh:                Partition:
        
                                    9---10--11   11--12
        9---10--11--12              |  *3*  |    |*4*|
        |   |   |   |               |       |    |   |
        |   |   |   |               4---3---6    6---7
        4---3---6---7            
        |   |\  |  /|               4---3---6    6---7
        |   |  \| / |               |  *1*  |    |*2*|
        1---2---5---8               |       |    |   |
                                    1---2---5    5---8
        '''
        nodes = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0],
                          [2.0, 0.0], [2.0, 1.0], [3.0, 1.0], [3.0, 0.0],
                          [0.0, 2.0], [1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],
                         dtype=np.float)
        connectivity = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([5, 7, 8], dtype=np.int),
            np.array([6, 7, 5], dtype=np.int),
            np.array([3, 4, 9, 10], dtype=np.int),
            np.array([6, 7, 11, 12], dtype=np.int),
            np.array([3, 6, 10, 11], dtype=np.int),
            # boundary elements
            np.array([4, 1], dtype=np.int),
            np.array([4, 9], dtype=np.int),
            np.array([7, 8], dtype=np.int),
            np.array([7, 12], dtype=np.int)
        ]

        self._connectivity = connectivity

        data = {
            'shape': [
                'Tri3', 'Tri3', 'Quad4', 'Tri3', 'Tri3', 'Quad4', 'Quad4',
                'Quad4', 'straight_line', 'straight_line', 'straight_line',
                'straight_line'
            ],
            'is_boundary': [
                False, False, False, False, False, False, False, False, True,
                True, True, True
            ],
            'connectivity':
            connectivity,
            'no_of_mesh_partitions': [4, 3, 2, 3, 4, 2, 4, 4, 2, 2, 2, 2],
            'partition_id': [1, 1, 1, 2, 2, 3, 4, 3, 1, 3, 2, 4],
            'partitions_neighbors': [(2, 3, 4), (2, 3), 3, (1, 4), (1, 3, 4),
                                     1, (1, 2, 3), (1, 2, 4), 3, 1, 4, 2]
        }
        indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        el_df = pd.DataFrame(data, index=indices)

        x = nodes[:, 0]
        y = nodes[:, 1]
        nodeids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        nodes_df = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        groups = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6]
            },
            'left_boundary': {
                'elements': [9, 10],
                'nodes': [1, 4]
            },
            'right_boundary': {
                'elements': [11, 12],
                'nodes': [7, 8]
            }
        }

        self.testmesh.nodes_df = nodes_df
        self.testmesh.groups = groups
        self.testmesh._el_df = el_df
        self.no_of_partitions = len(
            self.testmesh.get_uniques_by_tag('partition_id'))

        self.testcomponent = StructuralComponent(self.testmesh)
        self.testcomponent.assign_material(DummyMaterial1(),
                                           [1, 2, 5, 6, 7, 8, 9, 10, 11, 12],
                                           'S', '_eleids')
        self.testcomponent.assign_material(DummyMaterial2(), [3, 4], 'S',
                                           '_eleids')
        self.partitioner = PartitionedMeshComponentSeparator()
示例#6
0
class TestPartitioner(TestCase):
    def setUp(self):
        self.testmesh = Mesh(dimension=2)
        '''
        Testmesh:                Partition:
        
                                    9---10--11   11--12
        9---10--11--12              |  *3*  |    |*4*|
        |   |   |   |               |       |    |   |
        |   |   |   |               4---3---6    6---7
        4---3---6---7            
        |   |\  |  /|               4---3---6    6---7
        |   |  \| / |               |  *1*  |    |*2*|
        1---2---5---8               |       |    |   |
                                    1---2---5    5---8
        '''
        nodes = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0],
                          [2.0, 0.0], [2.0, 1.0], [3.0, 1.0], [3.0, 0.0],
                          [0.0, 2.0], [1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],
                         dtype=np.float)
        connectivity = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([5, 7, 8], dtype=np.int),
            np.array([6, 7, 5], dtype=np.int),
            np.array([3, 4, 9, 10], dtype=np.int),
            np.array([6, 7, 11, 12], dtype=np.int),
            np.array([3, 6, 10, 11], dtype=np.int),
            # boundary elements
            np.array([4, 1], dtype=np.int),
            np.array([4, 9], dtype=np.int),
            np.array([7, 8], dtype=np.int),
            np.array([7, 12], dtype=np.int)
        ]

        self._connectivity = connectivity

        data = {
            'shape': [
                'Tri3', 'Tri3', 'Quad4', 'Tri3', 'Tri3', 'Quad4', 'Quad4',
                'Quad4', 'straight_line', 'straight_line', 'straight_line',
                'straight_line'
            ],
            'is_boundary': [
                False, False, False, False, False, False, False, False, True,
                True, True, True
            ],
            'connectivity':
            connectivity,
            'no_of_mesh_partitions': [4, 3, 2, 3, 4, 2, 4, 4, 2, 2, 2, 2],
            'partition_id': [1, 1, 1, 2, 2, 3, 4, 3, 1, 3, 2, 4],
            'partitions_neighbors': [(2, 3, 4), (2, 3), 3, (1, 4), (1, 3, 4),
                                     1, (1, 2, 3), (1, 2, 4), 3, 1, 4, 2]
        }
        indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        el_df = pd.DataFrame(data, index=indices)

        x = nodes[:, 0]
        y = nodes[:, 1]
        nodeids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        nodes_df = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        groups = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6]
            },
            'left_boundary': {
                'elements': [9, 10],
                'nodes': [1, 4]
            },
            'right_boundary': {
                'elements': [11, 12],
                'nodes': [7, 8]
            }
        }

        self.testmesh.nodes_df = nodes_df
        self.testmesh.groups = groups
        self.testmesh._el_df = el_df
        self.no_of_partitions = len(
            self.testmesh.get_uniques_by_tag('partition_id'))

        self.testcomponent = StructuralComponent(self.testmesh)
        self.testcomponent.assign_material(DummyMaterial1(),
                                           [1, 2, 5, 6, 7, 8, 9, 10, 11, 12],
                                           'S', '_eleids')
        self.testcomponent.assign_material(DummyMaterial2(), [3, 4], 'S',
                                           '_eleids')
        self.partitioner = PartitionedMeshComponentSeparator()

    def tearDown(self):
        pass

    def test_separate_common_nodes_of_partitions(self):
        nodes_desired = np.array(
            [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [2.0, 0.0],
             [2.0, 1.0], [3.0, 1.0], [3.0, 0.0], [0.0, 2.0], [1.0, 2.0],
             [2.0, 2.0], [3.0, 2.0], [2.0, 0.0], [2.0, 1.0], [1.0, 1.0],
             [0.0, 1.0], [2.0, 1.0], [2.0, 1.0], [3.0, 1.0], [2.0, 2.0]],
            dtype=np.float)
        x = nodes_desired[:, 0]
        y = nodes_desired[:, 1]
        nodeids = [
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
            20
        ]
        nodes_df_desired = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        connectivity_desired = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([13, 7, 8], dtype=np.int),
            np.array([14, 7, 13], dtype=np.int),
            np.array([15, 16, 9, 10], dtype=np.int),
            np.array([18, 19, 20, 12], dtype=np.int),
            np.array([15, 17, 10, 11], dtype=np.int),
            # boundary elements
            np.array([4, 1], dtype=np.int),
            np.array([16, 9], dtype=np.int),
            np.array([7, 8], dtype=np.int),
            np.array([19, 12], dtype=np.int)
        ]

        data = {'connectivity': connectivity_desired}
        indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        el_df_desired = pd.DataFrame(data, index=indices)

        groups_desired = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6, 13, 14, 15, 17, 18]
            },
            'left_boundary': {
                'elements': [9, 10],
                'nodes': [1, 4, 16]
            },
            'right_boundary': {
                'elements': [11, 12],
                'nodes': [7, 8, 19]
            }
        }

        new_mesh, nodes_map_actual = self.partitioner._separate_common_nodes_of_partitions(
            self.testmesh)

        nodes_map_desired = pd.DataFrame({
            'partition_id':
            [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4],
            'global_nodeid':
            [1, 2, 3, 4, 5, 6, 5, 6, 7, 8, 3, 4, 6, 9, 10, 11, 6, 7, 11, 12],
            'local_nodeid': [
                1, 2, 3, 4, 5, 6, 13, 14, 7, 8, 15, 16, 17, 9, 10, 11, 18, 19,
                20, 12
            ]
        })

        assert_allclose(new_mesh.nodes_df, nodes_df_desired)
        assert_series_equal(new_mesh._el_df['connectivity'],
                            el_df_desired['connectivity'])
        assert_equal(new_mesh.groups, groups_desired)
        assert_frame_equal(nodes_map_actual, nodes_map_desired)

    def test_get_submesh_by_partition_id(self):
        separated_mesh, copied_nodes = self.partitioner._separate_common_nodes_of_partitions(
            self.testmesh)
        submesh = self.partitioner._get_submesh_by_partition_id(
            1, separated_mesh)

        nodes_desired = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0],
                                  [0.0, 1.0], [2.0, 0.0], [2.0, 1.0]],
                                 dtype=np.float)
        x = nodes_desired[:, 0]
        y = nodes_desired[:, 1]
        nodeids = [1, 2, 3, 4, 5, 6]
        nodes_df_desired = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        connectivity_desired = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([4, 1], dtype=np.int)
        ]
        data = {'connectivity': connectivity_desired}
        indices = [1, 2, 3, 9]
        el_df_desired = pd.DataFrame(data, index=indices)

        groups_desired = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6]
            },
            'left_boundary': {
                'elements': [9],
                'nodes': [1, 4]
            }
        }

        self.assertTrue(isinstance(submesh, Mesh))
        assert_allclose(submesh.nodes_df, nodes_df_desired)
        assert_series_equal(submesh._el_df['connectivity'],
                            el_df_desired['connectivity'])
        assert_equal(submesh.groups, groups_desired)

        submesh = self.partitioner._get_submesh_by_partition_id(
            4, separated_mesh)

        nodes_desired = np.array(
            [[3.0, 2.0], [2.0, 1.0], [3.0, 1.0], [2.0, 2.0]], dtype=np.float)
        x = nodes_desired[:, 0]
        y = nodes_desired[:, 1]
        nodeids = [12, 16, 19, 20]
        nodes_df_desired = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        connectivity_desired = [
            np.array([18, 19, 20, 12], dtype=np.int),
            np.array([19, 12], dtype=np.int)
        ]
        data = {'connectivity': connectivity_desired}
        indices = [7, 12]
        el_df_desired = pd.DataFrame(data, index=indices)

        groups_desired = {
            'right': {
                'elements': [],
                'nodes': [18]
            },
            'right_boundary': {
                'elements': [12],
                'nodes': [19]
            }
        }

        self.assertTrue(isinstance(submesh, Mesh))
        assert_allclose(submesh.nodes_df, nodes_df_desired)
        assert_series_equal(submesh._el_df['connectivity'],
                            el_df_desired['connectivity'])
        assert_equal(submesh.groups, groups_desired)

    def test_map_dofs_local2global(self):
        d = {
            'partition_id': [3, 3, 3, 3, 3, 3],
            'global_nodeid': [3, 4, 6, 9, 10, 11],
            'local_nodeid': [15, 16, 17, 9, 10, 11]
        }
        nodes_mapping_df = pd.DataFrame(data=d)

        mesh, nodes_mapping = self.partitioner._separate_common_nodes_of_partitions(
            self.testcomponent._mesh)
        local_component = StructuralComponent(
            self.partitioner._get_submesh_by_partition_id(3, mesh))

        local_component.assign_material(DummyMaterial1(), [6, 8, 10], 'S',
                                        '_eleids')

        dofs_map_actual = self.partitioner._map_dofs_local2global(
            nodes_mapping_df, local_component._mapping,
            self.testcomponent._mapping, self.testcomponent.fields)

        dofs_map_desired = {
            0: 4,
            1: 5,
            2: 10,
            3: 11,
            8: 2,
            9: 3,
            4: 12,
            5: 13,
            6: 14,
            7: 15,
            10: 16,
            11: 17
        }

        assert_equal(dofs_map_desired, dofs_map_actual)

    def test_separate_partitioned_component(self):
        new_component_ids, new_components, dof_map_list = self.partitioner.separate_partitioned_component(
            self.testcomponent)
        component_ids_desired = [1, 2, 3, 4]

        for comp_id, icomp in zip(new_component_ids, new_components):
            self.assertTrue(isinstance(icomp, StructuralComponent))
            self.assertTrue(comp_id in component_ids_desired)
            assert_equal(len(icomp.mesh.get_uniques_by_tag('partition_id')), 1)
            for idx, element in icomp._ele_obj_df.iterrows():
                if not isinstance(element['fk_mesh'], Iterable):
                    eleids = [element['fk_mesh']]
                else:
                    eleids = element['fk_mesh']
                if 3 in eleids or 4 in eleids:
                    self.assertTrue(
                        isinstance(element['ele_obj'].material,
                                   DummyMaterial2))
                else:
                    self.assertTrue(
                        isinstance(element['ele_obj'].material,
                                   DummyMaterial1))

        assert_equal(len(new_components), self.no_of_partitions)
        assert_equal(len(dof_map_list), self.no_of_partitions)
示例#7
0
    def test_strains_and_stresses(self):
        # Rigid body-movement not causing strains and stresses
        q = np.array([
            0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
            0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
            0.1, 0.1, 0.1, 0.1
        ])
        dq = np.zeros(self.my_comp.constraints.no_of_dofs_unconstrained)
        strains_actual, stresses_actual = self.my_comp.strains_and_stresses(
            q, dq, 0.0)

        strains_desired = np.zeros((15, 6))
        stresses_desired = np.zeros((15, 6))

        assert_array_almost_equal(strains_actual, strains_desired, 8)
        assert_array_almost_equal(stresses_actual, stresses_desired, 4)

        # 1D-deformation resulting in 1D-strains and -stresses
        # 2 Quad4-Elements
        mesh_input = amfe_dir('tests/meshes/gmsh_2_quads.msh')
        mesh_reader = GmshAsciiMeshReader(mesh_input)
        converter = AmfeMeshConverter()
        mesh_reader.parse(converter)
        mesh = converter.return_mesh()
        amp = 1.0
        my_comp = StructuralComponent(mesh)

        my_material = KirchhoffMaterial(E=30e6, nu=0.0)
        my_comp.assign_material(my_material, ['volume'], 'S')

        q = np.array(
            [0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.2, 0.0, 0.2, 0.0])
        dq = np.zeros(my_comp.constraints.no_of_dofs_unconstrained)
        strains_actual, stresses_actual = my_comp.strains_and_stresses(
            q, dq, 0.0)

        strains_desired = np.array([[1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0]])

        stresses_desired = np.array([[3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0]])

        assert_array_almost_equal(strains_actual, strains_desired)
        assert_array_almost_equal(stresses_actual, stresses_desired)

        # 8 Tri3-Elements
        mesh_input = amfe_dir('tests/meshes/gmsh_8_tris.msh')
        mesh_reader = GmshAsciiMeshReader(mesh_input)
        converter = AmfeMeshConverter()
        mesh_reader.parse(converter)
        mesh = converter.return_mesh()
        amp = 1.0
        my_comp = StructuralComponent(mesh)

        my_material = KirchhoffMaterial(E=30e6, nu=0.0, plane_stress=True)
        my_comp.assign_material(my_material, ['volume'], 'S')

        q = np.array([
            0.15, 0, 0.1, 0, 0.1, 0, 0.05, 0, 0, 0, 0.2, 0, 0.2, 0, 0, 0, 0, 0
        ])
        dq = np.zeros(my_comp.constraints.no_of_dofs_unconstrained)
        strains_actual, stresses_actual = my_comp.strains_and_stresses(
            q, dq, 0.0)

        strains_desired = np.array([[1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0],
                                    [1.05e-1, 0, 0, 0, 0, 0]])

        stresses_desired = np.array([[3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0],
                                     [3.15e6, 0, 0, 0, 0, 0]])

        assert_array_almost_equal(strains_actual, strains_desired)
        assert_array_almost_equal(stresses_actual, stresses_desired, 5)
示例#8
0
    def setUp(self):
        class DummyConstraint:
            def __init__(self):
                self.no_of_constrained_dofs = 2

            def unconstrain_vector(self, u_free, u_constr=None):
                return np.array([0, 0, 0])

            def constrain_matrix(self, K_unconstr, t=0):
                return K_unconstr[0:2, 0:2]

        class DummyAssembly:
            def __init__(self):
                pass

            def assemble_k_and_f(self,
                                 nodes,
                                 ele_objects,
                                 connectivities,
                                 elements2dofs,
                                 dofvalues=None,
                                 t=0.,
                                 C_csr=None,
                                 f_glob=None):
                if C_csr is None:
                    C_csr = np.array([[10, -5, 0], [-5, 10, -5], [0, -5, 10]])
                else:
                    C_csr[:, :] = np.array([[10, -5, 0], [-5, 10, -5],
                                            [0, -5, 10]])
                if f_glob is None:
                    f_glob = np.array([2, 0, 0])
                else:
                    f_glob[:] = np.array([2, 0, 0])
                return C_csr, f_glob

            def preallocate(self, no_of_dofs, elements2dof):
                return np.zeros((3, 3))

        class DummyMesh:
            def __init__(self, dimension):
                self.dimension = dimension
                self.nodes_df = pd.DataFrame({
                    'x': [0.0, 1.0, 0.0],
                    'y': [0.0, 0.0, 1.0]
                })
                self.connectivity = None
                self.el_df = pd.DataFrame({
                    'shape': ['Tri3'],
                    'is_boundary': [False],
                    'connectivity': [np.array([1, 2, 3], dtype=int)]
                })
                self.no_of_nodes = 3

            @property
            def no_of_elements(self):
                return 0

            @property
            def nodes(self):
                return np.zeros(3)

            def get_nodeidxs_by_all(self):
                return np.arange(0, 3)

            def get_nodeids_by_nodeidxs(self, nodeidxs):
                return np.arange(0, 3)

            def get_iconnectivity_by_elementids(self, elementids):
                return None

        class DummyMapping:
            def __init__(self):
                pass

            @property
            def no_of_dofs(self):
                return 3

            def get_dofs_by_nodeids(self, nodeids):
                return np.arange(0, 3)

            def get_dofs_by_ids(self, ids):
                return None

        self.mesh = DummyMesh(2)
        self.assembly = DummyAssembly()

        self.structComp = []
        comp = StructuralComponent(self.mesh)
        comp._mapping = DummyMapping()
        comp._constraints = DummyConstraint()
        comp._assembly = DummyAssembly()
        comp._C_csr = comp._assembly.preallocate(2, None)
        comp._f_glob_int = np.zeros(comp._C_csr.shape[0])
        self.structComp.append(comp)
示例#9
0
class TestPartitioner(TestCase):
    def setUp(self):
        self.custom_asserter = CustomDictAssertTest()
        self.testmesh = Mesh(dimension=2)
        '''
        Testmesh:                Partition:
        
                                    9---10--11   11--12
        9---10--11--12              |  *3*  |    |*4*|
        |   |   |   |               |       |    |   |
        |   |   |   |               4---3---6    6---7
        4---3---6---7            
        |   |\  |  /|               4---3---6    6---7
        |   |  \| / |               |  *1*  |    |*2*|
        1---2---5---8               |       |    |   |
                                    1---2---5    5---8
        '''
        nodes = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0],
                          [2.0, 0.0], [2.0, 1.0], [3.0, 1.0], [3.0, 0.0],
                          [0.0, 2.0], [1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],
                         dtype=np.float)
        connectivity = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([5, 7, 8], dtype=np.int),
            np.array([6, 7, 5], dtype=np.int),
            np.array([3, 4, 9, 10], dtype=np.int),
            np.array([6, 7, 11, 12], dtype=np.int),
            np.array([3, 6, 10, 11], dtype=np.int),
            # boundary elements
            np.array([4, 1], dtype=np.int),
            np.array([4, 9], dtype=np.int),
            np.array([7, 8], dtype=np.int),
            np.array([7, 12], dtype=np.int)
        ]

        self._connectivity = connectivity

        data = {
            'shape': [
                'Tri3', 'Tri3', 'Quad4', 'Tri3', 'Tri3', 'Quad4', 'Quad4',
                'Quad4', 'straight_line', 'straight_line', 'straight_line',
                'straight_line'
            ],
            'is_boundary': [
                False, False, False, False, False, False, False, False, True,
                True, True, True
            ],
            'connectivity':
            connectivity,
            'no_of_mesh_partitions': [4, 3, 2, 3, 4, 2, 4, 4, 2, 2, 2, 2],
            'partition_id': [1, 1, 1, 2, 2, 3, 4, 3, 1, 3, 2, 4],
            'partitions_neighbors': [(2, 3, 4), (2, 3), 3, (1, 4), (1, 3, 4),
                                     1, (1, 2, 3), (1, 2, 4), 3, 1, 4, 2]
        }
        indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        el_df = pd.DataFrame(data, index=indices)

        x = nodes[:, 0]
        y = nodes[:, 1]
        nodeids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        nodes_df = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        groups = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6]
            },
            'left_boundary': {
                'elements': [9, 10],
                'nodes': [1, 4]
            },
            'right_boundary': {
                'elements': [11, 12],
                'nodes': [7, 8]
            }
        }

        self.testmesh.nodes_df = nodes_df
        self.testmesh.groups = groups
        self.testmesh._el_df = el_df
        self.no_of_partitions = len(
            self.testmesh.get_uniques_by_tag('partition_id'))

        self.testcomponent = StructuralComponent(self.testmesh)
        self.testcomponent.assign_material(DummyMaterial1(),
                                           [1, 2, 5, 6, 7, 8, 9, 10, 11, 12],
                                           'S', '_eleids')
        self.testcomponent.assign_material(DummyMaterial2(), [3, 4], 'S',
                                           '_eleids')
        self.partitioner = PartitionedMeshComponentSeparator()

    def tearDown(self):
        pass

    def test_set_partition_tags_by_tag_type(self):
        # Desired nodes
        mesh = Mesh(2)
        nodes = {
            'x':
            np.array([
                0., 0., 5., 5., 10., 10., 0., 10., 2.5, 5., 2.5, 0.,
                7.17636084, 7.17636084, 5., 2.5, 7.17636084, 5., 0., 2.5, 1.25,
                1.25, 3.75, 3.75, 8.22303669, 6.54073581, 6.30235631,
                2.84272972, 6.08818042, 8.31613532, 1.33568243
            ]),
            'y':
            np.array([
                0., 5., 5., 0., 0., 5., 10., 10., 0., 2.5, 5., 2.5, 0., 5.,
                2.5, 5., 5., 10., 7.17636084, 2.5, 1.25, 3.75, 1.25, 3.75,
                2.55225559, 1.81142646, 3.48052601, 7.44941386, 7.5, 6.875,
                6.15644368
            ])
        }

        mesh.nodes_df = pd.DataFrame.from_dict(nodes)
        mesh.nodes_df.index = range(1, 32)

        # Desired elements
        # (internal name of Triangle Nnode 3 is 'Tri3')
        elements = {
            'shape':
            np.array([
                'straight_line', 'straight_line', 'straight_line',
                'straight_line', 'straight_line', 'straight_line', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3'
            ],
                     dtype=object),
            'is_boundary':
            np.array([
                True, True, True, True, True, True, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False
            ]),
            'connectivity':
            np.array([
                np.array([2, 12]),
                np.array([12, 1]),
                np.array([5, 6]),
                np.array([6, 8]),
                np.array([7, 19]),
                np.array([19, 2]),
                np.array([24, 23, 10]),
                np.array([20, 23, 24]),
                np.array([4, 23, 9]),
                np.array([3, 24, 10]),
                np.array([9, 23, 20]),
                np.array([9, 20, 21]),
                np.array([1, 21, 12]),
                np.array([12, 21, 20]),
                np.array([11, 20, 24]),
                np.array([11, 22, 20]),
                np.array([12, 20, 22]),
                np.array([3, 11, 24]),
                np.array([2, 22, 11]),
                np.array([2, 12, 22]),
                np.array([4, 10, 23]),
                np.array([1, 9, 21]),
                np.array([5, 25, 13]),
                np.array([6, 14, 25]),
                np.array([14, 27, 25]),
                np.array([13, 25, 26]),
                np.array([4, 13, 26]),
                np.array([4, 26, 15]),
                np.array([25, 27, 26]),
                np.array([3, 15, 27]),
                np.array([3, 27, 14]),
                np.array([15, 26, 27]),
                np.array([5, 6, 25]),
                np.array([7, 28, 18]),
                np.array([3, 28, 16]),
                np.array([7, 19, 28]),
                np.array([3, 29, 28]),
                np.array([8, 29, 30]),
                np.array([3, 17, 29]),
                np.array([8, 18, 29]),
                np.array([19, 31, 28]),
                np.array([2, 16, 31]),
                np.array([16, 28, 31]),
                np.array([6, 30, 17]),
                np.array([2, 31, 19]),
                np.array([17, 30, 29]),
                np.array([18, 28, 29]),
                np.array([6, 8, 30])
            ],
                     dtype=object),
            'no_of_mesh_partitions':
            np.array([
                1, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1,
                2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 1, 1, 1, 1
            ]),
            'partition_id':
            np.array([
                2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1,
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
                2, 2, 2, 2, 2, 2
            ]),
            'partitions_neighbors':
            np.array([
                None, None, 2, 1, None, None, None, 2, None, None, 2, 2, 1, 1,
                2, 1, 1, 2, 1, None, None, 2, None, None, None, None, None,
                None, None, None, None, None, None, None, None, None, None,
                None, None, None, None, None, None, None, None, None, None,
                None
            ],
                     dtype=object),
            'elemental_group':
            np.array([
                4, 4, 6, 11, 13, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
                3, 3, 3, 3, 3, 3, 3
            ])
        }

        mesh._el_df = pd.DataFrame.from_dict(elements)
        mesh._el_df.index = range(1, 49)

        groups = {
            'surface_left': {
                'elements':
                [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
                'nodes': []
            },
            'surface_right': {
                'elements': [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
                'nodes': []
            },
            'surface_top': {
                'elements':
                [34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48],
                'nodes': []
            },
            'x_dirichlet-line': {
                'elements': [1, 2, 5, 6],
                'nodes': []
            },
            'x_neumann': {
                'elements': [3, 4],
                'nodes': []
            }
        }

        mesh.groups = groups

        #Desired Mesh
        mesh_desired = Mesh(2)
        mesh_desired.nodes_df = copy(mesh.nodes_df)

        elements_desired = {
            'shape':
            np.array([
                'straight_line', 'straight_line', 'straight_line',
                'straight_line', 'straight_line', 'straight_line', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3', 'Tri3',
                'Tri3'
            ],
                     dtype=object),
            'is_boundary':
            np.array([
                True, True, True, True, True, True, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False, False, False, False, False, False, False, False,
                False, False
            ]),
            'connectivity':
            np.array([
                np.array([2, 12]),
                np.array([12, 1]),
                np.array([5, 6]),
                np.array([6, 8]),
                np.array([7, 19]),
                np.array([19, 2]),
                np.array([24, 23, 10]),
                np.array([20, 23, 24]),
                np.array([4, 23, 9]),
                np.array([3, 24, 10]),
                np.array([9, 23, 20]),
                np.array([9, 20, 21]),
                np.array([1, 21, 12]),
                np.array([12, 21, 20]),
                np.array([11, 20, 24]),
                np.array([11, 22, 20]),
                np.array([12, 20, 22]),
                np.array([3, 11, 24]),
                np.array([2, 22, 11]),
                np.array([2, 12, 22]),
                np.array([4, 10, 23]),
                np.array([1, 9, 21]),
                np.array([5, 25, 13]),
                np.array([6, 14, 25]),
                np.array([14, 27, 25]),
                np.array([13, 25, 26]),
                np.array([4, 13, 26]),
                np.array([4, 26, 15]),
                np.array([25, 27, 26]),
                np.array([3, 15, 27]),
                np.array([3, 27, 14]),
                np.array([15, 26, 27]),
                np.array([5, 6, 25]),
                np.array([7, 28, 18]),
                np.array([3, 28, 16]),
                np.array([7, 19, 28]),
                np.array([3, 29, 28]),
                np.array([8, 29, 30]),
                np.array([3, 17, 29]),
                np.array([8, 18, 29]),
                np.array([19, 31, 28]),
                np.array([2, 16, 31]),
                np.array([16, 28, 31]),
                np.array([6, 30, 17]),
                np.array([2, 31, 19]),
                np.array([17, 30, 29]),
                np.array([18, 28, 29]),
                np.array([6, 8, 30])
            ],
                     dtype=object),
            'no_of_mesh_partitions':
            np.array([
                2, 2, 2, 2, 1, 2, 2, 2, 2, 3, 2, 2, 2, 2, 3, 3, 2, 4, 3, 2, 2,
                2, 1, 2, 2, 1, 2, 2, 1, 3, 3, 2, 2, 1, 4, 1, 3, 1, 3, 1, 1, 3,
                3, 2, 2, 2, 1, 2
            ]),
            'partition_id':
            np.array([
                1, 1, 3, 4, 4, 4, 2, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2,
                2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
                4, 4, 4, 4, 4, 4
            ]),
            'partitions_neighbors':
            np.array([
                4, 2, 4, 3, None, 1, 3, 1, 3, (3, 4), 1, 1, 2, 2, (1, 4),
                (2, 4), 2, (1, 3, 4),
                (2, 4), 4, 3, 1, None, 4, 4, None, 2, 2, None,
                (2, 4), (2, 4), 2, 4, None, (1, 2, 3), None, (2, 3), None,
                (2, 3), None, None, (1, 2), (1, 2), 3, 1, 3, None, 3
            ],
                     dtype=object),
            'elemental_group':
            np.array([
                4, 4, 6, 11, 13, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
                3, 3, 3, 3, 3, 3, 3
            ])
        }

        mesh_desired._el_df = pd.DataFrame.from_dict(elements_desired)
        mesh_desired._el_df.index = range(1, 49)

        groups_desired = {
            'surface_left': {
                'elements':
                [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
                'nodes': []
            },
            'surface_right': {
                'elements': [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
                'nodes': []
            },
            'surface_top': {
                'elements':
                [34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48],
                'nodes': []
            },
            'x_dirichlet-line': {
                'elements': [1, 2, 5, 6],
                'nodes': []
            },
            'x_neumann': {
                'elements': [3, 4],
                'nodes': []
            }
        }

        mesh_desired.groups = groups_desired

        self.partitioner.set_partition_tags_by_group(mesh, 'surface')

        self.custom_asserter.assert_dict_equal(mesh._el_df['shape'],
                                               mesh_desired._el_df['shape'])
        self.custom_asserter.assert_dict_equal(
            mesh._el_df['is_boundary'], mesh_desired._el_df['is_boundary'])
        self.custom_asserter.assert_dict_equal(
            mesh._el_df['connectivity'], mesh_desired._el_df['connectivity'])
        self.custom_asserter.assert_dict_equal(
            mesh._el_df['partition_id'], mesh_desired._el_df['partition_id'])
        self.custom_asserter.assert_dict_equal(
            mesh._el_df['partitions_neighbors'],
            mesh_desired._el_df['partitions_neighbors'])
        self.custom_asserter.assert_dict_equal(
            mesh._el_df['no_of_mesh_partitions'],
            mesh_desired._el_df['no_of_mesh_partitions'])
        self.custom_asserter.assert_dict_equal(
            mesh._el_df['elemental_group'],
            mesh_desired._el_df['elemental_group'])

    def test_separate_common_nodes_of_partitions(self):
        nodes_desired = np.array(
            [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [2.0, 0.0],
             [2.0, 1.0], [3.0, 1.0], [3.0, 0.0], [0.0, 2.0], [1.0, 2.0],
             [2.0, 2.0], [3.0, 2.0], [2.0, 0.0], [2.0, 1.0], [1.0, 1.0],
             [0.0, 1.0], [2.0, 1.0], [2.0, 1.0], [3.0, 1.0], [2.0, 2.0]],
            dtype=np.float)
        x = nodes_desired[:, 0]
        y = nodes_desired[:, 1]
        nodeids = [
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
            20
        ]
        nodes_df_desired = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        connectivity_desired = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([13, 7, 8], dtype=np.int),
            np.array([14, 7, 13], dtype=np.int),
            np.array([15, 16, 9, 10], dtype=np.int),
            np.array([18, 19, 20, 12], dtype=np.int),
            np.array([15, 17, 10, 11], dtype=np.int),
            # boundary elements
            np.array([4, 1], dtype=np.int),
            np.array([16, 9], dtype=np.int),
            np.array([7, 8], dtype=np.int),
            np.array([19, 12], dtype=np.int)
        ]

        data = {'connectivity': connectivity_desired}
        indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        el_df_desired = pd.DataFrame(data, index=indices)

        groups_desired = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6, 13, 14, 15, 17, 18]
            },
            'left_boundary': {
                'elements': [9, 10],
                'nodes': [1, 4, 16]
            },
            'right_boundary': {
                'elements': [11, 12],
                'nodes': [7, 8, 19]
            }
        }

        new_mesh, nodes_map_actual = self.partitioner._separate_common_nodes_of_partitions(
            self.testmesh)

        nodes_map_desired = pd.DataFrame({
            'partition_id':
            [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4],
            'global_nodeid':
            [1, 2, 3, 4, 5, 6, 5, 6, 7, 8, 3, 4, 6, 9, 10, 11, 6, 7, 11, 12],
            'local_nodeid': [
                1, 2, 3, 4, 5, 6, 13, 14, 7, 8, 15, 16, 17, 9, 10, 11, 18, 19,
                20, 12
            ]
        })

        assert_allclose(new_mesh.nodes_df, nodes_df_desired)
        assert_series_equal(new_mesh._el_df['connectivity'],
                            el_df_desired['connectivity'])
        assert_equal(new_mesh.groups, groups_desired)
        assert_frame_equal(nodes_map_actual, nodes_map_desired)

    def test_get_submesh_by_partition_id(self):
        separated_mesh, copied_nodes = self.partitioner._separate_common_nodes_of_partitions(
            self.testmesh)
        submesh = self.partitioner._get_submesh_by_partition_id(
            1, separated_mesh)

        nodes_desired = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0],
                                  [0.0, 1.0], [2.0, 0.0], [2.0, 1.0]],
                                 dtype=np.float)
        x = nodes_desired[:, 0]
        y = nodes_desired[:, 1]
        nodeids = [1, 2, 3, 4, 5, 6]
        nodes_df_desired = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        connectivity_desired = [
            np.array([5, 6, 3], dtype=np.int),
            np.array([3, 2, 5], dtype=np.int),
            np.array([1, 2, 3, 4], dtype=np.int),
            np.array([4, 1], dtype=np.int)
        ]
        data = {'connectivity': connectivity_desired}
        indices = [1, 2, 3, 9]
        el_df_desired = pd.DataFrame(data, index=indices)

        groups_desired = {
            'left': {
                'elements': [3],
                'nodes': []
            },
            'right': {
                'elements': [1, 2],
                'nodes': [2, 3, 5, 6]
            },
            'left_boundary': {
                'elements': [9],
                'nodes': [1, 4]
            }
        }

        self.assertTrue(isinstance(submesh, Mesh))
        assert_allclose(submesh.nodes_df, nodes_df_desired)
        assert_series_equal(submesh._el_df['connectivity'],
                            el_df_desired['connectivity'])
        assert_equal(submesh.groups, groups_desired)

        submesh = self.partitioner._get_submesh_by_partition_id(
            4, separated_mesh)

        nodes_desired = np.array(
            [[3.0, 2.0], [2.0, 1.0], [3.0, 1.0], [2.0, 2.0]], dtype=np.float)
        x = nodes_desired[:, 0]
        y = nodes_desired[:, 1]
        nodeids = [12, 16, 19, 20]
        nodes_df_desired = pd.DataFrame({'x': x, 'y': y}, index=nodeids)

        connectivity_desired = [
            np.array([18, 19, 20, 12], dtype=np.int),
            np.array([19, 12], dtype=np.int)
        ]
        data = {'connectivity': connectivity_desired}
        indices = [7, 12]
        el_df_desired = pd.DataFrame(data, index=indices)

        groups_desired = {
            'right': {
                'elements': [],
                'nodes': [18]
            },
            'right_boundary': {
                'elements': [12],
                'nodes': [19]
            }
        }

        self.assertTrue(isinstance(submesh, Mesh))
        assert_allclose(submesh.nodes_df, nodes_df_desired)
        assert_series_equal(submesh._el_df['connectivity'],
                            el_df_desired['connectivity'])
        assert_equal(submesh.groups, groups_desired)

    def test_map_dofs_local2global(self):
        d = {
            'partition_id': [3, 3, 3, 3, 3, 3],
            'global_nodeid': [3, 4, 6, 9, 10, 11],
            'local_nodeid': [15, 16, 17, 9, 10, 11]
        }
        nodes_mapping_df = pd.DataFrame(data=d)

        mesh, nodes_mapping = self.partitioner._separate_common_nodes_of_partitions(
            self.testcomponent._mesh)
        local_component = StructuralComponent(
            self.partitioner._get_submesh_by_partition_id(3, mesh))

        local_component.assign_material(DummyMaterial1(), [6, 8, 10], 'S',
                                        '_eleids')

        dofs_map_actual = self.partitioner._map_dofs_local2global(
            nodes_mapping_df, local_component._mapping,
            self.testcomponent._mapping, self.testcomponent.fields)

        dofs_map_desired = {
            0: 4,
            1: 5,
            2: 10,
            3: 11,
            8: 2,
            9: 3,
            4: 12,
            5: 13,
            6: 14,
            7: 15,
            10: 16,
            11: 17
        }

        assert_equal(dofs_map_desired, dofs_map_actual)

    def test_separate_partitioned_component(self):
        new_component_ids, new_components, dof_map_list = self.partitioner.separate_partitioned_component(
            self.testcomponent)
        component_ids_desired = [1, 2, 3, 4]

        for comp_id, icomp in zip(new_component_ids, new_components):
            self.assertTrue(isinstance(icomp, StructuralComponent))
            self.assertTrue(comp_id in component_ids_desired)
            assert_equal(len(icomp.mesh.get_uniques_by_tag('partition_id')), 1)
            for idx, element in icomp._ele_obj_df.iterrows():
                if not isinstance(element['fk_mesh'], Iterable):
                    eleids = [element['fk_mesh']]
                else:
                    eleids = element['fk_mesh']
                if 3 in eleids or 4 in eleids:
                    self.assertTrue(
                        isinstance(element['ele_obj'].material,
                                   DummyMaterial2))
                else:
                    self.assertTrue(
                        isinstance(element['ele_obj'].material,
                                   DummyMaterial1))

        assert_equal(len(new_components), self.no_of_partitions)
        assert_equal(len(dof_map_list), self.no_of_partitions)