Esempio n. 1
0
def test_Schur_Sp_solve(load_nse_step_matrix, initialize_petsc_options):
    """Tests a KSP solve using the Sp Schur complement approximation.
       For this test, the global matrix does not have a null space."""
    mat_A = load_nse_step_matrix
    b, x = create_petsc_vecs(mat_A)

    solver_info = LS.ModelInfo(3, 'interlaced')
    schur_approx = LS.Schur_Sp(mat_A, '', solver_info=solver_info)
    ksp_obj = initialize_schur_ksp_obj(mat_A, schur_approx)
    ksp_obj.solve(b, x)

    assert ksp_obj.converged == True
    assert ksp_obj.its == 45
    assert np.allclose(ksp_obj.norm, 394.7036050627)
    assert ksp_obj.reason == 2
Esempio n. 2
0
def test_Schur_Sp_solve_global_null_space(load_nse_cavity_matrix,
                                          initialize_petsc_options):
    """Tests a KSP solve using the Sp Schur complement approximation.
    For this test, the global matrix has a null space because the
    boundary conditions are pure Dirichlet. """
    mat_A = load_nse_cavity_matrix
    b, x = create_petsc_vecs(mat_A)

    solver_info = LS.ModelInfo('interlaced', 3, bdy_null_space=True)
    schur_approx = LS.Schur_Sp(L=mat_A, prefix='', solver_info=solver_info)
    petsc_options = initialize_petsc_options
    ksp_obj = initialize_schur_ksp_obj(mat_A, schur_approx)
    ksp_obj.solve(b, x)

    assert ksp_obj.converged == True
    assert ksp_obj.its == 89
    assert ksp_obj.norm < np.linalg.norm(b) * 1.0e-9 + 1.0e-16
    assert ksp_obj.reason == 2
Esempio n. 3
0
def test_Schur_Sp_solve_global_null_space(load_nse_cavity_matrix,
                                          initialize_petsc_options):
    """Tests a KSP solve using the Sp Schur complement approximation.
    For this test, the global matrix has a null space because the
    boundary conditions are pure Dirichlet. """
    mat_A = load_nse_cavity_matrix
    b, x = create_petsc_vecs(mat_A)
    petsc_options = initialize_petsc_options

    solver_info = LS.ModelInfo(3, 'interlaced')
    schur_approx = LS.Schur_Sp(mat_A, '', True, solver_info=solver_info)
    ksp_obj = initialize_schur_ksp_obj(mat_A, schur_approx)
    ksp_obj.solve(b, x)

    assert ksp_obj.converged == True
    assert ksp_obj.its == 35
    assert np.allclose(ksp_obj.norm, 0.0007464632)
    assert ksp_obj.reason == 2
Esempio n. 4
0
def test_Schur_Sp_solve():
    """Tests a KSP solve using the Sp Schur complement approximation.
       For this test, the global matrix does not have a null space."""
    mat_A = load_matrix_step_noslip()
    petsc_options = initialize_petsc_options()
    b, x = create_petsc_vecs(mat_A)

    solver_info = LS.ModelInfo('interlaced', 3)
    schur_approx = LS.Schur_Sp(mat_A,
                               '',
                               solver_info=solver_info)
    ksp_obj = initialize_schur_ksp_obj(mat_A, schur_approx)
    ksp_obj.solve(b,x)

    assert ksp_obj.converged == True
    assert ksp_obj.reason == 2
    assert float(ksp_obj.norm) < 1.0e-5
    assert ksp_obj.its == 63
Esempio n. 5
0
def test_interlaced_vel_bdy_dof_order(ownership_range, num_components,
                                      bdy_nodes):
    interlaced = LS.InterlacedDofOrderType()

    num_equations = ownership_range[1] - ownership_range[0] + 1
    bdy_nodes = [bdy_nodes, bdy_nodes]
    strong_vel_is = interlaced.create_no_dirichlet_bdy_nodes_is(
        ownership_range, num_equations, num_components, bdy_nodes)

    test_array = strong_vel_is.array - np.array([13, 14, 22, 23, 31, 32])
    assert np.linalg.norm(test_array) < 1.0E-12
