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 namespace Teuchos {
56  // forward declarations
57  class ParameterList;
58  class Time;
59 } // namespace Teuchos
60 
61 namespace Ifpack2 {
62 
221 template<class MatrixType>
222 class Relaxation :
223  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
224  typename MatrixType::local_ordinal_type,
225  typename MatrixType::global_ordinal_type,
226  typename MatrixType::node_type>,
227  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
228  typename MatrixType::local_ordinal_type,
229  typename MatrixType::global_ordinal_type,
230  typename MatrixType::node_type> >
231 {
232 public:
234 
235 
237  typedef typename MatrixType::scalar_type scalar_type;
238 
240  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
241 
243  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
244 
246  typedef typename MatrixType::node_type node_type;
247 
249  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
250 
252  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
253  global_ordinal_type, node_type> row_matrix_type;
254 
255  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.");
256 
258 
260 
294  explicit Relaxation (const Teuchos::RCP<const row_matrix_type>& A);
295 
297  virtual ~Relaxation();
298 
300 
302 
380  void setParameters (const Teuchos::ParameterList& params);
381 
383  Teuchos::RCP<const Teuchos::ParameterList>
384  getValidParameters () const;
385 
394  void initialize ();
395 
397  inline bool isInitialized() const {
398  return isInitialized_;
399  }
400 
408  void compute ();
409 
410 
412  inline bool isComputed() const {
413  return(IsComputed_);
414  }
415 
417 
419 
442  virtual void
443  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
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,
467  Teuchos::ETransp mode = Teuchos::NO_TRANS,
468  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
469  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
470 
472  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
473  getDomainMap () const;
474 
476  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
477  getRangeMap () const;
478 
480  bool hasTransposeApply () const;
481 
494  void
495  applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
496  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
497  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
498 
500 
502 
504  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
505 
507  Teuchos::RCP<const row_matrix_type> getMatrix () const;
508 
510  double getComputeFlops() const;
511 
513  double getApplyFlops() const;
514 
516  int getNumInitialize() const;
517 
519  int getNumCompute() const;
520 
522  int getNumApply() const;
523 
525  double getInitializeTime() const;
526 
528  double getComputeTime() const;
529 
531  double getApplyTime() const;
532 
534 
536 
543  std::string description () const;
544 
567  void
568  describe (Teuchos::FancyOStream &out,
569  const Teuchos::EVerbosityLevel verbLevel =
570  Teuchos::Describable::verbLevel_default) const;
572 
573 private:
575 
576 
577  typedef Teuchos::ScalarTraits<scalar_type> STS;
578  typedef Teuchos::ScalarTraits<magnitude_type> STM;
579 
584  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
585  global_ordinal_type, node_type> crs_matrix_type;
586  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
587  global_ordinal_type, node_type> block_crs_matrix_type;
588  typedef Tpetra::Experimental::BlockMultiVector<scalar_type, local_ordinal_type,
589  global_ordinal_type, node_type> block_multivector_type;
591 
593 
595  Relaxation (const Relaxation<MatrixType>& RHS);
596 
598  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
599 
601 
603 
608  void setParametersImpl (Teuchos::ParameterList& params);
609 
611  void ApplyInverseJacobi(
612  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
613  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
614 
616  void ApplyInverseJacobi_BlockCrsMatrix(
617  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
618  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
619 
621  void ApplyInverseGS(
622  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
623  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
624 
626  void ApplyInverseGS_RowMatrix(
627  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
628  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
629 
631  void
632  ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
633  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
634  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
635 
637  void
638  ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
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);
641 
643  void ApplyInverseSGS(
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 ApplyInverseSGS_RowMatrix(
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
654  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
655  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
656  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
657 
659  void
660  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
661  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
662  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
663 
664  void computeBlockCrs ();
665 
666 
668 
670 
677  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
678 
680  Teuchos::RCP<const row_matrix_type> A_;
682  Teuchos::RCP<Teuchos::Time> Time_;
684  Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
686  Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
687 
688 
689  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
690  typename block_crs_matrix_type::device_type> block_diag_type;
691  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
692  typename block_crs_matrix_type::device_type,
693  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
694 
709  block_diag_type blockDiag_;
710 
711  typedef Kokkos::View<int**, typename block_crs_matrix_type::device_type> pivots_type;
712  typedef Kokkos::View<int**, typename block_crs_matrix_type::device_type,
713  Kokkos::MemoryUnmanaged> unmanaged_pivots_type;
714 
728  pivots_type blockDiagFactPivots_;
729 
730  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
731 
733  int NumSweeps_;
735  Details::RelaxationType PrecType_;
737  scalar_type DampingFactor_;
739  bool IsParallel_;
741  bool ZeroStartingSolution_;
743  bool DoBackwardGS_;
745  bool DoL1Method_;
747  magnitude_type L1Eta_;
749  scalar_type MinDiagonalValue_;
751  bool fixTinyDiagEntries_;
753  bool checkDiagEntries_;
754 
756  bool isInitialized_;
758  bool IsComputed_;
760  int NumInitialize_;
762  int NumCompute_;
764  mutable int NumApply_;
766  double InitializeTime_;
768  double ComputeTime_;
770  mutable double ApplyTime_;
772  double ComputeFlops_;
774  mutable double ApplyFlops_;
775 
777  magnitude_type globalMinMagDiagEntryMag_;
779  magnitude_type globalMaxMagDiagEntryMag_;
781  size_t globalNumSmallDiagEntries_;
783  size_t globalNumZeroDiagEntries_;
785  size_t globalNumNegDiagEntries_;
790  magnitude_type globalDiagNormDiff_;
791 
797  Teuchos::ArrayRCP<size_t> diagOffsets_;
803  bool savedDiagOffsets_;
804 
805  bool hasBlockCrsMatrix_;
806 
808  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
809 
811 }; //class Relaxation
812 
813 }//namespace Ifpack2
814 
815 #endif // IFPACK2_RELAXATION_DECL_HPP
816 
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:246
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
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:243
Declaration of interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:63
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:240
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:237
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:397
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:222
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:253
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:249