Esempio n. 1
0
    def test_tppcd_shell_with_chebyshev_iteration(self):
        ''' Test for the lsc operator shell '''
        Qp_visc = LAT.petsc_load_matrix(os.path.join(self._scriptdir,'import_modules/Qp_visc.bin'))
        Qp_dens = LAT.petsc_load_matrix(os.path.join(self._scriptdir,'import_modules/Qp_dens.bin'))
        Ap_rho = LAT.petsc_load_matrix(os.path.join(self._scriptdir, 'import_modules/Ap_rho.bin'))
        Np_rho = LAT.petsc_load_matrix(os.path.join(self._scriptdir, 'import_modules/Np_rho.bin'))
        alpha = True
        delta_t = 0.001
        x_vec = LAT.petsc_load_vector(os.path.join(self._scriptdir,'import_modules/input_vec_tppcd.bin'))

        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_type','preonly')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_constant_null_space', '')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_type','hypre')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_hypre_type','boomeramg')
        TPPCD_shell = LAT.TwoPhase_PCDInv_shell(Qp_visc,
                                                Qp_dens,
                                                Ap_rho,
                                                Np_rho,
                                                alpha,
                                                delta_t,
                                                5,
                                                laplace_null_space=True)
        y_vec = x_vec.copy()
        y_vec.zeroEntries()
        A = None
        TPPCD_shell.apply(A,x_vec,y_vec)
        true_solu = LAT.petsc_load_vector(os.path.join(self._scriptdir, 'import_modules/tp_pcd_y_output.bin'))
        assert np.allclose(y_vec.getArray(),true_solu.getArray())
Esempio n. 2
0
    def test_tppcd_shell(self):
        ''' Test for the lsc operator shell '''
        Qp_visc = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Qp_visc'))
        Qp_dens = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Qp_dens'))
        Ap_rho = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Ap_rho'))
        Np_rho = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Np_rho'))
        alpha = True
        delta_t = 0.001
        x_vec = LAT.petsc_load_vector(
            os.path.join(self._scriptdir, 'import_modules/input_vec_tppcd'))

        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_type',
                                    'preonly')
        self.petsc_options.setValue(
            'innerTPPCDsolver_Ap_rho_ksp_constant_null_space', '')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_type', 'hypre')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_hypre_type',
                                    'boomeramg')
        TPPCD_shell = LAT.TwoPhase_PCDInv_shell(Qp_visc, Qp_dens, Ap_rho,
                                                Np_rho, alpha, delta_t, 5)
        y_vec = x_vec.copy()
        y_vec.zeroEntries()
        A = None
        TPPCD_shell.apply(A, x_vec, y_vec)
        true_solu = LAT.petsc_load_vector(
            os.path.join(self._scriptdir, 'import_modules/tp_pcd_y_output'))
        assert np.allclose(y_vec.getArray(), true_solu.getArray())
Esempio n. 3
0
    def test_tppcd_shell_with_dirichlet_pressure(self):
        ''' Test for the lsc operator shell '''
        Qp_visc = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Qp_visc.bin'))
        Qp_dens = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Qp_dens.bin'))
        Ap_rho = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Ap_rho.bin'))
        Np_rho = LAT.petsc_load_matrix(
            os.path.join(self._scriptdir, 'import_modules/Np_rho.bin'))
        alpha = True
        delta_t = 0.001
        x_vec = LAT.petsc_load_vector(
            os.path.join(self._scriptdir,
                         'import_modules/input_vec_tppcd.bin'))
        self.petsc_options.clear()
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_type',
                                    'preonly')
        self.petsc_options.setValue(
            'innerTPPCDsolver_Ap_rho_ksp_constant_null_space', '')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_type', 'hypre')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_hypre_type',
                                    'boomeramg')

        dirichlet_nodes = [3, 12, 15, 21, 33]
        TPPCD_shell = LAT.TwoPhase_PCDInv_shell(
            Qp_visc,
            Qp_dens,
            Ap_rho,
            Np_rho,
            alpha=alpha,
            delta_t=delta_t,
            num_chebyshev_its=5,
            strong_dirichlet_DOF=dirichlet_nodes)
        # Test the index set is set correctly
        unknown_indices = np.arange(TPPCD_shell.getSize())
        known_indices_mask = np.ones(TPPCD_shell.getSize(), dtype=bool)
        known_indices_mask[dirichlet_nodes] = False
        unknown_is = unknown_indices[known_indices_mask]
        np.testing.assert_equal(unknown_is,
                                TPPCD_shell.unknown_dof_is.getIndices())

        y_vec = x_vec.copy()
        y_vec.zeroEntries()
        A = None
        TPPCD_shell.apply(A, x_vec, y_vec)
        assert np.array_equal(y_vec[dirichlet_nodes], [0., 0., 0., 0., 0.])
        #np.savetxt(os.path.join(self._scriptdir,'comparison_files/tppcd_y_dirichlet_dof.csv'),y_vec.getArray(),delimiter=',')
        true_solu = np.loadtxt(os.path.join(
            self._scriptdir, 'comparison_files/tppcd_y_dirichlet_dof.csv'),
                               delimiter=',')
        np.testing.assert_allclose(y_vec.getArray(),
                                   true_solu,
                                   rtol=1e-8,
                                   atol=1e-8)
