Exemplo n.º 1
0
def setup_LSC_shell(petsc_options, fixture_data):
    petsc_options.setValue('innerLSCsolver_BTinvBt_ksp_type', 'preonly')
    petsc_options.setValue('innerLSCsolver_T_ksp_type', 'preonly')
    petsc_options.setValue('innerLSCsolver_BTinvBt_pc_type', 'lu')
    petsc_options.setValue('innerLSCsolver_T_pc_type', 'lu')

    return LAT.LSCInv_shell(fixture_data.petsc_matD, fixture_data.petsc_matB,
                            fixture_data.petsc_matBt, fixture_data.petsc_matF)
Exemplo n.º 2
0
    def test_lsc_shell(self, create_simple_saddle_point_problem):
        ''' Test for the lsc operator shell '''
        fixture_data = create_simple_saddle_point_problem

        self.petsc_options.setValue('innerLSCsolver_BTinvBt_ksp_type',
                                    'preonly')
        self.petsc_options.setValue('innerLSCsolver_T_ksp_type', 'preonly')
        self.petsc_options.setValue('innerLSCsolver_BTinvBt_pc_type', 'lu')
        self.petsc_options.setValue('innerLSCsolver_T_pc_type', 'lu')

        LSC_shell = LAT.LSCInv_shell(fixture_data.petsc_matD,
                                     fixture_data.petsc_matB,
                                     fixture_data.petsc_matBt,
                                     fixture_data.petsc_matF)
        LSC_shell.apply(None, fixture_data.x_vec, fixture_data.y_vec)
        true_solu = np.mat('[-0.01096996,0.00983216]')
        assert np.allclose(fixture_data.y_vec.getArray(), true_solu)
Exemplo n.º 3
0
    def test_lsc_shell(self):
        ''' Test for the lsc operator shell '''
        vals_A = [5.5, 7.1, 1.0]
        col_idx_A = [0, 1, 2]
        row_idx_A = [0, 1, 2, 3]
        vals_B = [1.1, 6.3, 7.3, 3.6, 6.3]
        col_idx_B = [0, 2, 0, 1, 2]
        row_idx_B = [0, 2, 5]
        vals_Bt = [1.1, 7.3, 3.6, 6.3, 6.3]
        col_idx_Bt = [0, 1, 1, 0, 1]
        row_idx_Bt = [0, 2, 3, 5]
        vals_F = [3.2, 1.1, 6.3, 1., -5.1]
        col_idx_F = [0, 1, 0, 2, 0]
        row_idx_F = [0, 2, 4, 5]
        num_B_rows = len(row_idx_B) - 1
        num_B_cols = len(row_idx_A) - 1

        petsc_matA = LAT.csr_2_petsc(size=(num_B_cols, num_B_cols),
                                     csr=(row_idx_A, col_idx_A, vals_A))
        petsc_matB = LAT.csr_2_petsc(size=(num_B_rows, num_B_cols),
                                     csr=(row_idx_B, col_idx_B, vals_B))
        petsc_matBt = LAT.csr_2_petsc(size=(num_B_cols, num_B_rows),
                                      csr=(row_idx_Bt, col_idx_Bt, vals_Bt))
        petsc_matF = LAT.csr_2_petsc(size=(num_B_cols, num_B_cols),
                                     csr=(row_idx_F, col_idx_F, vals_F))

        self.petsc_options.setValue('innerLSCsolver_BTinvBt_ksp_type',
                                    'preonly')
        self.petsc_options.setValue('innerLSCsolver_T_ksp_type', 'preonly')
        self.petsc_options.setValue('innerLSCsolver_BTinvBt_pc_type', 'lu')
        self.petsc_options.setValue('innerLSCsolver_T_pc_type', 'lu')
        LSC_shell = LAT.LSCInv_shell(petsc_matA, petsc_matB, petsc_matBt,
                                     petsc_matF)
        x_vec = np.ones(num_B_rows)
        y_vec = np.zeros(num_B_rows)
        x_PETSc_vec = p4pyPETSc.Vec().createWithArray(x_vec)
        y_PETSc_vec = p4pyPETSc.Vec().createWithArray(y_vec)
        A = None
        LSC_shell.apply(A, x_PETSc_vec, y_PETSc_vec)
        true_solu = np.mat('[-0.01096996,0.00983216]')
        assert np.allclose(y_vec, true_solu)