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