コード例 #1
0
ファイル: test_io.py プロジェクト: vijaypolimeru/AMfe
    def test_gmshascii_to_dummy_hexa20(self):
        # Desired nodes
        # old ordering: [5, 42, 60, 30, 21, 45, 75, 65, 44, 32, 22,
        # 63, 47, 64, 76, 67, 49, 66, 77, 78]
        element_57_desired = (57, 'Hexa20', [
            5, 42, 60, 30, 21, 45, 75, 65, 44, 63, 64, 32, 49, 77, 78, 66, 22,
            47, 76, 67
        ])

        dimension_desired = 3
        # Define input file path
        file = amfe_dir('tests/meshes/gmsh_ascii_v2_hexa20.msh')
        # Define Reader Object, initialized with AmfeMeshConverter
        reader = GmshAsciiMeshReader(file)
        # Parse dummy mesh
        dummy = DummyMeshConverter()
        reader.parse(dummy)
        mesh = dummy.return_mesh()

        # Check elements
        self.assertEqual(
            mesh._elements[mesh._elements.index(element_57_desired)],
            element_57_desired)
        # Check mesh dimension
        self.assertEqual(mesh._no_of_nodes, 81)
        self.assertEqual(mesh._no_of_elements, 64)
        self.assertEqual(mesh._dimension, dimension_desired)
コード例 #2
0
ファイル: test_io.py プロジェクト: vijaypolimeru/AMfe
    def test_gmshascii_to_dummy(self):
        # Desired nodes
        nodes_desired = [(1, 0.0, 0.0, 0.0), (2, 2.0, 0.0, 0.0),
                         (3, 2.0, 1.0, 0.0), (4, 0.0, 1.0, 0.0),
                         (5, 0.999999999997388, 0.0, 0.0),
                         (6, 1.000000000004118, 1.0, 0.0),
                         (7, 0.5000000000003766, 0.5, 0.0),
                         (8, 1.500000000000857, 0.5, 0.0)]

        # Desired elements
        # (internal name of Triangle Nnode 3 is 'Tri3')
        elements_desired = [(1, 'straight_line', [2, 3]),
                            (2, 'straight_line', [4, 1]),
                            (3, 'Tri3', [8, 6, 5]), (4, 'Tri3', [5, 6, 7]),
                            (5, 'Tri3', [4, 7, 6]), (6, 'Tri3', [2, 8, 5]),
                            (7, 'Tri3', [2, 3, 8]), (8, 'Tri3', [1, 7, 4]),
                            (9, 'Tri3', [1, 5, 7]), (10, 'Tri3', [3, 6, 8])]

        dimension_desired = 2
        groups_desired = [('right_boundary', [], [1]),
                          ('left_boundary', [], [2]),
                          ('volume', [], [3, 4, 5, 6, 7, 8, 9, 10])]

        # Define input file path
        file = amfe_dir('tests/meshes/gmsh_ascii_8_tets.msh')
        # Define Reader Object, initialized with AmfeMeshConverter
        reader = GmshAsciiMeshReader(file)
        # Parse dummy mesh
        dummy = DummyMeshConverter()
        reader.parse(dummy)
        mesh = dummy.return_mesh()

        # Check nodes
        for i, node in enumerate(nodes_desired):
            self.assertAlmostEqual(mesh._nodes[i], node)
        # Check elements
        for i, element in enumerate(elements_desired):
            self.assertEqual(mesh._elements[mesh._elements.index(element)],
                             element)
        # Check mesh dimension
        self.assertEqual(mesh._dimension, dimension_desired)
        self.assertEqual(mesh._groups, groups_desired)
        self.assertEqual(mesh._no_of_nodes, 8)
        self.assertEqual(mesh._no_of_elements, 10)
