def test_assign_neumann_by_tags(self): component = StructuralComponent(self.testmesh) tagvalue = 1 tagname = 'tag_boundaries' time_func = lambda t: 3.0*t direction = (1, 0) condition = component._neumann.create_fixed_direction_neumann(direction, time_func) component.assign_neumann('TestCondition', condition, [tagvalue], tagname) # It must be set: # - neumann_df # - neumann_obj_df neumann_obj_df = component._neumann._neumann_obj_df neumann_obj_array = neumann_obj_df[['neumann_obj', 'fk_mesh']].values self.assertIsInstance(neumann_obj_array[0, 0]._boundary_element, LineLinearBoundary) self.assertEqual(neumann_obj_array[0, 1], 4) self.assertEqual(neumann_obj_array.shape, (1, 2)) neumann_df_actual = component._neumann._neumann_df df_dict = { 'name': {0: 'TestCondition'}, 'tag': {0: tagname}, 'property_names': {0: np.array([1])}, 'neumann_obj': {0: condition} } neumann_df_desired = pd.DataFrame.from_dict(df_dict) assert_frame_equal(neumann_df_actual, neumann_df_desired, check_like=True)
def test_assign_neumann_by_groups_nonexistent_group(self): # Test, that nothing happens if group is wrong and switch is set True component = StructuralComponent(self.testmesh) group = 'wrong_group' time_func = lambda t: 3.0 * t direction = (1, 0) condition = component._neumann.create_fixed_direction_neumann(direction, time_func) component.assign_neumann('TestCondition', condition, [group], '_groups', True) # It must be set: # - neumann_df # - neumann_obj_df neumann_obj_df = component._neumann._neumann_obj_df neumann_obj_array = neumann_obj_df[['neumann_obj', 'fk_mesh']].values self.assertEqual(neumann_obj_array.shape, (0, 2)) neumann_df_actual = component._neumann._neumann_df neumann_df_desired = pd.DataFrame(columns=['name', 'tag', 'property_names', 'neumann_obj']) assert_frame_equal(neumann_df_actual, neumann_df_desired, check_like=True) # Test, that error is thrown for a wrong group in the default case with self.assertRaises(ValueError): component.assign_neumann('TestCondition', condition, ['left_boundary', group]) # Test in case of multiple passed groups, that only existing groups are handled and nothing happens for wrong # ones component = StructuralComponent(self.testmesh) time_func = lambda t: 3.0 * t direction = (1, 0) condition = component._neumann.create_fixed_direction_neumann(direction, time_func) component.assign_neumann('TestCondition', condition, ['right_boundary', 'wrong_group', 'left_boundary'], '_groups', True) # It must be set: # - neumann_df # - neumann_obj_df neumann_obj_df = component._neumann._neumann_obj_df neumann_obj_array = neumann_obj_df[['neumann_obj', 'fk_mesh']].values self.assertIsInstance(neumann_obj_array[0, 0]._boundary_element, LineLinearBoundary) self.assertEqual(neumann_obj_array[0, 1], 5) self.assertEqual(neumann_obj_array[1, 1], 4) self.assertEqual(neumann_obj_array.shape, (2, 2)) neumann_df_actual = component._neumann._neumann_df df_dict = { 'name': {0: 'TestCondition'}, 'tag': {0: '_groups'}, 'property_names': {0: np.array(['right_boundary', 'left_boundary'])}, 'neumann_obj': {0: condition} } neumann_df_desired = pd.DataFrame.from_dict(df_dict) assert_frame_equal(neumann_df_actual, neumann_df_desired, check_like=True)
# Force: g mm s-2 = µN # Stiffness: g s-2 mm-1 = Pa # velocity: mm/s # acceleration: mm/s^2 # density: g/mm3 E_alu = 70e6 nu_alu = 0.34 rho_alu = 2.7e-3 logging.basicConfig(level=logging.DEBUG) input_file = amfe_dir('meshes/amfe_json/simple_beam/simple_beam.json') my_mesh = GidJsonMeshReader(input_file, AmfeMeshConverter()).parse() my_material = KirchhoffMaterial(E_alu, nu_alu, rho_alu, thickness=10) my_component = StructuralComponent(my_mesh) my_component.assign_material(my_material, 'Quad8', 'S', 'shape') my_neumann = FixedDirectionNeumann(np.array([0, 1]), time_func = lambda t: 2) my_component.assign_neumann('Neumann0', my_neumann, ['right_boundary'], '_groups') my_constraint = my_component.constraints.create_dirichlet_constraint() fixed_nodeids = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype=int) my_component.assign_constraint('Dirichlet0', my_constraint, fixed_nodeids, '_nodeids', 'elim') print('END')