Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Relaxation_decl.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_RELAXATION_DECL_HPP
44 #define IFPACK2_RELAXATION_DECL_HPP
45 
48 #include "Ifpack2_Parameters.hpp"
49 #include "Tpetra_Vector.hpp"
50 #include "Teuchos_ScalarTraits.hpp"
51 #include "Tpetra_CrsMatrix_decl.hpp" // Don't need the definition here
52 #include "Tpetra_Experimental_BlockCrsMatrix_decl.hpp"
53 #include <type_traits>
54 
55 #ifdef HAVE_IFPACK2_EXPERIMENTAL_KOKKOSKERNELS_FEATURES
56 #include <KokkosKernels_Handle.hpp>
57 #endif
58 
59 namespace Teuchos {
60  // forward declarations
61  class ParameterList;
62  class Time;
63 } // namespace Teuchos
64 
65 namespace Ifpack2 {
66 
225 template<class MatrixType>
226 class Relaxation :
227  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
228  typename MatrixType::local_ordinal_type,
229  typename MatrixType::global_ordinal_type,
230  typename MatrixType::node_type>,
231  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
232  typename MatrixType::local_ordinal_type,
233  typename MatrixType::global_ordinal_type,
234  typename MatrixType::node_type> >
235 {
236 public:
238 
239 
241  typedef typename MatrixType::scalar_type scalar_type;
242 
244  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
245 
247  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
248 
250  typedef typename MatrixType::node_type node_type;
251 
254 
256  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
258 
259  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.");
260 
262 
264 
299 
301  virtual ~Relaxation();
302 
304 
306 
384  void setParameters (const Teuchos::ParameterList& params);
385 
388  getValidParameters () const;
389 
398  void initialize ();
399 
401  inline bool isInitialized() const {
402  return isInitialized_;
403  }
404 
412  void compute ();
413 
414 
416  inline bool isComputed() const {
417  return(IsComputed_);
418  }
419 
421 
423 
446  virtual void
448 
450 
452 
468  void
469  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
470  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
471  Teuchos::ETransp mode = Teuchos::NO_TRANS,
474 
477  getDomainMap () const;
478 
481  getRangeMap () const;
482 
484  bool hasTransposeApply () const;
485 
498  void
499  applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
500  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
501  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
502 
504 
506 
509 
512 
514  double getComputeFlops() const;
515 
517  double getApplyFlops() const;
518 
520  int getNumInitialize() const;
521 
523  int getNumCompute() const;
524 
526  int getNumApply() const;
527 
529  double getInitializeTime() const;
530 
532  double getComputeTime() const;
533 
535  double getApplyTime() const;
536 
538 
540 
547  std::string description () const;
548 
571  void
573  const Teuchos::EVerbosityLevel verbLevel =
576 
577 private:
579 
580 
583 
588  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
589  global_ordinal_type, node_type> crs_matrix_type;
590  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
591  global_ordinal_type, node_type> block_crs_matrix_type;
592  typedef Tpetra::Experimental::BlockMultiVector<scalar_type, local_ordinal_type,
593  global_ordinal_type, node_type> block_multivector_type;
594 
595 #ifdef HAVE_IFPACK2_EXPERIMENTAL_KOKKOSKERNELS_FEATURES
596  typedef typename crs_matrix_type::local_matrix_type kokkos_csr_matrix;
597  typedef typename kokkos_csr_matrix::StaticCrsGraphType crs_graph_type;
598  typedef typename kokkos_csr_matrix::StaticCrsGraphType::row_map_type lno_row_view_t;
599  typedef typename kokkos_csr_matrix::StaticCrsGraphType::entries_type lno_nonzero_view_t;
600  typedef typename kokkos_csr_matrix::values_type scalar_nonzero_view_t;
601  typedef typename kokkos_csr_matrix::StaticCrsGraphType::device_type TemporaryWorkSpace;
602  typedef typename kokkos_csr_matrix::StaticCrsGraphType::device_type PersistentWorkSpace;
603  typedef typename kokkos_csr_matrix::StaticCrsGraphType::execution_space MyExecSpace;
604  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
605  <lno_row_view_t,lno_nonzero_view_t, scalar_nonzero_view_t,
606  MyExecSpace, TemporaryWorkSpace,PersistentWorkSpace > KernelHandle;
608 #endif
609 
610 
612 
614  Relaxation (const Relaxation<MatrixType>& RHS);
615 
617  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
618 
620 
622 
627  void setParametersImpl (Teuchos::ParameterList& params);
628 
630  void ApplyInverseJacobi(
631  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
632  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
633 
635  void ApplyInverseJacobi_BlockCrsMatrix(
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 ApplyInverseGS(
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 ApplyInverseMTGS_CrsMatrix(
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 
649 
651  void ApplyInverseGS_RowMatrix(
652  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
653  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
654 
656  void
657  ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
658  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
659  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
660 
662  void
663  ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
664  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
665  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
666 
668  void ApplyInverseSGS(
669  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
670  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
671 
673  void ApplyInverseMTSGS_CrsMatrix(
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) const;
676 
677  void MTGaussSeidel (
678  const crs_matrix_type* crsMat,
679  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
680  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
681  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
682  const scalar_type& dampingFactor,
683  const Tpetra::ESweepDirection direction,
684  const int numSweeps,
685  const bool zeroInitialGuess) const;
686 
688  void ApplyInverseSGS_RowMatrix(
689  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
690  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
691 
693  void
694  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
695  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
696  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
697 
699  void
700  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
701  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
702  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
703 
704  void computeBlockCrs ();
705 
706 
708 
710 
717  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
718 
727 
728 
729  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
730  typename block_crs_matrix_type::device_type> block_diag_type;
731  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
732  typename block_crs_matrix_type::device_type,
733  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
734 
749  block_diag_type blockDiag_;
750 
751  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
752 
754  int NumSweeps_;
756  Details::RelaxationType PrecType_;
758  scalar_type DampingFactor_;
760  bool IsParallel_;
762  bool ZeroStartingSolution_;
764  bool DoBackwardGS_;
766  bool DoL1Method_;
768  magnitude_type L1Eta_;
770  scalar_type MinDiagonalValue_;
772  bool fixTinyDiagEntries_;
774  bool checkDiagEntries_;
775 
777  bool isInitialized_;
779  bool IsComputed_;
781  int NumInitialize_;
783  int NumCompute_;
785  mutable int NumApply_;
787  double InitializeTime_;
789  double ComputeTime_;
791  mutable double ApplyTime_;
793  double ComputeFlops_;
795  mutable double ApplyFlops_;
796 
798  magnitude_type globalMinMagDiagEntryMag_;
800  magnitude_type globalMaxMagDiagEntryMag_;
802  size_t globalNumSmallDiagEntries_;
804  size_t globalNumZeroDiagEntries_;
806  size_t globalNumNegDiagEntries_;
811  magnitude_type globalDiagNormDiff_;
812 
818  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
819 
825  bool savedDiagOffsets_;
826 
827  bool hasBlockCrsMatrix_;
828 
830  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
831 
833 }; //class Relaxation
834 
835 }//namespace Ifpack2
836 
837 #endif // IFPACK2_RELAXATION_DECL_HPP
838 
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Relaxation_def.hpp:2480
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:377
int getNumInitialize() const
Total number of calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:393
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:423
Relaxation(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Relaxation_def.hpp:175
void compute()
Compute the preconditioner.
Definition: Ifpack2_Relaxation_def.hpp:827
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:443
bool hasTransposeApply() const
Whether apply() and applyMat() let you apply the transpose or conjugate transpose.
Definition: Ifpack2_Relaxation_def.hpp:387
int getNumApply() const
Total number of calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:405
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:401
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:411
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:155
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:364
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:355
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:250
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition: Ifpack2_Relaxation_def.hpp:334
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:435
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_Relaxation_def.hpp:220
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:247
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default
double getComputeFlops() const
Total number of floating-point operations over all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:429
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Relaxation_decl.hpp:416
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:417
int getNumCompute() const
Total number of calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:399
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:244
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition: Ifpack2_Relaxation_def.hpp:344
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:241
virtual ~Relaxation()
Destructor.
Definition: Ifpack2_Relaxation_def.hpp:215
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 preconditioner to X, returning the result in Y.
Definition: Ifpack2_Relaxation_def.hpp:541
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:226
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:2535
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Relaxation_def.hpp:562
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:257
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:253