示例#1
0
 def test_constructor(self):
     from amfe.mesh import Mesh
     mesh = Mesh(dimension=2)
     self.assertEqual(mesh.dimension, 2)
     mesh = Mesh(dimension=3)
     self.assertEqual(mesh.dimension, 3)
     with self.assertRaises(ValueError) as err:
         mesh = Mesh(dimension=1)
示例#2
0
    def _get_submesh_by_partition_id(partition_id, mesh):
        """
        Getter for a submesh, derived from the given mesh, but only possesses elements, nodes and groups, which belong
        to the given partition.
        
        Parameters
        ----------
        partition_id : int
            ID of the partition
            
        mesh : Mesh
            partitioned Mesh-object
        """
        submesh = Mesh(mesh.dimension)

        ele_ids = mesh.get_elementids_by_tags(['partition_id'], partition_id)
        nodes_df, el_df = mesh.get_submesh_by_elementids(ele_ids)
        ele_groups = mesh.get_groups_dict_by_elementids(el_df.index.tolist())
        node_groups = mesh.get_groups_dict_by_nodeids(nodes_df.index.tolist())
        submesh.nodes_df = deepcopy(nodes_df)
        submesh._el_df = deepcopy(el_df)
        submesh.merge_into_groups(ele_groups)
        submesh.merge_into_groups(node_groups)
        submesh._update_iconnectivity()

        return submesh
示例#3
0
    def __init__(self, l, h, n_ele_l, n_ele_h, x_start=0.0, y_start=0.0):
        self.l = l
        self.h = h
        self.n_ele_l = n_ele_l
        self.n_ele_h = n_ele_h
        self.delta_h_x = self.l / self.n_ele_l
        self.delta_h_y = self.h / self.n_ele_h
        self.x_start = x_start
        self.y_start = y_start

        self._mesh = Mesh(2)
示例#4
0
 def __init__(self, mesh=Mesh()):
     super().__init__(mesh)
     self.rayleigh_damping = None
     self._assembly = StructuralAssembly()
     self._M_constr = None
     self._D_constr = None
     self._C_csr = None
     self._M_csr = None
     self._f_glob_int = None
     self._f_glob_ext = None
     self._stresses = None
     self._strains = None
示例#5
0
 def __init__(self, mesh=Mesh()):
     super().__init__()
     self._mesh = mesh
     self._mapping = StandardMapping()
     self._ele_obj_df = pd.DataFrame(
         [], columns=['physics', 'fk_mesh', 'ele_obj', 'fk_mapping'])
     self._ele_obj_df['fk_mapping'] = self._ele_obj_df['fk_mapping'].astype(
         int)
     self._ele_obj_df['fk_mesh'] = self._ele_obj_df['fk_mesh'].astype(int)
     self._neumann = NeumannManager()
     self._assembly = Assembly()
     self._constraints = ConstraintManager()
示例#6
0
    def setUp(self):
        from amfe.mesh import Mesh
        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
示例#7
0
    def setUp(self):
        self.testmesh = Mesh(dimension=2)
        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]], 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),
                        # boundary elements
                        np.array([4, 1], dtype=np.int), np.array([5, 6], dtype=np.int)]

        shapes = ['Tri3', 'Tri3', 'Quad4', 'straight_line', 'straight_line']

        data = {'shape': shapes,
                'is_boundary': [False, False, False, True, True],
                'connectivity': connectivity}
        indices = [1, 2, 3, 4, 5]

        el_df = pd.DataFrame(data, index=indices)

        x = nodes[:, 0]
        y = nodes[:, 1]
        nodeids = [1, 2, 3, 4, 5, 6]
        self._nodeids = nodeids
        self._nodes = nodes
        self._eleids = indices
        self._connectivity = connectivity
        self._connectivity = connectivity
        self._shapes = shapes
        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': [4], 'nodes': []},
                  'right_boundary': {'elements': [5], 'nodes': [1, 2]}
                  }

        self.testmesh.nodes_df = nodes_df
        self.testmesh.groups = groups
        self.testmesh._el_df = el_df

        self.testmesh3d = deepcopy(self.testmesh)
        nodes3d = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0],
                            [1.0, 1.0, 0.0], [0.0, 1.0, 0.0],
                            [2.0, 0.0, 1.0], [2.0, 1.0, 1.0]], dtype=np.float)
        self.testmesh3d.dimension = 3
        x = nodes3d[:, 0]
        y = nodes3d[:, 1]
        z = nodes3d[:, 2]
        nodes_df3d = pd.DataFrame({'x': x, 'y': y, 'z': z}, index=nodeids)
        self.testmesh3d.nodes_df = nodes_df3d
