Example #1
0
 def __init__(self,
              Z_dict,
              B_dict,
              f_dict,
              tol=1.0e-3,
              dtype=np.float,
              dual_interface_algorithm='PCPG'):
     #f_dict = manager.vector2localdict(f,manager.global2local_primal_dofs)
     #self.feti_obj = SerialFETIsolver(Z_dict,B_dict,f_dict,tolerance=tol,dtype=np.complex)
     #self.mapdict = manager.local2global_primal_dofs
     self.Z_dict = Z_dict
     self.B_dict = B_dict
     self.tol = tol
     self.feti_obj = SerialFETIsolver(
         self.Z_dict,
         self.B_dict,
         f_dict,
         tolerance=self.tol,
         dtype=dtype,
         max_int=100,
         dual_interface_algorithm=dual_interface_algorithm,
         pseudoinverse_kargs={
             'method': 'splusps',
             'tolerance': 1.0E-12
         })
     self.dtype = dtype
Example #2
0
    def test_elimination_matrix(self):

        self.setUp()
        L_target = self.L
        Lexp_target = self.Lexp
        solver_obj = SerialFETIsolver(self.K_dict, self.B_dict, self.f_dict)
        sol_obj = solver_obj.solve()

        u_dual = np.array([])
        u_dict = sol_obj.u_dict
        lambda_dict = sol_obj.lambda_dict
        alpha_dict = sol_obj.alpha_dict

        for domain_id in self.domain_list:
            u_dual = np.append(u_dual, u_dict[domain_id])

        L_calc = solver_obj.manager.assemble_global_L()
        Lexp_calc = solver_obj.manager.assemble_global_L_exp()

        n = L_target.shape[0]
        #testing orthogonality
        np.testing.assert_array_almost_equal(L_calc.dot(Lexp_calc), np.eye(n))

        # testing L matrix asseblying method
        np.testing.assert_array_almost_equal(np.sort(L_calc.dot(u_dual)),
                                             np.sort(self.u_global))
Example #3
0
def system(u, tol=1.0e-8):
    global counts
    f = P.T.dot(M.dot(P.dot(u)))
    f_dict = manager.vector2localdict(f, manager.global2local_primal_dofs)
    feti_obj = SerialFETIsolver(K_dict, B_dict, f_dict, tolerance=tol)
    solution_obj = feti_obj.solve()
    u_dict = solution_obj.u_dict
    counts += 1
    return solution_obj.displacement
Example #4
0
def system_without_projection(u, tol=1.0e-8):

    global countswp
    f = M.dot(u)
    f_dict = manager.vector2localdict(f, manager.global2local_primal_dofs)
    feti_obj = SerialFETIsolver(K_dict, B_dict, f_dict, tolerance=tol)
    solution_obj = feti_obj.solve()
    u_dict = solution_obj.u_dict
    countswp += 1
    return solution_obj.displacement
Example #5
0
 def system(u, tol=1.0e-8):
     f = P.T.dot(M.dot(P.dot(u)))
     f_dict = manager.vector2localdict(f, manager.global2local_primal_dofs)
     feti_obj = SerialFETIsolver(K_dict,
                                 B_dict,
                                 f_dict,
                                 tolerance=tol,
                                 pseudoinverse_kargs={
                                     'method': 'splusps',
                                     'tolerance': 1.0E-8
                                 })
     solution_obj = feti_obj.solve()
     u_dict = solution_obj.u_dict
     return P.dot(solution_obj.displacement)