コード例 #3
0
ファイル: test_io.py プロジェクト: vijaypolimeru/AMfe
    def test_gmsh_parser_with_2_partitions(self):

        msh_filename = amfe_dir('tests/meshes/2_partitions_2quad_mesh.msh')
        reader_obj = GmshAsciiMeshReader(msh_filename)
        converter = AmfeMeshConverter()
        reader_obj.parse(converter)
        mesh_obj = converter.return_mesh()

        self.assertTrue('no_of_mesh_partitions' in mesh_obj.el_df)
        self.assertTrue('partition_id' in mesh_obj.el_df)
        self.assertTrue('partitions_neighbors' in mesh_obj.el_df)

        desired_list_1 = [1, 1, 2, 2]
        desired_list_2 = [1, 1, 1, 2]
        desired_list_3 = [None, None, 2, 1]
        actual_list_1 = mesh_obj.el_df['no_of_mesh_partitions'].tolist()
        actual_list_2 = mesh_obj.el_df['partition_id'].tolist()
        actual_list_3 = mesh_obj.el_df['partitions_neighbors'].tolist()

        self.assertListEqual(actual_list_1, desired_list_1)
        self.assertListEqual(actual_list_2, desired_list_2)
        self.assertListEqual(actual_list_3, desired_list_3)
コード例 #4
0
ファイル: test_io.py プロジェクト: vijaypolimeru/AMfe
    def test_gmshascii_to_dummy_tet10(self):

        element_65_desired = (65, 'Tet10',
                              [61, 9, 45, 72, 84, 85, 86, 87, 79, 88])
        dimension_desired = 3
        # Define input file path
        file = amfe_dir('tests/meshes/gmsh_ascii_v2_tet10.msh')
        # Define Reader Object, initialized with AmfeMeshConverter
        reader = GmshAsciiMeshReader(file)
        # Parse dummy mesh
        dummy = DummyMeshConverter()
        reader.parse(dummy)
        mesh = dummy.return_mesh()

        # Check elements
        self.assertEqual(
            mesh._elements[mesh._elements.index(element_65_desired)],
            element_65_desired)
        # Check mesh dimension
        self.assertEqual(mesh._no_of_nodes, 113)
        self.assertEqual(mesh._no_of_elements, 112)
        self.assertEqual(mesh._dimension, dimension_desired)
コード例 #5
0
ファイル: test_io.py プロジェクト: vijaypolimeru/AMfe
    def test_gmsh_parser_with_8_partitions(self):

        msh_filename = amfe_dir(
            'tests/meshes/retangule_5_by_2_quad_par_8_irreg.msh')
        reader_obj = GmshAsciiMeshReader(msh_filename)
        converter = AmfeMeshConverter()
        reader_obj.parse(converter)
        mesh_obj = converter.return_mesh()

        self.assertTrue('no_of_mesh_partitions' in mesh_obj.el_df)
        self.assertTrue('partition_id' in mesh_obj.el_df)
        self.assertTrue('partitions_neighbors' in mesh_obj.el_df)

        actual_list_1 = mesh_obj.el_df['no_of_mesh_partitions'].tolist()
        actual_list_2 = mesh_obj.el_df['partition_id'].tolist()
        actual_list_3 = mesh_obj.el_df['partitions_neighbors'].tolist()

        desired_list_1 = load_object(amfe_dir('tests/pickle_obj/l1.pkl'))
        desired_list_2 = load_object(amfe_dir('tests/pickle_obj/l2.pkl'))
        desired_list_3 = load_object(amfe_dir('tests/pickle_obj/l3.pkl'))

        self.assertListEqual(actual_list_1, desired_list_1)
        self.assertListEqual(actual_list_2, desired_list_2)
        self.assertListEqual(actual_list_3, desired_list_3)
