Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_Chebyshev_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
11 #define IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
12 
19 
20 #include "Ifpack2_ConfigDefs.hpp"
22 #include "Teuchos_Describable.hpp"
23 #include "Tpetra_CrsMatrix.hpp"
24 
25 namespace Ifpack2 {
26 namespace Details {
27 
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 template<class TpetraOperatorType>
30 class ChebyshevKernel; // forward declaration
31 #endif // DOXYGEN_SHOULD_SKIP_THIS
32 
74 template<class ScalarType, class MV>
76 public:
78 
79 
81  typedef ScalarType ST;
85  typedef typename STS::magnitudeType MT;
87  typedef Tpetra::Operator<typename MV::scalar_type,
88  typename MV::local_ordinal_type,
89  typename MV::global_ordinal_type,
90  typename MV::node_type> op_type;
92  typedef Tpetra::RowMatrix<typename MV::scalar_type,
93  typename MV::local_ordinal_type,
94  typename MV::global_ordinal_type,
95  typename MV::node_type> row_matrix_type;
97  typedef Tpetra::Vector<typename MV::scalar_type,
98  typename MV::local_ordinal_type,
99  typename MV::global_ordinal_type,
100  typename MV::node_type> V;
102  typedef Tpetra::Map<typename MV::local_ordinal_type,
103  typename MV::global_ordinal_type,
104  typename MV::node_type> map_type;
106 
115 
126 
236 
237  void setZeroStartingSolution (bool zeroStartingSolution) { zeroStartingSolution_ = zeroStartingSolution; }
238 
272  void compute ();
273 
290  MT apply (const MV& B, MV& X);
291 
292  ST getLambdaMaxForApply() const;
293 
296 
303 
305  bool hasTransposeApply () const;
306 
308  void print (std::ostream& out);
309 
311 
313 
315  std::string description() const;
316 
318  void
320  const Teuchos::EVerbosityLevel verbLevel =
323 private:
325 
326 
334 
337 
349 
351  typedef Kokkos::View<size_t*, typename MV::node_type::device_type> offsets_type;
352 
358  offsets_type diagOffsets_;
359 
367  bool savedDiagOffsets_;
368 
370 
372 
376  Teuchos::RCP<MV> W_;
377  Teuchos::RCP<MV> W2_;
378 
384  ST computedLambdaMax_;
385 
391  ST computedLambdaMin_;
392 
394 
396 
399  ST lambdaMaxForApply_;
400 
407  MT boostFactor_;
410  ST lambdaMinForApply_;
413  ST eigRatioForApply_;
414 
416 
418 
423  Teuchos::RCP<const V> userInvDiag_;
424 
428  ST userLambdaMax_;
429 
433  ST userLambdaMin_;
434 
438  ST userEigRatio_;
439 
444  ST minDiagVal_;
445 
447  int numIters_;
448 
450  int eigMaxIters_;
451 
453  MT eigRelTolerance_;
454 
456  bool eigKeepVectors_;
457 
459  std::string eigenAnalysisType_;
460 
462  Teuchos::RCP<V> eigVector_;
463  Teuchos::RCP<V> eigVector2_;
464 
466  int eigNormalizationFreq_;
467 
469  bool zeroStartingSolution_;
470 
477  bool assumeMatrixUnchanged_;
478 
480  std::string chebyshevAlgorithm_;
481 
483  bool computeMaxResNorm_;
484 
486  bool computeSpectralRadius_;
487 
490  bool ckUseNativeSpMV_;
491 
496 
498  bool debug_;
499 
501 
503 
505  void checkConstructorInput () const;
506 
508  void checkInputMatrix () const;
509 
517  void reset ();
518 
524  Teuchos::RCP<MV> makeTempMultiVector (const MV& B);
525 
532  Teuchos::RCP<MV> makeSecondTempMultiVector (const MV& B);
533 
535  void
536  firstIterationWithZeroStartingSolution
537  (MV& W,
538  const ScalarType& alpha,
539  const V& D_inv,
540  const MV& B,
541  MV& X);
542 
544  static void
545  computeResidual (MV& R, const MV& B, const op_type& A, const MV& X,
546  const Teuchos::ETransp mode = Teuchos::NO_TRANS);
547 
553  static void solve (MV& Z, const V& D_inv, const MV& R);
554 
560  static void solve (MV& Z, const ST alpha, const V& D_inv, const MV& R);
561 
570  makeInverseDiagonal (const row_matrix_type& A, const bool useDiagOffsets=false) const;
571 
581  Teuchos::RCP<V> makeRangeMapVector (const Teuchos::RCP<V>& D) const;
582 
585  makeRangeMapVectorConst (const Teuchos::RCP<const V>& D) const;
586 
605  void
606  textbookApplyImpl (const op_type& A,
607  const MV& B,
608  MV& X,
609  const int numIters,
610  const ST lambdaMax,
611  const ST lambdaMin,
612  const ST eigRatio,
613  const V& D_inv) const;
614 
636  void
637  fourthKindApplyImpl (const op_type& A,
638  const MV& B,
639  MV& X,
640  const int numIters,
641  const ST lambdaMax,
642  const V& D_inv);
643 
666  void
667  ifpackApplyImpl (const op_type& A,
668  const MV& B,
669  MV& X,
670  const int numIters,
671  const ST lambdaMax,
672  const ST lambdaMin,
673  const ST eigRatio,
674  const V& D_inv);
675 
688  ST
689  cgMethodWithInitGuess (const op_type& A, const V& D_inv, const int numIters, V& x);
690 
700  ST
701  cgMethod (const op_type& A, const V& D_inv, const int numIters);
702 
704  static MT maxNormInf (const MV& X);
705 
706  // mfh 22 Jan 2013: This code builds correctly, but does not
707  // converge. I'm leaving it in place in case someone else wants to
708  // work on it.
709 #if 0
710  void
733  mlApplyImpl (const op_type& A,
734  const MV& B,
735  MV& X,
736  const int numIters,
737  const ST lambdaMax,
738  const ST lambdaMin,
739  const ST eigRatio,
740  const V& D_inv)
741  {
742  const ST zero = Teuchos::as<ST> (0);
743  const ST one = Teuchos::as<ST> (1);
744  const ST two = Teuchos::as<ST> (2);
745 
746  MV pAux (B.getMap (), B.getNumVectors ()); // Result of A*X
747  MV dk (B.getMap (), B.getNumVectors ()); // Solution update
748  MV R (B.getMap (), B.getNumVectors ()); // Not in original ML; need for B - pAux
749 
750  ST beta = Teuchos::as<ST> (1.1) * lambdaMax;
751  ST alpha = lambdaMax / eigRatio;
752 
753  ST delta = (beta - alpha) / two;
754  ST theta = (beta + alpha) / two;
755  ST s1 = theta / delta;
756  ST rhok = one / s1;
757 
758  // Diagonal: ML replaces entries containing 0 with 1. We
759  // shouldn't have any entries like that in typical test problems,
760  // so it's OK not to do that here.
761 
762  // The (scaled) matrix is the identity: set X = D_inv * B. (If A
763  // is the identity, then certainly D_inv is too. D_inv comes from
764  // A, so if D_inv * A is the identity, then we still need to apply
765  // the "preconditioner" D_inv to B as well, to get X.)
766  if (lambdaMin == one && lambdaMin == lambdaMax) {
767  solve (X, D_inv, B);
768  return;
769  }
770 
771  // The next bit of code is a direct translation of code from ML's
772  // ML_Cheby function, in the "normal point scaling" section, which
773  // is in lines 7365-7392 of ml_smoother.c.
774 
775  if (! zeroStartingSolution_) {
776  // dk = (1/theta) * D_inv * (B - (A*X))
777  A.apply (X, pAux); // pAux = A * X
778  R = B;
779  R.update (-one, pAux, one); // R = B - pAux
780  dk.elementWiseMultiply (one/theta, D_inv, R, zero); // dk = (1/theta)*D_inv*R
781  X.update (one, dk, one); // X = X + dk
782  } else {
783  dk.elementWiseMultiply (one/theta, D_inv, B, zero); // dk = (1/theta)*D_inv*B
784  X = dk;
785  }
786 
787  ST rhokp1, dtemp1, dtemp2;
788  for (int k = 0; k < numIters-1; ++k) {
789  A.apply (X, pAux);
790  rhokp1 = one / (two*s1 - rhok);
791  dtemp1 = rhokp1*rhok;
792  dtemp2 = two*rhokp1/delta;
793  rhok = rhokp1;
794 
795  R = B;
796  R.update (-one, pAux, one); // R = B - pAux
797  // dk = dtemp1 * dk + dtemp2 * D_inv * (B - pAux)
798  dk.elementWiseMultiply (dtemp2, D_inv, B, dtemp1);
799  X.update (one, dk, one); // X = X + dk
800  }
801  }
802 #endif // 0
803 
804 };
805 
806 } // namespace Details
807 } // namespace Ifpack2
808 
809 #endif // IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
void setParameters(Teuchos::ParameterList &plist)
Set (or reset) parameters.
Definition: Ifpack2_Details_Chebyshev_def.hpp:349
MT apply(const MV &B, MV &X)
Solve Ax=b for x with Chebyshev iteration with left diagonal scaling.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1010
Tpetra::Operator< typename MV::scalar_type, typename MV::local_ordinal_type, typename MV::global_ordinal_type, typename MV::node_type > op_type
Specialization of Tpetra::Operator.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:90
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print a description of the Chebyshev solver to out.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1703
void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set the matrix.
Definition: Ifpack2_Details_Chebyshev_def.hpp:776
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the matrix given to the constructor.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1634
Chebyshev(Teuchos::RCP< const row_matrix_type > A)
Definition: Ifpack2_Details_Chebyshev_def.hpp:283
Tpetra::Map< typename MV::local_ordinal_type, typename MV::global_ordinal_type, typename MV::node_type > map_type
Specialization of Tpetra::Map.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:104
void print(std::ostream &out)
Print instance data to the given output stream.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1066
STS::magnitudeType MT
The type of the absolute value of a ScalarType.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:85
ScalarType ST
The type of entries in the matrix and vectors.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:81
Tpetra::RowMatrix< typename MV::scalar_type, typename MV::local_ordinal_type, typename MV::global_ordinal_type, typename MV::node_type > row_matrix_type
Specialization of Tpetra::RowMatrix.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:95
Left-scaled Chebyshev iteration.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:75
static const EVerbosityLevel verbLevel_default
std::string description() const
A single-line description of the Chebyshev solver.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1682
Teuchos::ScalarTraits< ScalarType > STS
Traits class for ST.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:83
bool hasTransposeApply() const
Whether it&#39;s possible to apply the transpose of this operator.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1641
void compute()
(Re)compute the left scaling D_inv, and estimate min and max eigenvalues of D_inv * A...
Definition: Ifpack2_Details_Chebyshev_def.hpp:817
Tpetra::Vector< typename MV::scalar_type, typename MV::local_ordinal_type, typename MV::global_ordinal_type, typename MV::node_type > V
Specialization of Tpetra::Vector.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:100