Example #6
0
    def test_compare_serial_and_parallel_solver(self,
                                                pseudoinverse_kargs={
                                                    'method': 'svd',
                                                    'tolerance': 1.0E-8
                                                }):

        print(
            'Starting Comparison between Serial and Parallel FETI solver ..........'
        )
        case_id, nx, ny = 1, 2, 1
        print('Critial Case Selected %i ' % case_id)
        print('Number of Domain in the X-direction %i ' % nx)
        print('Number of Domain in the Y-direction %i ' % ny)
        K_dict, B_dict, f_dict = create_FETI_case(case_id, nx, ny)

        solver_obj = SerialFETIsolver(K_dict,
                                      B_dict,
                                      f_dict,
                                      pseudoinverse_kargs=pseudoinverse_kargs)
        start_time = time.time()
        print('Starting Serial FETI solver ..........')
        sol_obj = solver_obj.solve()
        elapsed_time = time.time() - start_time
        print('Serial Solver : Elapsed time : %f ' % elapsed_time)
        u_dual_serial, lambda_serial, alpha_serial = self.obj_to_array(sol_obj)

        print('\n\n Starting Parallel FETI solver ..........')
        solver_obj = ParallelFETIsolver(
            K_dict, B_dict, f_dict, pseudoinverse_kargs=pseudoinverse_kargs)
        start_time = time.time()
        sol_obj = solver_obj.solve()
        elapsed_time = time.time() - start_time
        print('Parallel Solver : Elapsed time : %f ' % elapsed_time)

        u_dual_parallel, lambda_parallel, alpha_parallel = self.obj_to_array(
            sol_obj)

        np.testing.assert_almost_equal(u_dual_serial,
                                       u_dual_parallel,
                                       decimal=10)
        np.testing.assert_almost_equal(
            lambda_serial / np.linalg.norm(lambda_serial),
            lambda_parallel / np.linalg.norm(lambda_parallel),
            decimal=10)
        np.testing.assert_almost_equal(alpha_serial,
                                       alpha_parallel,
                                       decimal=10)

        print('End Comparison Serial and Parallel FETI solver ..........\n\n')
Example #7
0
    def test_total_FETI_approach(self):
        ''' This test incorporate Dirichlet constraint in the Boolean matrix
        The constraint are considered the 0-th Neighbor
                                           F->
        |>0   0-----0-----0    0-----0-----0
        Dir        D1                D2 
        '''

        print('Test Total FETI solver ..........')
        K1 = np.array([[1, -1], [-1, 1]])
        K2 = np.array([[1, -1], [-1, 1]])
        B0 = np.array([[-1, 0]])
        B1 = np.array([[0, 1]])
        B2 = np.array([[-1, 0]])

        f1 = np.array([0., 0.])
        f2 = np.array([0., 1.])

        # Using PyFETI to solve the probrem described above
        K_dict = {1: K1, 2: K2}
        B_dict = {1: {(1, 2): B1, (1, 1): B0}, 2: {(2, 1): B2}}
        f_dict = {1: f1, 2: f2}

        solver_obj = SerialFETIsolver(K_dict, B_dict, f_dict)

        solution_obj = solver_obj.solve()

        u_dual = solution_obj.displacement
        lambda_ = solution_obj.interface_lambda
        alpha = solution_obj.alpha

        solver_obj = ParallelFETIsolver(K_dict, B_dict, f_dict)

        solution_obj = solver_obj.solve()

        solver_obj.manager.delete()

        u_dual_par = solution_obj.displacement
        lambda_par = solution_obj.interface_lambda
        alpha_par = solution_obj.alpha

        np.testing.assert_almost_equal(u_dual, u_dual_par, decimal=10)
        np.testing.assert_almost_equal(lambda_, lambda_par, decimal=10)
        np.testing.assert_almost_equal(alpha, alpha_par, decimal=10)

        print('End Total FETI solver ..........')
Example #8
0
    def test_simple_bar_problem(self):
        K1 = np.array([[2., -1.], [-1., 1.]])
        K2 = np.array([[1., -1.], [-1., 2.]])
        B1 = np.array([[0., 1]])
        B2 = np.array([[-1, 0]])
        f1 = np.array([0., 0.])
        f2 = np.array([0., 1.])

        K_dict = {1: K1, 2: K2}
        B_dict = {1: {(1, 2): B1}, 2: {(2, 1): B2}}
        f_dict = {1: f1, 2: f2}
        solver_obj = SerialFETIsolver(K_dict, B_dict, f_dict)
        solution_obj = solver_obj.solve()
        u_dual = solution_obj.displacement
        lambda_ = solution_obj.interface_lambda
        alpha = solution_obj.alpha

        u_target = np.array([0.25, 0.5, 0.5, 0.75])
        np.testing.assert_almost_equal(u_dual, u_target, decimal=10)
