Beispiel #1
0
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()
Beispiel #2
0
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)
Beispiel #3
0
 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
#
"""
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')

#%% Modal analysis
Beispiel #5
0
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')

#%%
dt = 0.01
T = np.arange(0, 1, dt)
Beispiel #6
0

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
Beispiel #7
0
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)
Beispiel #8
0
# 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')

#%%
# load packages
import amfe
import scipy as sp
import numpy as np

# define input files
input_file1 = amfe.amfe_dir('meshes/gmsh/beam/Beam10x1Quad8.msh')
input_file2 = amfe.amfe_dir('meshes/gmsh/beam/Beam10x1Quad4.msh')

# define system 1
material1 = amfe.KirchhoffMaterial(E=2.1e11,
                                   nu=0.3,
                                   rho=7.867e3,
                                   plane_stress=False)
system1 = amfe.MechanicalSystem()
system1.load_mesh_from_gmsh(input_file1, 1, material1)
system1.apply_dirichlet_boundaries(5, 'xy')
ndof1 = system1.dirichlet_class.no_of_constrained_dofs
system1.apply_neumann_boundaries(key=3,
                                 val=1.0,
                                 direct=(0, -1),
                                 time_func=lambda t: 1)
system1.apply_rayleigh_damping(1e0, 1e-5)
state_space_system1 = amfe.mechanical_system.convert_mechanical_system_to_state_space(
    system1, regular_matrix=system1.K(), overwrite=False)

# define system 2
material2 = amfe.KirchhoffMaterial(E=2.1e11,
                                   nu=0.3,
                                   rho=7.867e3,
Beispiel #10
0
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