Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_SparseContainer_decl.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_SPARSECONTAINER_DECL_HPP
44 #define IFPACK2_SPARSECONTAINER_DECL_HPP
45 
48 
49 #include "Ifpack2_Container.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 #include "Tpetra_Map.hpp"
53 #include "Tpetra_RowMatrix.hpp"
54 #include "Tpetra_CrsMatrix.hpp"
55 #include "Teuchos_ParameterList.hpp"
56 
57 
58 namespace Ifpack2 {
59 
129 template<typename MatrixType, typename InverseType>
130 class SparseContainer : public Container<MatrixType> {
131 public:
133 
134 
141  typedef MatrixType matrix_type;
147  typedef InverseType inverse_type;
148 
150  typedef typename MatrixType::scalar_type scalar_type;
152  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
154  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
156  typedef typename MatrixType::node_type node_type;
157 
158  static_assert(std::is_same<MatrixType,
159  Tpetra::RowMatrix<typename MatrixType::scalar_type,
160  typename MatrixType::local_ordinal_type,
161  typename MatrixType::global_ordinal_type,
162  typename MatrixType::node_type> >::value,
163  "Ifpack2::SparseContainer: Please use MatrixType = Tpetra::RowMatrix.");
164 
173  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
174 
176 
178 
192  SparseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
193  const Teuchos::ArrayView<const local_ordinal_type>& localRows);
194 
196  virtual ~SparseContainer();
197 
199 
201 
206  virtual size_t getNumRows() const;
207 
209  virtual bool isInitialized() const;
210 
212  virtual bool isComputed() const;
213 
215  virtual void setParameters(const Teuchos::ParameterList& List);
216 
218 
220 
222  virtual void initialize();
223 
225  virtual void compute ();
226 
228  virtual void
229  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
230  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
231  Teuchos::ETransp mode=Teuchos::NO_TRANS,
232  scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(),
233  scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const;
234 
236  virtual void
237  weightedApply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
238  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
239  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
240  Teuchos::ETransp mode=Teuchos::NO_TRANS,
241  scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(),
242  scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const;
243 
245 
247 
251  virtual std::ostream& print(std::ostream& os) const;
252 
254 
256 
258  virtual std::string description () const;
259 
261  virtual void
262  describe (Teuchos::FancyOStream &out,
263  const Teuchos::EVerbosityLevel verbLevel =
264  Teuchos::Describable::verbLevel_default) const;
265 
267 private:
268  typedef typename InverseType::scalar_type InverseScalar;
269  typedef typename InverseType::local_ordinal_type InverseLocalOrdinal;
270  typedef typename InverseType::global_ordinal_type InverseGlobalOrdinal;
271  typedef typename InverseType::node_type InverseNode;
272 
275 
277  void extract (const Teuchos::RCP<const row_matrix_type>& globalMatrix);
278 
290  void
291  applyImpl (const Tpetra::MultiVector<InverseScalar,InverseLocalOrdinal,InverseGlobalOrdinal,InverseNode>& X,
292  Tpetra::MultiVector<InverseScalar,InverseLocalOrdinal,InverseGlobalOrdinal,InverseNode>& Y,
293  Teuchos::ETransp mode,
294  InverseScalar alpha,
295  InverseScalar beta) const;
296 
298  size_t numRows_;
300  Teuchos::RCP<Tpetra::Map<InverseLocalOrdinal,InverseGlobalOrdinal,InverseNode> > localMap_;
302  Teuchos::RCP<Tpetra::CrsMatrix<InverseScalar,InverseLocalOrdinal,InverseGlobalOrdinal,InverseNode> > diagBlock_;
304  mutable Teuchos::RCP<Tpetra::MultiVector<InverseScalar,InverseLocalOrdinal,InverseGlobalOrdinal,InverseNode> > Y_;
306  mutable Teuchos::RCP<Tpetra::MultiVector<InverseScalar,InverseLocalOrdinal,InverseGlobalOrdinal,InverseNode> > X_;
308  bool IsInitialized_;
310  bool IsComputed_;
312  Teuchos::RCP<Teuchos::Comm<int> > localComm_;
313 
321  Teuchos::RCP<InverseType> Inverse_;
322 
324  Teuchos::ParameterList List_;
325 };
326 
327 }// namespace Ifpack2
328 
329 
330 
331 #endif // IFPACK2_SPARSECONTAINER_HPP
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_SparseContainer_decl.hpp:156
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
Compute Y := alpha * M^{-1} X + beta*Y.
Definition: Ifpack2_SparseContainer_def.hpp:194
Ifpack2::Container class declaration.
virtual bool isComputed() const
Whether the container has been successfully computed.
Definition: Ifpack2_SparseContainer_def.hpp:97
Store and solve a local sparse linear problem.
Definition: Ifpack2_SparseContainer_decl.hpp:130
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to the given FancyOStream.
Definition: Ifpack2_SparseContainer_def.hpp:498
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
Compute Y := alpha * diag(D) * M^{-1} (diag(D) * X) + beta*Y.
Definition: Ifpack2_SparseContainer_def.hpp:304
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_SparseContainer_decl.hpp:154
virtual void initialize()
Do all set-up operations that only require matrix structure.
Definition: Ifpack2_SparseContainer_def.hpp:111
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_SparseContainer_decl.hpp:152
virtual std::ostream & print(std::ostream &os) const
Print information about this object to the given output stream.
Definition: Ifpack2_SparseContainer_def.hpp:466
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
virtual size_t getNumRows() const
The number of rows in the local matrix on the calling process.
Definition: Ifpack2_SparseContainer_def.hpp:79
virtual std::string description() const
A one-line description of this object.
Definition: Ifpack2_SparseContainer_def.hpp:476
virtual bool isInitialized() const
Whether the container has been successfully initialized.
Definition: Ifpack2_SparseContainer_def.hpp:90
InverseType inverse_type
The second template parameter of this class.
Definition: Ifpack2_SparseContainer_decl.hpp:147
virtual ~SparseContainer()
Destructor (declared virtual for memory safety of derived classes).
Definition: Ifpack2_SparseContainer_def.hpp:74
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:103
SparseContainer(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::ArrayView< const local_ordinal_type > &localRows)
Constructor.
Definition: Ifpack2_SparseContainer_def.hpp:59
virtual void setParameters(const Teuchos::ParameterList &List)
Set all necessary parameters.
Definition: Ifpack2_SparseContainer_def.hpp:104
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_SparseContainer_decl.hpp:150
virtual void compute()
Extract the local diagonal block and prepare the solver.
Definition: Ifpack2_SparseContainer_def.hpp:145
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
Container< MatrixType >::row_matrix_type row_matrix_type
The (base class) type of the input matrix.
Definition: Ifpack2_SparseContainer_decl.hpp:163
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_SparseContainer_decl.hpp:141