Example #9
0
def case2():
    Ks_dict = {}
    Ks_dict[1] = K_dict[1]
    Ks_dict[2] = K_dict[6]

    Ms_dict = {}
    Ms_dict[1] = M_dict[1]
    Ms_dict[2] = M_dict[6]

    Bs_dict = {}
    Bs_dict[1] = {(1,1) : B_dict[1][1,1], (1,2) : B_dict[1][1,6] }
    Bs_dict[2] = {(2,1) : B_dict[6][6,1]}


    fs_dict = {1 : np.zeros(K_dict[1].shape[0]),
            2 : np.zeros(K_dict[6].shape[0])} 

    K_feti_obj = SerialFETIsolver(Ks_dict,Bs_dict,fs_dict)
    M_feti_obj = SerialFETIsolver(Ms_dict,Bs_dict,fs_dict)

    Ks, _ = K_feti_obj.manager.assemble_global_K_and_f()
    Ms, _ = M_feti_obj.manager.assemble_global_K_and_f()
    B = K_feti_obj.manager.assemble_global_B()
    from scipy.sparse import linalg 
    BBT_inv = linalg.inv(B.dot(B.T))
    Ps = np.eye(B.shape[1]) - B.T.dot(BBT_inv.dot(B))


    obj = ProjLinearSys(Ks.A,Ms.A,Ps.A)
    Dp = obj.getLinearOperator()

    v0 = np.random.rand(Ks.shape[0])
    nmodes= 9
    eigval_, Vp = sparse.linalg.eigsh(Dp,k=nmodes,v0=Ps.A.dot(v0))

    val_wp_ = np.sort(1/eigval_)
    freq_wp_ = np.sqrt(val_wp_)/(2.0*np.pi)
    freq_wp_

    ansys_freq = np.array([4.5495,39.845,59.994,72.253,131.34,148.82,169.8,197.68,231.13])
Example #10
0
    def test_simple_bar_with_redundante_contraints(self):
        '''
        A simple example with Reduntant Constraints Positive Define Domains
        '''
        K1 = np.array([[2, -1], [-1, 1]])
        K2 = np.array([[1, -1], [-1, 2]])
        B1 = np.array([[0, 1], [0, 1], [0, 1]])
        B2 = np.array([[-1, 0], [-1, 0], [-1, 0]])
        f1 = np.array([0., 0.])
        f2 = np.array([0., 1.])

        K_dict = {1: K1, 2: K2}
        B_dict = {1: {(1, 2): B1}, 2: {(2, 1): B2}}
        f_dict = {1: f1, 2: f2}
        solver_obj = SerialFETIsolver(K_dict, B_dict, f_dict)
        solution_obj = solver_obj.solve()
        u_dual = solution_obj.displacement
        lambda_ = solution_obj.interface_lambda
        alpha = solution_obj.alpha

        u_target = np.array([0.25, 0.5, 0.5, 0.75])
        np.testing.assert_almost_equal(u_dual, u_target, decimal=10)
Example #11
0
    def test_serial_solver(self, precond_type=None):
        print('Testing Serial FETI solver ..........\n\n')
        solver_obj = SerialFETIsolver(self.K_dict,
                                      self.B_dict,
                                      self.f_dict,
                                      precond_type=precond_type,
                                      tolerance=1E-11)
        sol_obj = solver_obj.solve()
        self.postproc(sol_obj)

        K_dual = sparse.block_diag((self.K_dict[1], self.K_dict[2]))
        f_dual = np.concatenate((self.f_dict[1].data, self.f_dict[2].data))
        u_dual = sol_obj.displacement

        np.testing.assert_almost_equal(self.f_global.data,
                                       self.L @ f_dual,
                                       decimal=10)
        u_primal = self.dual2primal(K_dual, u_dual, f_dual, self.L, self.Lexp)
        np.testing.assert_almost_equal(self.u_global, u_primal, decimal=10)

        print('end Serial FETI solver ..........\n\n')
        return u_dual, sol_obj
