예제 #1
0
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
예제 #2
0
try:
    connectivity = []
    for _, item in m2.el_df.iloc[:, m2.node_idx:].iterrows():
        connectivity.append(list(item.dropna().astype(dtype='int64')))
    m2.el_df['connectivity'] = connectivity
except:
    pass

nnodes = len(m2.nodes)
id_matrix = np.array(range(nnodes * 2)).reshape(nnodes, 2)

id_dict = {}
for i in range(len(id_matrix)):
    id_dict[i] = list(id_matrix[i])

id_map_df = dict2dfmap(id_dict)

el_df = m2.el_df

try:
    connectivity = []
    for _, item in m3.el_df.iloc[:, m3.node_idx:].iterrows():
        connectivity.append(list(item.dropna().astype(dtype='int64')))
    m3.el_df['connectivity'] = connectivity
except:
    pass

nnodes = len(m3.nodes)
id_matrix = np.array(range(nnodes * 2)).reshape(nnodes, 2)

id_dict3 = {}
예제 #3
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)
예제 #4
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