From: Stefano Zampini Date: Thu, 20 Apr 2023 15:56:33 +0000 (+0300) Subject: Get rid of old destroy_matrix function X-Git-Tag: v9.5.0-rc1~302^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15119%2Fhead;p=dealii.git Get rid of old destroy_matrix function --- diff --git a/include/deal.II/lac/petsc_compatibility.h b/include/deal.II/lac/petsc_compatibility.h index 12e04b00e8..96bd230629 100644 --- a/include/deal.II/lac/petsc_compatibility.h +++ b/include/deal.II/lac/petsc_compatibility.h @@ -53,24 +53,6 @@ namespace PETScWrappers - /** - * Destroy a PETSc matrix. This function wraps MatDestroy with a version - * check (the signature of this function changed in PETSc 3.2.0). - * - * @warning Since the primary intent of this function is to enable RAII - * semantics in the PETSc wrappers, this function will not throw an - * exception if an error occurs, but instead just returns the error code - * given by MatDestroy. - */ - inline PetscErrorCode - destroy_matrix(Mat &matrix) - { - // PETSc will check whether or not matrix is nullptr. - return MatDestroy(&matrix); - } - - - /** * Destroy a Krylov Subspace (KSP) PETSc solver. This function wraps * KSPDestroy with a version check (the signature of this function changed diff --git a/source/lac/petsc_full_matrix.cc b/source/lac/petsc_full_matrix.cc index f090aaa150..9997c6758b 100644 --- a/source/lac/petsc_full_matrix.cc +++ b/source/lac/petsc_full_matrix.cc @@ -40,7 +40,7 @@ namespace PETScWrappers { // get rid of old matrix and generate a // new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); do_reinit(m, n); diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index 5e1555468b..2b1202f909 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -97,13 +97,16 @@ namespace PETScWrappers PetscErrorCode ierr = PetscObjectReference(reinterpret_cast(A)); AssertThrow(ierr == 0, ExcPETScError(ierr)); - destroy_matrix(matrix); + ierr = MatDestroy(&matrix); + AssertThrow(ierr == 0, ExcPETScError(ierr)); matrix = A; } MatrixBase::~MatrixBase() { - destroy_matrix(matrix); + PetscErrorCode ierr = MatDestroy(&matrix); + (void)ierr; + AssertNothrow(ierr == 0, ExcPETScError(ierr)); } void @@ -111,7 +114,7 @@ namespace PETScWrappers { // destroy the matrix... { - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); } @@ -625,7 +628,7 @@ namespace PETScWrappers PETSC_DEFAULT, &result.petsc_matrix()); AssertThrow(ierr == 0, ExcPETScError(ierr)); - ierr = PETScWrappers::destroy_matrix(tmp); + ierr = MatDestroy(&tmp); AssertThrow(ierr == 0, ExcPETScError(ierr)); } } @@ -764,7 +767,7 @@ namespace PETScWrappers } if (vmatrix != matrix) { - ierr = PETScWrappers::destroy_matrix(vmatrix); + ierr = MatDestroy(&vmatrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); } AssertThrow(out.fail() == false, ExcIO()); diff --git a/source/lac/petsc_matrix_free.cc b/source/lac/petsc_matrix_free.cc index 83e3a61432..bcbde6697d 100644 --- a/source/lac/petsc_matrix_free.cc +++ b/source/lac/petsc_matrix_free.cc @@ -105,7 +105,7 @@ namespace PETScWrappers const unsigned int local_columns) { // destroy the matrix and generate a new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); do_reinit(communicator, m, n, local_rows, local_columns); @@ -126,7 +126,7 @@ namespace PETScWrappers local_columns_per_process.size())); Assert(this_process < local_rows_per_process.size(), ExcInternalError()); - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr != 0, ExcPETScError(ierr)); do_reinit(communicator, @@ -169,7 +169,7 @@ namespace PETScWrappers void MatrixFree::clear() { - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); const int m = 0; diff --git a/source/lac/petsc_parallel_block_sparse_matrix.cc b/source/lac/petsc_parallel_block_sparse_matrix.cc index 85e740188d..b91d4cfb7e 100644 --- a/source/lac/petsc_parallel_block_sparse_matrix.cc +++ b/source/lac/petsc_parallel_block_sparse_matrix.cc @@ -72,7 +72,7 @@ namespace PETScWrappers BlockSparseMatrix::~BlockSparseMatrix() { - PetscErrorCode ierr = destroy_matrix(petsc_nest_matrix); + PetscErrorCode ierr = MatDestroy(&petsc_nest_matrix); (void)ierr; AssertNothrow(ierr == 0, ExcPETScError(ierr)); } @@ -245,7 +245,7 @@ namespace PETScWrappers MPI_Comm comm = PETSC_COMM_SELF; - ierr = destroy_matrix(petsc_nest_matrix); + ierr = MatDestroy(&petsc_nest_matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); std::vector psub_objects(m * n); for (unsigned int r = 0; r < m; r++) diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index 7f32a3910f..8d1469c866 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -48,7 +48,9 @@ namespace PETScWrappers SparseMatrix::~SparseMatrix() { - destroy_matrix(matrix); + PetscErrorCode ierr = MatDestroy(&matrix); + (void)ierr; + AssertNothrow(ierr == 0, ExcPETScError(ierr)); } @@ -78,7 +80,7 @@ namespace PETScWrappers if (&other == this) return; - PetscErrorCode ierr = destroy_matrix(matrix); + PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); ierr = MatDuplicate(other.matrix, MAT_DO_NOT_COPY_VALUES, &matrix); @@ -95,7 +97,7 @@ namespace PETScWrappers const MPI_Comm & communicator) { // get rid of old matrix and generate a new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); do_reinit(communicator, @@ -138,7 +140,7 @@ namespace PETScWrappers const bool preset_nonzero_locations) { // get rid of old matrix and generate a new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); @@ -169,7 +171,7 @@ namespace PETScWrappers const MPI_Comm & communicator) { // get rid of old matrix and generate a new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); do_reinit(communicator, local_rows, local_columns, sparsity_pattern); diff --git a/source/lac/petsc_sparse_matrix.cc b/source/lac/petsc_sparse_matrix.cc index 51bd14a442..99f66f1113 100644 --- a/source/lac/petsc_sparse_matrix.cc +++ b/source/lac/petsc_sparse_matrix.cc @@ -85,7 +85,7 @@ namespace PETScWrappers { // get rid of old matrix and generate a // new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); do_reinit(m, n, n_nonzero_per_row, is_symmetric); @@ -116,7 +116,7 @@ namespace PETScWrappers { // get rid of old matrix and generate a // new one - const PetscErrorCode ierr = destroy_matrix(matrix); + const PetscErrorCode ierr = MatDestroy(&matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); do_reinit(sparsity_pattern, preset_nonzero_locations);