Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_OneLevelFactory_def.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated 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_DETAILS_ONELEVELFACTORY_DEF_HPP
44 #define IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
45 
46 #include "Ifpack2_Factory.hpp"
47 #include "Ifpack2_Utilities.hpp"
48 #include "Ifpack2_Chebyshev.hpp"
49 #include "Ifpack2_Details_DenseSolver.hpp"
50 #include "Ifpack2_Diagonal.hpp"
51 #include "Ifpack2_IdentitySolver.hpp"
52 #include "Ifpack2_ILUT.hpp"
53 #include "Ifpack2_MDF.hpp"
54 #include "Ifpack2_Relaxation.hpp"
55 #include "Ifpack2_RILUK.hpp"
56 #include "Ifpack2_Experimental_RBILUK.hpp"
57 #include "Ifpack2_BlockRelaxation.hpp"
58 #include "Ifpack2_BandedContainer.hpp"
59 #include "Ifpack2_DenseContainer.hpp"
60 #include "Ifpack2_DatabaseSchwarz.hpp"
61 #include "Ifpack2_SparseContainer.hpp"
62 #include "Ifpack2_TriDiContainer.hpp"
63 #include "Ifpack2_LocalSparseTriangularSolver.hpp"
64 #include "Ifpack2_Hiptmair.hpp"
65 
66 #ifdef HAVE_IFPACK2_SHYLU_NODEFASTILU
67 #include "Ifpack2_Details_Fic.hpp"
68 #include "Ifpack2_Details_Fildl.hpp"
69 #include "Ifpack2_Details_Filu.hpp"
70 #endif // HAVE_IFPACK2_SHYLU_NODEFASTILU
71 
72 #ifdef HAVE_IFPACK2_AMESOS2
73 # include "Ifpack2_Details_Amesos2Wrapper.hpp"
74 #endif // HAVE_IFPACK2_AMESOS2
75 
76 #ifdef HAVE_IFPACK2_HYPRE
77 # include "Ifpack2_Hypre.hpp"
78 #endif // HAVE_IFPACK2_HYPRE
79 
80 
81 namespace Ifpack2 {
82 namespace Details {
83 
84 template<class MatrixType>
86 OneLevelFactory<MatrixType>::create (const std::string& precType,
87  const Teuchos::RCP<const row_matrix_type>& matrix) const
88 {
89  using Teuchos::RCP;
90  using Teuchos::rcp;
91 
92  RCP<prec_type> prec;
93 
94  // precTypeUpper is the upper-case version of precType.
95  std::string precTypeUpper = canonicalize(precType);
96 
97  if (precTypeUpper == "CHEBYSHEV") {
98  // We have to distinguish Ifpack2::Chebyshev from its
99  // implementation class Ifpack2::Details::Chebyshev.
100  prec = rcp (new ::Ifpack2::Chebyshev<row_matrix_type> (matrix));
101  }
102  else if (precTypeUpper == "DENSE" || precTypeUpper == "LAPACK") {
103  prec = rcp (new Details::DenseSolver<row_matrix_type> (matrix));
104  }
105  else if (precTypeUpper == "AMESOS2") {
106 #ifdef HAVE_IFPACK2_AMESOS2
107  prec = rcp (new Details::Amesos2Wrapper<row_matrix_type> (matrix));
108 #else
110  true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory: "
111  "You may not ask for the preconditioner \"AMESOS2\" unless "
112  "you have built Trilinos with the Amesos2 package enabled.");
113 #endif // HAVE_IFPACK2_AMESOS2
114  }
115  else if (precTypeUpper == "DIAGONAL") {
116  prec = rcp (new Diagonal<row_matrix_type> (matrix));
117  }
118  else if (precTypeUpper == "ILUT") {
119  prec = rcp (new ILUT<row_matrix_type> (matrix));
120  }
121  else if (precTypeUpper == "RELAXATION") {
122  prec = rcp (new Relaxation<row_matrix_type> (matrix));
123  }
124  else if (precTypeUpper == "RILUK") {
125  prec = rcp (new RILUK<row_matrix_type> (matrix));
126  }
127  else if (precTypeUpper == "MDF") {
128  prec = rcp (new MDF<row_matrix_type> (matrix));
129  }
130  else if (precTypeUpper == "RBILUK") {
131  prec = rcp (new Experimental::RBILUK<row_matrix_type>(matrix));
132  }
133  else if (precTypeUpper == "FAST_IC" || precTypeUpper == "FAST_ILU" || precTypeUpper == "FAST_ILU_B" || precTypeUpper == "FAST_ILDL") {
134  #ifdef HAVE_IFPACK2_SHYLU_NODEFASTILU
135  {
136  if(precTypeUpper == "FAST_IC")
138  else if(precTypeUpper == "FAST_ILU")
140  else if(precTypeUpper == "FAST_ILU_B")
142  else if(precTypeUpper == "FAST_ILDL")
144  }
145  #else
146  {
147  throw std::invalid_argument("The Ifpack2 FastIC, FastILU and FastILDL preconditioners require the FastILU subpackage of ShyLU to be enabled\n"
148  "To enable FastILU, set the CMake option Trilinos_ENABLE_ShyLU_NodeFastILU=ON");
149  }
150  #endif
151  }
152  else if (precTypeUpper == "KRYLOV") {
154  (true, std::invalid_argument, "The \"KRYLOV\" preconditioner option has "
155  "been deprecated and removed. If you want a Krylov solver, use the "
156  "Belos package.");
157  }
158  else if (precTypeUpper == "BLOCK_RELAXATION" ||
159  precTypeUpper == "BLOCK RELAXATION" ||
160  precTypeUpper == "BLOCKRELAXATION" ||
161  precTypeUpper == "DENSE_BLOCK_RELAXATION" ||
162  precTypeUpper == "DENSE BLOCK RELAXATION" ||
163  precTypeUpper == "DENSEBLOCKRELAXATION" ) {
164  // NOTE (mfh 12 Aug 2016) Choice of "container type" is now a
165  // run-time parameter. The "ContainerType" template parameter is
166  // now always Container<row_matrix_type>.
167  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
168  Teuchos::ParameterList params;
169  params.set ("relaxation: container", "Dense");
170  prec->setParameters (params);
171  }
172  else if (precTypeUpper == "DATABASE SCHWARZ") {
173  prec = rcp (new DatabaseSchwarz<row_matrix_type> (matrix));
174  }
175  else if (precTypeUpper == "SPARSE_BLOCK_RELAXATION" ||
176  precTypeUpper == "SPARSE BLOCK RELAXATION" ||
177  precTypeUpper == "SPARSEBLOCKRELAXATION" ) {
178  // FIXME (mfh 22 May 2014) We would prefer to have the choice of
179  // dense or sparse blocks (the "container type") be a run-time
180  // decision. This will require refactoring BlockRelaxation so
181  // that the "container type" is not a template parameter. For
182  // now, we default to use dense blocks.
183  //typedef SparseContainer<row_matrix_type, ILUT<row_matrix_type>> container_type;
184 #ifdef HAVE_IFPACK2_AMESOS2
185  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
186  Teuchos::ParameterList params;
187  params.set ("relaxation: container", "SparseAmesos2");
188  prec->setParameters (params);
189 #else
191  (true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory: "
192  "\"SPARSE BLOCK RELAXATION\" requires building Trilinos with Amesos2 enabled.");
193 #endif
194  }
195  else if (precTypeUpper == "TRIDI_RELAXATION" ||
196  precTypeUpper == "TRIDI RELAXATION" ||
197  precTypeUpper == "TRIDIRELAXATION" ||
198  precTypeUpper == "TRIDIAGONAL_RELAXATION" ||
199  precTypeUpper == "TRIDIAGONAL RELAXATION" ||
200  precTypeUpper == "TRIDIAGONALRELAXATION") {
201  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
202  Teuchos::ParameterList params;
203  params.set ("relaxation: container", "TriDi");
204  prec->setParameters (params);
205  }
206  else if (precTypeUpper == "BANDED_RELAXATION" ||
207  precTypeUpper == "BANDED RELAXATION" ||
208  precTypeUpper == "BANDEDRELAXATION") {
209  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
210  Teuchos::ParameterList params;
211  params.set ("relaxation: container", "Banded");
212  prec->setParameters (params);
213  }
214  else if (precTypeUpper == "IDENTITY" || precTypeUpper == "IDENTITY_SOLVER") {
215  prec = rcp (new IdentitySolver<row_matrix_type> (matrix));
216  }
217 
218  else if (precTypeUpper == "LOCAL SPARSE TRIANGULAR SOLVER" ||
219  precTypeUpper == "LOCAL_SPARSE_TRIANGULAR_SOLVER" ||
220  precTypeUpper == "LOCALSPARSETRIANGULARSOLVER" ||
221  precTypeUpper == "SPARSE TRIANGULAR SOLVER" ||
222  precTypeUpper == "SPARSE_TRIANGULAR_SOLVER" ||
223  precTypeUpper == "SPARSETRIANGULARSOLVER") {
225  }
226  else if(precTypeUpper == "HIPTMAIR") {
227  prec = rcp (new Hiptmair<row_matrix_type> (matrix));
228  }
229 #ifdef HAVE_IFPACK2_HYPRE
230  else if (precTypeUpper == "HYPRE") {
231  prec = rcp (new Hypre<row_matrix_type> (matrix));
232  }
233 #endif
234  else {
236  true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory::create: "
237  "Invalid preconditioner type \"" << precType << "\".");
238  }
239 
241  prec.is_null (), std::logic_error, "Ifpack2::Details::OneLevelFactory::"
242  "create: Return value is null right before return. This should never "
243  "happen. Please report this bug to the Ifpack2 developers.");
244  return prec;
245 }
246 
247 template<class MatrixType>
248 bool
249 OneLevelFactory<MatrixType>::isSupported (const std::string& precType) const
250 {
251  // precTypeUpper is the upper-case version of precType.
252  std::string precTypeUpper = canonicalize(precType);
253  std::vector<std::string> supportedNames = {
254  "CHEBYSHEV", "DENSE", "LAPACK",
255 #ifdef HAVE_IFPACK2_AMESOS2
256  "AMESOS2",
257 #endif
258  "DIAGONAL", "ILUT", "RELAXATION", "RILUK", "RBILUK", "MDF",
259 #ifdef HAVE_IFPACK2_SHYLU_NODEFASTILU
260  "FAST_IC", "FAST_ILU", "FAST_ILU_B", "FAST_ILDL",
261 #endif
262  "BLOCK_RELAXATION", "BLOCK RELAXATION", "BLOCKRELAXATION", "DENSE_BLOCK_RELAXATION", "DENSE BLOCK RELAXATION", "DENSEBLOCKRELAXATION",
263  "DATABASE SCHWARZ",
264 #ifdef HAVE_IFPACK2_AMESOS2
265  "SPARSE_BLOCK_RELAXATION", "SPARSE BLOCK RELAXATION", "SPARSEBLOCKRELAXATION",
266 #endif
267  #ifdef HAVE_IFPACK2_HYPRE
268  "HYPRE",
269 #endif
270  "TRIDI_RELAXATION", "TRIDI RELAXATION", "TRIDIRELAXATION", "TRIDIAGONAL_RELAXATION", "TRIDIAGONAL RELAXATION", "TRIDIAGONALRELAXATION",
271  "BANDED_RELAXATION", "BANDED RELAXATION", "BANDEDRELAXATION",
272  "IDENTITY", "IDENTITY_SOLVER",
273  "LOCAL SPARSE TRIANGULAR SOLVER", "LOCAL_SPARSE_TRIANGULAR_SOLVER", "LOCALSPARSETRIANGULARSOLVER", "SPARSE TRIANGULAR SOLVER", "SPARSE_TRIANGULAR_SOLVER", "SPARSETRIANGULARSOLVER",
274  "HIPTMAIR"
275  };
276  // const size_t numSupportedNames = supportedNames.size();
277  // const auto end = supportedNames + numSupportedNames;
278  auto it = std::find(std::begin(supportedNames), std::end(supportedNames), precTypeUpper);
279  return it != std::end(supportedNames);
280 }
281 
282 } // namespace Details
283 } // namespace Ifpack2
284 
285 #define IFPACK2_DETAILS_ONELEVELFACTORY_INSTANT(S,LO,GO,N) \
286  template class Ifpack2::Details::OneLevelFactory< Tpetra::RowMatrix<S, LO, GO, N> >;
287 
288 #endif // IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
MDF (incomplete LU factorization with minimum discarded fill reordering) of a Tpetra sparse matrix...
Definition: Ifpack2_MDF_decl.hpp:83
Teuchos::RCP< prec_type > create(const std::string &precType, const Teuchos::RCP< const row_matrix_type > &matrix) const
Create an instance of Preconditioner given the string name of the preconditioner type.
Definition: Ifpack2_Details_OneLevelFactory_def.hpp:86
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ILU(k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:245
&quot;Preconditioner&quot; that uses LAPACK&#39;s dense LU.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:75
The Ifpack2 wrapper to the ILDL preconditioner of ShyLU FastILU.
Definition: Ifpack2_Details_Fildl_decl.hpp:62
The Ifpack2 wrapper to the ILU preconditioner of ShyLU FastILU.
Definition: Ifpack2_Details_Filu_decl.hpp:62
ILUT (incomplete LU factorization with threshold) of a Tpetra sparse matrix.
Definition: Ifpack2_ILUT_decl.hpp:93
Block relaxation preconditioners (or smoothers) for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse ma...
Definition: Ifpack2_BlockRelaxation_decl.hpp:82
&quot;Identity&quot; preconditioner.
Definition: Ifpack2_IdentitySolver_decl.hpp:60
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Wrapper for Hiptmair smoothers.
Definition: Ifpack2_Hiptmair_decl.hpp:71
Wrapper class for direct solvers in Amesos2.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:102
&quot;Preconditioner&quot; that solves local sparse triangular systems.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:79
File for utility functions.
ParameterList & setParameters(const ParameterList &source)
Overlapping Schwarz where redundant patches are not stored explicitly.
Definition: Ifpack2_DatabaseSchwarz_decl.hpp:97
The Ifpack2 wrapper to the incomplete Chebyshev preconditioner of ShyLU FastILU.
Definition: Ifpack2_Details_Fic_decl.hpp:62
&quot;Factory&quot; for creating single-level preconditioners.
Definition: Ifpack2_Details_OneLevelFactory_decl.hpp:125
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:237
ILU(k) factorization of a given Tpetra::BlockCrsMatrix.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:128