コード例 #6
0
ファイル: test_io.py プロジェクト: sivasanarul/amfe_topopt
    def test_gmshascii_to_dummy_physical_surfaces_and_partitions(self):
        # Desired nodes
        nodes_desired = [(1, 0.0, 0.0, 0.0), (2, 0.0, 5.0, 0.0),
                         (3, 5.0, 5.0, 0.0), (4, 5.0, 0.0, 0.0),
                         (5, 10.0, 0.0, 0.0), (6, 10.0, 5.0, 0.0),
                         (7, 0.0, 10.0, 0.0), (8, 10.0, 10.0, 0.0),
                         (9, 2.499999999996199, 0.0, 0.0),
                         (10, 5, 2.499999999996199, 0), (11, 2.5, 5, 0),
                         (12, 0, 2.5, 0), (13, 7.176360840382222, 0, 0),
                         (14, 7.176360840382227, 5, 0), (15, 5, 2.5, 0),
                         (16, 2.499999999996199, 5, 0),
                         (17, 7.176360840382222, 5, 0), (18, 5, 10, 0),
                         (19, 0, 7.176360840382227, 0), (20, 2.5, 2.5, 0),
                         (21, 1.2499999999981, 1.25, 0), (22, 1.25, 3.75, 0),
                         (23, 3.7499999999981, 1.2499999999981, 0),
                         (24, 3.750000000001901, 3.749999999998099, 0),
                         (25, 8.22303669484285, 2.552255592639131, 0),
                         (26, 6.540735812640291, 1.811426457748249, 0),
                         (27, 6.3023563126068, 3.480526007198198, 0),
                         (28, 2.842729718643214, 7.449413862174849, 0),
                         (29, 6.088180420191112, 7.499999999999999, 0),
                         (30, 8.316135315143335, 6.875, 0),
                         (31, 1.335682429659853, 6.156443675639268, 0)]

        # Desired elements
        # (internal name of Triangle Nnode 3 is 'Tri3')
        elements_desired = [
            (1, 'straight_line', [2, 12]), (2, 'straight_line', [12, 1]),
            (3, 'straight_line', [5, 6]), (4, 'straight_line', [6, 8]),
            (5, 'straight_line', [7, 19]), (6, 'straight_line', [19, 2]),
            (7, 'Tri3', [24, 23, 10]), (8, 'Tri3', [20, 23, 24]),
            (9, 'Tri3', [4, 23, 9]), (10, 'Tri3', [3, 24, 10]),
            (11, 'Tri3', [9, 23, 20]), (12, 'Tri3', [9, 20, 21]),
            (13, 'Tri3', [1, 21, 12]), (14, 'Tri3', [12, 21, 20]),
            (15, 'Tri3', [11, 20, 24]), (16, 'Tri3', [11, 22, 20]),
            (17, 'Tri3', [12, 20, 22]), (18, 'Tri3', [3, 11, 24]),
            (19, 'Tri3', [2, 22, 11]), (20, 'Tri3', [2, 12, 22]),
            (21, 'Tri3', [4, 10, 23]), (22, 'Tri3', [1, 9, 21]),
            (23, 'Tri3', [5, 25, 13]), (24, 'Tri3', [6, 14, 25]),
            (25, 'Tri3', [14, 27, 25]), (26, 'Tri3', [13, 25, 26]),
            (27, 'Tri3', [4, 13, 26]), (28, 'Tri3', [4, 26, 15]),
            (29, 'Tri3', [25, 27, 26]), (30, 'Tri3', [3, 15, 27]),
            (31, 'Tri3', [3, 27, 14]), (32, 'Tri3', [15, 26, 27]),
            (33, 'Tri3', [5, 6, 25]), (34, 'Tri3', [7, 28, 18]),
            (35, 'Tri3', [3, 28, 16]), (36, 'Tri3', [7, 19, 28]),
            (37, 'Tri3', [3, 29, 28]), (38, 'Tri3', [8, 29, 30]),
            (39, 'Tri3', [3, 17, 29]), (40, 'Tri3', [8, 18, 29]),
            (41, 'Tri3', [19, 31, 28]), (42, 'Tri3', [2, 16, 31]),
            (43, 'Tri3', [16, 28, 31]), (44, 'Tri3', [6, 30, 17]),
            (45, 'Tri3', [2, 31, 19]), (46, 'Tri3', [17, 30, 29]),
            (47, 'Tri3', [18, 28, 29]), (48, 'Tri3', [6, 8, 30])
        ]

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

        tags_desired = {
            'no_of_mesh_partitions': {
                1: [
                    1, 2, 5, 6, 7, 9, 10, 20, 21, 23, 24, 25, 26, 27, 28, 29,
                    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
                    45, 46, 47, 48
                ],
                2: [3, 4, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22]
            },
            'partition_id': {
                2: [
                    1, 2, 4, 5, 6, 13, 14, 16, 17, 19, 20, 34, 35, 36, 37, 38,
                    39, 40, 41, 42, 43, 44, 45, 46, 47, 48
                ],
                1: [
                    3, 7, 8, 9, 10, 11, 12, 15, 18, 21, 22, 23, 24, 25, 26, 27,
                    28, 29, 30, 31, 32, 33
                ]
            },
            'partitions_neighbors': {
                (None, ): [
                    1, 2, 5, 6, 7, 9, 10, 20, 21, 23, 24, 25, 26, 27, 28, 29,
                    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
                    45, 46, 47, 48
                ],
                (2, ): [3, 8, 11, 12, 15, 18, 22],
                (1, ): [4, 13, 14, 16, 17, 19]
            },
            'elemental_group': {
                4: [1, 2],
                6: [3],
                11: [4],
                13: [5, 6],
                1:
                [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
                2: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33],
                3:
                [34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]
            }
        }

        # Define input file path
        file = amfe_dir('tests/meshes/3_surfaces_2_partitions_mesh.msh')
        # Define Reader Object, initialized with AmfeMeshConverter
        reader = GmshAsciiMeshReader(file)
        # Parse dummy mesh
        dummy = DummyMeshConverter()
        reader.parse(dummy)
        mesh = dummy.return_mesh()

        # Check nodes
        for i, node in enumerate(nodes_desired):
            self.assertEqual(mesh._nodes[i], node)
        # Check elements
        for i, element in enumerate(elements_desired):
            self.assertEqual(mesh._elements[mesh._elements.index(element)],
                             element)
        # Check mesh dimension
        self.assertEqual(mesh._dimension, dimension_desired)
        self.assertEqual(mesh._groups, groups_desired)
        self.custom_asserter.assert_dict_almost_equal(mesh._tags, tags_desired)
        self.assertEqual(mesh._no_of_nodes, 31)
        self.assertEqual(mesh._no_of_elements, 48)
コード例 #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
from amfe.io.mesh.writer import AmfeMeshConverter
from amfe.material import KirchhoffMaterial
from amfe.component import StructuralComponent
from amfe.solver import SolverFactory, AmfeSolution
from amfe.io.postprocessing import *
from amfe.io.postprocessing.tools import write_xdmf_from_hdf5
from amfe.io.postprocessing.reader import AmfeSolutionReader
from amfe.io.postprocessing.writer import Hdf5PostProcessorWriter
from amfe.solver.translators import *


times = dict([])
input_file = amfe_dir('meshes/gmsh/bar.msh')
output_file = amfe_dir('results/test_refactoring/nonlinear_beam_new_translators')

mesh_reader = GmshAsciiMeshReader(input_file)
mesh_converter = AmfeMeshConverter()
mesh_reader.parse(mesh_converter)
mesh = mesh_converter.return_mesh()

my_component = StructuralComponent(mesh)
my_material = KirchhoffMaterial(E=210E9, nu=0.3, rho=1E4, plane_stress=True)
my_component.assign_material(my_material, [7], 'S', '_groups')



dirichlet = my_component.constraints.create_dirichlet_constraint()

# Variant A
# (xy, direction)
#nodeids = mesh.get_nodeids_by_groups([8])