Example #12
0
class FETI_system():
    def __init__(self,
                 Z_dict,
                 B_dict,
                 f_dict,
                 tol=1.0e-3,
                 dtype=np.float,
                 dual_interface_algorithm='PCPG'):
        #f_dict = manager.vector2localdict(f,manager.global2local_primal_dofs)
        #self.feti_obj = SerialFETIsolver(Z_dict,B_dict,f_dict,tolerance=tol,dtype=np.complex)
        #self.mapdict = manager.local2global_primal_dofs
        self.Z_dict = Z_dict
        self.B_dict = B_dict
        self.tol = tol
        self.feti_obj = SerialFETIsolver(
            self.Z_dict,
            self.B_dict,
            f_dict,
            tolerance=self.tol,
            dtype=dtype,
            max_int=100,
            dual_interface_algorithm=dual_interface_algorithm,
            pseudoinverse_kargs={
                'method': 'splusps',
                'tolerance': 1.0E-12
            })
        self.dtype = dtype

    def apply(self, f):

        f_dict = self.array2dict(f)
        self.feti_obj.f_dict = f_dict
        solution_obj = self.feti_obj.solve()
        u_dict = solution_obj.u_dict
        return solution_obj.displacement

    def array2dict(self, v):
        v_dict = {}
        for key, posid in mapdict.items():
            if v.ndim < 2:
                v_dict[key] = v[posid]
            else:
                v_dict[key] = v[posid, :]
        return v_dict

    def dict2array(self, v_dict):
        v = np.zeros(self.shape[0], dtype=self.dtype)
        for key, posid in self.mapdict.items():
            v[posid] = v_dict[key]
        return v
Example #13
0
def solve_eig(K_dict, M_dict, B_dict, nmodes=10):
    f_dict = {}
    for i, K in K_dict.items():
        f_dict[i] = np.zeros(K.shape[0])

    K_feti_obj = SerialFETIsolver(K_dict, B_dict, f_dict)
    M_feti_obj = SerialFETIsolver(M_dict, B_dict, f_dict)

    K, _ = K_feti_obj.manager.assemble_global_K_and_f()
    M, _ = M_feti_obj.manager.assemble_global_K_and_f()
    B = K_feti_obj.manager.assemble_global_B()
    from scipy.sparse import linalg
    #BBT_inv = linalg.inv(B.dot(B.T))
    P = sparse.eye(B.shape[1]) - 0.5 * (B.T.dot(B))
    obj = ProjLinearSys(K, M, P)
    Dp = obj.getLinearOperator()

    v0 = np.random.rand(K.shape[0])
    eigval_, Vp = sparse.linalg.eigsh(Dp, k=nmodes, v0=P.dot(v0))
    print(eigval_)
    val_wp_ = np.sort(1 / eigval_)
    freq_wp_ = np.sqrt(val_wp_) / (2.0 * np.pi)
    return freq_wp_, Vp, B.shape[0]
