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 
46 #include <Ifpack2_ConfigDefs.hpp>
47 #include <Ifpack2_Preconditioner.hpp>
48 #include <Ifpack2_Condest.hpp>
49 #include <Ifpack2_Parameters.hpp>
50 #include <Tpetra_Vector.hpp>
51 #include <Teuchos_Assert.hpp>
52 #include <Teuchos_RCP.hpp>
53 #include <Teuchos_ScalarTraits.hpp>
54 
55 
56 namespace Teuchos {
57  // forward declarations
58  class ParameterList;
59  class Time;
60 }
61 
62 namespace Ifpack2 {
63 enum RelaxationType {
64  JACOBI,
65  GS,
66  SGS
67 };
68 
230 template<class MatrixType>
231 class Relaxation :
232  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
233  typename MatrixType::local_ordinal_type,
234  typename MatrixType::global_ordinal_type,
235  typename MatrixType::node_type>
236 {
237 public:
239 
240 
242  typedef typename MatrixType::scalar_type scalar_type;
243 
245  TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar;
246 
247 
249  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
250 
252  TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal;
253 
254 
256  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
257 
259  TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
260 
261 
263  typedef typename MatrixType::node_type node_type;
264 
266  TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node;
267 
268 
270  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
271 
273  TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType;
274 
276 
278 
312  explicit Relaxation(const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> >& Matrix);
313 
315  virtual ~Relaxation();
316 
318 
320 
398  void setParameters (const Teuchos::ParameterList& params);
399 
401  Teuchos::RCP<const Teuchos::ParameterList>
402  getValidParameters () const;
403 
405  void initialize();
406 
408  inline bool isInitialized() const {
409  return(IsInitialized_);
410  }
411 
413  void compute();
414 
416  inline bool isComputed() const {
417  return(IsComputed_);
418  }
419 
421 
423 
439  void apply(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
440  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
441  Teuchos::ETransp mode = Teuchos::NO_TRANS,
442  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
443  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
444 
446  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getDomainMap() const;
447 
449  const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& getRangeMap() const;
450 
452  bool hasTransposeApply() const;
453 
466  void applyMat(const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
467  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
468  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
469 
471 
473 
485  magnitude_type computeCondEst(CondestType CT = Cheap,
486  local_ordinal_type MaxIters = 1550,
487  magnitude_type Tol = 1e-9,
488  const Teuchos::Ptr<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &matrix = Teuchos::null);
489 
491 
493 
497  magnitude_type getCondEst() const;
498 
500  const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
501 
503  Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > getMatrix() const;
504 
506  double getComputeFlops() const;
507 
509  double getApplyFlops() const;
510 
512  int getNumInitialize() const;
513 
515  int getNumCompute() const;
516 
518  int getNumApply() const;
519 
521  double getInitializeTime() const;
522 
524  double getComputeTime() const;
525 
527  double getApplyTime() const;
528 
530 
532 
539  std::string description() const;
540 
563  void
564  describe (Teuchos::FancyOStream &out,
565  const Teuchos::EVerbosityLevel verbLevel =
566  Teuchos::Describable::verbLevel_default) const;
568 
569 private:
570 
571  typedef Teuchos::ScalarTraits<scalar_type> STS;
572  typedef Teuchos::ScalarTraits<magnitude_type> STM;
573 
575 
576 
578  Relaxation (const Relaxation<MatrixType>& RHS);
579 
581  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
582 
584 
586 
591  void setParametersImpl (Teuchos::ParameterList& params);
592 
594  void ApplyInverseJacobi(
595  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
596  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
597 
599  void ApplyInverseGS(
600  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
601  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
602 
604  void ApplyInverseGS_RowMatrix(
605  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
606  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
607 
609  void ApplyInverseGS_CrsMatrix(
610  const MatrixType& A,
611  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
612  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
613 
615  void ApplyInverseSGS(
616  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
617  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
618 
620  void ApplyInverseSGS_RowMatrix(
621  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
622  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
623 
625  void ApplyInverseSGS_CrsMatrix(
626  const MatrixType& A,
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 
633 
640  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
641 
643  const Teuchos::RCP<const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > A_;
645  Teuchos::RCP<Teuchos::Time> Time_;
647  Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
649  mutable Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
650 
652  int NumSweeps_;
654  int PrecType_;
656  scalar_type DampingFactor_;
658  bool IsParallel_;
660  bool ZeroStartingSolution_;
662  bool DoBackwardGS_;
664  bool DoL1Method_;
666  magnitude_type L1Eta_;
668  scalar_type MinDiagonalValue_;
670  bool fixTinyDiagEntries_;
672  bool checkDiagEntries_;
673 
675  magnitude_type Condest_;
677  bool IsInitialized_;
679  bool IsComputed_;
681  int NumInitialize_;
683  int NumCompute_;
685  mutable int NumApply_;
687  double InitializeTime_;
689  double ComputeTime_;
691  mutable double ApplyTime_;
693  double ComputeFlops_;
695  mutable double ApplyFlops_;
696 
698  magnitude_type globalMinMagDiagEntryMag_;
700  magnitude_type globalMaxMagDiagEntryMag_;
702  size_t globalNumSmallDiagEntries_;
704  size_t globalNumZeroDiagEntries_;
706  size_t globalNumNegDiagEntries_;
711  magnitude_type globalDiagNormDiff_;
712 
718  Teuchos::ArrayRCP<size_t> diagOffsets_;
724  bool savedDiagOffsets_;
726 
727 }; //class Relaxation
728 
729 }//namespace Ifpack2
730 
731 #endif // IFPACK2_RELAXATION_DECL_HPP
732 
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
TEUCHOS_DEPRECATED typedef MatrixType::scalar_type Scalar
Preserved only for backwards compatibility. Please use "scalar_type".
Definition: Ifpack2_Relaxation_decl.hpp:245
MatrixType::node_type node_type
The type of the Kokkos Node used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:263
TEUCHOS_DEPRECATED typedef MatrixType::node_type Node
Preserved only for backwards compatibility. Please use "node_type".
Definition: Ifpack2_Relaxation_decl.hpp:266
Base class for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:130
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Relaxation_decl.hpp:416
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:256
TEUCHOS_DEPRECATED typedef Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitudeType
Preserved only for backwards compatibility. Please use "magnitude_type".
Definition: Ifpack2_Relaxation_decl.hpp:273
Definition: Ifpack2_BlockRelaxation_decl.hpp:64
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:249
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:242
TEUCHOS_DEPRECATED typedef MatrixType::local_ordinal_type LocalOrdinal
Preserved only for backwards compatibility. Please use "local_ordinal_type".
Definition: Ifpack2_Relaxation_decl.hpp:252
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:408
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:231
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
TEUCHOS_DEPRECATED typedef MatrixType::global_ordinal_type GlobalOrdinal
Preserved only for backwards compatibility. Please use "global_ordinal_type".
Definition: Ifpack2_Relaxation_decl.hpp:259
void getValidParameters(Teuchos::ParameterList &params)
Fills a list which contains all the parameters possibly used by Ifpack2.
Definition: Ifpack2_Parameters.cpp:47
cheap estimate
Definition: Ifpack2_CondestType.hpp:51
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:270