IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends Pages
Ifpack.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 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #include "Ifpack_ConfigDefs.h"
44 #include "Ifpack.h"
45 #include "Ifpack_Preconditioner.h"
46 #include "Ifpack_PointRelaxation.h"
47 #include "Ifpack_BlockRelaxation.h"
48 #include "Ifpack_IC.h"
49 #include "Ifpack_ICT.h"
50 #include "Ifpack_ILU.h"
51 #include "Ifpack_SILU.h"
52 #include "Ifpack_ILUT.h"
53 #include "Ifpack_SPARSKIT.h"
54 #include "Ifpack_AdditiveSchwarz.h"
55 #include "Ifpack_DenseContainer.h"
56 #include "Ifpack_SparseContainer.h"
57 #ifdef HAVE_IFPACK_AMESOS
58 #include "Ifpack_Amesos.h"
59 #endif
60 #ifdef HAVE_IFPACK_HIPS
61 #include "Ifpack_HIPS.h"
62 #endif
63 #ifdef HAVE_IFPACK_SUPERLU
64 #include "Ifpack_SILU.h"
65 #endif
66 
67 #include "Ifpack_Chebyshev.h"
68 #include "Ifpack_Polynomial.h"
69 #include "Ifpack_Krylov.h"
70 #include "Ifpack_IHSS.h"
71 #include "Ifpack_SORa.h"
72 
73 #include "Teuchos_CommandLineProcessor.hpp"
74 #include "Teuchos_StringToIntMap.hpp"
75 #include "Epetra_CrsMatrix.h"
76 
77 
78 namespace {
79 
80 const Teuchos::StringToIntMap
81 precTypeNameToIntMap(
82  "parameter \"Prec Type\"", Ifpack::numPrecTypes, Ifpack::precTypeNames
83  );
84 
85 } // namespace
86 
87 //==============================================================================
89 {
90  POINT_RELAXATION
91  ,POINT_RELAXATION_STAND_ALONE
92  ,BLOCK_RELAXATION
93  ,BLOCK_RELAXATION_STAND_ALONE
94  ,BLOCK_RELAXATION_STAND_ALONE_ILU
95  ,BLOCK_RELAXATION_STAND_ALONE_ILUT
96  ,BLOCK_RELAXATION_STAND_ALONE_IC
97 #ifdef HAVE_IFPACK_SUPERLU
98  ,BLOCK_RELAXATION_STAND_ALONE_SILU
99 #endif
100 #ifdef HAVE_IFPACK_AMESOS
101  ,BLOCK_RELAXATION_STAND_ALONE_AMESOS
102  ,BLOCK_RELAXATION_AMESOS
103  ,AMESOS
104  ,AMESOS_STAND_ALONE
105 #endif // HAVE_IFPACK_AMESOS
106  ,IC
107  ,IC_STAND_ALONE
108  ,ICT
109  ,ICT_STAND_ALONE
110  ,ILU
111  ,ILU_STAND_ALONE
112  ,ILUT
113  ,ILUT_STAND_ALONE
114 #ifdef HAVE_IFPACK_SPARSKIT
115  ,SPARSKIT
116 #endif // HAVE_IFPACK_SPARSKIT
117 #ifdef HAVE_IFPACK_HIPS
118  ,HIPS
119 #endif
120 #ifdef HAVE_HYPRE
121  ,HYPRE
122 #endif
123 #ifdef HAVE_IFPACK_SUPERLU
124  ,SILU
125 #endif
126  ,CHEBYSHEV
127  ,POLYNOMIAL
128  ,KRYLOV
129  ,IHSS
130  ,SORA
131 };
132 
133 //==============================================================================
135 {
136  "point relaxation"
137  ,"point relaxation stand-alone"
138  ,"block relaxation"
139  ,"block relaxation stand-alone"
140  ,"block relaxation stand-alone (ILU)"
141  ,"block relaxation stand-alone (ILUT)"
142  ,"block relaxation stand-alone (IC)"
143 #ifdef HAVE_IFPACK_SUPERLU
144  ,"block relaxation stand-alone (SILU)"
145 #endif
146 #ifdef HAVE_IFPACK_AMESOS
147  ,"block relaxation stand-alone (Amesos)"
148  ,"block relaxation (Amesos)"
149  ,"Amesos"
150  ,"Amesos stand-alone"
151 #endif
152  ,"IC"
153  ,"IC stand-alone"
154  ,"ICT"
155  ,"ICT stand-alone"
156  ,"ILU"
157  ,"ILU stand-alone"
158  ,"ILUT"
159  ,"ILUT stand-alone"
160 #ifdef HAVE_IFPACK_SPARSKIT
161  ,"SPARSKIT"
162 #endif
163 #ifdef HAVE_IFPACK_HIPS
164  ,"HIPS"
165 #endif
166 #ifdef HAVE_HYPRE
167  ,"Hypre"
168 #endif
169 #ifdef HAVE_IFPACK_SUPERLU
170  ,"SILU"
171 #endif
172  ,"Chebyshev"
173  ,"Polynomial"
174  ,"Krylov"
175  ,"IHSS"
176  ,"SORa"
177 };
178 
179 //==============================================================================
181 {
182  true // point relaxation
183  ,true // point relaxation stand-alone
184  ,true // block relaxation
185  ,true // block relaxation stand-alone
186  ,true // block relaxation stand-alone (ILU)
187  ,true // block relaxation stand-alone (ILUT)
188  ,false // block relaxation stand-alone (IC)
189 #ifdef HAVE_IFPACK_SUPERLU
190  ,true // block relaxation stand-alone (SILU)
191 #endif
192 #ifdef HAVE_IFPACK_AMESOS
193  ,true // block relaxation stand-alone (Amesos)
194  ,true // block relaxation (Amesos)
195  ,true // Amesos
196  ,true // Amesos stand-alone
197 #endif
198  ,false // IC
199  ,false // IC stand-alone
200  ,false // ICT
201  ,false // ICT stand-alone
202  ,true // ILU
203  ,true // ILU stand-alone
204  ,true // ILUT
205  ,true // ILUT stand-alone
206 #ifdef HAVE_IFPACK_SPARSKIT
207  ,true // SPARSKIT
208 #endif
209 #ifdef HAVE_IFPACK_HIPS
210  ,true // HIPS
211 #endif
212 #ifdef HAVE_HYPRE
213  ,true
214 #endif
215 #ifdef HAVE_IFPACK_SUPERLU
216  ,true // SuperLU's Supernodal ILUTP
217 #endif
218  ,false // CHEBYSHEV
219  ,true // POLYNOMIAL
220  ,true // KRYLOV
221  ,true // IHSS
222  ,true // SORa
223 };
224 
225 //==============================================================================
227  Epetra_RowMatrix* Matrix,
228  const int Overlap,
229  bool overrideSerialDefault)
230 {
231  const bool serial = (Matrix->Comm().NumProc() == 1);
232 
233  switch(PrecType) {
234  case POINT_RELAXATION:
235  if (serial && !overrideSerialDefault)
236  return(new Ifpack_PointRelaxation(Matrix));
237  else
238  return(new Ifpack_AdditiveSchwarz<Ifpack_PointRelaxation>(Matrix, Overlap));
239  case POINT_RELAXATION_STAND_ALONE:
240  return(new Ifpack_PointRelaxation(Matrix));
241  case BLOCK_RELAXATION:
242  if (serial && !overrideSerialDefault)
244  else
245  return(new Ifpack_AdditiveSchwarz<
247  case BLOCK_RELAXATION_STAND_ALONE:
249  case BLOCK_RELAXATION_STAND_ALONE_ILU:
251  case BLOCK_RELAXATION_STAND_ALONE_ILUT:
253  case BLOCK_RELAXATION_STAND_ALONE_IC:
255 #ifdef HAVE_IFPACK_SUPERLU
256  case BLOCK_RELAXATION_STAND_ALONE_SILU:
258 #endif
259 #ifdef HAVE_IFPACK_AMESOS
260  case BLOCK_RELAXATION_STAND_ALONE_AMESOS:
262  case BLOCK_RELAXATION_AMESOS:
263  return(new Ifpack_AdditiveSchwarz<
265  case AMESOS:
266  if (serial && !overrideSerialDefault)
267  return(new Ifpack_Amesos(Matrix));
268  else
269  return(new Ifpack_AdditiveSchwarz<Ifpack_Amesos>(Matrix,Overlap));
270  case AMESOS_STAND_ALONE:
271  return(new Ifpack_Amesos(Matrix));
272 #endif
273  case IC:
274  if (serial && !overrideSerialDefault)
275  return(new Ifpack_IC(Matrix));
276  else
277  return(new Ifpack_AdditiveSchwarz<Ifpack_IC>(Matrix,Overlap));
278  case IC_STAND_ALONE:
279  return(new Ifpack_IC(Matrix));
280  case ICT:
281  if (serial && !overrideSerialDefault)
282  return(new Ifpack_ICT(Matrix));
283  else
284  return(new Ifpack_AdditiveSchwarz<Ifpack_ICT>(Matrix,Overlap));
285  case ICT_STAND_ALONE:
286  return(new Ifpack_ICT(Matrix));
287  case ILU:
288  if (serial && !overrideSerialDefault)
289  return(new Ifpack_ILU(Matrix));
290  else
291  return(new Ifpack_AdditiveSchwarz<Ifpack_ILU>(Matrix,Overlap));
292  case ILU_STAND_ALONE:
293  return(new Ifpack_ILU(Matrix));
294  case ILUT:
295  if (serial && !overrideSerialDefault)
296  return(new Ifpack_ILUT(Matrix));
297  else
298  return(new Ifpack_AdditiveSchwarz<Ifpack_ILUT>(Matrix,Overlap));
299  case ILUT_STAND_ALONE:
300  return(new Ifpack_ILUT(Matrix));
301 #ifdef HAVE_IFPACK_SPARSKIT
302  case SPARSKIT:
303  return(new Ifpack_SPARSKIT(Matrix));
304 #endif
305 #ifdef HAVE_IFPACK_HIPS
306  case HIPS:
307  return(new Ifpack_HIPS(Matrix));
308 #endif
309 #ifdef HAVE_HYPRE
310  case HYPRE:
311  return(new Ifpack_Hypre(Matrix));
312 #endif
313 #ifdef HAVE_IFPACK_SUPERLU
314  case SILU:
315  return(new Ifpack_SILU(Matrix));
316 #endif
317  case CHEBYSHEV:
318  return(new Ifpack_Chebyshev(Matrix));
319  case POLYNOMIAL:
320  return(new Ifpack_Polynomial(Matrix));
321  case KRYLOV:
322  return(new Ifpack_Krylov(Matrix));
323 #ifdef HAVE_IFPACK_EPETRAEXT
324  case IHSS:
325  return(new Ifpack_IHSS(Matrix));
326  case SORA:
327  return(new Ifpack_SORa(Matrix));
328 #endif
329  default:
330  TEUCHOS_TEST_FOR_EXCEPT(true);
331  // The only way to get here is if some code developer does a cast like
332  // (EPrecType)(anyNumber). You can never get here by passing in a
333  // string value for the preconditioner!
334  } // end switch
335  return 0; // This will never ever be executed!
336 }
337 
338 //==============================================================================
339 Ifpack_Preconditioner* Ifpack::Create(const string PrecType,
340  Epetra_RowMatrix* Matrix,
341  const int Overlap,
342  bool overrideSerialDefault)
343 {
344  try {
345  return Ifpack::Create(Teuchos::get<EPrecType>(::precTypeNameToIntMap,PrecType),Matrix,Overlap,overrideSerialDefault);
346  }
347  catch( const Teuchos::StringToIntMap::DoesNotExist &excpt ) {
348  // The old implementation of this function just silently returned a NULL
349  // when a preconditiner type name was not recognized. If you like this
350  // behavior then you should use this function. If you do not like this
351  // behavior, then consider using the Ifpack/Thyra adapter
352  // Thyra::IfpackPreconditionerFactory or better yet the Stratimikos
353  // wrapper class Stratimikos::DefaultLinearSolverBuilder.
354  }
355  return 0;
356 }
357 
358 // ======================================================================
359 int Ifpack::SetParameters(int argc, char* argv[],
360  Teuchos::ParameterList& List, string& PrecType,
361  int& Overlap)
362 {
363  // THIS FUNCTION IS VERY INCOMPLETE...
364 
365  Teuchos::CommandLineProcessor CLP;
366 
367  // prec type
368  string ifp_prec_type = "ILU";
369  CLP.setOption("ifp-prec-type",&ifp_prec_type,"Preconditioner type");
370  // overlap among the processors
371  int ifp_overlap = 0;
372  CLP.setOption("ifp-overlap",&ifp_overlap,"Overlap among processors");
373  // relaxation type
374  string ifp_relax_type = "Jacobi";
375  CLP.setOption("ifp-relax-type",&ifp_relax_type,"Relaxation type");
376  // sweeps (for relax only)
377  int ifp_relax_sweeps = 1;
378  CLP.setOption("ifp-relax-sweeps",
379  &ifp_relax_sweeps,"Number of sweeps for relaxation");
380  // damping (for relax only)
381  double ifp_relax_damping = 1.0;
382  CLP.setOption("ifp-relax-damping",
383  &ifp_relax_damping,"Damping for relaxation");
384  // partitioner type (for block relaxation only)
385  string ifp_part_type = "greedy";
386  CLP.setOption("ifp-part-type",&ifp_part_type,"Partitioner type");
387  // number of local parts (for block relaxation only)
388  int ifp_part_local = 1;
389  CLP.setOption("ifp-part-local",&ifp_part_local,"number of local partitions");
390 
391  // allow users to specify other options for other packages
392  CLP.recogniseAllOptions(false);
393  CLP.throwExceptions(false);
394  CLP.parse(argc,argv);
395 
396  // I cannot really set those in the List, I pass them back to the user
397  PrecType = ifp_prec_type;
398  Overlap = ifp_overlap;
399 
400  // set the list here
401  List.set("relaxation: type", ifp_relax_type);
402  List.set("relaxation: sweeps", ifp_relax_sweeps);
403  List.set("relaxation: damping factor", ifp_relax_damping);
404  List.set("partitioner: type", ifp_part_type);
405  List.set("partitioner: local parts", ifp_part_local);
406 
407  return(0);
408 }
static const int numPrecTypes
Definition: Ifpack.h:187
Ifpack_BlockRelaxation: a class to define block relaxation preconditioners of Epetra_RowMatrix&#39;s.
static const EPrecType precTypeValues[numPrecTypes]
List of the preconditioner types as enum values .
Definition: Ifpack.h:209
EPrecType
Enum for the type of preconditioner.
Definition: Ifpack.h:142
A wrapper to SuperLU 4.0&#39;s supernodal ILUT w/ partial pivoting.
Definition: Ifpack_SILU.h:83
int SetParameters(int argc, char *argv[], Teuchos::ParameterList &List, string &PrecType, int &Overlap)
Sets the options in List from the command line.
Definition: Ifpack.cpp:359
static const char * precTypeNames[numPrecTypes]
List of preconditioner types as string values.
Definition: Ifpack.h:212
Ifpack_ILU: A class for constructing and using an incomplete lower/upper (ILU) factorization of a giv...
Definition: Ifpack_ILU.h:82
Ifpack_Amesos: a class to use Amesos&#39; factorizations as preconditioners.
Definition: Ifpack_Amesos.h:81
Ifpack_AdditiveSchwarz: a class to define Additive Schwarz preconditioners of Epetra_RowMatrix&#39;s.
Ifpack_SparseContainer: a class for storing and solving linear systems using sparse matrices...
Ifpack_Chebyshev: class for preconditioning with Chebyshev polynomials in Ifpack. ...
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
Ifpack_PointRelaxation: a class to define point relaxation preconditioners of for Epetra_RowMatrix&#39;s...
Ifpack_Polynomial: class for preconditioning with least squares polynomials in Ifpack.
Ifpack_Krylov: class for smoothing with Krylov solvers in Ifpack.
Definition: Ifpack_Krylov.h:81
Ifpack_IC: A class for constructing and using an incomplete Cholesky factorization of a given Epetra_...
Definition: Ifpack_IC.h:80
Ifpack_ICT: A class for constructing and using an incomplete Cholesky factorization of a given Epetra...
Definition: Ifpack_ICT.h:83
static Ifpack_Preconditioner * Create(EPrecType PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Creates an instance of Ifpack_Preconditioner given the enum value of the preconditioner type (can not...
Definition: Ifpack.cpp:226
static const bool supportsUnsymmetric[numPrecTypes]
List of bools that determines if the preconditioner type supports unsymmetric matrices.
Definition: Ifpack.h:216
Ifpack_ILUT: A class for constructing and using an incomplete LU factorization of a given Epetra_RowM...
Definition: Ifpack_ILUT.h:81