Example #14
0
    def test_compare_svd_splusps(self):
        print('Starting Comparison between Serial SVD and SPLUSPS ..........')
        case_id, nx, ny = 4, 4, 4
        print('Critical Case Selected %i ' % case_id)
        print('Number of Domain in the X-direction %i ' % nx)
        print('Number of Domain in the Y-direction %i ' % ny)
        K_dict, B_dict, f_dict = create_FETI_case(case_id, nx, ny)

        solver_obj = SerialFETIsolver(K_dict,
                                      B_dict,
                                      f_dict,
                                      pseudoinverse_kargs={
                                          'method': 'svd',
                                          'tolerance': 1.0E-8
                                      })
        start_time = time.time()
        print('....................................')
        print('Starting SVD FETI solver ..........')
        sol_obj = solver_obj.solve()
        elapsed_time = time.time() - start_time
        print('SVD Solver : Elapsed time : %f ' % elapsed_time)
        u_dual_svd, lambda_svd, alpha_svd = self.obj_to_array(sol_obj)

        print('\n\n Starting SPLUSPS FETI solver ..........')
        solver_obj = SerialFETIsolver(K_dict,
                                      B_dict,
                                      f_dict,
                                      pseudoinverse_kargs={
                                          'method': 'splusps',
                                          'tolerance': 1.0E-8
                                      })
        start_time = time.time()
        sol_obj_slu = solver_obj.solve()
        elapsed_time = time.time() - start_time
        print('SPLUSPS Solver : Elapsed time : %f ' % elapsed_time)
        print('....................................')

        # check gap using SPLUSPS local solver
        self.check_interface_gap(sol_obj_slu.u_dict, solver_obj.B_dict)

        # assembling dual vectors
        u_dual_slu, lambda_slu, alpha_slu = self.obj_to_array(sol_obj_slu)

        # compare results
        norm = np.linalg.norm(u_dual_svd)
        norm_lambda = np.linalg.norm(lambda_svd)
        norm_alpha = np.linalg.norm(alpha_svd)
        np.testing.assert_almost_equal(u_dual_svd / norm,
                                       u_dual_slu / norm,
                                       decimal=10)
        np.testing.assert_almost_equal(lambda_svd / norm_lambda,
                                       lambda_slu / norm_lambda,
                                       decimal=10)

        print('End Comparison SVD and SPLUSPS FETI solver ..........\n\n')
Example #15
0
    def test_verify_F_operator(self):
        K_dict = {1: K1, 2: K2, 3: K3, 4: K4}
        B_dict = {
            1: {
                (1, 2): B12,
                (1, 3): B13,
                (1, 4): B14
            },
            2: {
                (2, 1): B21,
                (2, 4): B24,
                (2, 3): B23
            },
            3: {
                (3, 1): B31,
                (3, 4): B34,
                (3, 2): B32
            },
            4: {
                (4, 2): B42,
                (4, 3): B43,
                (4, 1): B41
            }
        }

        q_dict = {1: q1, 2: q2, 3: q3, 4: q4}

        solver_obj = SerialFETIsolver(K_dict, B_dict, q_dict)

        L = solver_obj.manager.assemble_global_L()
        Lexp = solver_obj.manager.assemble_global_L_exp()
        B = solver_obj.manager.assemble_global_B()
        K, f = solver_obj.manager.assemble_global_K_and_f()
        R = solver_obj.manager.assemble_global_kernel()
        e = solver_obj.manager.assemble_e()
        F_feti = solver_obj.manager.assemble_global_F()

        K_inv = np.linalg.pinv(K.A)
        F = B @ K_inv @ B.T
        d = B @ K_inv @ f

        x = np.ones(F.shape[0])
        np.testing.assert_almost_equal(F.dot(x), F_feti.dot(x), decimal=10)
