From f1ad006829fc2c0f0eb9e3c8d188bfafac9ca6ad Mon Sep 17 00:00:00 2001 From: Nicolas Barnafi Date: Wed, 7 Sep 2022 00:13:30 +0200 Subject: [PATCH] Added Wells corrections. Missing only fixes on test --- include/deal.II/lac/petsc_precondition.h | 29 +++----- include/deal.II/lac/petsc_sparse_matrix.h | 28 ++++---- source/lac/petsc_parallel_sparse_matrix.cc | 79 +++++++++++----------- source/lac/petsc_precondition.cc | 46 ++++++++----- source/lac/petsc_sparse_matrix.cc | 2 +- 5 files changed, 92 insertions(+), 92 deletions(-) diff --git a/include/deal.II/lac/petsc_precondition.h b/include/deal.II/lac/petsc_precondition.h index 244b33eb34..70416e60f0 100644 --- a/include/deal.II/lac/petsc_precondition.h +++ b/include/deal.II/lac/petsc_precondition.h @@ -19,6 +19,7 @@ # include +# include # include # ifdef DEAL_II_WITH_PETSC @@ -974,6 +975,7 @@ namespace PETScWrappers * * @ingroup PETScWrappers */ + template class PreconditionBDDC : public PreconditionBase { public: @@ -987,13 +989,12 @@ namespace PETScWrappers * Constructor. Note that BDDC offers a lot more options to set * than what is exposed here. */ - AdditionalData(const bool use_vertices = true, - const bool use_edges = false, - const bool use_faces = false, - const bool symmetric = false, - const unsigned int coords_cdim = 0, - const types::global_dof_index coords_n = 0, - const PetscReal * coords_data = nullptr); + AdditionalData(const bool use_vertices = true, + const bool use_edges = false, + const bool use_faces = false, + const bool symmetric = false, + std::vector> coords = {}); + /** * This flag sets the use of degrees of freedom in the vertices of the * subdomains as primal variables for the creation of the coarse space. @@ -1019,22 +1020,11 @@ namespace PETScWrappers */ bool symmetric; - /** - * Set the number of coordinates that each DoF has, i.e. 2 in 2D and 3 in - * 3D. - */ - unsigned int coords_cdim; - - /** - * Set the number of degrees of freedom that the problem has. - */ - types::global_dof_index coords_n; - /** * Set the location of each DoF. This helps in improving the definition of * the vertices for unstructured meshes. */ - const PetscReal *coords_data; + const std::vector> coords; }; /** @@ -1090,7 +1080,6 @@ namespace PETScWrappers } // namespace PETScWrappers - DEAL_II_NAMESPACE_CLOSE diff --git a/include/deal.II/lac/petsc_sparse_matrix.h b/include/deal.II/lac/petsc_sparse_matrix.h index d061c14f53..473eaf4bf2 100644 --- a/include/deal.II/lac/petsc_sparse_matrix.h +++ b/include/deal.II/lac/petsc_sparse_matrix.h @@ -25,10 +25,10 @@ # include # include -# include +# include +# include -# include "petscis.h" -# include "petscistypes.h" +# include DEAL_II_NAMESPACE_OPEN // forward declaration @@ -512,12 +512,12 @@ namespace PETScWrappers */ template void - reinit_IS(const IndexSet & local_rows, - const IndexSet & local_active_rows, - const IndexSet & local_columns, - const IndexSet & local_active_columns, - const SparsityPatternType &sparsity_pattern, - const MPI_Comm & communicator); + reinit(const IndexSet & local_rows, + const IndexSet & local_active_rows, + const IndexSet & local_columns, + const IndexSet & local_active_columns, + const SparsityPatternType &sparsity_pattern, + const MPI_Comm & communicator); /** * Return a reference to the MPI communicator object in use with this @@ -640,11 +640,11 @@ namespace PETScWrappers */ template void - do_reinit_IS(const IndexSet & local_rows, - const IndexSet & local_active_rows, - const IndexSet & local_columns, - const IndexSet & local_active_columns, - const SparsityPatternType &sparsity_pattern); + do_reinit(const IndexSet & local_rows, + const IndexSet & local_active_rows, + const IndexSet & local_columns, + const IndexSet & local_active_columns, + const SparsityPatternType &sparsity_pattern); // To allow calling protected prepare_add() and prepare_set(). friend class BlockMatrixBase; diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index 09aa47a09e..12a2955e79 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -87,12 +87,12 @@ namespace PETScWrappers template void - SparseMatrix::reinit_IS(const IndexSet & local_rows, - const IndexSet & local_active_rows, - const IndexSet & local_columns, - const IndexSet & local_active_columns, - const SparsityPatternType &sparsity_pattern, - const MPI_Comm & communicator) + SparseMatrix::reinit(const IndexSet & local_rows, + const IndexSet & local_active_rows, + const IndexSet & local_columns, + const IndexSet & local_active_columns, + const SparsityPatternType &sparsity_pattern, + const MPI_Comm & communicator) { this->communicator = communicator; @@ -100,11 +100,11 @@ namespace PETScWrappers const PetscErrorCode ierr = destroy_matrix(matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); - do_reinit_IS(local_rows, - local_active_rows, - local_columns, - local_active_columns, - sparsity_pattern); + do_reinit(local_rows, + local_active_rows, + local_columns, + local_active_columns, + sparsity_pattern); } @@ -431,11 +431,11 @@ namespace PETScWrappers // BDDC template void - SparseMatrix::do_reinit_IS(const IndexSet & local_rows, - const IndexSet & local_active_rows, - const IndexSet & local_columns, - const IndexSet & local_active_columns, - const SparsityPatternType &sparsity_pattern) + SparseMatrix::do_reinit(const IndexSet & local_rows, + const IndexSet & local_active_rows, + const IndexSet & local_columns, + const IndexSet & local_active_columns, + const SparsityPatternType &sparsity_pattern) { Assert(sparsity_pattern.n_rows() == local_rows.size(), ExcMessage( @@ -479,14 +479,13 @@ namespace PETScWrappers IndexSet::size_type n_local_active_rows = local_active_rows.n_elements(); IndexSet::size_type n_local_active_cols = local_active_columns.n_elements(); - std::vector idx_glob_row(n_local_active_rows); - std::vector idx_glob_col(n_local_active_cols); - unsigned int k; - for (k = 0; k < n_local_active_rows; ++k) + std::vector idx_glob_row(n_local_active_rows); + std::vector idx_glob_col(n_local_active_cols); + for (IndexSet::size_type k = 0; k < n_local_active_rows; ++k) { idx_glob_row[k] = local_active_rows.nth_index_in_set(k); } - for (k = 0; k < n_local_active_cols; ++k) + for (IndexSet::size_type k = 0; k < n_local_active_cols; ++k) { idx_glob_col[k] = local_active_columns.nth_index_in_set(k); } @@ -707,32 +706,32 @@ namespace PETScWrappers const DynamicSparsityPattern &); template void - SparseMatrix::reinit_IS(const IndexSet &, + SparseMatrix::reinit(const IndexSet &, + const IndexSet &, + const IndexSet &, + const IndexSet &, + const SparsityPattern &, + const MPI_Comm &); + template void + SparseMatrix::reinit(const IndexSet &, + const IndexSet &, + const IndexSet &, + const IndexSet &, + const DynamicSparsityPattern &, + const MPI_Comm &); + + template void + SparseMatrix::do_reinit(const IndexSet &, const IndexSet &, const IndexSet &, const IndexSet &, - const SparsityPattern &, - const MPI_Comm &); + const SparsityPattern &); template void - SparseMatrix::reinit_IS(const IndexSet &, + SparseMatrix::do_reinit(const IndexSet &, const IndexSet &, const IndexSet &, const IndexSet &, - const DynamicSparsityPattern &, - const MPI_Comm &); - - template void - SparseMatrix::do_reinit_IS(const IndexSet &, - const IndexSet &, - const IndexSet &, - const IndexSet &, - const SparsityPattern &); - template void - SparseMatrix::do_reinit_IS(const IndexSet &, - const IndexSet &, - const IndexSet &, - const IndexSet &, - const DynamicSparsityPattern &); + const DynamicSparsityPattern &); # endif diff --git a/source/lac/petsc_precondition.cc b/source/lac/petsc_precondition.cc index 64ffbfc3cd..7950579cc6 100644 --- a/source/lac/petsc_precondition.cc +++ b/source/lac/petsc_precondition.cc @@ -852,25 +852,24 @@ namespace PETScWrappers /* ----------------- PreconditionBDDC -------------------- */ - PreconditionBDDC::AdditionalData::AdditionalData( + template + PreconditionBDDC::AdditionalData::AdditionalData( const bool use_vertices, const bool use_edges, const bool use_faces, const bool symmetric, - const unsigned int coords_cdim, - const types::global_dof_index coords_n, - const PetscReal * coords_data) + const std::vector> coords) : use_vertices(use_vertices) , use_edges(use_edges) , use_faces(use_faces) , symmetric(symmetric) - , coords_cdim(coords_cdim) - , coords_n(coords_n) - , coords_data(coords_data) + , coords(coords) {} - PreconditionBDDC::PreconditionBDDC(const MPI_Comm comm, - const AdditionalData &additional_data_) + template + PreconditionBDDC::PreconditionBDDC( + const MPI_Comm comm, + const AdditionalData &additional_data_) { additional_data = additional_data_; @@ -880,14 +879,17 @@ namespace PETScWrappers initialize(); } - PreconditionBDDC::PreconditionBDDC(const MatrixBase & matrix, - const AdditionalData &additional_data) + template + PreconditionBDDC::PreconditionBDDC(const MatrixBase & matrix, + const AdditionalData &additional_data) { initialize(matrix, additional_data); } + + template void - PreconditionBDDC::initialize() + PreconditionBDDC::initialize() { PetscErrorCode ierr = PCSetType(pc, const_cast(PCBDDC)); AssertThrow(ierr == 0, ExcPETScError(ierr)); @@ -914,10 +916,19 @@ namespace PETScWrappers additional_data.coords_data) { set_option_value("-pc_bddc_corner_selection", "true"); + // Convert coords vector to PETSc data array + std::vector coords_petsc(additional_data.coords.size() * + dim); + for (unsigned int i = 0, j = 0; i < additional_data.coords.size(); ++i) + { + for (j = 0; j < dim; ++j) + coords_petsc[dim * i + j] = additional_data.coords[i][j]; + } + ierr = PCSetCoordinates(pc, - additional_data.coords_cdim, - additional_data.coords_n, - (PetscReal *)additional_data.coords_data); + dim, + additional_data.coords.size(), + coords_petsc.data()); AssertThrow(ierr == 0, ExcPETScError(ierr)); } else @@ -932,9 +943,10 @@ namespace PETScWrappers AssertThrow(ierr == 0, ExcPETScError(ierr)); } + template void - PreconditionBDDC::initialize(const MatrixBase & matrix_, - const AdditionalData &additional_data_) + PreconditionBDDC::initialize(const MatrixBase & matrix_, + const AdditionalData &additional_data_) { clear(); diff --git a/source/lac/petsc_sparse_matrix.cc b/source/lac/petsc_sparse_matrix.cc index ca8ddaf97a..194549925b 100644 --- a/source/lac/petsc_sparse_matrix.cc +++ b/source/lac/petsc_sparse_matrix.cc @@ -99,7 +99,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, row_lengths, is_symmetric); -- 2.39.5