Ejemplo n.º 1
0
    def setUp(self):

        nodes = [(1, (0.0, 0.0)), (2, (1.0, 0.0)), (3, (1.0, 1.0)), (4, (0.0, 1.0)), (5, (2.0, 0.0)), (6, (2.0, 1.0))]
        elements = [(1, 'Tri3', (5, 6, 3)), (2, 'Tri3', (3, 2, 5)), (3, 'Quad4', (1, 2, 3, 4)),
                    (4, 'straight_line', (4, 1)), (5, 'straight_line', (5, 6))]
        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]}
                  }
        tags = {'tag_boundaries': {1: [4], 2: [5]}}
        converter = AmfeMeshConverter()
        for node in nodes:
            converter.build_node(node[0], node[1][0], node[1][1], 0.0)
        for element in elements:
            converter.build_element(element[0], element[1], element[2])
        for group in groups:
            converter.build_group(group, groups[group]['nodes'], groups[group]['elements'])
        converter.build_tag(tags)
        converter.build_mesh_dimension(2)

        self.testmesh = converter.return_mesh()          

        class DummyMaterial:
            def __init__(self, name):
                self.name = name

        self.mat1 = DummyMaterial('steel')
        self.mat2 = DummyMaterial('rubber')
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def setUp(self):
        # Define input file path
        file = amfe_dir('tests/meshes/gid_json_4_tets.json')
        # Define Reader Object, initialized with AmfeMeshConverter
        reader = GidJsonMeshReader(file)

        # Initialize component
        converter = AmfeMeshConverter()
        reader.parse(converter)
        self.my_mesh = converter.return_mesh()
        self.my_component = StructuralComponent(self.my_mesh)
        my_material = KirchhoffMaterial()
        self.my_component.assign_material(my_material, ['left', 'right'], 'S')

        # Get number of dofs for snapshot generation
        self.no_of_dofs = self.my_component.mapping.no_of_dofs
        # create 2 random snapshots
        self.no_of_snapshots = 2
        self.S = np.random.rand(self.no_of_dofs, self.no_of_snapshots) * 0.05
        self.W = np.eye(self.no_of_dofs)
        self.timesteps = np.zeros(self.no_of_snapshots)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def test_dummy_to_amfe(self):
        # Desired nodes
        nodes_input = [(1, 1.345600000e-02, 3.561675700e-02, 0.000000000e+00),
                       (2, 5.206839561e-01, 3.740820950e-02, 6.193195000e-04),
                       (3, 3.851982918e-02, 5.460016703e-01, 4.489461500e-03),
                       (4, 5.457667372e-01, 5.477935420e-01, 6.984401105e-04),
                       (5, 1.027911912e+00, 3.919966200e-02, 1.238639000e-03),
                       (6, 6.358365836e-02, 1.056386584e+00, 8.978923000e-03),
                       (7, 1.040469476e+00, 5.445628213e-01, 1.301993398e-03),
                       (8, 5.582746582e-01, 1.053154002e+00, 7.377279750e-03),
                       (9, 1.052965658e+00, 1.049921420e+00, 5.775636500e-03),
                       (10, 1.535139868e+00, 4.099111450e-02, 1.857958500e-03),
                       (11, 1.547697432e+00, 5.463542738e-01, 1.921312898e-03),
                       (12, 1.547656658e+00, 1.046688838e+00, 4.173993250e-03),
                       (13, 2.042367825e+00, 4.278256700e-02, 2.477278000e-03),
                       (14, 2.042357741e+00, 5.431194119e-01, 2.524814000e-03),
                       (15, 2.042347658e+00, 1.043456257e+00, 2.572350000e-03)]
        # Desired elements
        # (internal name of Triangle Nnode 3 is 'Tri3')
        elements_input = [(1, 'Tri6', [13, 15, 9, 14, 12, 11]),
                          (2, 'Tri6', [9, 6, 5, 8, 4, 7]),
                          (3, 'Tri6', [9, 5, 13, 7, 10, 11]),
                          (4, 'Tri6', [1, 5, 6, 2, 4, 3]),
                          (5, 'quadratic_line', [5, 13, 10]),
                          (6, 'quadratic_line', [1, 5, 2]),
                          (7, 'quadratic_line', [6, 1, 3]),
                          (8, 'quadratic_line', [9, 6, 8]),
                          (9, 'quadratic_line', [13, 15, 14]),
                          (10, 'quadratic_line', [15, 9, 12])]
        groups_input = [('left', [], [2, 4]), ('right', [], [1, 3]),
                        ('left_boundary', [], [7]),
                        ('right_boundary', [], [9]),
                        ('top_boundary', [], [8, 10]),
                        ('left_dirichlet', [1, 3, 6], [])]

        converter = AmfeMeshConverter()
        # Build nodes
        for node in nodes_input:
            converter.build_node(node[0], node[1], node[2], node[3])
        for element in elements_input:
            converter.build_element(element[0], element[1], element[2])
        for group in groups_input:
            converter.build_group(group[0], group[1], group[2])
        mesh = converter.return_mesh()

        # CHECK NODES

        nodes_desired = np.array([[node[1], node[2]] for node in nodes_input])
        assert_allclose(mesh.nodes, nodes_desired)

        # CHECK CONNECTIVITIES
        # connectivity_desired = [np.array(element[2]) for element in elements_input[:]]
        for element in elements_input:
            assert_array_equal(
                mesh.get_connectivity_by_elementids([element[0]])[0],
                np.array(element[2], dtype=int))

        # CHECK DIMENSION
        self.assertEqual(mesh.dimension, 2)

        # CHECK NODE MAPPING
        for node in nodes_input:
            nodeid = node[0]
            node_actual = mesh.nodes_df.loc[nodeid]
            self.assertAlmostEqual(node_actual['x'], node[1])
            self.assertAlmostEqual(node_actual['y'], node[2])

        # CHECK ELESHAPES AND ELEMENTMAPPING IN DATAFRAME
        indices = list(np.arange(1, 11))
        data = {
            'shape': [
                'Tri6', 'Tri6', 'Tri6', 'Tri6', 'quadratic_line',
                'quadratic_line', 'quadratic_line', 'quadratic_line',
                'quadratic_line', 'quadratic_line'
            ],
            'is_boundary':
            [False, False, False, False, True, True, True, True, True, True],
            'connectivity': [element[2] for element in elements_input]
        }
        el_df_desired = pd.DataFrame(data, index=indices)

        assert_frame_equal(mesh.el_df, el_df_desired)

        # CHECK GROUPS
        groups_desired = dict()
        for group in groups_input:
            groups_desired.update(
                {group[0]: {
                     'nodes': group[1],
                     'elements': group[2]
                 }})
        self.assertEqual(mesh.groups, groups_desired)
Ejemplo n.º 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)
Ejemplo n.º 8
0
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])
#dofs = my_component.mapping.get_dofs_by_nodeids(nodeids, ('ux', 'uy'))
#for dof in dofs.reshape(-1):
    #my_component.assign_constraint('Leftfixation', dirichlet, np.array([dof], dtype=int), np.array([], dtype=int))