示例#8
0
 def __init__(self, verbose=False):
     super().__init__()
     self._verbose = verbose
     self._mesh = Mesh()
     self._dimension = None
     self._no_of_nodes = None
     self._no_of_elements = None
     self._nodes = np.empty((0, 4), dtype=float)
     self._currentnodeid = 0
     self._groups = dict()
     self._tags = dict()
     # df information
     self._el_df_indices = list()
     self._el_df_eleshapes = list()
     self._el_df_connectivity = list()
     self._el_df_is_boundary = list()
     return
示例#9
0
    def test_add_element(self):
        mesh = Mesh(2)
        for nodeid, coords in zip(self._nodeids, self._nodes):
            mesh.add_node(coords, nodeid)

        conn_desired = np.array([5, 6, 3], dtype=np.int)
        shape_desired = 'Tri3'
        new_id = mesh.add_element(shape_desired, conn_desired)
        shape_actual = mesh.get_ele_shapes_by_elementids([new_id])[0]
        conn_actual = mesh.get_connectivity_by_elementids([new_id])[0]
        self.assertEqual(shape_actual, shape_desired)
        assert_array_equal(conn_actual, conn_desired)

        conn_desired = np.array([4, 1], dtype=np.int)
        shape_desired = 'straight_line'
        new_id = mesh.add_element(shape_desired, conn_desired)
        shape_actual = mesh.get_ele_shapes_by_elementids([new_id])[0]
        conn_actual = mesh.get_connectivity_by_elementids([new_id])[0]
        self.assertEqual(shape_actual, shape_desired)
        assert_array_equal(conn_actual, conn_desired)

        conn_desired = np.array([3, 2, 5], dtype=np.int)
        shape_desired = 'Tri3'
        new_id = mesh.add_element(shape_desired,
                                  np.array([3, 2, 5], dtype=np.int), 5)
        shape_actual = mesh.get_ele_shapes_by_elementids([new_id])[0]
        conn_actual = mesh.get_connectivity_by_elementids([new_id])[0]
        self.assertEqual(shape_actual, shape_desired)
        assert_array_equal(conn_actual, conn_desired)
        self.assertEqual(new_id, 5)

        with self.assertRaises(ValueError):
            mesh.add_element('Quad4', np.array([1, 2, 3, 4], dtype=np.int), 5)

        conn_desired = np.array([1, 2, 3, 4], dtype=np.int)
        shape_desired = 'Quad4'
        new_id = mesh.add_element('Quad4',
                                  np.array([1, 2, 3, 4], dtype=np.int),
                                  5,
                                  overwrite=True)
        shape_actual = mesh.get_ele_shapes_by_elementids([new_id])[0]
        conn_actual = mesh.get_connectivity_by_elementids([new_id])[0]
        self.assertEqual(shape_actual, shape_desired)
        assert_array_equal(conn_actual, conn_desired)
        self.assertEqual(new_id, 5)

        # Test wrong dtype
        new_id = mesh.add_element('Quad4',
                                  np.array([1, 2, 3, 4], dtype=np.float), 6)
        shape_actual = mesh.get_ele_shapes_by_elementids([new_id])[0]
        conn_actual = mesh.get_connectivity_by_elementids([new_id])[0]
        self.assertEqual(shape_actual, shape_desired)
        assert_array_equal(conn_actual, conn_desired)
        self.assertEqual(new_id, 6)

        # Test with tuple instead of array
        new_id = mesh.add_element('Quad4', (1, 2, 3, 4), 7)
        shape_actual = mesh.get_ele_shapes_by_elementids([new_id])[0]
        conn_actual = mesh.get_connectivity_by_elementids([new_id])[0]
        self.assertEqual(shape_actual, shape_desired)
        assert_array_equal(conn_actual, conn_desired)
        self.assertEqual(new_id, 7)

        # Test wrong shape
        with self.assertRaises(ValueError):
            mesh.add_element('wrong_shape', np.array([1, 2, 3, 4],
                                                     dtype=np.int), 8)