Example #16
0
    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)
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')
Example #17
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)
Example #18
0
    def _test_2d_thermal_problem(self):

        # Using PyFETI to solve the probrem described above
        num_domain = 3
        if num_domain == 4:
            K_dict = {1: K1, 2: K2, 3: K3, 4: K4}
            B_dict = {
                1: {
                    (1, 2): B12,
                    (1, 3): B13,
                    (1, 4): B14
                },
                2: {
                    (2, 1): B21,
                    (2, 4): B24,
                    (2, 3): B23
                },
                3: {
                    (3, 1): B31,
                    (3, 4): B34,
                    (3, 2): B32
                },
                4: {
                    (4, 2): B42,
                    (4, 3): B43,
                    (4, 1): B41
                }
            }

            q_dict = {1: q1, 2: q2, 3: q3, 4: q4}

        elif num_domain == 2:
            K_dict = {1: K1, 2: K2}
            B_dict = {1: {(1, 2): B12}, 2: {(2, 1): B21}}

            q_dict = {1: q1, 2: q4}

        elif num_domain == 3:
            K_dict = {1: K1, 2: K2, 3: K3}
            B_dict = {
                1: {
                    (1, 2): B12
                },
                2: {
                    (2, 1): B21,
                    (2, 3): B12
                },
                3: {
                    (3, 2): B21
                }
            }

            q_dict = {1: q1, 2: q2, 3: q4}

        solver_obj = SerialFETIsolver(K_dict, B_dict, q_dict)

        L = solver_obj.manager.assemble_global_L()
        Lexp = solver_obj.manager.assemble_global_L_exp()
        B = solver_obj.manager.assemble_global_B()
        K, f = solver_obj.manager.assemble_global_K_and_f()
        R = solver_obj.manager.assemble_global_kernel()
        e = solver_obj.manager.assemble_e()
        G = solver_obj.manager.assemble_G()
        GGT_inv = np.linalg.inv(G.dot(G.T))
        P = np.eye(B.shape[0]) - (G.T.dot(GGT_inv)).dot(G)
        F_feti = solver_obj.manager.assemble_global_F()

        f_primal = L.dot(f)
        K_primal = L.dot(K.dot(Lexp))
        T_primal = np.linalg.solve(K_primal, f_primal)

        T_dual = Lexp.dot(T_primal)
        interface_gap = B.dot(T_dual)
        np.testing.assert_almost_equal(interface_gap,
                                       0 * interface_gap,
                                       decimal=10)

        K_inv = np.linalg.pinv(K.A)

        F = B @ K_inv @ B.T
        d = B @ K_inv @ f

        lambda_im = G.T.dot(GGT_inv).dot(e)
        r0 = d - F.dot(lambda_im)
        Fp = P.T.dot(F.dot(P))
        dp = P.T.dot(d)
        lambda_ker, info = sparse.linalg.cg(Fp, dp, M=P)
        #lambda_ker, info = sparse.linalg.minres(Fp,dp,M=P)
        F_action = lambda x: F.dot(x)
        Projection_action = lambda x: P.dot(x)
        lampda_ker, rk, proj_r_hist, lambda_hist = PCPG(F_action,
                                                        r0,
                                                        Projection_action,
                                                        tolerance=1.e-16,
                                                        max_int=1000)

        lambda_cg = lambda_im + lambda_ker
        r = d - F.dot(lambda_cg)
        alpha = GGT_inv.dot(G.dot(r))

        T_cg = K_inv @ (f - B.T @ lambda_cg) + R.dot(alpha)

        np.testing.assert_almost_equal(T_cg, T_dual, decimal=10)
Example #19
0
# In[5]:

zeros = np.zeros(K1.shape[0])
case = FETIcase_builder(domains_X,
                        domains_Y,
                        K1,
                        zeros,
                        B_local_dict,
                        s,
                        BC_type='G',
                        force_scaling=1.0)
K_dict, B_dict, f_dict = case.build_subdomain_matrices()

# In[6]:

feti_obj = SerialFETIsolver(K_dict, B_dict, f_dict, tolerance=1.0e-6)
solution_obj = feti_obj.solve()
u_dict = solution_obj.u_dict

for i, sysi in enumerate(system_list):
    sysi.u_output = [u_dict[i + 1]]

# In[7]:

p0 = 1
fig, ax2 = plt.subplots(1, 1, figsize=(10, 3))
for i, sysi in enumerate(system_list):
    amfe.plot_2D_system_solution(sysi, u_id=0, ax=ax2, factor=p0)

delta_ = 1.5
ax2.set_xlim([-delta_, (2.0 + delta_) * width])
Example #20
0
Ks_dict = {}
Ks_dict[1] = K_dict[1]
Ks_dict[2] = K_dict[6]

Ms_dict = {}
Ms_dict[1] = M_dict[1]
Ms_dict[2] = M_dict[6]

Bs_dict = {}
Bs_dict[1] = {(1, 1): B_dict[1][1, 1], (1, 2): B_dict[1][1, 6]}
Bs_dict[2] = {(2, 1): B_dict[6][6, 1]}

fs_dict = {1: np.zeros(K_dict[1].shape[0]), 2: np.zeros(K_dict[6].shape[0])}

K_feti_obj = SerialFETIsolver(Ks_dict, Bs_dict, fs_dict)
M_feti_obj = SerialFETIsolver(Ms_dict, Bs_dict, fs_dict)

