]> https://gitweb.dealii.org/ - dealii.git/commitdiff
allow creation of PETSc preconditioners without a matrix
authorDenis Davydov <davydden@gmail.com>
Sat, 12 Dec 2015 19:18:02 +0000 (20:18 +0100)
committerDenis Davydov <davydden@gmail.com>
Tue, 29 Dec 2015 09:12:01 +0000 (10:12 +0100)
include/deal.II/lac/petsc_precondition.h
source/lac/petsc_precondition.cc

index da608b85e1a01fb2270e5c46d092b2d1d983b902..4750f06b0c6a7e09f17fa6b45c97bcf7dbd282f2 100644 (file)
@@ -137,6 +137,12 @@ namespace PETScWrappers
      */
     PreconditionJacobi ();
 
+    /**
+     * A constructor intended to be used with SLEPc objects.
+     */
+    PreconditionJacobi (const MPI_Comm communicator,
+                        const AdditionalData &additional_data = AdditionalData());
+
 
     /**
      * Constructor. Take the matrix which is used to form the preconditioner,
@@ -159,6 +165,13 @@ namespace PETScWrappers
      * Store a copy of the flags for this particular preconditioner.
      */
     AdditionalData additional_data;
+
+    /**
+     * Initializes the preconditioner object without knowing a particular matrix.
+     * This function sets up appropriate parameters to the underlying PETSc object
+     * after it has been created.
+     */
+    void initialize();
   };
 
 
index e93175998a817b68a08f0856a3d8729a554ddecf..b4ab5d23f41133f76426520a852d76a4db0419ec 100644 (file)
@@ -101,6 +101,17 @@ namespace PETScWrappers
 
 
   /* ----------------- PreconditionJacobi -------------------- */
+  PreconditionJacobi::PreconditionJacobi (const MPI_Comm comm,
+                                          const AdditionalData &additional_data_)
+  {
+    additional_data = additional_data_;
+
+    int ierr = PCCreate(comm, &pc);
+    AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+    initialize();
+  }
+
 
   PreconditionJacobi::PreconditionJacobi ()
   {}
@@ -112,6 +123,16 @@ namespace PETScWrappers
     initialize(matrix, additional_data);
   }
 
+  void
+  PreconditionJacobi::initialize()
+  {
+    int ierr;
+    ierr = PCSetType (pc, const_cast<char *>(PCJACOBI));
+    AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+    ierr = PCSetFromOptions (pc);
+    AssertThrow (ierr == 0, ExcPETScError(ierr));
+  }
 
   void
   PreconditionJacobi::initialize (const MatrixBase     &matrix_,
@@ -121,15 +142,9 @@ namespace PETScWrappers
     additional_data = additional_data_;
 
     create_pc();
+    initialize();
 
-    int ierr;
-    ierr = PCSetType (pc, const_cast<char *>(PCJACOBI));
-    AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-    ierr = PCSetFromOptions (pc);
-    AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-    ierr = PCSetUp (pc);
+    int ierr = PCSetUp (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
 

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.