Exemplo n.º 1
0
feti_obj1 = SerialFETIsolver(K_dict, B_dict, f_dict, tolerance=1.0e-12)
feti_obj2 = SerialFETIsolver(M_dict, B_dict, f_dict, tolerance=1.0e-12)
manager = feti_obj1.manager
managerM = feti_obj2.manager

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_

save_object(B, 'B.pkl')
save_object(M, 'M.pkl')
save_object(K, 'K.pkl')

L = manager.assemble_global_L()
Lexp = manager.assemble_global_L_exp()

save_object(L, 'L.pkl')
save_object(Lexp, 'Lexp.pkl')

Kp = L.dot(K.dot(Lexp))
Mp = L.dot(M.dot(Lexp))
lu = sparse.linalg.splu(Kp.tocsc())
Dp = sparse.LinearOperator(shape=Kp.shape,
                           matvec=lambda x: lu.solve(Mp.dot(x)))
nmodes = 5
Exemplo n.º 2
0
    def save_to_file(self, filename=None):
        if filename is None:
            filename = self.name + '.pkl'
            print('Filename is = %s' % filename)

        save_object(self, filename)
Exemplo n.º 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)
Exemplo n.º 4
0
    def mpi_solver(self):
        ''' solve linear FETI problem with PCGP with partial reorthogonalization
        '''

        start_time = time.time()

        logging.info('Assembling  local G, GGT, and e')
        self.assemble_local_G_GGT_and_e()
        build_local_matrix_time = time.time() - start_time
        logging.info(
            '{"elaspsed_time_local_matrix_preprocessing" : %2.4f} # Elapsed time [s]'
            % (build_local_matrix_time))

        logging.info('Exchange local G_dict and  local e_dict')
        t1 = time.time()
        #G_dict = exchange_global_dict(self.course_problem.G_dict,self.obj_id,self.partitions_list)
        logging.info(
            '{"elaspsed_time_exchange_G_dict" : %2.4f} # Elapsed time [s]' %
            (time.time() - t1))
        t1 = time.time()
        e_dict = exchange_global_dict(self.course_problem.e_dict, self.obj_id,
                                      self.partitions_list)
        logging.info(
            '{"elaspsed_time_exchange_e_dict" : %2.4f} # Elapsed time [s]' %
            (time.time() - t1))

        #self.course_problem.G_dict = G_dict
        self.course_problem.e_dict = e_dict

        logging.info('Exchange global size')
        t1 = time.time()
        self._exchange_global_size()
        logging.info(
            '{"elaspsed_time_exchange_global_size" : %2.4f} # Elapsed time [s]'
            % (time.time() - t1))

        t1 = time.time()
        self.assemble_cross_GGT()
        self.GGT_dict = self.course_problem.GGT_dict
        GGT_dict = exchange_global_dict(self.GGT_dict, self.obj_id,
                                        self.partitions_list)
        self.course_problem.GGT_dict = GGT_dict
        logging.info(
            '{"elaspsed_time_assemble_GGT_dict" : %2.4f} # Elapsed time [s]' %
            (time.time() - t1))

        t1 = time.time()
        self.build_local_to_global_mapping()
        logging.info(
            '{"elaspsed_time_build_global_map": %2.4f} # Elapsed time [s]' %
            (time.time() - t1))

        t1 = time.time()
        GGT = self.assemble_GGT()
        logging.info(
            '{"elaspsed_time_assemble_GGT": %2.4f} # Elapsed time [s]' %
            (time.time() - t1))

        t1 = time.time()
        G = self.G = G = ParallelRetangularLinearOperator(
            self.course_problem.G_dict,
            self.local2global_alpha_dofs,
            self.local2global_lambda_dofs,
            shape=(self.alpha_size, self.lambda_size),
            neighbors_id=self.neighbors_id)
        logging.info(
            '{"elaspsed_time_parallel_G_operator": %2.4f} # Elapsed time [s]' %
            (time.time() - t1))

        t1 = time.time()
        e = self.assemble_e()

        logging.info('{"elaspsed_time_assemble_e": %2.4f} # Elapsed time [s]' %
                     (time.time() - t1))

        logging.info('{"primal_variable_size"} = %i' % self.primal_size)
        logging.info('{"dual_variable_size"} = %i' % self.lambda_size)
        logging.info('{"coarse_variable_size"} = %i' % self.alpha_size)

        t1 = time.time()
        lambda_sol, alpha_sol, rk, proj_r_hist, lambda_hist, info_dict = self.solve_dual_interface_problem(
        )
        elaspsed_time_PCPG = time.time() - t1
        logging.info('{"elaspsed_time_PCPG" : %2.4f} # Elapsed time' %
                     (elaspsed_time_PCPG))

        t1 = time.time()
        u_dict, lambda_dict, alpha_dict = self.assemble_solution_dict(
            lambda_sol, alpha_sol)
        logging.info(
            '{"elaspsed_time_primal_assembly": %2.4f} # Elapsed time [s]' %
            (time.time() - t1))

        # Serialization the results, Displacement and alpha
        t1 = time.time()
        # serializing displacement
        save_object(u_dict[self.obj_id],
                    'displacement_' + str(self.obj_id) + '.pkl')

        # serializing rigid body correction (alpha)
        try:
            save_object(alpha_dict[self.obj_id],
                        'alpha_' + str(self.obj_id) + '.pkl')
        except:
            pass

        elapsed_time = time.time() - start_time
        if self.obj_id == 1:
            sol_obj = Solution({},
                               lambda_dict, {},
                               rk,
                               proj_r_hist,
                               lambda_hist,
                               lambda_map=self.local2global_lambda_dofs,
                               alpha_map=self.local2global_alpha_dofs,
                               u_map=self.local2global_primal_dofs,
                               lambda_size=self.lambda_size,
                               alpha_size=self.alpha_size,
                               solver_time=elapsed_time,
                               local_matrix_time=build_local_matrix_time,
                               time_PCPG=elaspsed_time_PCPG,
                               tolerance=self.tolerance,
                               precond=self.precond_type,
                               info_dict=info_dict)

            save_object(sol_obj, 'solution.pkl')

        logging.info('{"serialization_time":%2.4f}' % (time.time() - t1))
        logging.info('{"Total_mpisolver_elaspsed_time":%2.4f}' %
                     (time.time() - start_time))
