Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ifpack_DynamicFactory.h
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 */
29 
30 #ifndef IFPACK_DYNAMIC_FACTORY_H
31 #define IFPACK_DYNAMIC_FACTORY_H
32 
33 #include <ostream>
34 #include <string>
35 #include <map>
36 #include <algorithm>
37 
38 #include "Ifpack_ConfigDefs.h"
39 #include "Ifpack_Preconditioner.h"
40 #include "Teuchos_iostream_helpers.hpp"
41 #include "Ifpack_AdditiveSchwarz.h"
42 
43 
44 #ifdef HAVE_HYPRE
45 #include "Ifpack_Hypre.h"
46 #endif
47 
48 
50 
58 public:
59  // The prototype of the preconditioner builder function
60  typedef Ifpack_Preconditioner* (*builderFunction)(Epetra_RowMatrix*, int, bool, bool);
61 
76  Ifpack_Preconditioner* Create(const std::string PrecType,
77  Epetra_RowMatrix* Matrix,
78  const int overlap = 0,
79  bool overrideSerialDefault = false);
80 
81  // Static methods
87  static bool Initialize();
88 
97  static int RegisterPreconditioner(const std::string PrecName,
98  builderFunction PrecBuilder);
99 
100  // Static methods
104  static void Print(std::ostream& os = std::cout);
105 
106  // Templated build function
107  template <typename PrecType, bool StandAlone>
109  int Overlap,
110  bool Serial,
111  bool OverrideSerialDefault);
112 
113 private:
114  static std::map<std::string, builderFunction> PreconditionerMap_;
116  static bool Initialized_;
117 };
118 
119 // Templated build function
120 template <typename PrecType, bool StandAlone>
123  int Overlap,
124  bool Serial,
125  bool OverrideSerialDefault)
126 {
127  if (StandAlone || (Serial && !OverrideSerialDefault)) {
128  return new PrecType(Matrix);
129  } else {
130  return new Ifpack_AdditiveSchwarz<PrecType>(Matrix, Overlap);
131  }
132 }
133 
134 #endif // IFPACK_DYNAMIC_FACTORY_H
static void Print(std::ostream &os=std::cout)
Prints the current list of registered preconditioners.
static std::map< std::string, builderFunction > PreconditionerMap_
static Ifpack_Preconditioner * buildPreconditioner(Epetra_RowMatrix *Matrix, int Overlap, bool Serial, bool OverrideSerialDefault)
Ifpack_DynamicFactory.
Ifpack_AdditiveSchwarz: a class to define Additive Schwarz preconditioners of Epetra_RowMatrix&#39;s.
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
static bool Initialize()
Initializes the static data of the Ifpac_DynamicFactory class.
int bool
Ifpack_Preconditioner * Create(const std::string PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Creates an instance of Ifpack_Preconditioner given the std::string name of the preconditioner type (c...
Ifpack_Preconditioner *(* builderFunction)(Epetra_RowMatrix *, int, bool, bool)
static int RegisterPreconditioner(const std::string PrecName, builderFunction PrecBuilder)
Register a new preconditioner with the factory.