示例#10
0
    def test_add_node(self):
        # Test 3D mesh
        mesh = Mesh(3)

        # test with tuple
        coords = (0.0, 1.0, 2.0)
        new_id = mesh.add_node(coords)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y', 'z']]
        assert_array_equal(coords_actual, np.array(coords, dtype=float))

        # test with array
        coords = np.array([5, 6, 3], dtype=float)
        new_id = mesh.add_node(coords)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y', 'z']]
        assert_array_equal(coords_actual, np.array(coords, dtype=float))

        # test with dict and id
        coords = {'x': 5.0, 'y': 6.0, 'z': 3}
        new_id = mesh.add_node(coords, 8)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y', 'z']]
        assert_array_equal(coords_actual, np.array([5, 6, 3], dtype=float))
        self.assertEqual(new_id, 8)

        # test raise error no overwrite
        coords = np.array([10, 4, 2], dtype=float)
        with self.assertRaises(ValueError):
            new_id = mesh.add_node(coords, 8)

        # test overwrite and with int array
        coords = np.array([10, 4, 2], dtype=int)
        new_id = mesh.add_node(coords, 8, overwrite=True)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y', 'z']]
        assert_array_equal(coords_actual, np.array(coords, dtype=float))
        self.assertEqual(new_id, 8)

        # Test 2D mesh
        mesh = Mesh(2)

        # test with tuple
        coords = (0.0, 1.0, 2.0)
        new_id = mesh.add_node(coords)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y']]
        assert_array_equal(coords_actual, np.array(coords[0:2], dtype=float))

        # test with array
        coords = np.array([5, 6, 3], dtype=float)
        new_id = mesh.add_node(coords)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y']]
        assert_array_equal(coords_actual, np.array(coords[0:2], dtype=float))

        # test with dict and id
        coords = {'x': 5.0, 'y': 6.0, 'z': 3}
        new_id = mesh.add_node(coords, 8)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y']]
        assert_array_equal(coords_actual, np.array([5, 6], dtype=float))
        self.assertEqual(new_id, 8)

        # test raise error no overwrite
        coords = np.array([10, 4, 2], dtype=float)
        with self.assertRaises(ValueError):
            new_id = mesh.add_node(coords, 8)

        # test overwrite and with int array
        coords = np.array([10, 4, 2], dtype=int)
        new_id = mesh.add_node(coords, 8, overwrite=True)
        coords_actual = mesh.nodes_df.loc[new_id, ['x', 'y']]
        assert_array_equal(coords_actual, np.array(coords[0:2], dtype=float))
        self.assertEqual(new_id, 8)
示例#11
0
def create_amfe_obj():
    # Define input file path
    meshobj = Mesh(dimension=2)

    nodes = np.array([
        [1.345600000e-02, 3.561675700e-02], [5.206839561e-01, 3.740820950e-02],
        [3.851982918e-02, 5.460016703e-01], [5.457667372e-01, 5.477935420e-01],
        [1.027911912e+00, 3.919966200e-02], [6.358365836e-02, 1.056386584e+00],
        [1.040469476e+00, 5.445628213e-01], [5.582746582e-01, 1.053154002e+00],
        [1.052965658e+00, 1.049921420e+00], [1.535139868e+00, 4.099111450e-02],
        [1.547697432e+00, 5.463542738e-01], [1.547656658e+00, 1.046688838e+00],
        [2.042367825e+00, 4.278256700e-02], [2.042357741e+00, 5.431194119e-01],
        [2.042347658e+00, 1.043456257e+00]
    ],
                     dtype=float)

    connectivity = [
        np.array([13, 15, 9, 14, 12, 11], dtype=int),
        np.array([9, 6, 5, 8, 4, 7], dtype=int),
        np.array([9, 5, 13, 7, 10, 11], dtype=int),
        np.array([1, 5, 6, 2, 4, 3], dtype=int),
        np.array([5, 13, 10], dtype=int),
        np.array([1, 5, 2], dtype=int),
        np.array([6, 1, 3], dtype=int),
        np.array([9, 6, 8], dtype=int),
        np.array([13, 15, 14], dtype=int),
        np.array([15, 9, 12], dtype=int)
    ]

    data = {
        'shape': [
            'Tri6', 'Tri6', 'Tri6', 'Tri6', 'quadratic_line', 'quadratic_line',
            'quadratic_line', 'quadratic_line', 'quadratic_line',
            'quadratic_line'
        ],
        'connectivity':
        connectivity,
        'is_boundary':
        [False, False, False, False, True, True, True, True, True, True]
    }
    indices = list(np.arange(1, 11))

    meshobj.el_df = pd.DataFrame(data, index=indices)

    meshobj.groups = {
        'left': {
            'nodes': [],
            'elements': [2, 4]
        },
        'right': {
            'nodes': [],
            'elements': [1, 3]
        },
        'left_boundary': {
            'nodes': [],
            'elements': [7]
        },
        'right_boundary': {
            'nodes': [],
            'elements': [9]
        },
        'top_boundary': {
            'nodes': [],
            'elements': [8, 10]
        },
        'left_dirichlet': {
            'nodes': [1, 3, 6],
            'elements': []
        }
    }

    nodeids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

    meshobj.nodes_df = pd.DataFrame({
        'x': nodes[:, 0],
        'y': nodes[:, 1]
    },
                                    index=nodeids)
    return meshobj