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>
93  typedef Tpetra::RowMatrix<typename MV::scalar_type,
94  typename MV::local_ordinal_type,
95  typename MV::global_ordinal_type,
96  typename MV::node_type>
99  typedef Tpetra::Vector<typename MV::scalar_type,
100  typename MV::local_ordinal_type,
101  typename MV::global_ordinal_type,
102  typename MV::node_type>
103  V;
105  typedef Tpetra::Map<typename MV::local_ordinal_type,
106  typename MV::global_ordinal_type,
107  typename MV::node_type>
110 
119 
130 
240 
241  void setZeroStartingSolution(bool zeroStartingSolution) { zeroStartingSolution_ = zeroStartingSolution; }
242 
276  void compute();
277 
294  MT apply(const MV& B, MV& X);
295 
296  ST getLambdaMaxForApply() const;
297 
300 
307 
309  bool hasTransposeApply() const;
310 
312  void print(std::ostream& out);
313 
315 
317 
319  std::string description() const;
320 
322  void
324  const Teuchos::EVerbosityLevel verbLevel =
327  private:
329 
330 
338 
341 
353 
355  typedef Kokkos::View<size_t*, typename MV::node_type::device_type> offsets_type;
356 
362  offsets_type diagOffsets_;
363 
371  bool savedDiagOffsets_;
372 
374 
376 
380  Teuchos::RCP<MV> W_;
381  Teuchos::RCP<MV> W2_;
382 
388  ST computedLambdaMax_;
389 
395  ST computedLambdaMin_;
396 
398 
400 
403  ST lambdaMaxForApply_;
404 
411  MT boostFactor_;
414  ST lambdaMinForApply_;
417  ST eigRatioForApply_;
418 
420 
422 
427  Teuchos::RCP<const V> userInvDiag_;
428 
432  ST userLambdaMax_;
433 
437  ST userLambdaMin_;
438 
442  ST userEigRatio_;
443 
448  ST minDiagVal_;
449 
451  int numIters_;
452 
454  int eigMaxIters_;
455 
457  MT eigRelTolerance_;
458 
460  bool eigKeepVectors_;
461 
463  std::string eigenAnalysisType_;
464 
466  Teuchos::RCP<V> eigVector_;
467  Teuchos::RCP<V> eigVector2_;
468 
470  int eigNormalizationFreq_;
471 
473  bool zeroStartingSolution_;
474 
481  bool assumeMatrixUnchanged_;
482 
484  std::string chebyshevAlgorithm_;
485 
487  bool computeMaxResNorm_;
488 
490  bool computeSpectralRadius_;
491 
494  bool ckUseNativeSpMV_;
495 
500 
502  bool debug_;
503 
505 
507 
509  void checkConstructorInput() const;
510 
512  void checkInputMatrix() const;
513 
521  void reset();
522 
528  Teuchos::RCP<MV> makeTempMultiVector(const MV& B);
529 
536  Teuchos::RCP<MV> makeSecondTempMultiVector(const MV& B);
537 
539  void
540  firstIterationWithZeroStartingSolution(MV& W,
541  const ScalarType& alpha,
542  const V& D_inv,
543  const MV& B,
544  MV& X);
545 
547  static void
548  computeResidual(MV& R, const MV& B, const op_type& A, const MV& X,
549  const Teuchos::ETransp mode = Teuchos::NO_TRANS);
550 
556  static void solve(MV& Z, const V& D_inv, const MV& R);
557 
563  static void solve(MV& Z, const ST alpha, const V& D_inv, const MV& R);
564 
573  makeInverseDiagonal(const row_matrix_type& A, const bool useDiagOffsets = false) const;
574 
584  Teuchos::RCP<V> makeRangeMapVector(const Teuchos::RCP<V>& D) const;
585 
588  makeRangeMapVectorConst(const Teuchos::RCP<const V>& D) const;
589 
608  void
609  textbookApplyImpl(const op_type& A,
610  const MV& B,
611  MV& X,
612  const int numIters,
613  const ST lambdaMax,
614  const ST lambdaMin,
615  const ST eigRatio,
616  const V& D_inv) const;
617 
639  void
640  fourthKindApplyImpl(const op_type& A,
641  const MV& B,
642  MV& X,
643  const int numIters,
644  const ST lambdaMax,
645  const V& D_inv);
646 
669  void
670  ifpackApplyImpl(const op_type& A,
671  const MV& B,
672  MV& X,
673  const int numIters,
674  const ST lambdaMax,
675  const ST lambdaMin,
676  const ST eigRatio,
677  const V& D_inv);
678 
691  ST cgMethodWithInitGuess(const op_type& A, const V& D_inv, const int numIters, V& x);
692 
702  ST cgMethod(const op_type& A, const V& D_inv, const int numIters);
703 
705  static MT maxNormInf(const MV& X);
706 
707  // mfh 22 Jan 2013: This code builds correctly, but does not
708  // converge. I'm leaving it in place in case someone else wants to
709  // work on it.
710 #if 0
711  void
734  mlApplyImpl (const op_type& A,
735  const MV& B,
736  MV& X,
737  const int numIters,
738  const ST lambdaMax,
739  const ST lambdaMin,
740  const ST eigRatio,
741  const V& D_inv)
742  {
743  const ST zero = Teuchos::as<ST> (0);
744  const ST one = Teuchos::as<ST> (1);
745  const ST two = Teuchos::as<ST> (2);
746 
747  MV pAux (B.getMap (), B.getNumVectors ()); // Result of A*X
748  MV dk (B.getMap (), B.getNumVectors ()); // Solution update
749  MV R (B.getMap (), B.getNumVectors ()); // Not in original ML; need for B - pAux
750 
751  ST beta = Teuchos::as<ST> (1.1) * lambdaMax;
752  ST alpha = lambdaMax / eigRatio;
753 
754  ST delta = (beta - alpha) / two;
755  ST theta = (beta + alpha) / two;
756  ST s1 = theta / delta;
757  ST rhok = one / s1;
758 
759  // Diagonal: ML replaces entries containing 0 with 1. We
760  // shouldn't have any entries like that in typical test problems,
761  // so it's OK not to do that here.
762 
763  // The (scaled) matrix is the identity: set X = D_inv * B. (If A
764  // is the identity, then certainly D_inv is too. D_inv comes from
765  // A, so if D_inv * A is the identity, then we still need to apply
766  // the "preconditioner" D_inv to B as well, to get X.)
767  if (lambdaMin == one && lambdaMin == lambdaMax) {
768  solve (X, D_inv, B);
769  return;
770  }
771 
772  // The next bit of code is a direct translation of code from ML's
773  // ML_Cheby function, in the "normal point scaling" section, which
774  // is in lines 7365-7392 of ml_smoother.c.
775 
776  if (! zeroStartingSolution_) {
777  // dk = (1/theta) * D_inv * (B - (A*X))
778  A.apply (X, pAux); // pAux = A * X
779  R = B;
780  R.update (-one, pAux, one); // R = B - pAux
781  dk.elementWiseMultiply (one/theta, D_inv, R, zero); // dk = (1/theta)*D_inv*R
782  X.update (one, dk, one); // X = X + dk
783  } else {
784  dk.elementWiseMultiply (one/theta, D_inv, B, zero); // dk = (1/theta)*D_inv*B
785  X = dk;
786  }
787 
788  ST rhokp1, dtemp1, dtemp2;
789  for (int k = 0; k < numIters-1; ++k) {
790  A.apply (X, pAux);
791  rhokp1 = one / (two*s1 - rhok);
792  dtemp1 = rhokp1*rhok;
793  dtemp2 = two*rhokp1/delta;
794  rhok = rhokp1;
795 
796  R = B;
797  R.update (-one, pAux, one); // R = B - pAux
798  // dk = dtemp1 * dk + dtemp2 * D_inv * (B - pAux)
799  dk.elementWiseMultiply (dtemp2, D_inv, B, dtemp1);
800  X.update (one, dk, one); // X = X + dk
801  }
802  }
803 #endif // 0
804 
805 };
806 
807 } // namespace Details
808 } // namespace Ifpack2
809 
810 #endif // IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
void setParameters(Teuchos::ParameterList &plist)
Set (or reset) parameters.
Definition: Ifpack2_Details_Chebyshev_def.hpp:326
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:959
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:91
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:1613
void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set the matrix.
Definition: Ifpack2_Details_Chebyshev_def.hpp:734
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the matrix given to the constructor.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1549
Chebyshev(Teuchos::RCP< const row_matrix_type > A)
Definition: Ifpack2_Details_Chebyshev_def.hpp:263
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:108
void print(std::ostream &out)
Print instance data to the given output stream.
Definition: Ifpack2_Details_Chebyshev_def.hpp:1009
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:97
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:1593
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:1555
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:770
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:103