Esempio n. 4
0
def load_matrix_step_noslip():
    """
    Loads a medium sized backwards facing step matrix for studying
    different AMG preconditioners.
    """
    A = LAT.petsc_load_matrix('dump_test_2_step2d_1.0par_j_0')
    return A
Esempio n. 5
0
def load_saddle_point_matrix_1(request):
    """
    Loads a small example of a backwards facing step matrix for
    testing purposes. (Note: this matrix does not have advection)
    """
    A = LAT.petsc_load_matrix(os.path.join
                              (os.path.dirname(__file__),
                               'import_modules/saddle_point_mat_1'))
    yield A
Esempio n. 6
0
def load_small_step_matrix(request):
    """
    Loads a small example of a backwards facing step matrix for
    testing purposes. (Note: this matrix does not have advection)
    """
    A = LAT.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__),
                     'import_modules/saddle_point_small.bin'))
    yield A
Esempio n. 7
0
def load_nse_step_matrix(request):
    """
    Loads a Navier-Stokes matrix for the backwards step problem from
    the MPRANS module.  This matrix is constructed using no-slip
    boundary conditions, and weakly enforced Dirichlet conditions.
    """
    A = LAT.petsc_load_matrix(os.path.join
                              (os.path.dirname(__file__),
                               'import_modules/NSE_step_no_slip.bin'))
    yield A
Esempio n. 8
0
def load_nse_step_matrix(request):
    """
    Loads a Navier-Stokes matrix for the backwards step problem from
    the MPRANS module.  This matrix is constructed using no-slip
    boundary conditions, and weakly enforced Dirichlet conditions.
    """
    A = LAT.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__),
                     'import_modules/NSE_step_no_slip.bin'))
    yield A
Esempio n. 9
0
def load_medium_step_matrix(request):
    """
    Loads a medium sized backwards facing step matrix for studying
    different AMG preconditioners. (Note: this matrix does not have
    advection)
    """
    A = LAT.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__),
                     'import_modules/saddle_point_matrix.bin'))
    yield A
Esempio n. 10
0
def load_medium_step_matrix(request):
    """
    Loads a medium sized backwards facing step matrix for studying
    different AMG preconditioners. (Note: this matrix does not have
    advection)
    """
    A = LAT.petsc_load_matrix(os.path.join
                              (os.path.dirname(__file__),
                               'import_modules/saddle_point_matrix'))
    yield A
