|
Ifpack2 Templated Preconditioning Package
Version 1.0
|
00001 /*@HEADER 00002 // *********************************************************************** 00003 // 00004 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package 00005 // Copyright (2009) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 */ 00029 00030 #ifndef IFPACK2_DIAGONAL_DEF_HPP 00031 #define IFPACK2_DIAGONAL_DEF_HPP 00032 00033 #include "Ifpack2_Diagonal_decl.hpp" 00034 #include "Ifpack2_Condest.hpp" 00035 00036 namespace Ifpack2 { 00037 00038 template<class MatrixType> 00039 Diagonal<MatrixType>::Diagonal(const Teuchos::RCP<const MatrixType>& A) 00040 : isInitialized_(false), 00041 isComputed_(false), 00042 domainMap_(A->getDomainMap()), 00043 rangeMap_(A->getRangeMap()), 00044 matrix_(A), 00045 inversediag_(), 00046 numInitialize_(0), 00047 numCompute_(0), 00048 numApply_(0), 00049 condEst_(-1.0) 00050 { 00051 } 00052 00053 template<class MatrixType> 00054 Diagonal<MatrixType>::Diagonal(const Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& diag) 00055 : isInitialized_(false), 00056 isComputed_(false), 00057 domainMap_(), 00058 rangeMap_(), 00059 matrix_(), 00060 inversediag_(diag), 00061 numInitialize_(0), 00062 numCompute_(0), 00063 numApply_(0), 00064 condEst_(-1.0) 00065 { 00066 } 00067 00068 template<class MatrixType> 00069 Diagonal<MatrixType>::~Diagonal() 00070 { 00071 } 00072 00073 template<class MatrixType> 00074 void Diagonal<MatrixType>::setParameters(const Teuchos::ParameterList& /*params*/) 00075 { 00076 } 00077 00078 template<class MatrixType> 00079 void Diagonal<MatrixType>::initialize() 00080 { 00081 if (isInitialized_ == true) return; 00082 isInitialized_ = true; 00083 ++numInitialize_; 00084 //nothing to do 00085 } 00086 00087 template<class MatrixType> 00088 void Diagonal<MatrixType>::compute() 00089 { 00090 initialize(); 00091 ++numCompute_; 00092 00093 if (isComputed_ == true) return; 00094 00095 isComputed_ = true; 00096 00097 if (matrix_ == Teuchos::null) return; 00098 00099 Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tmp_vec = Teuchos::rcp(new Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrix_->getRowMap())); 00100 00101 matrix_->getLocalDiagCopy(*tmp_vec); 00102 tmp_vec->reciprocal(*tmp_vec); 00103 00104 inversediag_ = tmp_vec; 00105 } 00106 00107 template<class MatrixType> 00108 void Diagonal<MatrixType>::apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X, 00109 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y, 00110 Teuchos::ETransp /*mode*/, 00111 Scalar alpha, 00112 Scalar beta) const 00113 { 00114 TEUCHOS_TEST_FOR_EXCEPTION(!isComputed(), std::runtime_error, 00115 "Ifpack2::Diagonal::apply() ERROR, compute() hasn't been called yet."); 00116 00117 ++numApply_; 00118 Y.elementWiseMultiply(alpha, *inversediag_, X, beta); 00119 } 00120 00121 template<class MatrixType> 00122 typename Teuchos::ScalarTraits<typename MatrixType::scalar_type>::magnitudeType 00123 Diagonal<MatrixType>::computeCondEst( 00124 CondestType CT, 00125 LocalOrdinal MaxIters, 00126 magnitudeType Tol, 00127 const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix) { 00128 if (!isComputed()) { // cannot compute right now 00129 return(-1.0); 00130 } 00131 // NOTE: this is computing the *local* condest 00132 if (condEst_ == -1.0) { 00133 condEst_ = Ifpack2::Condest(*this, CT, MaxIters, Tol, matrix); 00134 } 00135 return(condEst_); 00136 } 00137 00138 template <class MatrixType> 00139 int Diagonal<MatrixType>::getNumInitialize() const { 00140 return(numInitialize_); 00141 } 00142 00143 template <class MatrixType> 00144 int Diagonal<MatrixType>::getNumCompute() const { 00145 return(numCompute_); 00146 } 00147 00148 template <class MatrixType> 00149 int Diagonal<MatrixType>::getNumApply() const { 00150 return(numApply_); 00151 } 00152 00153 template <class MatrixType> 00154 double Diagonal<MatrixType>::getInitializeTime() const { 00155 return(initializeTime_); 00156 } 00157 00158 template<class MatrixType> 00159 double Diagonal<MatrixType>::getComputeTime() const { 00160 return(computeTime_); 00161 } 00162 00163 template<class MatrixType> 00164 double Diagonal<MatrixType>::getApplyTime() const { 00165 return(applyTime_); 00166 } 00167 00168 template <class MatrixType> 00169 std::string Diagonal<MatrixType>::description() const 00170 { 00171 return std::string("Ifpack2::Diagonal"); 00172 } 00173 00174 template <class MatrixType> 00175 void Diagonal<MatrixType>::describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const 00176 { 00177 if (verbLevel != Teuchos::VERB_NONE) { 00178 out << this->description() << std::endl; 00179 out << " numApply: " << numApply_ << std::endl; 00180 } 00181 } 00182 00183 }//namespace Ifpack2 00184 00185 #endif
1.7.6.1