Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Details_OneLevelFactory_def.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_DETAILS_ONELEVELFACTORY_DEF_HPP
44 #define IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
45 
46 #include "Ifpack2_Chebyshev.hpp"
47 #include "Ifpack2_Details_DenseSolver.hpp"
48 #include "Ifpack2_Diagonal.hpp"
49 #include "Ifpack2_IdentitySolver.hpp"
50 #include "Ifpack2_ILUT.hpp"
51 #include "Ifpack2_Relaxation.hpp"
52 #include "Ifpack2_RILUK.hpp"
53 #include "Ifpack2_Experimental_RBILUK.hpp"
54 #include "Ifpack2_BlockRelaxation.hpp"
55 #include "Ifpack2_BandedContainer.hpp"
56 #include "Ifpack2_DenseContainer.hpp"
57 #include "Ifpack2_SparseContainer.hpp"
58 #include "Ifpack2_TriDiContainer.hpp"
59 #include "Ifpack2_LocalSparseTriangularSolver.hpp"
60 
61 #ifdef HAVE_IFPACK2_AMESOS2
62 # include "Ifpack2_Details_Amesos2Wrapper.hpp"
63 #endif // HAVE_IFPACK2_AMESOS2
64 
65 namespace Ifpack2 {
66 namespace Details {
67 
68 template<class MatrixType>
69 Teuchos::RCP<typename OneLevelFactory<MatrixType>::prec_type>
70 OneLevelFactory<MatrixType>::create (const std::string& precType,
71  const Teuchos::RCP<const row_matrix_type>& matrix) const
72 {
73  using Teuchos::RCP;
74  using Teuchos::rcp;
75 
76  RCP<prec_type> prec;
77 
78  // precTypeUpper is the upper-case version of precType.
79  std::string precTypeUpper (precType);
80  if (precTypeUpper.size () > 0) {
81  std::locale locale;
82  for (size_t k = 0; k < precTypeUpper.size (); ++k) {
83  precTypeUpper[k] = std::toupper<char> (precTypeUpper[k], locale);
84  }
85  }
86 
87  if (precTypeUpper == "CHEBYSHEV") {
88  // We have to distinguish Ifpack2::Chebyshev from its
89  // implementation class Ifpack2::Details::Chebyshev.
90  prec = rcp (new ::Ifpack2::Chebyshev<row_matrix_type> (matrix));
91  }
92  else if (precTypeUpper == "DENSE" || precTypeUpper == "LAPACK") {
93  prec = rcp (new Details::DenseSolver<row_matrix_type> (matrix));
94  }
95  else if (precTypeUpper == "AMESOS2") {
96 #ifdef HAVE_IFPACK2_AMESOS2
97  prec = rcp (new Details::Amesos2Wrapper<row_matrix_type> (matrix));
98 #else
99  TEUCHOS_TEST_FOR_EXCEPTION(
100  true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory: "
101  "You may not ask for the preconditioner \"AMESOS2\" unless "
102  "you have built Trilinos with the Amesos2 package enabled.");
103 #endif // HAVE_IFPACK2_AMESOS2
104  }
105  else if (precTypeUpper == "DIAGONAL") {
106  prec = rcp (new Diagonal<row_matrix_type> (matrix));
107  }
108  else if (precTypeUpper == "ILUT") {
109  prec = rcp (new ILUT<row_matrix_type> (matrix));
110  }
111  else if (precTypeUpper == "RELAXATION") {
112  prec = rcp (new Relaxation<row_matrix_type> (matrix));
113  }
114  else if (precTypeUpper == "RILUK") {
115  prec = rcp (new RILUK<row_matrix_type> (matrix));
116  }
117  else if (precTypeUpper == "RBILUK") {
118  prec = rcp (new Experimental::RBILUK<row_matrix_type>(matrix));
119  }
120  else if (precTypeUpper == "KRYLOV") {
121  TEUCHOS_TEST_FOR_EXCEPTION
122  (true, std::invalid_argument, "The \"KRYLOV\" preconditioner option has "
123  "been deprecated and removed. If you want a Krylov solver, use the "
124  "Belos package.");
125  }
126  else if (precTypeUpper == "BLOCK_RELAXATION" ||
127  precTypeUpper == "BLOCK RELAXATION" ||
128  precTypeUpper == "BLOCKRELAXATION" ||
129  precTypeUpper == "DENSE_BLOCK_RELAXATION" ||
130  precTypeUpper == "DENSE BLOCK RELAXATION" ||
131  precTypeUpper == "DENSEBLOCKRELAXATION" ) {
132  // NOTE (mfh 12 Aug 2016) Choice of "container type" is now a
133  // run-time parameter. The "ContainerType" template parameter is
134  // now always Container<row_matrix_type>.
135  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
136  Teuchos::ParameterList params;
137  params.set ("relaxation: container", "Dense");
138  prec->setParameters (params);
139  }
140  else if (precTypeUpper == "SPARSE_BLOCK_RELAXATION" ||
141  precTypeUpper == "SPARSE BLOCK RELAXATION" ||
142  precTypeUpper == "SPARSEBLOCKRELAXATION" ) {
143  // FIXME (mfh 22 May 2014) We would prefer to have the choice of
144  // dense or sparse blocks (the "container type") be a run-time
145  // decision. This will require refactoring BlockRelaxation so
146  // that the "container type" is not a template parameter. For
147  // now, we default to use dense blocks.
148  //typedef SparseContainer<row_matrix_type, ILUT<row_matrix_type>> container_type;
149 #ifdef HAVE_IFPACK2_AMESOS2
150  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
151  Teuchos::ParameterList params;
152  params.set ("relaxation: container", "SparseAmesos2");
153  prec->setParameters (params);
154 #else
155  TEUCHOS_TEST_FOR_EXCEPTION
156  (true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory: "
157  "\"SPARSE BLOCK RELAXATION\" requires building Trilinos with Amesos2 enabled.");
158 #endif
159  }
160  else if (precTypeUpper == "TRIDI_RELAXATION" ||
161  precTypeUpper == "TRIDI RELAXATION" ||
162  precTypeUpper == "TRIDIRELAXATION" ||
163  precTypeUpper == "TRIDIAGONAL_RELAXATION" ||
164  precTypeUpper == "TRIDIAGONAL RELAXATION" ||
165  precTypeUpper == "TRIDIAGONALRELAXATION") {
166  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
167  Teuchos::ParameterList params;
168  params.set ("relaxation: container", "TriDi");
169  prec->setParameters (params);
170  }
171  else if (precTypeUpper == "BANDED_RELAXATION" ||
172  precTypeUpper == "BANDED RELAXATION" ||
173  precTypeUpper == "BANDEDRELAXATION") {
174  prec = rcp (new BlockRelaxation<row_matrix_type> (matrix));
175  Teuchos::ParameterList params;
176  params.set ("relaxation: container", "Banded");
177  prec->setParameters (params);
178  }
179  else if (precTypeUpper == "IDENTITY" || precTypeUpper == "IDENTITY_SOLVER") {
180  prec = rcp (new IdentitySolver<row_matrix_type> (matrix));
181  }
182 
183  else if (precTypeUpper == "LOCAL SPARSE TRIANGULAR SOLVER" ||
184  precTypeUpper == "LOCAL_SPARSE_TRIANGULAR_SOLVER" ||
185  precTypeUpper == "LOCALSPARSETRIANGULARSOLVER" ||
186  precTypeUpper == "SPARSE TRIANGULAR SOLVER" ||
187  precTypeUpper == "SPARSE_TRIANGULAR_SOLVER" ||
188  precTypeUpper == "SPARSETRIANGULARSOLVER") {
189  prec = rcp (new LocalSparseTriangularSolver<row_matrix_type> (matrix));
190  }
191  else {
192  TEUCHOS_TEST_FOR_EXCEPTION(
193  true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory::create: "
194  "Invalid preconditioner type \"" << precType << "\".");
195  }
196 
197  TEUCHOS_TEST_FOR_EXCEPTION(
198  prec.is_null (), std::logic_error, "Ifpack2::Details::OneLevelFactory::"
199  "create: Return value is null right before return. This should never "
200  "happen. Please report this bug to the Ifpack2 developers.");
201  return prec;
202 }
203 
204 } // namespace Details
205 } // namespace Ifpack2
206 
207 #define IFPACK2_DETAILS_ONELEVELFACTORY_INSTANT(S,LO,GO,N) \
208  template class Ifpack2::Details::OneLevelFactory< Tpetra::RowMatrix<S, LO, GO, N> >;
209 
210 #endif // IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
ILU(k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:254
"Preconditioner" that uses LAPACK&#39;s dense LU.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:73
ILUT (incomplete LU factorization with threshold) of a Tpetra sparse matrix.
Definition: Ifpack2_ILUT_decl.hpp:91
Block relaxation preconditioners (or smoothers) for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse ma...
Definition: Ifpack2_BlockRelaxation_decl.hpp:83
Ifpack2 implementation details.
"Identity" preconditioner.
Definition: Ifpack2_IdentitySolver_decl.hpp:59
Wrapper class for direct solvers in Amesos2.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:102
"Preconditioner" that solves local sparse triangular systems.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:83
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:226
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
ILU(k) factorization of a given Tpetra::Experimental::BlockCrsMatrix.
Definition: Ifpack2_Experimental_RBILUK_decl.hpp:128
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:70