]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Disable BoomerAMG/Hypre when not available through this PETSc installation.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 14 Nov 2010 22:30:00 +0000 (22:30 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 14 Nov 2010 22:30:00 +0000 (22:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@22724 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/petsc_precondition.h
deal.II/source/lac/petsc_precondition.cc

index 6f40b5b1c2ed206506930a0bb99d59ec5e836c34..0e9a3ad4a8622b11da76eba7ee95af90af244795 100644 (file)
@@ -31,8 +31,8 @@ namespace PETScWrappers
   class MatrixBase;
   class VectorBase;
   class SolverBase;
-  
-  
+
+
 /**
  * Base class for preconditioner classes using the PETSc functionality. The
  * classes in this hierarchy don't do a whole lot, except for providing a
@@ -58,7 +58,7 @@ namespace PETScWrappers
                                         * shall be constructed.
                                         */
       PreconditionerBase (const MatrixBase &matrix);
-      
+
                                        /**
                                         * Destructor.
                                         */
@@ -71,7 +71,7 @@ namespace PETScWrappers
                                         * a preconditioner.
                                         */
       const Mat matrix;
-      
+
                                        /**
                                         * Conversion operator to get a
                                         * representation of the matrix that
@@ -118,7 +118,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {};
 
@@ -130,7 +130,7 @@ namespace PETScWrappers
                                         */
       PreconditionJacobi (const MatrixBase     &matrix,
                           const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -145,10 +145,10 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
 
-      
+
 
 /**
  * A class that implements the interface to use the PETSc Block Jacobi
@@ -174,7 +174,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {};
 
@@ -186,7 +186,7 @@ namespace PETScWrappers
                                         */
       PreconditionBlockJacobi (const MatrixBase     &matrix,
                                const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -201,10 +201,10 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
 
-      
+
 
 /**
  * A class that implements the interface to use the PETSc SOR
@@ -223,7 +223,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -232,7 +232,7 @@ namespace PETScWrappers
                                             * to one.
                                             */
           AdditionalData (const double omega = 1);
-       
+
                                            /**
                                             * Relaxation parameter.
                                             */
@@ -247,7 +247,7 @@ namespace PETScWrappers
                                         */
       PreconditionSOR (const MatrixBase     &matrix,
                        const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -262,9 +262,9 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
-      
+
 
 
 /**
@@ -284,7 +284,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -293,7 +293,7 @@ namespace PETScWrappers
                                             * to one.
                                             */
           AdditionalData (const double omega = 1);
-       
+
                                            /**
                                             * Relaxation parameter.
                                             */
@@ -308,7 +308,7 @@ namespace PETScWrappers
                                         */
       PreconditionSSOR (const MatrixBase     &matrix,
                         const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -323,9 +323,9 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
-      
+
 
 
 /**
@@ -345,7 +345,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -354,7 +354,7 @@ namespace PETScWrappers
                                             * to one.
                                             */
           AdditionalData (const double omega = 1);
-       
+
                                            /**
                                             * Relaxation parameter.
                                             */
@@ -369,7 +369,7 @@ namespace PETScWrappers
                                         */
       PreconditionEisenstat (const MatrixBase     &matrix,
                              const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -384,9 +384,9 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
-      
+
 
 
 /**
@@ -406,7 +406,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -415,7 +415,7 @@ namespace PETScWrappers
                                             * to zero.
                                             */
           AdditionalData (const unsigned int levels = 0);
-       
+
                                            /**
                                             * Fill-in parameter.
                                             */
@@ -430,7 +430,7 @@ namespace PETScWrappers
                                         */
       PreconditionICC (const MatrixBase     &matrix,
                        const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -445,11 +445,11 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
 
 
-  
+
 /**
  * A class that implements the interface to use the PETSc ILU
  * preconditioner.
@@ -467,7 +467,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -476,7 +476,7 @@ namespace PETScWrappers
                                             * to zero.
                                             */
           AdditionalData (const unsigned int levels = 0);
-       
+
                                            /**
                                             * Fill-in parameter.
                                             */
@@ -491,7 +491,7 @@ namespace PETScWrappers
                                         */
       PreconditionILU (const MatrixBase     &matrix,
                        const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -506,7 +506,7 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
 
 
@@ -530,7 +530,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -558,7 +558,7 @@ namespace PETScWrappers
                                            * Confer PetSC manual for more
                                            * details.
                                            */
-         double zero_pivot;                                        
+         double zero_pivot;
 
                                            /**
                                             * This quantity is added to the
@@ -576,7 +576,7 @@ namespace PETScWrappers
                                         */
       PreconditionLU (const MatrixBase     &matrix,
                      const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -591,7 +591,7 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
 
 
@@ -615,7 +615,7 @@ namespace PETScWrappers
                                         * Standardized data struct to
                                         * pipe additional flags to the
                                         * preconditioner.
-                                        */      
+                                        */
       struct AdditionalData
       {
                                            /**
@@ -676,7 +676,7 @@ namespace PETScWrappers
                                            * created.
                                            */
          double max_row_sum;
-         
+
                                             /**
                                            * Number of levels of aggressive
                                            * coarsening. Increasing this
@@ -684,7 +684,7 @@ namespace PETScWrappers
                                            * time and memory requirements but
                                            * may decrease effectiveness.*/
          unsigned int aggressive_coarsening_num_levels;
-         
+
                                                   /**
                                            * Setting this flag to true
                                            * produces debug output from
@@ -692,14 +692,10 @@ namespace PETScWrappers
                                            * is constructed.
                                            */
          bool output_details;
-         
-         
-         
-
       };
 
 
-      
+
                                        /**
                                         * Constructor. Take the matrix which
                                         * is used to form the preconditioner,
@@ -708,7 +704,7 @@ namespace PETScWrappers
                                         */
       PreconditionBoomerAMG (const MatrixBase     &matrix,
                             const AdditionalData &additional_data = AdditionalData());
-      
+
     protected:
                                        /**
                                         * Store a copy of the flags for this
@@ -723,10 +719,8 @@ namespace PETScWrappers
                                         * preconditioner that is appropriate
                                         * for the present class.
                                         */
-      virtual void set_preconditioner_type (PC &pc) const;      
+      virtual void set_preconditioner_type (PC &pc) const;
   };
-
-  
 }
 
 
index 15d13c5108d9be913d20d6f0edd05a939d3d48ec..d1b0e496eaef3d92cad1d95e3325ea70a0cceba8 100644 (file)
@@ -19,6 +19,7 @@
 #  include <base/utilities.h>
 #  include <lac/petsc_matrix_base.h>
 #  include <lac/petsc_vector_base.h>
+#  include <petscconf.h>
 #  include <cmath>
 
 DEAL_II_NAMESPACE_OPEN
@@ -31,11 +32,11 @@ namespace PETScWrappers
   {}
 
 
-  
+
   PreconditionerBase::~PreconditionerBase ()
   {}
 
-  
+
 
   PreconditionerBase::operator Mat () const
   {
@@ -53,7 +54,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionJacobi::set_preconditioner_type (PC &pc) const
   {
@@ -66,7 +67,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionJacobi -------------------- */
 
@@ -79,7 +80,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionBlockJacobi::set_preconditioner_type (PC &pc) const
   {
@@ -92,7 +93,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionSOR -------------------- */
 
@@ -102,8 +103,8 @@ namespace PETScWrappers
                   omega (omega)
   {}
 
-  
-  
+
+
   PreconditionSOR::PreconditionSOR (const MatrixBase     &matrix,
                                     const AdditionalData &additional_data)
                   :
@@ -111,7 +112,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionSOR::set_preconditioner_type (PC &pc) const
   {
@@ -128,7 +129,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionSSOR -------------------- */
 
@@ -138,8 +139,8 @@ namespace PETScWrappers
                   omega (omega)
   {}
 
-  
-  
+
+
   PreconditionSSOR::PreconditionSSOR (const MatrixBase     &matrix,
                                       const AdditionalData &additional_data)
                   :
@@ -147,7 +148,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionSSOR::set_preconditioner_type (PC &pc) const
   {
@@ -168,7 +169,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionEisenstat -------------------- */
 
@@ -178,8 +179,8 @@ namespace PETScWrappers
                   omega (omega)
   {}
 
-  
-  
+
+
   PreconditionEisenstat::PreconditionEisenstat (const MatrixBase     &matrix,
                                                 const AdditionalData &additional_data)
                   :
@@ -187,7 +188,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionEisenstat::set_preconditioner_type (PC &pc) const
   {
@@ -204,7 +205,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionICC -------------------- */
 
@@ -215,8 +216,8 @@ namespace PETScWrappers
                   levels (levels)
   {}
 
-  
-  
+
+
   PreconditionICC::PreconditionICC (const MatrixBase     &matrix,
                                     const AdditionalData &additional_data)
                   :
@@ -224,7 +225,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionICC::set_preconditioner_type (PC &pc) const
   {
@@ -245,7 +246,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionILU -------------------- */
 
@@ -255,8 +256,8 @@ namespace PETScWrappers
                   levels (levels)
   {}
 
-  
-  
+
+
   PreconditionILU::PreconditionILU (const MatrixBase     &matrix,
                                     const AdditionalData &additional_data)
                   :
@@ -264,7 +265,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionILU::set_preconditioner_type (PC &pc) const
   {
@@ -276,7 +277,7 @@ namespace PETScWrappers
 
                                      // then set flags
 #if DEAL_II_PETSC_VERSION_LT(2,3,1)
-    PCILUSetLevels (pc, additional_data.levels);  
+    PCILUSetLevels (pc, additional_data.levels);
 #else
     PCFactorSetLevels (pc, additional_data.levels);
 #endif
@@ -285,7 +286,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
   }
-  
+
 
 /* ----------------- PreconditionBoomerAMG -------------------- */
 
@@ -304,7 +305,7 @@ namespace PETScWrappers
                  output_details(output_details)
   {}
 
-  
+
   PreconditionBoomerAMG::PreconditionBoomerAMG (const MatrixBase     &matrix,
                                                const AdditionalData &additional_data)
                   :
@@ -312,22 +313,23 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionBoomerAMG::set_preconditioner_type (PC &pc) const
   {
+#ifdef PETSC_HAVE_HYPRE
                                      // set the right type for the
                                      // preconditioner
     int ierr;
     ierr = PCSetType (pc, const_cast<char *>(PCHYPRE));
     AssertThrow (ierr == 0, ExcPETScError(ierr));
-    
+
     ierr = PCHYPRESetType(pc, "boomeramg");
     AssertThrow (ierr == 0, ExcPETScError(ierr));
 
     if (additional_data.output_details)
       PetscOptionsSetValue("-pc_hypre_boomeramg_print_statistics","1");
-    
+
     PetscOptionsSetValue("-pc_hypre_boomeramg_agg_nl",
                         Utilities::int_to_string(
                           additional_data.aggressive_coarsening_num_levels
@@ -336,9 +338,9 @@ namespace PETScWrappers
     std::stringstream ssStream;
     ssStream << additional_data.max_row_sum;
     PetscOptionsSetValue("-pc_hypre_boomeramg_max_row_sum", ssStream.str().c_str());
-    
+
     ssStream.str(""); // empty the stringstream
-    ssStream << additional_data.strong_threshold;    
+    ssStream << additional_data.strong_threshold;
     PetscOptionsSetValue("-pc_hypre_boomeramg_strong_threshold", ssStream.str().c_str());
 
     if (additional_data.symmetric_operator)
@@ -353,9 +355,15 @@ namespace PETScWrappers
        PetscOptionsSetValue("-pc_hypre_boomeramg_relax_type_down", "SOR/Jacobi");
        PetscOptionsSetValue("-pc_hypre_boomeramg_relax_type_coarse", "Gaussian-elimination");
       }
-    
+
     ierr = PCSetFromOptions (pc);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
+#else // PETSC_HAVE_HYPRE
+    (void)pc;
+    Assert (false,
+           ExcMessage ("Your PETSc installation does not include a copy of "
+                       "the hypre package necessary for this preconditioner."));
+#endif
   }
 
 
@@ -371,8 +379,8 @@ namespace PETScWrappers
                  damping (damping)
   {}
 
-  
-  
+
+
   PreconditionLU::PreconditionLU (const MatrixBase     &matrix,
                                  const AdditionalData &additional_data)
                   :
@@ -380,7 +388,7 @@ namespace PETScWrappers
                   additional_data (additional_data)
   {}
 
-  
+
   void
   PreconditionLU::set_preconditioner_type (PC &pc) const
   {
@@ -405,7 +413,7 @@ namespace PETScWrappers
 #else
     ierr = PCFactorSetZeroPivot (pc, additional_data.zero_pivot);
 #endif
-    
+
     AssertThrow (ierr == 0, ExcPETScError(ierr));
 
 #if DEAL_II_PETSC_VERSION_LT(2,3,0)
@@ -420,7 +428,7 @@ namespace PETScWrappers
     ierr = PCSetFromOptions (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.