Esempio n. 11
0
 def test_tppcd_shell_with_chebyshev_iteration(self):
     ''' Test for the lsc operator shell '''
     Qp_visc = LAT.petsc_load_matrix(
         os.path.join(self._scriptdir, 'import_modules/Qp_visc.bin'))
     Qp_dens = LAT.petsc_load_matrix(
         os.path.join(self._scriptdir, 'import_modules/Qp_dens.bin'))
     Ap_rho = LAT.petsc_load_matrix(
         os.path.join(self._scriptdir, 'import_modules/Ap_rho.bin'))
     Np_rho = LAT.petsc_load_matrix(
         os.path.join(self._scriptdir, 'import_modules/Np_rho.bin'))
     alpha = True
     delta_t = 0.001
     x_vec = LAT.petsc_load_vector(
         os.path.join(self._scriptdir,
                      'import_modules/input_vec_tppcd.bin'))
     self.petsc_options.clear()
     self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_type',
                                 'preonly')
     self.petsc_options.setValue(
         'innerTPPCDsolver_Ap_rho_ksp_constant_null_space', '')
     self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_type', 'hypre')
     self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_hypre_type',
                                 'boomeramg')
     TPPCD_shell = LAT.TwoPhase_PCDInv_shell(Qp_visc,
                                             Qp_dens,
                                             Ap_rho,
                                             Np_rho,
                                             alpha,
                                             delta_t,
                                             5,
                                             laplace_null_space=True)
     y_vec = x_vec.copy()
     y_vec.zeroEntries()
     A = None
     TPPCD_shell.apply(A, x_vec, y_vec)
     #np.savetxt(os.path.join(self._scriptdir,'comparison_files/tp_pcd_y_output_cheb.csv'),y_vec.getArray(),delimiter=',')
     true_solu = np.loadtxt(os.path.join(
         self._scriptdir, 'comparison_files/tp_pcd_y_output_cheb.csv'),
                            delimiter=',')
     np.testing.assert_allclose(y_vec.getArray(),
                                true_solu,
                                rtol=1e-8,
                                atol=1e-8)
Esempio n. 12
0
def test_petsc_load_matrix(tmpdir):
    """test petsc_load_matrix """
    from petsc4py import PETSc as p4pyPETSc
    from proteus import LinearAlgebraTools as LAT

    vals_A = [5.5, 7.1, 1.0]
    col_idx_A = [0, 1, 2]
    row_idx_A = [0, 1, 2, 3]
    A = LAT.csr_2_petsc(size=(3, 3), csr=(row_idx_A, col_idx_A, vals_A))

    A_tmp = tmpdir.join('A.petsc_mat')
    LAT._petsc_view(A, A_tmp.strpath)
    A_test = LAT.petsc_load_matrix(A_tmp.strpath)
    csr_values = A_test.getValuesCSR()

    assert np.allclose(csr_values[0], row_idx_A)
    assert np.allclose(csr_values[1], col_idx_A)
    assert np.allclose(csr_values[2], vals_A)

    A_test = LAT.petsc_load_matrix('dne.txt')
    assert A_test is None
Esempio n. 13
0
def test_petsc_load_matrix(tmpdir):
    """test petsc_load_matrix """
    from petsc4py import PETSc as p4pyPETSc
    from proteus import LinearAlgebraTools as LAT

    vals_A =     [5.5,7.1,1.0]
    col_idx_A =  [0 , 1 , 2  ]
    row_idx_A =  [0, 1, 2, 3]
    A = LAT.csr_2_petsc(size = (3,3),
                        csr = (row_idx_A,col_idx_A,vals_A))

    A_tmp = tmpdir.join('A.petsc_mat')
    LAT._petsc_view(A,A_tmp.strpath)
    A_test = LAT.petsc_load_matrix(A_tmp.strpath)
    csr_values = A_test.getValuesCSR()

    assert np.allclose(csr_values[0], row_idx_A)
    assert np.allclose(csr_values[1], col_idx_A)
    assert np.allclose(csr_values[2], vals_A)

    A_test = LAT.petsc_load_matrix('dne.txt')
    assert A_test is None
