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 
253  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
254 
256  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
257  global_ordinal_type, node_type> row_matrix_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 
298  explicit Relaxation (const Teuchos::RCP<const row_matrix_type>& A);
299 
301  virtual ~Relaxation();
302 
304 
306 
384  void setParameters (const Teuchos::ParameterList& params);
385 
387  Teuchos::RCP<const Teuchos::ParameterList>
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
447  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
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,
472  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
473  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
474 
476  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
477  getDomainMap () const;
478 
480  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
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 
508  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
509 
511  Teuchos::RCP<const row_matrix_type> getMatrix () const;
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  size_t getNodeSmootherComplexity() const;
539 
541 
543 
550  std::string description () const;
551 
574  void
575  describe (Teuchos::FancyOStream &out,
576  const Teuchos::EVerbosityLevel verbLevel =
577  Teuchos::Describable::verbLevel_default) const;
579 
580 private:
582 
583 
584  typedef Teuchos::ScalarTraits<scalar_type> STS;
585  typedef Teuchos::ScalarTraits<magnitude_type> STM;
586 
591  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
592  global_ordinal_type, node_type> crs_matrix_type;
593  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
594  global_ordinal_type, node_type> block_crs_matrix_type;
595  typedef Tpetra::Experimental::BlockMultiVector<scalar_type, local_ordinal_type,
596  global_ordinal_type, node_type> block_multivector_type;
597 
598 #ifdef HAVE_IFPACK2_EXPERIMENTAL_KOKKOSKERNELS_FEATURES
599 
601 
603 
604  typedef typename crs_matrix_type::local_matrix_type local_matrix_type;
605  typedef typename local_matrix_type::StaticCrsGraphType::row_map_type lno_row_view_t;
606  typedef typename local_matrix_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
607  typedef typename local_matrix_type::values_type scalar_nonzero_view_t;
608  typedef typename local_matrix_type::StaticCrsGraphType::device_type TemporaryWorkSpace;
609  typedef typename local_matrix_type::StaticCrsGraphType::device_type PersistentWorkSpace;
610  typedef typename local_matrix_type::StaticCrsGraphType::execution_space MyExecSpace;
611  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
612  <lno_row_view_t,lno_nonzero_view_t, scalar_nonzero_view_t,
613  MyExecSpace, TemporaryWorkSpace,PersistentWorkSpace > mt_kernel_handle_type;
614  Teuchos::RCP<mt_kernel_handle_type> mtKernelHandle_;
615 #endif // HAVE_IFPACK2_EXPERIMENTAL_KOKKOSKERNELS_FEATURES
616 
618 
620 
622  Relaxation (const Relaxation<MatrixType>& RHS);
623 
625  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
626 
628 
630 
635  void setParametersImpl (Teuchos::ParameterList& params);
636 
638  void ApplyInverseJacobi(
639  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
640  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
641 
643  void ApplyInverseJacobi_BlockCrsMatrix(
644  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
645  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
646 
648  void ApplyInverseGS(
649  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
650  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
651 
653  void ApplyInverseMTGS_CrsMatrix(
654  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
655  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
656 
657 
659  void ApplyInverseGS_RowMatrix(
660  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
661  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
662 
664  void
665  ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
666  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
667  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
668 
670  void
671  ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
672  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
673  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
674 
676  void ApplyInverseSGS(
677  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
678  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
679 
681  void ApplyInverseMTSGS_CrsMatrix(
682  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
683  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
684 
685  void MTGaussSeidel (
686  const crs_matrix_type* crsMat,
687  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
688  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
689  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
690  const scalar_type& dampingFactor,
691  const Tpetra::ESweepDirection direction,
692  const int numSweeps,
693  const bool zeroInitialGuess) const;
694 
696  void ApplyInverseSGS_RowMatrix(
697  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
698  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
699 
701  void
702  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
703  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
704  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
705 
707  void
708  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
709  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
710  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
711 
712  void computeBlockCrs ();
713 
714 
716 
718 
725  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
726 
728  Teuchos::RCP<const row_matrix_type> A_;
730  Teuchos::RCP<Teuchos::Time> Time_;
732  Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
734  Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
735 
736 
737  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
738  typename block_crs_matrix_type::device_type> block_diag_type;
739  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
740  typename block_crs_matrix_type::device_type,
741  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
742 
757  block_diag_type blockDiag_;
758 
759  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
760 
762  int NumSweeps_;
764  Details::RelaxationType PrecType_;
766  scalar_type DampingFactor_;
768  bool IsParallel_;
770  bool ZeroStartingSolution_;
772  bool DoBackwardGS_;
774  bool DoL1Method_;
776  magnitude_type L1Eta_;
778  scalar_type MinDiagonalValue_;
780  bool fixTinyDiagEntries_;
782  bool checkDiagEntries_;
783 
785  bool isInitialized_;
787  bool IsComputed_;
789  int NumInitialize_;
791  int NumCompute_;
793  mutable int NumApply_;
795  double InitializeTime_;
797  double ComputeTime_;
799  mutable double ApplyTime_;
801  double ComputeFlops_;
803  mutable double ApplyFlops_;
804 
806  magnitude_type globalMinMagDiagEntryMag_;
808  magnitude_type globalMaxMagDiagEntryMag_;
810  size_t globalNumSmallDiagEntries_;
812  size_t globalNumZeroDiagEntries_;
814  size_t globalNumNegDiagEntries_;
819  magnitude_type globalDiagNormDiff_;
820 
826  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
827 
833  bool savedDiagOffsets_;
834 
835  bool hasBlockCrsMatrix_;
836 
838  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
839 
841 }; //class Relaxation
842 
843 }//namespace Ifpack2
844 
845 #endif // IFPACK2_RELAXATION_DECL_HPP
846 
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:401
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:250
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
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.
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Relaxation_decl.hpp:416
Definition: Ifpack2_Container.hpp:761
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:244
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:241
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:226
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
void getValidParameters(Teuchos::ParameterList &params)
Fills a list which contains all the parameters possibly used by Ifpack2.
Definition: Ifpack2_Parameters.cpp:50
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