def test_quad4_pressure(): my_material = amfe.KirchhoffMaterial(rho=1) my_quad4 = amfe.Quad4(my_material) X = X_quad4 u = np.zeros(8) X += sp.rand(8) * 0.2 M = my_quad4.m_int(X, u) t = np.array([ 0., 1., 0., 1., 0., 1., 0., 1., ]) f_2d = M @ t f_1d = f_2d[1::2] my_boundary = amfe.Quad4Boundary(val=1., direct='normal') X_3D = np.zeros(3 * 4) X_3D[0::3] = X[0::2] X_3D[1::3] = X[1::2] u_3D = np.zeros(3 * 4) K, f = my_boundary.k_and_f_int(X_3D, u_3D) np.testing.assert_equal(K, np.zeros((12, 12))) # as the skin element produces a force acting on the right hand side, # f has a negative sign. np.testing.assert_allclose(f_1d, -f[2::3], rtol=1E-6, atol=1E-7)
def plot_sector_solution(): # creating material my_material = amfe.KirchhoffMaterial(E=210.0E9, nu=0.3, rho=7.86E3, plane_stress=True, thickness=1.0) my_system1 = amfe.MechanicalSystem() my_system1.set_mesh_obj(m2) my_system1.set_domain(1,my_material) my_system2 = amfe.MechanicalSystem() my_system2.set_mesh_obj(m3) my_system2.set_domain(11,my_material) manager = K_feti_obj.manager v_dict = manager.vector2localdict(Vp,manager.global2local_primal_dofs) p0 = 10.0 u1=p0*v_dict[1] u2=p0*v_dict[2] my_system1.u_output = list(u1.T) my_system2.u_output = list(u2.T) fig, ax1_list = plt.subplots(3,3,figsize=(10,10)) counter = 0 delta_ = 1.0 for ax_ij in ax1_list: for ax2 in ax_ij: amfe.plot_2D_system_solution(my_system1,u_id=(counter),ax=ax2) amfe.plot_2D_system_solution(my_system2,u_id=(counter),ax=ax2) ax2.set_aspect('equal') ax2.set_xlabel('Width [m]') ax2.set_ylabel('Heigh [m]') ax2.set_title('Mode id = %i' %(counter+1) ) counter+=1 plt.legend('off') plt.tight_layout()
def case1(): dict_key = (1,5) K1 = K_dict[1] M1 = M_dict[1] B = s.build_B(dict_key).A BBT_inv = np.linalg.inv(B.dot(B.T)) P = np.eye(B.shape[1]) - B.T.dot(BBT_inv.dot(B)) obj = ProjLinearSys(K1.A,M1.A,P) Dp = obj.getLinearOperator() v0 = np.random.rand(K1.shape[0]) nmodes= 9 eigval_, Vp = sparse.linalg.eigsh(Dp,k=nmodes,v0=P.dot(v0)) val_wp_ = np.sort(1/eigval_) freq_wp_ = np.sqrt(val_wp_)/(2.0*np.pi) freq_wp_ # creating material my_material = amfe.KirchhoffMaterial(E=210.0E9, nu=0.3, rho=7.86E3, plane_stress=True, thickness=1.0) my_system1 = amfe.MechanicalSystem() my_system1.set_mesh_obj(m2) my_system1.set_domain(1,my_material) m = 1 my_system1.u_output = list(Vp.T)
def setUp(self): # define input-file and prefix for output self.input_file = amfe.amfe_dir('meshes/gmsh/beam/Beam10x1Quad8.msh') self.output_file_prefix = amfe.amfe_dir('results/beam/Beam10x1Quad8') # setup mechanical system self.material = amfe.KirchhoffMaterial(E=2.1e11, nu=0.3, rho=7.867e3, plane_stress=False) self.system = amfe.MechanicalSystem() self.system.load_mesh_from_gmsh(self.input_file, 1, self.material) self.system.apply_dirichlet_boundaries(5, 'xy') ndof = self.system.dirichlet_class.no_of_constrained_dofs self.system.apply_rayleigh_damping(1e0, 1e-5) # set damping and ... self.system.apply_no_damping() # ... reset damping for testing self.options = { 'number_of_load_steps': 10, 'newton_damping': 1.0, 'simplified_newton_iterations': 1, 't': 1.0, 't0': 0.0, 't_end': 0.4, 'dt': 5e-4, 'dt_output': 5e-4, 'rho_inf': 0.95, 'initial_conditions': { 'x0': np.zeros(2 * ndof), 'q0': np.zeros(ndof), 'dq0': np.zeros(ndof) }, 'relative_tolerance': 1.0E-6, 'absolute_tolerance': 1.0E-9, 'verbose': True, 'max_number_of_iterations': 99, 'convergence_abort': True, 'write_iterations': False, 'track_number_of_iterations': False, 'save_solution': True } rho_inf = 0.95 alpha = 0.0005
def test_tri6_pressure(): ''' Test, if the Tri3 pressure element reveals the same behavior as a mass element, which is accelerated in one direction only. ''' my_material = amfe.KirchhoffMaterial(rho=1) my_tri6 = amfe.Tri6(my_material) X = np.array([0, 0, 2, 0, 0, 2, 1, 0, 1, 1, 0, 1.]) u = np.zeros(12) X += sp.rand(12) * 0.2 M = my_tri6.m_int(X, u) t = np.array([0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1.]) f_2d = M @ t f_1d = f_2d[1::2] my_boundary = amfe.Tri6Boundary(val=1., direct='normal') X_3D = np.zeros(3 * 6) X_3D[0::3] = X[0::2] X_3D[1::3] = X[1::2] u_3D = np.zeros(3 * 6) K, f = my_boundary.k_and_f_int(X_3D, u_3D) np.testing.assert_equal(K, np.zeros((18, 18))) # as the skin element produces a force acting on the right hand side, # f has a negative sign. np.testing.assert_allclose(f_1d, -f[2::3], rtol=1E-6, atol=1E-7)
# Beam example # Distributed under BSD-3-Clause License. See LICENSE-File for more information # """ Example showing a cantilever beam which is loaded on the tip with a force showing nonlinear displacements. """ import amfe input_file = amfe.amfe_dir('meshes/gmsh/bar.msh') output_file = amfe.amfe_dir('results/beam_nonlinear/beam_ecsw') my_material = amfe.KirchhoffMaterial(E=210E9, nu=0.3, rho=1E4, plane_stress=True) my_system = amfe.MechanicalSystem() my_system.load_mesh_from_gmsh(input_file, 7, my_material) my_system.apply_dirichlet_boundaries(8, 'xy') # fixature of the left side my_system.apply_neumann_boundaries(key=9, val=1E8, direct=(0, -1), time_func=lambda t: t) amfe.solve_linear_displacement(my_system) my_system.export_paraview(output_file + '_linear') amfe.solve_nonlinear_displacement(my_system, no_of_load_steps=50) my_system.export_paraview(output_file + '_nonlinear')
os.chdir(local_folder) sys.path.append(project_folder) from utils.write import * mesh_inp = os.path.join(project_folder, r'cases\case_1\simple_blade_disc.inp') m = amfe.Mesh() m.import_inp(mesh_inp, 1.0) my_comp = amfe.CraigBamptonComponent() my_comp.set_mesh_obj(m) my_material = amfe.KirchhoffMaterial(E=210E9, nu=0.3, rho=7.86E3, plane_stress=True, thickness=1.0) my_comp.set_domain('SOLID_1_1_SOLID_ELSET', my_material) #----------------------------------------------------------------------------------------------------- # Assembly the system operator try: K = amfe.load_obj('K.pkl') M = amfe.load_obj('M.pkl') f = amfe.load_obj('f.pkl') my_comp = amfe.load_obj('my_comp.pkl') except: K, f = my_comp.assembly_class.assemble_k_and_f() K_, f = my_comp.assembly_class.assemble_k_and_f_neumann()
if scheme is 'GeneralizedAlpha': output_file += '_generalizedalpha' elif scheme is 'WBZAlpha': output_file += '_wbzalpha' elif scheme is 'HHTAlpha': output_file += '_hhtalpha' elif scheme is 'NewmarkBeta': output_file += '_newmarkbeta' elif scheme is 'JWHAlpha': output_file += '_jwhalpha' elif scheme is 'JWHAlphaStateSpace': output_file += '_jwhalphastatespace' # define system material = amfe.KirchhoffMaterial(E=2.1e11, nu=0.3, rho=7.867e3, plane_stress=False) system = amfe.ComponentComposite() system.load_mesh_from_gmsh(input_file, 1, material) system.apply_dirichlet_boundaries(5, 'xy') ndof = system.dirichlet_class.no_of_constrained_dofs if not statics: # dynamics system.apply_neumann_boundaries(key=3, val=2.5e8, direct=(0, -1), time_func=lambda t: 1) else: # statics system.apply_neumann_boundaries(key=3, val=5e8, direct=(0, -1), time_func=lambda t: t) # system.apply_rayleigh_damping(1e0, 1e-5) # define simulation parameters
# """ Dynamic Pipe test case """ import numpy as np import amfe input_file = amfe.amfe_dir('meshes/gmsh/pipe.msh') output_file = amfe.amfe_dir('results/pipe/pipe') # Steel #my_material = amfe.KirchhoffMaterial(E=210E9, nu=0.3, rho=1E4, plane_stress=True) # PE-LD my_material = amfe.KirchhoffMaterial(E=200E6, nu=0.3, rho=1E3, plane_stress=True) my_system = amfe.MechanicalSystem(stress_recovery=True) my_system.load_mesh_from_gmsh(input_file, 84, my_material) my_system.apply_dirichlet_boundaries(83, 'xyz') my_system.apply_neumann_boundaries(85, 1E7, (0, 1, 0), lambda t: t) #%% #amfe.solve_linear_displacement(my_system) amfe.solve_nonlinear_displacement(my_system, no_of_load_steps=100, track_niter=True) my_system.export_paraview(output_file + '_10')
# Copyright (c) 2017, Lehrstuhl fuer Angewandte Mechanik, Technische # Universitaet Muenchen. # # Distributed under BSD-3-Clause License. See LICENSE-File for more information # """ Running a 3D-tension bar """ import amfe mesh_file = amfe.amfe_dir('meshes/test_meshes/bar_Tet4_fine.msh') output_file = amfe.amfe_dir('results/bar_tet10/bar_tet4') # Building the mechanical system my_material = amfe.KirchhoffMaterial() my_system = amfe.MechanicalSystem() my_system.load_mesh_from_gmsh(mesh_file, 29, my_material) # Fixations are simple to realize my_system.apply_dirichlet_boundaries(30, 'xyz') my_system.apply_dirichlet_boundaries(31, 'yz') # make master-slave approach to add constraint that x-dofs are all the same at right end nodes, dofs = my_system.mesh_class.set_dirichlet_bc(31, 'x', output='external') my_system.dirichlet_class.apply_master_slave_list([ [dofs[0], dofs[1:], None], ]) my_system.dirichlet_class.update() # %%
def create(case_id): case_folder = 'case_' + str(case_id) try: os.mkdir(case_folder) except: pass m1 = load_pkl('3D_simple_bladed_disk_24_sectors_' + str(case_id) + '_nodes.pkl') m1.change_tag_in_eldf('phys_group', 'RIGHT_ELSET', cyclic_right_label) m1.change_tag_in_eldf('phys_group', 'LEFT_ELSET', cyclic_left_label) m1.change_tag_in_eldf('phys_group', 'BODY_1_1_SOLID_ELSET', domain_label) m1.change_tag_in_eldf('phys_group', 'BODY_1_1_ELSET', 5) m1.change_tag_in_eldf('phys_group', 'DIRICHLET_ELSET', dirichlet_label) # creating material my_material = amfe.KirchhoffMaterial(E=210.0E9, nu=0.3, rho=7.86E3, plane_stress=True, thickness=1.0) my_system1 = amfe.MechanicalSystem() my_system1.set_mesh_obj(m1) my_system1.set_domain(4, my_material) K1, _ = my_system1.assembly_class.assemble_k_and_f() M1 = my_system1.assembly_class.assemble_m() el_df = copy.deepcopy(m1.el_df) try: connectivity = [] for _, item in el_df.iloc[:, m1.node_idx:].iterrows(): connectivity.append(list(item.dropna().astype(dtype='int64'))) el_df['connectivity'] = connectivity except: pass sector_angle = 360 / Nsectors id_matrix = my_system1.assembly_class.id_matrix id_map_df = dict2dfmap(id_matrix) nodes_coord = m1.nodes cyc_obj = Cyclic_Constraint(id_map_df, el_df, nodes_coord, dirichlet_label, cyclic_left_label, cyclic_right_label, sector_angle, unit=unit, tol_radius=tol_radius, dimension=dimension) translate_dict = {} translate_dict['d'] = dirichlet_label translate_dict['r'] = cyclic_right_label translate_dict['l'] = cyclic_left_label s = cyc_obj.s B_local_dict = {} for key, value in translate_dict.items(): B_local_dict[value] = s.build_B(key) mesh_list = [m1.rot_z(i * 360 / Nsectors) for i in range(Nsectors)] #plot_mesh_list(mesh_list) system_list = [] K_dict = {} M_dict = {} B_dict = {} f_dict = {} for i, mi in enumerate(mesh_list): sysi = amfe.MechanicalSystem() sysi.set_mesh_obj(mi) sysi.set_domain(domain_label, my_material) system_list.append(sysi) K1, _ = sysi.assembly_class.assemble_k_and_f() M1 = sysi.assembly_class.assemble_m() K_dict[i + 1] = Matrix( K1, key_dict=s.selection_dict).eliminate_by_identity('d') M_dict[i + 1] = Matrix( M1, key_dict=s.selection_dict).eliminate_by_identity('d', multiplier=0.0) plus = +1 minus = -1 local_index = i + 1 if i + 2 > Nsectors: plus = -23 if i - 1 < 0: minus = +23 sign_plus = np.sign(plus) sign_minus = np.sign(plus) B_dict[local_index] = { (local_index, local_index + plus): sign_plus * B_local_dict[cyclic_left_label], (local_index, local_index + minus): sign_minus * B_local_dict[cyclic_right_label] } f_dict[local_index] = np.zeros(K1.shape[0]) feti_obj1 = SerialFETIsolver(K_dict, B_dict, f_dict, tolerance=1.0e-12, pseudoinverse_kargs={ 'method': 'splusps', 'tolerance': 1.0E-8 }) feti_obj2 = SerialFETIsolver(M_dict, B_dict, f_dict, tolerance=1.0e-12, pseudoinverse_kargs={ 'method': 'splusps', 'tolerance': 1.0E-8 }) manager = feti_obj1.manager managerM = feti_obj2.manager manager.build_local_to_global_mapping() print('Assembling Matrix') date_str = datetime.now().strftime('%Y_%m_%d_%H_%M_%S') print(date_str) B = manager.assemble_global_B() M_, _ = managerM.assemble_global_K_and_f() K, _ = manager.assemble_global_K_and_f() M = M_ L = manager.assemble_global_L() Lexp = manager.assemble_global_L_exp() save_object(B, os.path.join(case_folder, 'B.pkl')) save_object(M, os.path.join(case_folder, 'M.pkl')) save_object(K, os.path.join(case_folder, 'K.pkl')) save_object(L, os.path.join(case_folder, 'L.pkl')) save_object(Lexp, os.path.join(case_folder, 'Lexp.pkl')) save_object(K_dict, os.path.join(case_folder, 'K_dict.pkl')) save_object(M_dict, os.path.join(case_folder, 'M_dict.pkl')) save_object(B_dict, os.path.join(case_folder, 'B_dict.pkl')) save_object(f_dict, os.path.join(case_folder, 'f_dict.pkl')) print('End') date_str = datetime.now().strftime('%Y_%m_%d_%H_%M_%S') print(date_str)
# Copyright (c) 2017, Lehrstuhl fuer Angewandte Mechanik, Technische # Universitaet Muenchen. # # Distributed under BSD-3-Clause License. See LICENSE-File for more information # """ Rubber boot example """ import amfe input_file = amfe.amfe_dir('meshes/gmsh/rubber_boot.msh') output_file = amfe.amfe_dir('results/rubber_boot/boot') # PE-LD; better material would be Mooney-Rivlin my_material = amfe.KirchhoffMaterial(E=200E6, nu=0.3, rho=1E3) my_system = amfe.MechanicalSystem(stress_recovery=False) my_system.load_mesh_from_gmsh(input_file, 977, my_material, scale_factor=1E-3) my_system.apply_dirichlet_boundaries(978, 'xyz') my_system.apply_neumann_boundaries(979, 1E7, (0,1,0), lambda t:t) #%% amfe.vibration_modes(my_system, save=True) my_system.export_paraview(output_file + '_modes') #%%
# Distributed under BSD-3-Clause License. See LICENSE-File for more information # """ Created on Fri Dec 18 15:31:45 2015 @author: johannesr """ import numpy as np import scipy as sp import amfe input_file = amfe.amfe_dir('meshes/gmsh/AMFE_logo.msh') output_file = amfe.amfe_dir('results/AMFE_logo/logo_5') material_1 = amfe.KirchhoffMaterial(E=5E6, rho=1E4) material_2 = amfe.KirchhoffMaterial(E=5E7, rho=1E4) my_system = amfe.MechanicalSystem() my_system.load_mesh_from_gmsh(input_file, 299, material_1) my_system.load_mesh_from_gmsh(input_file, 300, material_1) my_system.load_mesh_from_gmsh(input_file, 301, material_2) my_system.load_mesh_from_gmsh(input_file, 302, material_2) my_system.apply_dirichlet_boundaries(298, 'xyz') M_unconstr = my_system.assembly_class.assemble_m() no_of_nodes = my_system.mesh_class.no_of_nodes #g = [(0, -9.81, 0) for i in range(no_of_nodes)] g = [(0, -9.81, 0) for i in range(no_of_nodes)] g = np.array(g).flatten() f_gravity = M_unconstr @ g
import numpy as np import scipy as sp import amfe warning = ''' ############################################################################### ############# This file is heavily deprecated. Don't use it. ############# ############################################################################### ''' print(warning) # Mesh generation input_file = amfe.amfe_dir('meshes/gmsh/2D_Rectangle_tri6_dehnstab.msh') # Building the mechanical system my_materal = amfe.KirchhoffMaterial(E=210E9, nu=0.3, rho=1E4) my_mechanical_system = amfe.MechanicalSystem() my_mechanical_system.load_mesh_from_gmsh(input_file, phys_group=0, material=my_materal) #%% # Boundary handling bottom_line_indices = my_mechanical_system.mesh_class.boundary_list[6] top_line_indices = my_mechanical_system.mesh_class.boundary_list[4] bottom_fixation_x = [ None, [amfe.node2total(i, 0) for i in bottom_line_indices], None ] bottom_fixation_y = [
def create_case(number_of_div=3, number_of_div_y=None, case_id=1): ''' This function create a subdomain matrices based on the number of divisions. paramenters: number_of_div : int (default = 3) number of nodes in the x direction number_of_div_y : Default = None number of nodes in the x direction, if None value = number_of_dif case_id : int if of the case to save files return create a directory called "matrices_{matrix shape[0]}" and store the matrices K, f, B_left, B_right, B_tio, B_bottom and also the selectionOperator with the matrices indeces ''' if number_of_div_y is None: number_of_div_y = number_of_div creator_obj = utils.DomainCreator(x_divisions=number_of_div, y_divisions=number_of_div) creator_obj.build_elements() mesh_folder = 'meshes' mesh_path = os.path.join(mesh_folder, 'mesh' + str(case_id) + '.msh') try: creator_obj.save_gmsh_file(mesh_path) except: os.mkdir(mesh_folder) creator_obj.save_gmsh_file(mesh_path) #import mesh m = amfe.Mesh() m.import_msh(mesh_path) # creating material my_material = amfe.KirchhoffMaterial(E=210E9, nu=0.3, rho=7.86E3, plane_stress=True, thickness=1.0) my_system = amfe.MechanicalSystem() my_system.set_mesh_obj(m) my_system.set_domain(3, my_material) value = 5.0E9 my_system.apply_neumann_boundaries(2, value, 'normal') id_matrix = my_system.assembly_class.id_matrix K, _ = my_system.assembly_class.assemble_k_and_f() ndof = K.shape[0] matrices_path = 'matrices' case_path = os.path.join(matrices_path, 'case_' + str(ndof)) try: os.mkdir(matrices_path) except: pass try: shutil.rmtree(case_path) except: pass os.mkdir(case_path) _, fext = my_system.assembly_class.assemble_k_and_f_neumann() save_object(K, os.path.join(case_path, 'K.pkl')) save_object(fext, os.path.join(case_path, 'f.pkl')) id_map_df = dict2dfmap(id_matrix) gdof = Get_dofs(id_map_df) tag_dict = {} tag_dict['left'] = 1 tag_dict['right'] = 2 tag_dict['bottom'] = 4 tag_dict['top'] = 5 get_nodes = lambda i: list(np.sort(m.groups[i].global_node_list)) all_dofs = set(gdof.get(get_nodes(3), 'xy')) #dof_dict = collections.OrderedDict() dof_dict = {} dofs = set() for key, value in tag_dict.items(): key_dofs = gdof.get(get_nodes(value), 'xy') dof_dict[key] = key_dofs dofs.update(key_dofs) dof_dict['internal'] = list(all_dofs - dofs) s = utils.SelectionOperator(dof_dict, id_map_df, remove_duplicated=False) save_object(s, os.path.join(case_path, 'selectionOperator.pkl')) B_list = [] for key, value in tag_dict.items(): B = s.build_B(key) B_list.append(B) B_path = os.path.join(case_path, 'B_' + key + '.pkl') save_object(B, B_path) amfe.plot2Dmesh(m) plt.savefig(os.path.join(case_path, 'mesh' + str(case_id) + '.png')) return case_path
Example: Cantilever beam loaded at tip solved with adaptive time stepping. """ # load packages import amfe import numpy as np # define in- and output files input_file = amfe.amfe_dir('meshes/gmsh/chimney/Chimney200x80Hex20.msh') output_file = amfe.amfe_dir('results/chimney/Chimney200x80Hex20_nonlinear_dynamics_generalizedalpha') # define system material = amfe.KirchhoffMaterial(E=2.1e11, nu=0.3, rho=7.867e3) system = amfe.MechanicalSystem() system.load_mesh_from_gmsh(input_file, 1, material) system.apply_dirichlet_boundaries(2, 'xy') ndof = system.dirichlet_class.no_of_constrained_dofs system.apply_neumann_boundaries(key=4, val=1.0e4, direct=(1, 1, 0), time_func=lambda t: np.sin(180.32*t)) # system.apply_rayleigh_damping(1e0, 1e-5) # vibration modes # amfe.vibration_modes(mechanical_system=system, n=10, save=True) # system.export_paraview(output_file + '_vibration_modes') # define simulation parameters options = {