Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Details_ContainerFactory.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_CONTAINERFACTORY_H
44 #define IFPACK2_DETAILS_CONTAINERFACTORY_H
45 
46 #include "Ifpack2_Container.hpp"
47 #include "Ifpack2_TriDiContainer.hpp"
48 #include "Ifpack2_DenseContainer.hpp"
49 #include "Ifpack2_SparseContainer.hpp"
50 #include "Ifpack2_BandedContainer.hpp"
51 #include "Ifpack2_Partitioner.hpp"
52 #include "Ifpack2_ILUT_decl.hpp"
53 #ifdef HAVE_IFPACK2_AMESOS2
54 # include "Ifpack2_Details_Amesos2Wrapper.hpp"
55 #endif
56 #include "Tpetra_RowMatrix_decl.hpp"
57 #include "Teuchos_RCP.hpp"
58 #include "Teuchos_Ptr.hpp"
59 #include "Teuchos_ArrayViewDecl.hpp"
60 #include <string>
61 
62 
63 namespace Ifpack2 {
64 namespace Details {
65 
66 //Based on the ETIs at the bottom of BlockRelaxation_def, these are all the supported container types:
67 //pass one of these as the container name
68 
69 //Dense
70 //SparseILUT
71 //SparseAmesos
72 //TriDi
73 //Banded
74 
75 template <typename MatrixType>
76 Teuchos::RCP< ::Ifpack2::Container< ::Tpetra::RowMatrix<typename MatrixType::scalar_type,
77  typename MatrixType::local_ordinal_type,
78  typename MatrixType::global_ordinal_type,
79  typename MatrixType::node_type> > >
80 createContainer (const std::string& containerName,
81  const Teuchos::RCP< const MatrixType>& A,
82  const Teuchos::Array< Teuchos::Array< typename MatrixType::local_ordinal_type> >& localRows,
83  const Teuchos::RCP<const Tpetra::Import<typename MatrixType::local_ordinal_type,
84  typename MatrixType::global_ordinal_type,
85  typename MatrixType::node_type> > importer,
86  int OverlapLevel,
87  typename MatrixType::scalar_type DampingFactor)
88 {
89  using Teuchos::rcp;
90  typedef Tpetra::RowMatrix<typename MatrixType::scalar_type,
91  typename MatrixType::local_ordinal_type,
92  typename MatrixType::global_ordinal_type,
93  typename MatrixType::node_type> row_matrix_type;
94  // Use std::decay to remove const-ness and references.
95  static_assert (std::is_same<typename std::decay<MatrixType>::type, row_matrix_type>::value,
96  "MatrixType must be a Tpetra::RowMatrix specialization.");
97 
98  if (containerName == "TriDi") {
99  return rcp (new TriDiContainer<MatrixType, typename MatrixType::scalar_type> (A, localRows, importer, OverlapLevel, DampingFactor));
100  }
101  else if (containerName == "Dense") {
102  return rcp (new DenseContainer<MatrixType, typename MatrixType::scalar_type> (A, localRows, importer, OverlapLevel, DampingFactor));
103  }
104  else if (containerName == "SparseILUT") {
105  return rcp (new SparseContainer<MatrixType, ILUT<MatrixType> > (A, localRows, importer, OverlapLevel, DampingFactor));
106  }
107 #ifdef HAVE_IFPACK2_AMESOS2
108  else if (containerName == "SparseAmesos2" || containerName == "SparseAmesos") {
109  return rcp (new SparseContainer<MatrixType, Amesos2Wrapper<MatrixType> > (A, localRows, importer, OverlapLevel, DampingFactor));
110  }
111 #endif
112  else if (containerName == "Banded") {
113  return rcp (new BandedContainer<MatrixType, typename MatrixType::scalar_type> (A, localRows, importer, OverlapLevel, DampingFactor));
114  }
115 
116  TEUCHOS_TEST_FOR_EXCEPTION
117  (true, std::invalid_argument, "Ifpack2::Details::createContainer: Input "
118  "argument containerName=\"" << containerName << "\" is invalid. Valid "
119  "values include: \"TriDi\", \"Dense\", \"SparseILUT\", \"SparseAmesos2\", "
120  "and \"Banded\".");
121 }
122 
123 } // namespace Details
124 } // namespace Ifpack2
125 
126 #endif // IFPACK2_DETAILS_CONTAINERFACTORY_H
Ifpack2::Container class declaration.
Ifpack2 implementation details.
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:114
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
Declaration of ILUT preconditioner.