Esempio n. 14
0
    def test_tppcd_shell_with_dirichlet_pressure(self):
        ''' Test for the lsc operator shell '''
        Qp_visc = LAT.petsc_load_matrix(os.path.join(self._scriptdir,'import_modules/Qp_visc.bin'))
        Qp_dens = LAT.petsc_load_matrix(os.path.join(self._scriptdir,'import_modules/Qp_dens.bin'))
        Ap_rho = LAT.petsc_load_matrix(os.path.join(self._scriptdir, 'import_modules/Ap_rho.bin'))
        Np_rho = LAT.petsc_load_matrix(os.path.join(self._scriptdir, 'import_modules/Np_rho.bin'))
        alpha = True
        delta_t = 0.001
        x_vec = LAT.petsc_load_vector(os.path.join(self._scriptdir,'import_modules/input_vec_tppcd.bin'))

        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_type','preonly')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_ksp_constant_null_space', '')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_type','hypre')
        self.petsc_options.setValue('innerTPPCDsolver_Ap_rho_pc_hypre_type','boomeramg')

        dirichlet_nodes = [3, 12, 15, 21, 33]
        TPPCD_shell = LAT.TwoPhase_PCDInv_shell(Qp_visc,
                                                Qp_dens,
                                                Ap_rho,
                                                Np_rho,
                                                alpha = alpha,
                                                delta_t = delta_t,
                                                num_chebyshev_its = 5,
                                                strong_dirichlet_DOF = dirichlet_nodes)
        # Test the index set is set correctly
        unknown_indices = np.arange(TPPCD_shell.getSize())
        known_indices_mask = np.ones(TPPCD_shell.getSize(),dtype=bool)
        known_indices_mask[dirichlet_nodes] = False
        unknown_is = unknown_indices[known_indices_mask]
        assert np.array_equal(unknown_is, TPPCD_shell.unknown_dof_is.getIndices())

        y_vec = x_vec.copy()
        y_vec.zeroEntries()
        A = None
        TPPCD_shell.apply(A,x_vec,y_vec)
        assert np.array_equal(y_vec[dirichlet_nodes], [0.,0.,0.,0.,0.])
        true_solu = LAT.petsc_load_vector(os.path.join(self._scriptdir,
                                                       'import_modules/tppcd_y_dirichlet_dof.bin'))
        assert np.allclose(y_vec.getArray(),true_solu.getArray())
Esempio n. 15
0
def load_rans2p_step_newton_5(request):
    A = LAT.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__),
                     'import_modules/rans2p_step_newton_5.bin'))
    yield A
Esempio n. 16
0
def med_petsc_with_const_pressure():
    petsc_mat = LinearAlgebraTools.petsc_load_matrix(os.path.join(os.path.dirname(__file__),
                                                                  'jac.bin'))
    yield petsc_mat
Esempio n. 17
0
def load_rans2p_step_newton_5(request):
    A = LAT.petsc_load_matrix(os.path.join
                              (os.path.dirname(__file__),
                               'import_modules/rans2p_step_newton_5.bin'))
    yield A
def med_petsc_with_const_pressure():
    petsc_mat = LinearAlgebraTools.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__), 'jac.bin'))
    yield petsc_mat
Esempio n. 19
0
def load_nse_cavity_matrix(request):
    """Loads a Navier-Stokes matrix drawn from the MPRANS module. """
    A = LAT.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__),
                     'import_modules/NSE_cavity_matrix.bin'))
    yield A
Esempio n. 20
0
def load_matrix(mat_file_name):
    """Load a matrix """
    A = LAT.petsc_load_matrix(
        os.path.join(os.path.dirname(__file__),
                     'import_modules/' + mat_file_name))
    return A
Esempio n. 21
0
 def setup_method(self, method):
     self._scriptdir = os.path.dirname(__file__)
     self.saddle_point_matrix = LAT.petsc_load_matrix(
         os.path.join(self._scriptdir, 'import_modules/saddle_point_small'))
Esempio n. 22
0
def load_nse_cavity_matrix(request):
    """Loads a Navier-Stokes matrix drawn from the MPRANS module. """
    A = LAT.petsc_load_matrix('dump_stokes_drivenCavityStokesTrial_1.0par_j_1')
    yield A
Esempio n. 23
0
def load_nse_cavity_matrix(request):
    """Loads a Navier-Stokes matrix drawn from the MPRANS module. """
    A = LAT.petsc_load_matrix(os.path.join
                              (os.path.dirname(__file__),
                               'import_modules/NSE_cavity_matrix.bin'))
    yield A
Esempio n. 24
0
def load_matrix(mat_file_name):
    """Load a matrix """
    A = LAT.petsc_load_matrix(os.path.join
                              (os.path.dirname(__file__),
                               'import_modules/'+mat_file_name))
    return A
Esempio n. 25
0
 def setup_method(self,method):
     self._scriptdir = os.path.dirname(__file__)
     self.saddle_point_matrix=LAT.petsc_load_matrix(os.path.join(self._scriptdir,
                                                                 'import_modules/saddle_point_small'))