]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added Wells corrections. Missing only fixes on test
authorNicolas Barnafi <nabw91@gmail.com>
Tue, 6 Sep 2022 22:13:30 +0000 (00:13 +0200)
committerNicolas Barnafi <nabw91@gmail.com>
Tue, 6 Sep 2022 22:13:30 +0000 (00:13 +0200)
include/deal.II/lac/petsc_precondition.h
include/deal.II/lac/petsc_sparse_matrix.h
source/lac/petsc_parallel_sparse_matrix.cc
source/lac/petsc_precondition.cc
source/lac/petsc_sparse_matrix.cc

index 244b33eb3433ffd332aeeba67cba88f2a9c3f20e..70416e60f08bf640f716caa40b054218fbe8af99 100644 (file)
@@ -19,6 +19,7 @@
 
 #  include <deal.II/base/config.h>
 
+#  include <deal.II/base/point.h>
 #  include <deal.II/base/subscriptor.h>
 
 #  ifdef DEAL_II_WITH_PETSC
@@ -974,6 +975,7 @@ namespace PETScWrappers
    *
    * @ingroup PETScWrappers
    */
+  template <int dim>
   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<Point<dim>> 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<Point<dim>> coords;
     };
 
     /**
@@ -1090,7 +1080,6 @@ namespace PETScWrappers
 } // namespace PETScWrappers
 
 
-
 DEAL_II_NAMESPACE_CLOSE
 
 
index d061c14f5391a3782bfb26861980d3be6a2f3a12..473eaf4bf2b70bf447c3d8e9185d23d963ac4b53 100644 (file)
 #    include <deal.II/lac/petsc_matrix_base.h>
 #    include <deal.II/lac/petsc_vector.h>
 
-#    include <vector>
+#    include <petscis.h>
+#    include <petscistypes.h>
 
-#    include "petscis.h"
-#    include "petscistypes.h"
+#    include <vector>
 
 DEAL_II_NAMESPACE_OPEN
 // forward declaration
@@ -512,12 +512,12 @@ namespace PETScWrappers
        */
       template <typename SparsityPatternType>
       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 <typename SparsityPatternType>
       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<SparseMatrix>;
index 09aa47a09e00087eb5a2bb34d12b5b46c505950a..12a2955e79871c548f70c49021bf2c890d8651a4 100644 (file)
@@ -87,12 +87,12 @@ namespace PETScWrappers
 
     template <typename SparsityPatternType>
     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 <typename SparsityPatternType>
     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<int> idx_glob_row(n_local_active_rows);
-      std::vector<int> idx_glob_col(n_local_active_cols);
-      unsigned int     k;
-      for (k = 0; k < n_local_active_rows; ++k)
+      std::vector<PetscInt> idx_glob_row(n_local_active_rows);
+      std::vector<PetscInt> 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
 
 
index 64ffbfc3cd1bca165b1ea71c5771a175ee875721..7950579cc64687b021fdb79b1a7a268120772ec6 100644 (file)
@@ -852,25 +852,24 @@ namespace PETScWrappers
 
   /* ----------------- PreconditionBDDC -------------------- */
 
-  PreconditionBDDC::AdditionalData::AdditionalData(
+  template <int dim>
+  PreconditionBDDC<dim>::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<Point<dim>> 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 <int dim>
+  PreconditionBDDC<dim>::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 <int dim>
+  PreconditionBDDC<dim>::PreconditionBDDC(const MatrixBase &    matrix,
+                                          const AdditionalData &additional_data)
   {
     initialize(matrix, additional_data);
   }
 
+
+  template <int dim>
   void
-  PreconditionBDDC::initialize()
+  PreconditionBDDC<dim>::initialize()
   {
     PetscErrorCode ierr = PCSetType(pc, const_cast<char *>(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<PetscReal> 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 <int dim>
   void
-  PreconditionBDDC::initialize(const MatrixBase &    matrix_,
-                               const AdditionalData &additional_data_)
+  PreconditionBDDC<dim>::initialize(const MatrixBase &    matrix_,
+                                    const AdditionalData &additional_data_)
   {
     clear();
 
index ca8ddaf97ac151a5a5a93f0cd0c6434665a3fcfc..194549925b485df272c68cdd89dfc4c2e026d06a 100644 (file)
@@ -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);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.