Ks, _ = K_feti_obj.manager.assemble_global_K_and_f()
Ms, _ = M_feti_obj.manager.assemble_global_K_and_f()
B = K_feti_obj.manager.assemble_global_B()
from scipy.sparse import linalg
BBT_inv = linalg.inv(B.dot(B.T))
Ps = np.eye(B.shape[1]) - B.T.dot(BBT_inv.dot(B))

# In[45]:

obj = ProjLinearSys(Ks.A, Ms.A, Ps.A)
Dp = obj.getLinearOperator()

v0 = np.random.rand(Ks.shape[0])
Example #21
0
def run_case(tol_factor=6):
    Nsectors = 24
    domain_label = 4
    cyclic_left_label = 3
    cyclic_right_label = 2
    dirichlet_label = 1
    unit = 'deg'
    tol_radius = 1.0e-5
    dimension = 3
    FETI_tolerance = 10.0**-tol_factor

    feti_obj = SerialFETIsolver(K_dict,
                                B_dict,
                                f_dict,
                                tolerance=FETI_tolerance,
                                pseudoinverse_kargs={
                                    'method': 'splusps',
                                    'tolerance': 1.0E-8
                                })
    manager = feti_obj.manager
    manager.build_local_to_global_mapping()
    scaling = manager.assemble_global_scaling()
    S = sparse.diags(1. / scaling)
    B = manager.assemble_global_B()
    B_ = B
    P = sparse.eye(K.shape[0]) - S.dot(B_.T.dot(B_))

    print_date('Loading Matrix')

    def system_without_projection(u, tol=1.0e-8):
        f = M.dot(u)
        f_dict = manager.vector2localdict(f, manager.global2local_primal_dofs)
        feti_obj = SerialFETIsolver(K_dict,
                                    B_dict,
                                    f_dict,
                                    tolerance=tol,
                                    pseudoinverse_kargs={
                                        'method': 'splusps',
                                        'tolerance': 1.0E-8
                                    })
        solution_obj = feti_obj.solve()
        u_dict = solution_obj.u_dict
        return solution_obj.displacement

    D_wp = sparse.linalg.LinearOperator(
        shape=M.shape,
        matvec=lambda x: system_without_projection(x, tol=FETI_tolerance))

    nmodes = 30
    np.random.seed(1)
    u0 = np.random.rand(D_wp.shape[0])
    u0 /= np.linalg.norm(u0)

    print_date('Solving Classical Dual Eigenproblem')
    eigval_without_projection_, V_wp_ = sparse.linalg.eigsh(D_wp,
                                                            k=nmodes,
                                                            v0=u0)

    freq_dual_wp_, V_wp_ = eig2freq(eigval_without_projection_, V_wp_)
    save_pkl(V_wp_, '%i_cyclic_V_wp_.pkl' % tol_factor)
    save_pkl(freq_dual_wp_, '%i_cyclic_freq_dual_wp_.pkl' % tol_factor)

    def system(u, tol=1.0e-8):
        f = P.T.dot(M.dot(P.dot(u)))
        f_dict = manager.vector2localdict(f, manager.global2local_primal_dofs)
        feti_obj = SerialFETIsolver(K_dict,
                                    B_dict,
                                    f_dict,
                                    tolerance=tol,
                                    pseudoinverse_kargs={
                                        'method': 'splusps',
                                        'tolerance': 1.0E-8
                                    })
        solution_obj = feti_obj.solve()
        u_dict = solution_obj.u_dict
        return P.dot(solution_obj.displacement)

    D = sparse.linalg.LinearOperator(
        shape=M.shape, matvec=lambda x: system(x, tol=FETI_tolerance))

    print_date('Solving Projected Dual Eigenproblem')
    eigval, V = sparse.linalg.eigsh(D, k=nmodes, v0=P.dot(u0))

    freq_dual, V = eig2freq(eigval, V)

    save_pkl(V, '%i_cyclic_V.pkl' % tol_factor)
    save_pkl(freq_dual, '%i_cyclic_freq_dual.pkl' % tol_factor)

    freq_list = [freq_dual, freq_dual_wp_]
    V_list = [V, V_wp_]
    return freq_list, V_list