Esempio n. 6
0
def test_blocked_dof_order(ownership_range, num_components, n_DOF_pressure):
    array_start = ownership_range[0]
    array_end = ownership_range[1]

    blocked = LS.BlockedDofOrderType(n_DOF_pressure)
    num_equations = array_end - array_start + 1

    velocity, pressure = blocked.create_DOF_lists(ownership_range,
                                                  num_equations,
                                                  num_components)
    pressure_idx = np.arange(array_start, array_start + n_DOF_pressure)
    velocity_idx = np.arange(pressure_idx[-1] + 1, array_end + 1)
    assert np.array_equal(pressure_idx, pressure)
    assert np.array_equal(velocity_idx, velocity)
Esempio n. 7
0
def test_interlaced_dof_order(ownership_range, num_components):
    interlaced = LS.InterlacedDofOrderType()

    num_equations = ownership_range[1] - ownership_range[0] + 1
    velocity, pressure = interlaced.create_DOF_lists(ownership_range,
                                                     num_equations,
                                                     num_components)
    idx_range = np.arange(ownership_range[0], ownership_range[1] + 1)
    pressure_idx = np.arange(ownership_range[0], ownership_range[1],
                             num_components)
    velocity_mask = np.ones(len(idx_range), dtype='bool')

    velocity_mask[pressure_idx - ownership_range[0]] = 0
    assert np.array_equal(pressure_idx, pressure)
    assert np.array_equal(idx_range[velocity_mask], velocity)
Esempio n. 8
0
 def test_chebyshev_iteration_1(self):
     '''  Tests the pcd_shell operators produce correct output. '''
     A = self.quad_mass_matrix
     n = self.quad_mass_matrix.shape[0]
     alpha = 1. / 4
     beta = 9. / 4
     x0 = np.zeros(n)
     b1 = np.ones(n)
     for i in range(0, n, 2):
         b1[i] = 0.
     A_petsc = LAT.dense_numpy_2_petsc4py(A)
     x0_petsc = p4pyPETSc.Vec().createWithArray(x0)
     b1_petsc = p4pyPETSc.Vec().createWithArray(b1)
     solver = LS.ChebyshevSemiIteration(A_petsc, alpha, beta, True)
     solver.apply(b1_petsc, x0_petsc, 20)
     expected = np.load(
         os.path.join(self._scriptdir, 'import_modules/sol_10.npy'))
     actual = x0_petsc
     assert np.allclose(expected, actual.getArray())
Esempio n. 9
0
def test_interlaced_vel_dof_order(ownership_range,
                                  num_components):
    interlaced = LS.InterlacedDofOrderType()

    num_equations = ownership_range[1] - ownership_range[0] + 1
    global_IS, vel_IS = interlaced.create_vel_DOF_IS(ownership_range,
                                                     num_equations,
                                                     num_components)

    for i in range(1,num_components):
        global_vals = np.arange(ownership_range[0]+i,
                                ownership_range[1]+1,
                                num_components)
        assert np.array_equal(global_IS[i-1].array , global_vals)

    for i in range(1,num_components):
        scaled_ownership_range = ownership_range[0] * (num_components-1) // num_components
        local_vals = np.arange(start=scaled_ownership_range + i - 1,
                               stop=scaled_ownership_range + int( num_equations * (num_components-1) // num_components ),
                               step=num_components-1)
        assert np.array_equal(vel_IS[i-1].array, local_vals)
Esempio n. 10
0
 def test_chebyshev_iteration_2(self):
     '''  Tests the pcd_shell operators produce correct output. '''
     A = np.diag(1. / np.diag(self.quad_mass_matrix)).dot(
         self.quad_mass_matrix)
     n = self.quad_mass_matrix.shape[0]
     alpha = 1. / 4
     beta = 9. / 4
     x0 = np.zeros(n)
     b1 = np.zeros(n)
     for i in range(0, n):
         b1[i] = i
     A_petsc = LAT.dense_numpy_2_petsc4py(A)
     x0_petsc = p4pyPETSc.Vec().createWithArray(x0)
     b1_petsc = p4pyPETSc.Vec().createWithArray(b1)
     solver = LS.ChebyshevSemiIteration(A_petsc,
                                        alpha,
                                        beta,
                                        save_iterations=True)
     solver.apply(b1_petsc, x0_petsc, 20)
     expected = np.load(
         os.path.join(self._scriptdir, 'import_modules/sol_20_lst.npy'))
     for i, item in enumerate(expected):
         assert np.allclose(item, solver.iteration_results[i], 1e-12)