|
Ifpack2 Templated Preconditioning Package
Version 1.0
|
00001 /* 00002 @HEADER 00003 // *********************************************************************** 00004 // 00005 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package 00006 // Copyright (2009) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 //@HEADER 00042 */ 00043 00050 00051 #ifndef IFPACK2_CHEBYSHEV_DECL_HPP 00052 #define IFPACK2_CHEBYSHEV_DECL_HPP 00053 00054 #include <Ifpack2_ConfigDefs.hpp> 00055 #include <Ifpack2_Preconditioner.hpp> 00056 #include <Ifpack2_Details_CanChangeMatrix.hpp> 00057 00058 // FIXME (mfh 20 Nov 2013) We really shouldn't have to include both of 00059 // these, if we were to handle the implementation by pointer instead 00060 // of by value. 00061 #include <Ifpack2_Details_Chebyshev_decl.hpp> 00062 #include <Ifpack2_Details_Chebyshev_def.hpp> 00063 00064 #include <Tpetra_CrsMatrix.hpp> 00065 00066 #include <iostream> 00067 #include <string> 00068 #include <sstream> 00069 00070 00071 namespace Ifpack2 { 00072 00199 template<class MatrixType> 00200 class Chebyshev : 00201 virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type, 00202 typename MatrixType::local_ordinal_type, 00203 typename MatrixType::global_ordinal_type, 00204 typename MatrixType::node_type>, 00205 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type, 00206 typename MatrixType::local_ordinal_type, 00207 typename MatrixType::global_ordinal_type, 00208 typename MatrixType::node_type> > 00209 { 00210 public: 00212 00213 00215 typedef MatrixType matrix_type; 00216 00218 typedef typename MatrixType::scalar_type scalar_type; 00219 00221 TEUCHOS_DEPRECATED typedef typename MatrixType::scalar_type Scalar; 00222 00223 00225 typedef typename MatrixType::local_ordinal_type local_ordinal_type; 00226 00228 TEUCHOS_DEPRECATED typedef typename MatrixType::local_ordinal_type LocalOrdinal; 00229 00230 00232 typedef typename MatrixType::global_ordinal_type global_ordinal_type; 00233 00235 TEUCHOS_DEPRECATED typedef typename MatrixType::global_ordinal_type GlobalOrdinal; 00236 00237 00239 typedef typename MatrixType::node_type node_type; 00240 00242 TEUCHOS_DEPRECATED typedef typename MatrixType::node_type Node; 00243 00244 00246 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type; 00247 00249 TEUCHOS_DEPRECATED typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitudeType; 00250 00251 00258 typedef Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> row_matrix_type; 00259 00261 typedef Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> map_type; 00262 00268 typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vector_type; 00269 00271 // \name Constructors and destructors 00273 00295 explicit Chebyshev (const Teuchos::RCP<const row_matrix_type>& A); 00296 00298 virtual ~Chebyshev (); 00299 00301 00302 00303 00440 void setParameters (const Teuchos::ParameterList& params); 00441 00448 void initialize(); 00449 00452 inline bool isInitialized() const { 00453 return IsInitialized_; 00454 } 00455 00488 void compute (); 00489 00499 inline bool isComputed() const { 00500 return IsComputed_; 00501 } 00502 00504 00505 00506 00529 virtual void 00530 setMatrix (const Teuchos::RCP<const row_matrix_type>& A); 00531 00533 00534 00535 00564 void 00565 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X, 00566 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y, 00567 Teuchos::ETransp mode = Teuchos::NO_TRANS, 00568 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(), 00569 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const; 00570 00572 Teuchos::RCP<const map_type> getDomainMap() const; 00573 00575 Teuchos::RCP<const map_type> getRangeMap() const; 00576 00578 bool hasTransposeApply() const; 00579 00600 void 00601 applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X, 00602 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y, 00603 Teuchos::ETransp mode = Teuchos::NO_TRANS) const; 00604 00606 00607 00608 00618 virtual magnitude_type TEUCHOS_DEPRECATED 00619 computeCondEst (CondestType CT = Cheap, 00620 local_ordinal_type MaxIters = 1550, 00621 magnitude_type Tol = 1e-9, 00622 const Teuchos::Ptr<const row_matrix_type>& matrix = Teuchos::null); 00623 00625 00626 00627 00631 virtual magnitude_type TEUCHOS_DEPRECATED getCondEst() const; 00632 00634 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const; 00635 00637 Teuchos::RCP<const row_matrix_type> getMatrix() const; 00638 00640 Teuchos::RCP<const MatrixType > getCrsMatrix() const; 00641 00643 double getComputeFlops() const; 00644 00646 double getApplyFlops() const; 00647 00649 int getNumInitialize() const; 00650 00652 int getNumCompute() const; 00653 00655 int getNumApply() const; 00656 00658 double getInitializeTime() const; 00659 00661 double getComputeTime() const; 00662 00664 double getApplyTime() const; 00665 00667 typename MatrixType::scalar_type getLambdaMaxForApply() const; 00668 00670 00671 00672 00674 std::string description() const; 00675 00677 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const; 00678 00680 00681 00682 00689 static void TEUCHOS_DEPRECATED 00690 PowerMethod (const Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Operator, 00691 const vector_type& InvPointDiagonal, 00692 const int MaximumIterations, 00693 scalar_type& LambdaMax); 00694 00696 static void TEUCHOS_DEPRECATED 00697 CG (const Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Operator, 00698 const vector_type& InvPointDiagonal, 00699 const int MaximumIterations, 00700 scalar_type& lambda_min, scalar_type& lambda_max); 00701 00702 // This "template friend" declaration lets any Chebyshev 00703 // specialization be a friend of any of its other specializations. 00704 // That makes clone() easier to implement. 00705 template <class NewMatrixType> friend class Chebyshev; 00706 00729 template <typename NewMatrixType> 00730 Teuchos::RCP<Chebyshev<NewMatrixType> > 00731 clone (const Teuchos::RCP<const NewMatrixType>& A_newnode, 00732 const Teuchos::ParameterList& params) const; 00733 00735 00736 private: 00737 00739 typedef Teuchos::ScalarTraits<typename MatrixType::scalar_type> STS; 00740 00742 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV; 00743 00745 Chebyshev (const Chebyshev<MatrixType>&); 00746 00748 Chebyshev<MatrixType>& operator= (const Chebyshev<MatrixType>&); 00749 00757 void 00758 applyImpl (const MV& X, 00759 MV& Y, 00760 Teuchos::ETransp mode, 00761 scalar_type alpha, 00762 scalar_type beta) const; 00763 00765 00766 00774 mutable Details::Chebyshev<scalar_type, MV> impl_; 00775 00777 magnitude_type Condest_; 00779 bool IsInitialized_; 00781 bool IsComputed_; 00783 int NumInitialize_; 00785 int NumCompute_; 00790 mutable int NumApply_; 00792 double InitializeTime_; 00794 double ComputeTime_; 00799 mutable double ApplyTime_; 00801 double ComputeFlops_; 00806 mutable double ApplyFlops_; 00807 00809 }; // class Chebyshev 00810 00811 00812 template <typename MatrixType> 00813 template <typename NewMatrixType> 00814 Teuchos::RCP<Chebyshev<NewMatrixType> > 00815 Chebyshev<MatrixType>:: 00816 clone (const Teuchos::RCP<const NewMatrixType>& A_newnode, 00817 const Teuchos::ParameterList& params) const 00818 { 00819 using Teuchos::RCP; 00820 typedef Ifpack2::Chebyshev<NewMatrixType> new_prec_type; 00821 00822 RCP<new_prec_type> prec (new new_prec_type (A_newnode)); 00823 prec->setParameters (params); 00824 prec->initialize (); 00825 prec->compute (); 00826 return prec; 00827 } 00828 00829 } // namespace Ifpack2 00830 00831 #endif // IFPACK2_CHEBYSHEV_DECL_HPP 00832
1.7.6.1