IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
Ifpack_DynamicFactory.h
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 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
34 #ifdef __GNUC__
35 #warning "The Ifpack package is deprecated"
36 #endif
37 #endif
38 
39 #include <ostream>
40 #include <string>
41 #include <map>
42 #include <algorithm>
43 
44 #include "Ifpack_ConfigDefs.h"
45 #include "Ifpack_Preconditioner.h"
46 #include "Teuchos_iostream_helpers.hpp"
47 #include "Ifpack_AdditiveSchwarz.h"
48 
49 
50 #ifdef HAVE_HYPRE
51 #include "Ifpack_Hypre.h"
52 #endif
53 
54 
56 
64 public:
65  // The prototype of the preconditioner builder function
66  typedef Ifpack_Preconditioner* (*builderFunction)(Epetra_RowMatrix*, int, bool, bool);
67 
82  Ifpack_Preconditioner* Create(const std::string PrecType,
83  Epetra_RowMatrix* Matrix,
84  const int overlap = 0,
85  bool overrideSerialDefault = false);
86 
87  // Static methods
93  static bool Initialize();
94 
103  static int RegisterPreconditioner(const std::string PrecName,
104  builderFunction PrecBuilder);
105 
106  // Static methods
110  static void Print(std::ostream& os = std::cout);
111 
112  // Templated build function
113  template <typename PrecType, bool StandAlone>
114  static Ifpack_Preconditioner* buildPreconditioner(Epetra_RowMatrix* Matrix,
115  int Overlap,
116  bool Serial,
117  bool OverrideSerialDefault);
118 
119 private:
120  static std::map<std::string, builderFunction> PreconditionerMap_;
121  static int NumPreconditioners_;
122  static bool Initialized_;
123 };
124 
125 // Templated build function
126 template <typename PrecType, bool StandAlone>
128 Ifpack_DynamicFactory::buildPreconditioner(Epetra_RowMatrix* Matrix,
129  int Overlap,
130  bool Serial,
131  bool OverrideSerialDefault)
132 {
133  if (StandAlone || (Serial && !OverrideSerialDefault)) {
134  return new PrecType(Matrix);
135  } else {
136  return new Ifpack_AdditiveSchwarz<PrecType>(Matrix, Overlap);
137  }
138 }
139 
140 #endif // IFPACK_DYNAMIC_FACTORY_H
static void Print(std::ostream &os=std::cout)
Prints the current list of registered preconditioners.
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.
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...
static int RegisterPreconditioner(const std::string PrecName, builderFunction PrecBuilder)
Register a new preconditioner with the factory.