10#ifndef IFPACK2_CONTAINER_DECL_HPP
11#define IFPACK2_CONTAINER_DECL_HPP
16#include "Ifpack2_ConfigDefs.hpp"
17#include "Tpetra_RowMatrix.hpp"
18#include "Teuchos_Describable.hpp"
19#include <Tpetra_Map.hpp>
20#include <Tpetra_BlockCrsMatrix.hpp>
21#include <Teuchos_ParameterList.hpp>
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
78template <
class MatrixType>
81 using scalar_type =
typename MatrixType::scalar_type;
82 using local_ordinal_type =
typename MatrixType::local_ordinal_type;
83 using global_ordinal_type =
typename MatrixType::global_ordinal_type;
84 using node_type =
typename MatrixType::node_type;
85 using SC = scalar_type;
86 using LO = local_ordinal_type;
87 using GO = global_ordinal_type;
89 using import_type = Tpetra::Import<LO, GO, NO>;
90 using mv_type = Tpetra::MultiVector<SC, LO, GO, NO>;
91 using vector_type = Tpetra::Vector<SC, LO, GO, NO>;
92 using map_type = Tpetra::Map<LO, GO, NO>;
93 using crs_matrix_type = Tpetra::CrsMatrix<SC, LO, GO, NO>;
94 using block_crs_matrix_type = Tpetra::BlockCrsMatrix<SC, LO, GO, NO>;
95 using row_matrix_type = Tpetra::RowMatrix<SC, LO, GO, NO>;
97 static_assert(std::is_same<MatrixType, row_matrix_type>::value,
98 "Ifpack2::Container: Please use MatrixType = Tpetra::RowMatrix.");
101 using ISC =
typename KokkosKernels::ArithTraits<SC>::val_type;
105 using HostView =
typename mv_type::dual_view_type::t_host;
106 using ConstHostView =
typename HostView::const_type;
118 Container(
const Teuchos::RCP<const row_matrix_type>& matrix,
119 const Teuchos::Array<Teuchos::Array<LO> >& partitions,
140 Teuchos::ArrayView<const LO>
getBlockRows(
int blockIndex)
const;
153 void setBlockSizes(
const Teuchos::Array<Teuchos::Array<LO> >& partitions);
155 void getMatDiag()
const;
173 void DoJacobi(ConstHostView X,
HostView Y, SC dampingFactor)
const;
174 void DoOverlappingJacobi(ConstHostView X,
HostView Y, ConstHostView W, SC dampingFactor,
bool nonsymScaling)
const;
175 void DoGaussSeidel(ConstHostView X,
HostView Y,
HostView Y2, SC dampingFactor)
const;
176 void DoSGS(ConstHostView X,
HostView Y,
HostView Y2, SC dampingFactor)
const;
197 Teuchos::ETransp mode = Teuchos::NO_TRANS,
198 SC alpha = Teuchos::ScalarTraits<SC>::one(),
199 SC beta = Teuchos::ScalarTraits<SC>::zero())
const = 0;
207 Teuchos::ETransp mode = Teuchos::NO_TRANS,
208 SC alpha = Teuchos::ScalarTraits<SC>::one(),
209 SC beta = Teuchos::ScalarTraits<SC>::zero())
const = 0;
225 virtual void applyMV(
const mv_type& X, mv_type& Y)
const;
230 vector_type& W)
const;
232 virtual void clearBlocks();
235 virtual std::ostream&
print(std::ostream& os)
const = 0;
244 SC dampingFactor, LO i)
const;
264 mutable Teuchos::RCP<vector_type>
Diag_;
292template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293struct StridedRowView;
305template <
class MatrixType,
class LocalScalarType>
310 using local_scalar_type = LocalScalarType;
311 using SC =
typename Container<MatrixType>::scalar_type;
312 using LO =
typename Container<MatrixType>::local_ordinal_type;
313 using GO =
typename Container<MatrixType>::global_ordinal_type;
314 using NO =
typename Container<MatrixType>::node_type;
316 using typename Container<MatrixType>::import_type;
317 using typename Container<MatrixType>::row_matrix_type;
318 using typename Container<MatrixType>::crs_matrix_type;
319 using typename Container<MatrixType>::block_crs_matrix_type;
320 using typename Container<MatrixType>::mv_type;
321 using typename Container<MatrixType>::vector_type;
322 using typename Container<MatrixType>::map_type;
325 using LSC = LocalScalarType;
326 using LISC =
typename KokkosKernels::ArithTraits<LSC>::val_type;
328 using local_mv_type = Tpetra::MultiVector<LSC, LO, GO, NO>;
331 using typename Container<MatrixType>::ConstHostView;
332 using HostViewLocal =
typename local_mv_type::dual_view_type::t_host;
333 using HostSubviewLocal = Kokkos::View<LISC**, Kokkos::LayoutStride, typename HostViewLocal::memory_space>;
334 using ConstHostSubviewLocal = Kokkos::View<const LISC**, Kokkos::LayoutStride, typename HostViewLocal::memory_space>;
336 static_assert(std::is_same<MatrixType, row_matrix_type>::value,
337 "Ifpack2::Container: Please use MatrixType = Tpetra::RowMatrix.");
359 ContainerImpl(
const Teuchos::RCP<const row_matrix_type>& matrix,
360 const Teuchos::Array<Teuchos::Array<LO> >& partitions,
387 virtual void setParameters(
const Teuchos::ParameterList& List);
402 apply(ConstHostView X,
405 Teuchos::ETransp mode = Teuchos::NO_TRANS,
406 SC alpha = Teuchos::ScalarTraits<SC>::one(),
407 SC beta = Teuchos::ScalarTraits<SC>::zero())
const;
415 Teuchos::ETransp mode = Teuchos::NO_TRANS,
416 SC alpha = Teuchos::ScalarTraits<SC>::one(),
417 SC beta = Teuchos::ScalarTraits<SC>::zero())
const;
433 void applyMV(
const mv_type& X, mv_type& Y)
const;
438 vector_type& W)
const;
440 virtual void clearBlocks();
443 virtual std::ostream&
print(std::ostream& os)
const = 0;
452 SC dampingFactor, LO i)
const;
463 Teuchos::ETransp mode,
465 const LSC beta)
const;
469 mutable HostViewLocal Y_local_;
496template <
typename Scalar,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
499 using LO = LocalOrdinal;
501 using block_crs_matrix_type = Tpetra::BlockCrsMatrix<SC, LO, GlobalOrdinal, Node>;
503 using h_inds_type =
typename block_crs_matrix_type::local_inds_host_view_type;
504 using h_vals_type =
typename block_crs_matrix_type::values_host_view_type;
514 SC val(
size_t i)
const;
515 LO ind(
size_t i)
const;
525 Teuchos::Array<SC> valsCopy;
526 Teuchos::Array<LO> indsCopy;
533template <
class MatrixType>
542template <
class MatrixType>
545 static std::string name() {
546 return std::string(
"Ifpack2::Container<") +
547 TypeNameTraits<MatrixType>::name() +
">";
550 static std::string concreteName(const ::Ifpack2::Container<MatrixType>&) {
std::ostream & operator<<(std::ostream &os, const Ifpack2::Container< MatrixType > &obj)
Print information about the given Container to the output stream os.
Definition Ifpack2_Container_def.hpp:918
Interface for creating and solving a set of local linear problems.
Definition Ifpack2_Container_decl.hpp:79
virtual ~Container()
Destructor.
Definition Ifpack2_Container_def.hpp:81
bool hasBlockCrs_
Whether the input matrix is a BlockCRS matrix.
Definition Ifpack2_Container_decl.hpp:274
virtual void apply(ConstHostView X, HostView Y, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const =0
Compute Y := alpha * M^{-1} X + beta*Y.
Teuchos::RCP< const crs_matrix_type > inputCrsMatrix_
The input matrix, dynamic cast to CrsMatrix. May be null.
Definition Ifpack2_Container_decl.hpp:250
bool IsParallel_
Whether the problem is distributed across multiple MPI processes.
Definition Ifpack2_Container_decl.hpp:266
int numBlocks_
The number of blocks (partitions) in the container.
Definition Ifpack2_Container_decl.hpp:256
Teuchos::ArrayView< const LO > getBlockRows(int blockIndex) const
Local indices of the rows of the input matrix that belong to this block.
Definition Ifpack2_Container_def.hpp:85
static std::string getName()
Definition Ifpack2_Container_def.hpp:147
virtual void applyInverseJacobi(const mv_type &, mv_type &, SC dampingFactor, bool, int) const =0
Compute Y := (1 - a) Y + a D^{-1} (X - R*Y).
Teuchos::RCP< vector_type > Diag_
Diagonal elements.
Definition Ifpack2_Container_decl.hpp:264
virtual void weightedApply(ConstHostView X, HostView Y, ConstHostView D, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const =0
Compute Y := alpha * diag(D) * M^{-1} (diag(D) * X) + beta*Y.
int bcrsBlockSize_
If hasBlockCrs_, the number of DOFs per vertex. Otherwise 1.
Definition Ifpack2_Container_decl.hpp:276
Teuchos::RCP< const block_crs_matrix_type > inputBlockMatrix_
The input matrix, dynamic cast to BlockCrsMatrix. May be null.
Definition Ifpack2_Container_decl.hpp:253
virtual void setParameters(const Teuchos::ParameterList &List)=0
Set parameters, if any.
virtual void DoGSBlock(ConstHostView X, HostView Y, HostView Y2, HostView Resid, SC dampingFactor, LO i) const
Do one step of Gauss-Seidel on block i (used by DoGaussSeidel and DoSGS)
Definition Ifpack2_Container_def.hpp:152
virtual void applyMV(const mv_type &X, mv_type &Y) const
Wrapper for apply with MultiVector.
Definition Ifpack2_Container_def.hpp:135
LO NumLocalRows_
Number of local rows in input matrix.
Definition Ifpack2_Container_decl.hpp:268
bool isInitialized() const
Whether the container has been successfully initialized.
Definition Ifpack2_Container_def.hpp:124
void setBlockSizes(const Teuchos::Array< Teuchos::Array< LO > > &partitions)
Initialize arrays with information about block sizes.
Definition Ifpack2_Container_def.hpp:90
LO scalarsPerRow_
Definition Ifpack2_Container_decl.hpp:281
Teuchos::Array< LO > blockSizes_
Number of rows in each block.
Definition Ifpack2_Container_decl.hpp:260
GO NumGlobalNonzeros_
Number of nonzeros in input matrix.
Definition Ifpack2_Container_decl.hpp:272
virtual void initialize()=0
Do all set-up operations that only require matrix structure.
virtual std::ostream & print(std::ostream &os) const =0
Print basic information about the container to os.
virtual void weightedApplyMV(const mv_type &X, mv_type &Y, vector_type &W) const
Wrapper for weightedApply with MultiVector.
Definition Ifpack2_Container_def.hpp:141
Teuchos::RCP< const row_matrix_type > inputMatrix_
The input matrix to the constructor.
Definition Ifpack2_Container_decl.hpp:247
bool pointIndexed_
(If hasBlockCrs_) Whether the blocks are described using sub-block row indices instead of full block ...
Definition Ifpack2_Container_decl.hpp:278
bool IsInitialized_
If true, the container has been successfully initialized.
Definition Ifpack2_Container_decl.hpp:284
typename KokkosKernels::ArithTraits< SC >::val_type ISC
Internal representation of Scalar in Kokkos::View.
Definition Ifpack2_Container_decl.hpp:101
Teuchos::Array< LO > blockRows_
Local indices of the rows of the input matrix that belong to this block.
Definition Ifpack2_Container_decl.hpp:258
GO NumGlobalRows_
Number of global rows in input matrix.
Definition Ifpack2_Container_decl.hpp:270
bool isComputed() const
Whether the container has been successfully computed.
Definition Ifpack2_Container_def.hpp:129
typename mv_type::dual_view_type::t_host HostView
Definition Ifpack2_Container_decl.hpp:105
Teuchos::Array< LO > blockOffsets_
Starting index in blockRows_ of local row indices for each block.
Definition Ifpack2_Container_decl.hpp:262
bool IsComputed_
If true, the container has been successfully computed.
Definition Ifpack2_Container_decl.hpp:286
virtual void compute()=0
Extract the local diagonal blocks and prepare the solver.
The implementation of the numerical features of Container (Jacobi, Gauss-Seidel, SGS)....
Definition Ifpack2_Container_decl.hpp:306
std::vector< HostSubviewLocal > X_localBlocks_
Views for holding pieces of X corresponding to each block.
Definition Ifpack2_Container_decl.hpp:484
HostViewLocal X_local_
Scratch vectors used in apply().
Definition Ifpack2_Container_decl.hpp:468
virtual std::ostream & print(std::ostream &os) const =0
Print basic information about the container to os.
virtual void setParameters(const Teuchos::ParameterList &List)
Set parameters, if any.
Definition Ifpack2_Container_def.hpp:444
Details::StridedRowView< SC, LO, GO, NO > getInputRowView(LO row) const
View a row of the input matrix.
Definition Ifpack2_Container_def.hpp:804
virtual void extract()=0
Extract the submatrices identified by the local indices set by the constructor. BlockMatrix may be an...
std::vector< HostSubviewLocal > Y_localBlocks_
Views for holding pieces of Y corresponding to each block.
Definition Ifpack2_Container_decl.hpp:487
virtual void weightedApply(ConstHostView X, HostView Y, ConstHostView D, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const
Compute Y := alpha * diag(D) * M^{-1} (diag(D) * X) + beta*Y.
Definition Ifpack2_Container_def.hpp:649
virtual void compute()=0
Extract the local diagonal blocks and prepare the solver.
void applyMV(const mv_type &X, mv_type &Y) const
Wrapper for apply with MVs, used in unit tests (never called by BlockRelaxation)
Definition Ifpack2_Container_def.hpp:457
virtual void apply(ConstHostView X, HostView Y, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, SC alpha=Teuchos::ScalarTraits< SC >::one(), SC beta=Teuchos::ScalarTraits< SC >::zero()) const
Compute Y := alpha * M^{-1} X + beta*Y.
Definition Ifpack2_Container_def.hpp:540
LocalScalarType LSC
The internal representation of LocalScalarType in Kokkos::View.
Definition Ifpack2_Container_decl.hpp:325
void DoGSBlock(ConstHostView X, HostView Y, HostView Y2, HostView Resid, SC dampingFactor, LO i) const
Do one step of Gauss-Seidel on block i (used by DoGaussSeidel and DoSGS)
Definition Ifpack2_Container_def.hpp:232
virtual void solveBlock(ConstHostSubviewLocal X, HostSubviewLocal Y, int blockIndex, Teuchos::ETransp mode, const LSC alpha, const LSC beta) const
Definition Ifpack2_Container_def.hpp:482
HostViewLocal weightedApplyScratch_
Definition Ifpack2_Container_decl.hpp:481
static std::string getName()
Definition Ifpack2_Container_def.hpp:476
LO translateRowToCol(LO row)
Definition Ifpack2_Container_def.hpp:494
virtual void initialize()=0
Do all set-up operations that only require matrix structure.
virtual ~ContainerImpl()
Destructor.
Definition Ifpack2_Container_def.hpp:440
void weightedApplyMV(const mv_type &X, mv_type &Y, vector_type &W) const
Wrapper for weightedApply with MVs, used in unit tests (never called by BlockRelaxation)
Definition Ifpack2_Container_def.hpp:465
virtual void applyInverseJacobi(const mv_type &, mv_type &, SC dampingFactor, bool, int) const
Compute Y := (1 - a) Y + a D^{-1} (X - R*Y).
Definition Ifpack2_Container_def.hpp:448
Ifpack2's implementation of Trilinos::Details::LinearSolver interface.
Definition Ifpack2_Details_LinearSolver_decl.hpp:75
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40
Structure for read-only views of general matrix rows.
Definition Ifpack2_Container_decl.hpp:497