Exemplo n.º 5
0
def save_pkl(variable, variable_name):
    return save_object(variable, filepath(variable_name))
Exemplo n.º 6
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
Exemplo n.º 7
0

disk_mesh_file = 'disk_sector'
folder = 'meshes'

m2 = load_object(os.path.join(folder, disk_mesh_file + '.pkl'),tries=1)
if m2 is None:
    sector_mesh_file = os.path.join(folder, disk_mesh_file + '.inp')
    m2 = amfe.Mesh()
    m2.import_inp(sector_mesh_file)

    count=1
    for name in m2.get_phys_group_types():
        m2.change_tag_in_eldf('phys_group',name,translator(name))
        count+=1
    save_object(m2,os.path.join(folder, disk_mesh_file + '.pkl'))


blade_mesh_file = 'blade_sector'
m3 = load_object(os.path.join(folder, blade_mesh_file + '.pkl'),tries=1)
if m3 is None:
    sector_mesh_file = os.path.join(folder, blade_mesh_file + '.inp')
    m3 = amfe.Mesh()
    m3.import_inp(sector_mesh_file)

    count=1
    for name in m3.get_phys_group_types():
        m3.change_tag_in_eldf('phys_group',name,translator(name))
        count+=1

    save_object(m3,os.path.join(folder, blade_mesh_file + '.pkl'))
Exemplo n.º 8
0
cyclic_left_label = 3
cyclic_right_label = 2
dirichlet_label = 1
unit = 'deg'
tol_radius = 1.0e-5
dimension = 3

case_list = [512, 1524, 2649, 16480]

for case_id in case_list:
    mesh_file = 'meshes/3D_simple_bladed_disk_24_sectors_' + str(
        case_id) + '_nodes.inp'
    pkl_file = 'meshes/3D_simple_bladed_disk_24_sectors_' + str(
        case_id) + '_nodes.pkl'
    fig_file = 'meshes/3D_simple_bladed_disk_24_sectors_' + str(
        case_id) + '_nodes.png'

    scale = 1.0
    m1 = amfe.Mesh()
    m1.import_inp(mesh_file, scale)

    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)

    save_object(m1, pkl_file)

    save_pictute(m1, fig_file)