Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Relaxation_decl.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated 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 // ***********************************************************************
38 //@HEADER
39 */
40 
41 #ifndef IFPACK2_RELAXATION_DECL_HPP
42 #define IFPACK2_RELAXATION_DECL_HPP
43 
46 #include "Ifpack2_Parameters.hpp"
47 #include "Tpetra_Vector.hpp"
48 #include "Teuchos_ScalarTraits.hpp"
49 #include "Tpetra_CrsMatrix.hpp" // Don't need the definition here
50 #include "Tpetra_BlockCrsMatrix.hpp"
51 #include <type_traits>
52 #include <KokkosKernels_Handle.hpp>
53 
54 
55 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 namespace Ifpack2 {
57 namespace Details {
58 
59 template<class TpetraOperatorType>
60 class ScaledDampedResidual; // forward declaration
61 
62 } // namespace Details
63 } // namespace Ifpack2
64 
65 namespace Teuchos {
66  // forward declarations
67  class ParameterList;
68  class Time;
69 } // namespace Teuchos
70 #endif // DOXYGEN_SHOULD_SKIP_THIS
71 
72 namespace Ifpack2 {
73 
235 template<class MatrixType>
236 class Relaxation :
237  virtual public Ifpack2::Preconditioner<
238  typename MatrixType::scalar_type,
239  typename MatrixType::local_ordinal_type,
240  typename MatrixType::global_ordinal_type,
241  typename MatrixType::node_type>,
242  virtual public Ifpack2::Details::CanChangeMatrix<
243  Tpetra::RowMatrix<typename MatrixType::scalar_type,
244  typename MatrixType::local_ordinal_type,
245  typename MatrixType::global_ordinal_type,
246  typename MatrixType::node_type> >
247 {
248 public:
250 
251 
253  typedef typename MatrixType::scalar_type scalar_type;
254 
256  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
257 
259  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
260 
262  typedef typename MatrixType::node_type node_type;
263 
266 
268  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
270 
271  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Relaxation: Please use MatrixType = Tpetra::RowMatrix. This saves build times, library sizes, and executable sizes. Don't worry, this class still works with CrsMatrix and BlockCrsMatrix; those are both subclasses of RowMatrix.");
272 
274 
276 
308 
310  virtual ~Relaxation () = default;
311 
313 
315 
394  void setParameters (const Teuchos::ParameterList& params);
395 
398  getValidParameters () const;
399 
401  void initialize ();
402 
404  inline bool isInitialized() const {
405  return isInitialized_;
406  }
407 
409  void compute ();
410 
412  inline bool isComputed() const {
413  return IsComputed_;
414  }
415 
417 
419 
442  virtual void
444 
446 
448 
464  void
465  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
466  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
470 
473  getDomainMap () const;
474 
477  getRangeMap () const;
478 
481  bool hasTransposeApply () const;
482 
489  void
490  applyMat (const Tpetra::MultiVector<
491  scalar_type,
494  node_type>& X,
495  Tpetra::MultiVector<
496  scalar_type,
499  node_type>& Y,
500  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
501 
503 
505 
508 
511 
513  double getComputeFlops() const;
514 
516  double getApplyFlops() const;
517 
519  int getNumInitialize() const;
520 
522  int getNumCompute() const;
523 
525  int getNumApply() const;
526 
528  double getInitializeTime() const;
529 
531  double getComputeTime() const;
532 
534  double getApplyTime() const;
535 
537  size_t getNodeSmootherComplexity() const;
538 
540 
542 
549  std::string description () const;
550 
573  void
575  const Teuchos::EVerbosityLevel verbLevel =
578 
579 private:
581 
582 
585 
590  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
591  global_ordinal_type, node_type> crs_matrix_type;
592  typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type,
593  global_ordinal_type, node_type> block_crs_matrix_type;
594  typedef Tpetra::BlockMultiVector<scalar_type, local_ordinal_type,
595  global_ordinal_type, node_type> block_multivector_type;
596 
597 
599 
601 
602  typedef typename crs_matrix_type::local_matrix_type local_matrix_type;
603  typedef typename local_matrix_type::StaticCrsGraphType::row_map_type lno_row_view_t;
604  typedef typename local_matrix_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
605  typedef typename local_matrix_type::values_type scalar_nonzero_view_t;
606  typedef typename local_matrix_type::StaticCrsGraphType::device_type TemporaryWorkSpace;
607  typedef typename local_matrix_type::StaticCrsGraphType::device_type PersistentWorkSpace;
608  typedef typename local_matrix_type::StaticCrsGraphType::execution_space MyExecSpace;
609  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
610  <typename lno_row_view_t::const_value_type, local_ordinal_type,typename scalar_nonzero_view_t::value_type,
611  MyExecSpace, TemporaryWorkSpace,PersistentWorkSpace > mt_kernel_handle_type;
612  Teuchos::RCP<mt_kernel_handle_type> mtKernelHandle_;
613 
615 
617 
619  Relaxation (const Relaxation<MatrixType>& RHS);
620 
622  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
623 
625 
627 
632  void setParametersImpl (Teuchos::ParameterList& params);
633 
635  void ApplyInverseRichardson(
636  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
637  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
638 
640  void ApplyInverseJacobi(
641  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
642  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
643 
645  void ApplyInverseJacobi_BlockCrsMatrix(
646  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
647  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
648 
650  void ApplyInverseGS(
651  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
652  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
653 
655  void ApplyInverseMTGS_CrsMatrix(
656  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
657  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
658 
659 
661  void ApplyInverseGS_RowMatrix(
662  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
663  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
664 
666  void
667  ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
668  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
669  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
670 
672  void
673  ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
674  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
675  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
676 
678  void ApplyInverseSGS(
679  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
680  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
681 
683  void ApplyInverseMTSGS_CrsMatrix(
684  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
685  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
686 
687  void MTGaussSeidel (
688  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
689  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
690  const Tpetra::ESweepDirection direction) const;
691 
693  void ApplyInverseSGS_RowMatrix(
694  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
695  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
696 
698  void
699  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
700  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
701  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
702 
704  void
705  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
706  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
707  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
708 
709  void computeBlockCrs ();
710 
712  void updateCachedMultiVector(const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& map, size_t numVecs) const;
713 
714 
716 
718 
725  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
726 
738 
739  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
740  typename block_crs_matrix_type::device_type> block_diag_type;
741  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
742  typename block_crs_matrix_type::device_type,
743  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
744 
759  block_diag_type blockDiag_;
760 
761  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
762 
764  int NumSweeps_ = 1;
766  int NumInnerSweeps_ = 1;
768  Details::RelaxationType PrecType_ = Ifpack2::Details::JACOBI;
770  scalar_type DampingFactor_ = STS::one();
772  bool IsParallel_;
774  bool ZeroStartingSolution_ = true;
776  bool DoBackwardGS_ = false;
778  bool DoL1Method_ = false;
780  magnitude_type L1Eta_ = Teuchos::as<magnitude_type>(1.5);
782  scalar_type MinDiagonalValue_ = STS::zero();
784  bool fixTinyDiagEntries_ = false;
786  bool checkDiagEntries_ = false;
788  bool InnerSpTrsv_ = false;
790  int clusterSize_ = 1;
791 
793  bool is_matrix_structurally_symmetric_ = false;
794 
796  bool ifpack2_dump_matrix_ = false;
797 
798 
800  bool isInitialized_ = false;
802  bool IsComputed_ = false;
804  int NumInitialize_ = 0;
806  int NumCompute_ = 0;
808  mutable int NumApply_ = 0;
810  double InitializeTime_ = 0.0;
812  double ComputeTime_ = 0.0;
814  mutable double ApplyTime_ = 0.0;
816  double ComputeFlops_ = 0.0;
818  mutable double ApplyFlops_ = 0.0;
819 
821  magnitude_type globalMinMagDiagEntryMag_ = STM::zero();
823  magnitude_type globalMaxMagDiagEntryMag_ = STM::zero();
825  size_t globalNumSmallDiagEntries_ = 0;
827  size_t globalNumZeroDiagEntries_ = 0;
829  size_t globalNumNegDiagEntries_ = 0;
834  magnitude_type globalDiagNormDiff_ = STM::zero();
835 
841  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
842 
848  bool savedDiagOffsets_ = false;
849 
850  bool hasBlockCrsMatrix_ = false;
851 
853  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
854 
856 }; //class Relaxation
857 
858 }//namespace Ifpack2
859 
860 #endif // IFPACK2_RELAXATION_DECL_HPP
bool hasTransposeApply() const
Whether apply() and applyMat() let you apply the transpose or conjugate transpose.
Definition: Ifpack2_Relaxation_def.hpp:440
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
double getComputeFlops() const
Total number of floating-point operations over all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:482
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:488
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object&#39;s attributes to the given output stream.
Definition: Ifpack2_Relaxation_def.hpp:2681
Relaxation(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Relaxation_def.hpp:215
void compute()
Compute the preconditioner (&quot;numeric setup&quot;);.
Definition: Ifpack2_Relaxation_def.hpp:937
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Relaxation_def.hpp:495
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition: Ifpack2_Relaxation_def.hpp:397
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:194
int getNumApply() const
Total number of calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:458
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:470
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:262
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition: Ifpack2_Relaxation_def.hpp:417
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition: Ifpack2_Relaxation_def.hpp:387
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Relaxation_def.hpp:2622
int getNumInitialize() const
Total number of calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:446
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Relaxation_decl.hpp:412
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition: Ifpack2_Relaxation_def.hpp:430
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:259
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:464
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default
void applyMat(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) const
Apply the input matrix to X, returning the result in Y.
Definition: Ifpack2_Relaxation_def.hpp:616
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:408
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:256
virtual ~Relaxation()=default
Destructor.
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:253
int getNumCompute() const
Total number of calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:452
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:404
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:236
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:476
void initialize()
Initialize the preconditioner (&quot;symbolic setup&quot;).
Definition: Ifpack2_Relaxation_def.hpp:637
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition: Ifpack2_Relaxation_decl.hpp:269
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
Apply the preconditioner to X, returning the result in Y.
Definition: Ifpack2_Relaxation_def.hpp:508
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_Relaxation_def.hpp:227
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:265