Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_Details_Chebyshev_decl.hpp
Go to the documentation of this file.
1/*
2//@HEADER
3// ***********************************************************************
4//
5// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
6// Copyright (2009) Sandia Corporation
7//
8// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9// license for use of this work by or on behalf of the U.S. Government.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39//
40// ***********************************************************************
41//@HEADER
42*/
43
44#ifndef IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
45#define IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
46
53
54#include "Ifpack2_ConfigDefs.hpp"
55#include "Teuchos_VerbosityLevel.hpp"
56#include "Teuchos_Describable.hpp"
57#include "Tpetra_CrsMatrix.hpp"
58
59namespace Ifpack2 {
60namespace Details {
61
62#ifndef DOXYGEN_SHOULD_SKIP_THIS
63template<class TpetraOperatorType>
64class ChebyshevKernel; // forward declaration
65#endif // DOXYGEN_SHOULD_SKIP_THIS
66
108template<class ScalarType, class MV>
109class Chebyshev : public Teuchos::Describable {
110public:
112
113
115 typedef ScalarType ST;
117 typedef Teuchos::ScalarTraits<ScalarType> STS;
119 typedef typename STS::magnitudeType MT;
121 typedef Tpetra::Operator<typename MV::scalar_type,
122 typename MV::local_ordinal_type,
123 typename MV::global_ordinal_type,
124 typename MV::node_type> op_type;
126 typedef Tpetra::RowMatrix<typename MV::scalar_type,
127 typename MV::local_ordinal_type,
128 typename MV::global_ordinal_type,
129 typename MV::node_type> row_matrix_type;
131 typedef Tpetra::Vector<typename MV::scalar_type,
132 typename MV::local_ordinal_type,
133 typename MV::global_ordinal_type,
134 typename MV::node_type> V;
136 typedef Tpetra::Map<typename MV::local_ordinal_type,
137 typename MV::global_ordinal_type,
138 typename MV::node_type> map_type;
140
148 Chebyshev (Teuchos::RCP<const row_matrix_type> A);
149
159 Chebyshev (Teuchos::RCP<const row_matrix_type> A, Teuchos::ParameterList& params);
160
269 void setParameters (Teuchos::ParameterList& plist);
270
271 void setZeroStartingSolution (bool zeroStartingSolution) { zeroStartingSolution_ = zeroStartingSolution; }
272
306 void compute ();
307
324 MT apply (const MV& B, MV& X);
325
326 ST getLambdaMaxForApply() const;
327
329 Teuchos::RCP<const row_matrix_type> getMatrix () const;
330
336 void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
337
339 bool hasTransposeApply () const;
340
342 void print (std::ostream& out);
343
345
347
349 std::string description() const;
350
352 void
353 describe (Teuchos::FancyOStream& out,
354 const Teuchos::EVerbosityLevel verbLevel =
355 Teuchos::Describable::verbLevel_default) const;
357private:
359
360
367 Teuchos::RCP<const row_matrix_type> A_;
368
370 Teuchos::RCP<ChebyshevKernel<op_type> > ck_;
371
382 Teuchos::RCP<const V> D_;
383
385 typedef Kokkos::View<size_t*, typename MV::node_type::device_type> offsets_type;
386
392 offsets_type diagOffsets_;
393
401 bool savedDiagOffsets_;
402
404
406
410 Teuchos::RCP<MV> W_;
411 Teuchos::RCP<MV> W2_;
412
418 ST computedLambdaMax_;
419
425 ST computedLambdaMin_;
426
428
430
433 ST lambdaMaxForApply_;
434
441 MT boostFactor_;
444 ST lambdaMinForApply_;
447 ST eigRatioForApply_;
448
450
452
457 Teuchos::RCP<const V> userInvDiag_;
458
462 ST userLambdaMax_;
463
467 ST userLambdaMin_;
468
472 ST userEigRatio_;
473
478 ST minDiagVal_;
479
481 int numIters_;
482
484 int eigMaxIters_;
485
487 MT eigRelTolerance_;
488
490 bool eigKeepVectors_;
491
493 std::string eigenAnalysisType_;
494
496 Teuchos::RCP<V> eigVector_;
497 Teuchos::RCP<V> eigVector2_;
498
500 int eigNormalizationFreq_;
501
503 bool zeroStartingSolution_;
504
511 bool assumeMatrixUnchanged_;
512
514 std::string chebyshevAlgorithm_;
515
517 bool computeMaxResNorm_;
518
520 bool computeSpectralRadius_;
521
524 bool ckUseNativeSpMV_;
525
529 Teuchos::RCP<Teuchos::FancyOStream> out_;
530
532 bool debug_;
533
535
537
539 void checkConstructorInput () const;
540
542 void checkInputMatrix () const;
543
551 void reset ();
552
558 Teuchos::RCP<MV> makeTempMultiVector (const MV& B);
559
566 Teuchos::RCP<MV> makeSecondTempMultiVector (const MV& B);
567
569 void
570 firstIterationWithZeroStartingSolution
571 (MV& W,
572 const ScalarType& alpha,
573 const V& D_inv,
574 const MV& B,
575 MV& X);
576
578 static void
579 computeResidual (MV& R, const MV& B, const op_type& A, const MV& X,
580 const Teuchos::ETransp mode = Teuchos::NO_TRANS);
581
587 static void solve (MV& Z, const V& D_inv, const MV& R);
588
594 static void solve (MV& Z, const ST alpha, const V& D_inv, const MV& R);
595
603 Teuchos::RCP<const V>
604 makeInverseDiagonal (const row_matrix_type& A, const bool useDiagOffsets=false) const;
605
615 Teuchos::RCP<V> makeRangeMapVector (const Teuchos::RCP<V>& D) const;
616
618 Teuchos::RCP<const V>
619 makeRangeMapVectorConst (const Teuchos::RCP<const V>& D) const;
620
639 void
640 textbookApplyImpl (const op_type& A,
641 const MV& B,
642 MV& X,
643 const int numIters,
644 const ST lambdaMax,
645 const ST lambdaMin,
646 const ST eigRatio,
647 const V& D_inv) const;
648
670 void
671 fourthKindApplyImpl (const op_type& A,
672 const MV& B,
673 MV& X,
674 const int numIters,
675 const ST lambdaMax,
676 const V& D_inv);
677
700 void
701 ifpackApplyImpl (const op_type& A,
702 const MV& B,
703 MV& X,
704 const int numIters,
705 const ST lambdaMax,
706 const ST lambdaMin,
707 const ST eigRatio,
708 const V& D_inv);
709
722 ST
723 cgMethodWithInitGuess (const op_type& A, const V& D_inv, const int numIters, V& x);
724
734 ST
735 cgMethod (const op_type& A, const V& D_inv, const int numIters);
736
738 static MT maxNormInf (const MV& X);
739
740 // mfh 22 Jan 2013: This code builds correctly, but does not
741 // converge. I'm leaving it in place in case someone else wants to
742 // work on it.
743#if 0
766 void
767 mlApplyImpl (const op_type& A,
768 const MV& B,
769 MV& X,
770 const int numIters,
771 const ST lambdaMax,
772 const ST lambdaMin,
773 const ST eigRatio,
774 const V& D_inv)
775 {
776 const ST zero = Teuchos::as<ST> (0);
777 const ST one = Teuchos::as<ST> (1);
778 const ST two = Teuchos::as<ST> (2);
779
780 MV pAux (B.getMap (), B.getNumVectors ()); // Result of A*X
781 MV dk (B.getMap (), B.getNumVectors ()); // Solution update
782 MV R (B.getMap (), B.getNumVectors ()); // Not in original ML; need for B - pAux
783
784 ST beta = Teuchos::as<ST> (1.1) * lambdaMax;
785 ST alpha = lambdaMax / eigRatio;
786
787 ST delta = (beta - alpha) / two;
788 ST theta = (beta + alpha) / two;
789 ST s1 = theta / delta;
790 ST rhok = one / s1;
791
792 // Diagonal: ML replaces entries containing 0 with 1. We
793 // shouldn't have any entries like that in typical test problems,
794 // so it's OK not to do that here.
795
796 // The (scaled) matrix is the identity: set X = D_inv * B. (If A
797 // is the identity, then certainly D_inv is too. D_inv comes from
798 // A, so if D_inv * A is the identity, then we still need to apply
799 // the "preconditioner" D_inv to B as well, to get X.)
800 if (lambdaMin == one && lambdaMin == lambdaMax) {
801 solve (X, D_inv, B);
802 return;
803 }
804
805 // The next bit of code is a direct translation of code from ML's
806 // ML_Cheby function, in the "normal point scaling" section, which
807 // is in lines 7365-7392 of ml_smoother.c.
808
809 if (! zeroStartingSolution_) {
810 // dk = (1/theta) * D_inv * (B - (A*X))
811 A.apply (X, pAux); // pAux = A * X
812 R = B;
813 R.update (-one, pAux, one); // R = B - pAux
814 dk.elementWiseMultiply (one/theta, D_inv, R, zero); // dk = (1/theta)*D_inv*R
815 X.update (one, dk, one); // X = X + dk
816 } else {
817 dk.elementWiseMultiply (one/theta, D_inv, B, zero); // dk = (1/theta)*D_inv*B
818 X = dk;
819 }
820
821 ST rhokp1, dtemp1, dtemp2;
822 for (int k = 0; k < numIters-1; ++k) {
823 A.apply (X, pAux);
824 rhokp1 = one / (two*s1 - rhok);
825 dtemp1 = rhokp1*rhok;
826 dtemp2 = two*rhokp1/delta;
827 rhok = rhokp1;
828
829 R = B;
830 R.update (-one, pAux, one); // R = B - pAux
831 // dk = dtemp1 * dk + dtemp2 * D_inv * (B - pAux)
832 dk.elementWiseMultiply (dtemp2, D_inv, B, dtemp1);
833 X.update (one, dk, one); // X = X + dk
834 }
835 }
836#endif // 0
838};
839
840} // namespace Details
841} // namespace Ifpack2
842
843#endif // IFPACK2_DETAILS_CHEBYSHEV_DECL_HPP
Compute scaled damped residual for Chebyshev.
Definition Ifpack2_Details_ChebyshevKernel_decl.hpp:77
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:134
Teuchos::ScalarTraits< ScalarType > STS
Traits class for ST.
Definition Ifpack2_Details_Chebyshev_decl.hpp:117
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:822
void setParameters(Teuchos::ParameterList &plist)
Set (or reset) parameters.
Definition Ifpack2_Details_Chebyshev_def.hpp:354
void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set the matrix.
Definition Ifpack2_Details_Chebyshev_def.hpp:781
std::string description() const
A single-line description of the Chebyshev solver.
Definition Ifpack2_Details_Chebyshev_def.hpp:1678
Chebyshev(Teuchos::RCP< const row_matrix_type > A)
Definition Ifpack2_Details_Chebyshev_def.hpp:288
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:138
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:129
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:1699
void print(std::ostream &out)
Print instance data to the given output stream.
Definition Ifpack2_Details_Chebyshev_def.hpp:1071
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:124
ScalarType ST
The type of entries in the matrix and vectors.
Definition Ifpack2_Details_Chebyshev_decl.hpp:115
STS::magnitudeType MT
The type of the absolute value of a ScalarType.
Definition Ifpack2_Details_Chebyshev_decl.hpp:119
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:1015
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition Ifpack2_Details_Chebyshev_def.hpp:1637
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the matrix given to the constructor.
Definition Ifpack2_Details_Chebyshev_def.hpp:1630
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74