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')
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)