Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Factory.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) 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 #ifndef IFPACK2_FACTORY_HPP
44 #define IFPACK2_FACTORY_HPP
45 
46 #include "Ifpack2_ConfigDefs.hpp"
47 #include "Ifpack2_Preconditioner.hpp"
48 #include "Ifpack2_Relaxation.hpp"
49 #include "Ifpack2_Diagonal.hpp"
50 #include "Ifpack2_Chebyshev.hpp"
51 #include "Ifpack2_RILUK.hpp"
52 #include "Ifpack2_ILUT.hpp"
53 #include "Ifpack2_Krylov.hpp"
54 #include "Ifpack2_AdditiveSchwarz.hpp"
55 
57 namespace Ifpack2 {
58 
61 bool supportsUnsymmetric(const std::string& prec_type);
62 
64 
117 class Factory {
118 public:
119 
134  template<class MatrixType>
135  static
136  Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type,
137  typename MatrixType::local_ordinal_type,
138  typename MatrixType::global_ordinal_type,
139  typename MatrixType::node_type> >
140  create(const std::string& prec_type,
141  const Teuchos::RCP<const MatrixType>& matrix,
142  const int overlap = 0);
143 };
144 
147 
148 template<class MatrixType>
149 Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> >
150 Factory::create(const std::string& prec_type,
151  const Teuchos::RCP<const MatrixType>& matrix,
152  const int overlap)
153 {
154  typedef typename MatrixType::scalar_type Scalar;
155  typedef typename MatrixType::local_ordinal_type LocalOrdinal;
156  typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
157  typedef typename MatrixType::node_type Node;
158  (void)overlap;
159  Teuchos::RCP<Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> > prec;
160 
161  bool one_mpi_rank=(matrix->getComm()->getSize()==1);
162 
163  if (prec_type == "ILUT") {
164  /* Note: ILUT doesn't work for multiple MPI ranks... you have to use AdditiveSchwarz */
165  if(one_mpi_rank) prec = Teuchos::rcp(new Ifpack2::ILUT<MatrixType>(matrix));
166  else prec = Teuchos::rcp(new Ifpack2::AdditiveSchwarz<MatrixType,Ifpack2::ILUT<MatrixType> >(matrix,overlap));
167  }
168  else if (prec_type == "RILUK") {
169  prec = Teuchos::rcp(new Ifpack2::RILUK<MatrixType>(matrix));
170  }
171  else if (prec_type == "RELAXATION") {
172  prec = Teuchos::rcp(new Ifpack2::Relaxation<MatrixType>(matrix));
173  }
174  else if (prec_type == "CHEBYSHEV") {
175  prec = Teuchos::rcp(new Ifpack2::Chebyshev<MatrixType>(matrix));
176  }
177  else if (prec_type == "DIAGONAL") {
178  prec = Teuchos::rcp(new Ifpack2::Diagonal<MatrixType>(matrix));
179  }
180  else if (prec_type == "SCHWARZ") {
181  prec = Teuchos::rcp(new Ifpack2::AdditiveSchwarz<MatrixType,Ifpack2::ILUT<MatrixType> >(matrix,overlap));
182  }
183  else if (prec_type == "KRYLOV") {
184  prec = Teuchos::rcp(new Ifpack2::Krylov< MatrixType,Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(matrix));
185  }
186  else {
187  std::ostringstream os;
188  os << "Ifpack2::Factory::Create ERROR, invalid preconditioner type ("
189  << prec_type << ")";
190  std::string str = os.str();
191  throw std::runtime_error(str);
192  }
193  return prec;
194 }
195 
196 } //namespace Ifpack2
197 
198 #endif
A class for diagonal preconditioning.
Definition: Ifpack2_Diagonal_decl.hpp:68
ILU(k) (incomplete LU with fill level k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:214
bool supportsUnsymmetric(const std::string &prec_type)
Return true if the specified preconditioner type supports unsymmetric matrices.
Definition: Ifpack2_Factory.cpp:49
ILUT incomplete factorization of a Tpetra sparse matrix.
Definition: Ifpack2_ILUT_decl.hpp:96
Base class for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:130
A class for constructing and using a CG/GMRES smoother.
Definition: Ifpack2_Krylov_decl.hpp:110
Additive Schwarz domain decomposition for Tpetra::RowMatrix objects.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:123
A factory class to create Ifpack2 preconditioners.
Definition: Ifpack2_Factory.hpp:117
static Teuchos::RCP< Ifpack2::Preconditioner< typename MatrixType::scalar_type, typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type > > create(const std::string &prec_type, const Teuchos::RCP< const MatrixType > &matrix, const int overlap=0)
Creates an instance of Ifpack2_Preconditioner given the string name of the preconditioner type (throw...
Definition: Ifpack2_Factory.hpp:150
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:231
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67