Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Container.hpp
Go to the documentation of this file.
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_CONTAINER_HPP
44 #define IFPACK2_CONTAINER_HPP
45 
48 
49 #include <Ifpack2_ConfigDefs.hpp>
50 #include <Tpetra_RowMatrix.hpp>
51 #include <Teuchos_ParameterList.hpp>
52 #include <Teuchos_Describable.hpp>
53 #include <iostream>
54 #include <type_traits>
55 
56 namespace Ifpack2 {
57 
102 template<class MatrixType>
103 class Container : public Teuchos::Describable {
104 public:
105  typedef typename MatrixType::scalar_type scalar_type;
106  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
107  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
108  typedef typename MatrixType::node_type node_type;
109 
110  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
111 
112  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
113  "Ifpack2::Container: Please use MatrixType = Tpetra::RowMatrix.");
114 
126  Container (const Teuchos::RCP<const row_matrix_type>& matrix,
127  const Teuchos::ArrayView<const local_ordinal_type>& localRows) :
128  inputMatrix_ (matrix),
129  localRows_ (localRows.begin (), localRows.end ())
130  {
131  TEUCHOS_TEST_FOR_EXCEPTION(
132  matrix.is_null (), std::invalid_argument, "Ifpack2::Container: "
133  "The constructor's input matrix must be non-null.");
134  }
135 
137  virtual ~Container() {};
138 
147  Teuchos::RCP<const row_matrix_type> getMatrix() const {
148  return inputMatrix_;
149  }
150 
152  virtual size_t getNumRows() const = 0;
153 
169  Teuchos::ArrayView<const local_ordinal_type> getLocalRows () const {
170  return localRows_ ();
171  }
172 
181  virtual void initialize () = 0;
182 
188  virtual void compute () = 0;
189 
191  virtual void setParameters (const Teuchos::ParameterList& List) = 0;
192 
194  virtual bool isInitialized () const = 0;
195 
197  virtual bool isComputed () const = 0;
198 
211  virtual void
212  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
213  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
214  Teuchos::ETransp mode = Teuchos::NO_TRANS,
215  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
216  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const = 0;
217 
238  virtual void
239  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
240  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
241  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
242  Teuchos::ETransp mode = Teuchos::NO_TRANS,
243  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
244  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const = 0;
245 
247  virtual std::ostream& print (std::ostream& os) const = 0;
248 
249 private:
251  Teuchos::RCP<const row_matrix_type> inputMatrix_;
252 
254  Teuchos::Array<local_ordinal_type> localRows_;
255 };
256 
258 template <class MatrixType>
259 inline std::ostream&
260 operator<< (std::ostream& os, const Ifpack2::Container<MatrixType>& obj)
261 {
262  return obj.print (os);
263 }
264 
265 }
266 
267 #endif // IFPACK2_CONTAINER_HPP
virtual void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const =0
Compute Y := alpha * M^{-1} X + beta*Y.
virtual void initialize()=0
Do all set-up operations that only require matrix structure.
Teuchos::ArrayView< const local_ordinal_type > getLocalRows() const
Local indices of the rows of the input matrix that belong to this block.
Definition: Ifpack2_Container.hpp:169
virtual size_t getNumRows() const =0
The number of rows in the diagonal block.
virtual bool isComputed() const =0
Return true if the container has been successfully computed.
virtual void weightedApply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &D, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const =0
Compute Y := alpha * diag(D) * M^{-1} (diag(D) * X) + beta*Y.
virtual void compute()=0
Extract the local diagonal block and prepare the solver.
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:103
virtual void setParameters(const Teuchos::ParameterList &List)=0
Set parameters.
virtual std::ostream & print(std::ostream &os) const =0
Print basic information about the container to os.
virtual ~Container()
Destructor.
Definition: Ifpack2_Container.hpp:137
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
Container(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::ArrayView< const local_ordinal_type > &localRows)
Constructor.
Definition: Ifpack2_Container.hpp:126
virtual bool isInitialized() const =0
Return true if the container has been successfully initialized.
Teuchos::RCP< const row_matrix_type > getMatrix() const
The input matrix to the constructor.
Definition: Ifpack2_Container.hpp:147