IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
Ifpack_DynamicFactory.h
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #ifndef IFPACK_DYNAMIC_FACTORY_H
00031 #define IFPACK_DYNAMIC_FACTORY_H
00032 
00033 #include <ostream>
00034 #include <string>
00035 #include <map>
00036 #include <algorithm>
00037 
00038 #include "Ifpack_ConfigDefs.h"
00039 #include "Ifpack_Preconditioner.h"
00040 #include "Teuchos_iostream_helpers.hpp"
00041 #include "Ifpack_AdditiveSchwarz.h"
00042 
00043 
00044 #ifdef HAVE_HYPRE
00045 #include "Ifpack_Hypre.h"
00046 #endif
00047 
00048 
00050 
00057 class Ifpack_DynamicFactory {
00058 public:
00059   // The prototype of the preconditioner builder function
00060   typedef Ifpack_Preconditioner* (*builderFunction)(Epetra_RowMatrix*, int, bool, bool);
00061 
00076   Ifpack_Preconditioner* Create(const string PrecType,
00077                                 Epetra_RowMatrix* Matrix,
00078                                 const int overlap = 0,
00079                                 bool overrideSerialDefault = false);
00080 
00081   // Static methods
00087   static bool Initialize();
00088 
00097   static int RegisterPreconditioner(const std::string PrecName,
00098                                     builderFunction PrecBuilder);
00099 
00100   // Static methods
00104   static void Print(std::ostream& os = std::cout);
00105 
00106   // Templated build function
00107   template <typename PrecType, bool StandAlone>
00108   static Ifpack_Preconditioner* buildPreconditioner(Epetra_RowMatrix* Matrix,
00109                                                     int Overlap,
00110                                                     bool Serial,
00111                                                     bool OverrideSerialDefault);
00112 
00113 private:
00114   static std::map<std::string, builderFunction> PreconditionerMap_;
00115   static int NumPreconditioners_;
00116   static bool Initialized_;
00117 };
00118 
00119 // Templated build function
00120 template <typename PrecType, bool StandAlone>
00121 Ifpack_Preconditioner*
00122 Ifpack_DynamicFactory::buildPreconditioner(Epetra_RowMatrix* Matrix,
00123                                            int Overlap,
00124                                            bool Serial,
00125                                            bool OverrideSerialDefault)
00126 {
00127     if (StandAlone || (Serial && !OverrideSerialDefault)) {
00128         return new PrecType(Matrix);
00129     } else {
00130         return new Ifpack_AdditiveSchwarz<PrecType>(Matrix, Overlap);
00131     }
00132 }
00133 
00134 #endif // IFPACK_DYNAMIC_FACTORY_H
 All Classes Files Functions Variables Enumerations Friends