Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
0
            v_dict, precond_type='Dirichlet')
        v_id_ = list(s_local.keys())[0]
        i_id, j_id = v_id_
        if j_id < i_id:
            v_id = (j_id, i_id)
            sign = 1.0
        else:
            v_id = v_id_
            sign = 1.0
        d[mapdict[v_id], count] = sign * s_local[v_id_]
        #d[mapdict[v_id],count] = sign*v/2
        count += 1
    return d


solution = feti_obj1.solve()
lambda_target = solution.interface_lambda

d = manager.assemble_global_d()
e = manager.assemble_e()
F = manager.assemble_global_F()
G = manager.assemble_G()
GGT_inv = sparse.linalg.inv(G @ G.T)
P = sparse.linalg.LinearOperator(shape=F.shape,
                                 matvec=lambda x: x - G.T @ GGT_inv @ G.dot(x))

#solve lambda_im
lambda_im = G.T @ GGT_inv.dot(e)
d_ = d - F.dot(lambda_im)
li = 0.0 * lambda_im
Example #13
0
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])
ax2.set_ylim([-delta_ * 3, (1.0 + delta_) * heigh])