IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends Pages
Ifpack_DynamicFactory.cpp
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 */
29 
30 #include "Ifpack_ConfigDefs.h"
31 #include "Ifpack_DynamicFactory.h"
32 #include "Ifpack_Preconditioner.h"
33 #include "Ifpack_PointRelaxation.h"
34 #include "Ifpack_BlockRelaxation.h"
35 #include "Ifpack_IC.h"
36 #include "Ifpack_ICT.h"
37 #include "Ifpack_ILU.h"
38 #include "Ifpack_ILUT.h"
39 #include "Ifpack_SPARSKIT.h"
40 #include "Ifpack_AdditiveSchwarz.h"
41 #include "Ifpack_DenseContainer.h"
42 #include "Ifpack_SparseContainer.h"
43 #ifdef HAVE_IFPACK_AMESOS
44 #include "Ifpack_Amesos.h"
45 #endif
46 #ifdef HAVE_IFPACK_HIPS
47 #include "Ifpack_HIPS.h"
48 #endif
49 #ifdef HAVE_IFPACK_SUPERLU
50 #include "Ifpack_SILU.h"
51 #endif
52 
53 #include "Ifpack_Chebyshev.h"
54 #include "Ifpack_IHSS.h"
55 #include "Ifpack_SORa.h"
56 
57 #include "Teuchos_StringToIntMap.hpp"
58 #include "Epetra_CrsMatrix.h"
59 
60 std::map<std::string, Ifpack_DynamicFactory::builderFunction>
61  Ifpack_DynamicFactory::PreconditionerMap_;
62 bool Ifpack_DynamicFactory::Initialized_ = false;
63 int Ifpack_DynamicFactory::NumPreconditioners_ = 0;
64 
66 {
67  if (! Initialized_) {
68  PreconditionerMap_["point relaxation"]
69  = &buildPreconditioner<Ifpack_PointRelaxation, false>;
70  PreconditionerMap_["point relaxation stand-alone"]
71  = &buildPreconditioner<Ifpack_PointRelaxation, true>;
72  PreconditionerMap_["block relaxation"]
73  = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_DenseContainer>, false>;
74  PreconditionerMap_["block relaxation stand-alone"]
75  = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_DenseContainer>, true>;
76  PreconditionerMap_["block relaxation stand-alone (ILU)"]
77  = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_ILU> >, true>;
78 
79 #ifdef HAVE_IFPACK_AMESOS
80  PreconditionerMap_["block relaxation stand-alone (Amesos)"]
81  = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> >, true>;
82  PreconditionerMap_["block relaxation (Amesos)"]
83  = &buildPreconditioner<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> >, false>;
84  PreconditionerMap_["Amesos"]
85  = &buildPreconditioner<Ifpack_Amesos, false>;
86  PreconditionerMap_["Amesos stand-alone"]
87  = &buildPreconditioner<Ifpack_Amesos, true>;
88 #endif // HAVE_IFPACK_AMESOS
89 
90  PreconditionerMap_["IC"] = &buildPreconditioner<Ifpack_IC, false>;
91  PreconditionerMap_["IC stand-alone"] = &buildPreconditioner<Ifpack_IC, true>;
92  PreconditionerMap_["ICT"] = &buildPreconditioner<Ifpack_ICT, false>;
93  PreconditionerMap_["ICT stand-alone"] = &buildPreconditioner<Ifpack_ICT, true>;
94  PreconditionerMap_["ILU"] = &buildPreconditioner<Ifpack_ILU, false>;
95  PreconditionerMap_["ILU stand-alone"] = &buildPreconditioner<Ifpack_ILU, true>;
96  PreconditionerMap_["ILUT"] = &buildPreconditioner<Ifpack_ILUT, false>;
97  PreconditionerMap_["ILUT stand-alone"] = &buildPreconditioner<Ifpack_ILUT, true>;
98 
99 #ifdef HAVE_IFPACK_SPARSKIT
100  PreconditionerMap_["SPARSKIT"]
101  = &buildPreconditioner<Ifpack_SPARSKIT, true>;
102 #endif
103 
104 #ifdef HAVE_IFPACK_HIPS
105  PreconditionerMap_["HIPS"]
106  = &buildPreconditioner<Ifpack_HIPS, true>;
107 #endif
108 
109 #ifdef HAVE_HYPRE
110  PreconditionerMap_["Hypre"]
111  = &buildPreconditioner<Ifpack_Hypre, true>;
112 #endif
113 
114 #ifdef HAVE_IFPACK_SUPERLU
115  PreconditionerMap_["SILU"]
116  = &buildPreconditioner<Ifpack_SILU, true>;
117 #endif
118 
119  PreconditionerMap_["Chebyshev"]
120  = &buildPreconditioner<Ifpack_Chebyshev, true>;
121 
122 #ifdef HAVE_IFPACK_EPETRAEXT
123  PreconditionerMap_["IHSS"]
124  = &buildPreconditioner<Ifpack_IHSS, true>;
125  PreconditionerMap_["SORa"]
126  = &buildPreconditioner<Ifpack_SORa, true>;
127 #endif
128 
129  NumPreconditioners_ =
130  +5
131  #ifdef HAVE_IFPACK_AMESOS
132  +4
133  #endif
134  +8
135  #ifdef HAVE_IFPACK_SPARSKIT
136  +1
137  #endif
138  #ifdef HAVE_IFPACK_HIPS
139  +1
140  #endif
141  #ifdef HAVE_HYPRE
142  +1
143  #endif
144  #ifdef HAVE_IFPACK_SUPERLU
145  +1
146  #endif
147  +1
148  #ifdef HAVE_IFPACK_EPETRAEXT
149  +2
150  #endif
151  ;
152 
153  Initialized_ = true;
154  }
155 
156  return true;
157 }
158 
160  const std::string PrecName,
161  Ifpack_DynamicFactory::builderFunction PrecBuilder)
162 {
163  if (PreconditionerMap_.find(PrecName) == PreconditionerMap_.end()) {
164  PreconditionerMap_[PrecName] = PrecBuilder;
165  NumPreconditioners_++;
166  return 0;
167  }
168  return 1;
169 }
170 
171 void Ifpack_DynamicFactory::Print(std::ostream& os)
172 {
173  os << "Ifpack_DynamicFactory registered preconditioners: " << std::endl;
174  for (std::map<std::string, builderFunction>::const_iterator it = PreconditionerMap_.begin();
175  it != PreconditionerMap_.end(); ++it) {
176  os << it->first << std::endl;
177  }
178 }
179 
180 //==============================================================================
182  Epetra_RowMatrix* Matrix,
183  const int Overlap,
184  bool overrideSerialDefault)
185 {
186  bool serial = (Matrix->Comm().NumProc() == 1);
187 
188  std::map<std::string, builderFunction>::const_iterator it
189  = PreconditionerMap_.find(PrecType);
190  bool found = it != PreconditionerMap_.end();
191  if (found) {
192  builderFunction f = it->second;
193  return f(Matrix, Overlap, serial, overrideSerialDefault);
194  }
195 
196  return 0;
197 }
198 
199 // Let's initialize the factory upon compilation
200 namespace {
201  bool init = Ifpack_DynamicFactory::Initialize();
202 }
203 
static void Print(std::ostream &os=std::cout)
Prints the current list of registered preconditioners.
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
static bool Initialize()
Initializes the static data of the Ifpac_DynamicFactory class.
Ifpack_Preconditioner * Create(const string PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Creates an instance of Ifpack_Preconditioner given the string name of the preconditioner type (can fa...
static int RegisterPreconditioner(const std::string PrecName, builderFunction PrecBuilder)
Register a new preconditioner with the factory.