/usr/include/trilinos/Tifpack_Diagonal_decl.hpp is in libtrilinos-dev 10.4.0.dfsg-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | /*@HEADER
// ***********************************************************************
//
// Tifpack: Tempated Object-Oriented Algebraic Preconditioner Package
// Copyright (2009) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
//@HEADER
*/
#ifndef TIFPACK_DIAGONAL_DECL_HPP
#define TIFPACK_DIAGONAL_DECL_HPP
#include "Tifpack_Preconditioner.hpp"
namespace Tifpack {
//! A class for diagonal preconditioning.
/**
Tifpack::Diagonal wraps a vector as a diagonal preconditioner.
The preconditioner is simply defined by
\f[
z_i = D_i r_i,
\f]
where \f$r,z\f$ are the vector to be preconditioned and the preconditioned vector, and \f$D_i\f$ is the i-th element of the scaling vector.
When Tifpack::Diagonal is constructed with a matrix, \f$D\f$ contains the inverted diagonal elements from the matrix.
When Tifpack::Diagonal is constructed with a vector, \f$D\f$ is the caller-supplied vector.
\author Michael Heroux, ETHZ/D-INFK
\date Tifpack conversion (from Ifpack code) 31-Mar-2010
*/
template<class MatrixType>
class Diagonal : virtual public Tifpack::Preconditioner<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> {
public:
typedef typename MatrixType::scalar_type Scalar;
typedef typename MatrixType::local_ordinal_type LocalOrdinal;
typedef typename MatrixType::global_ordinal_type GlobalOrdinal;
typedef typename MatrixType::node_type Node;
typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
//! Constructor to create a Diagonal preconditioner using a Tpetra::CrsMatrix.
Diagonal(const Teuchos::RCP<const MatrixType>& A);
//! Constructor to create a Diagonal preconditioner using a Tpetra::Vector.
/**
* If your compiler complains about this constructor being ambigous with the
* other constructor overload, instead call the free-standing function
* Tifpack::createDiagonalPreconditioner which is located at the bottom
* of this header file.
* (This issue arises if this constructor is called with a RCP<Tpetra::Vector>
* that isn't const-qualified exactly as declared here.)
*/
Diagonal(const Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& diag);
public:
//! Destructor
virtual ~Diagonal();
//! Sets parameters on this object.
/**
Currently doesn't need any parameters.
*/
void setParameters(const Teuchos::ParameterList& params);
//! Initialize
void initialize();
//! Returns \c true if the preconditioner has been successfully initialized.
inline bool isInitialized() const {
return(isInitialized_);
}
//! compute the preconditioner
void compute();
//! Return true if compute() has been called.
inline bool isComputed() const {
return(isComputed_);
}
//! @name Methods implementing a Tpetra::Operator interface.
//@{
//! Applies the preconditioner to X, returns the result in Y.
/*!
\param
X - (In) A Tpetra::MultiVector of dimension NumVectors to be preconditioned.
\param
Y - (InOut) A Tpetra::MultiVector of dimension NumVectors containing result.
\return Integer error code, set to 0 if successful.
\warning This routine is NOT AztecOO compliant.
*/
void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
Teuchos::ETransp mode = Teuchos::NO_TRANS,
Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
//! Returns the Tpetra::Map object associated with the domain of this operator.
const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getDomainMap() const
{ return domainMap_; }
//! Returns the Tpetra::Map object associated with the range of this operator.
const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const
{ return rangeMap_; }
//! Applies the matrix to a Tpetra::MultiVector.
/*!
\param
X - (In) A Tpetra::MultiVector of dimension NumVectors to multiply with matrix.
\param
Y - (Out) A Tpetra::MultiVector of dimension NumVectors containing the result.
*/
void applyMat(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
//@}
//@{
//! \name Mathematical functions.
//! Computes the estimated condition number and returns the value.
magnitudeType computeCondEst(CondestType CT = Cheap,
LocalOrdinal MaxIters = 1550,
magnitudeType Tol = 1e-9,
const Teuchos::Ptr<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &matrix = Teuchos::null);
//@}
//@{
//! \name Attribute accessor methods
//! Returns the computed estimated condition number, or -1.0 if no computed.
magnitudeType getCondEst() const
{ return condEst_; }
//! Returns the Tpetra::BlockMap object associated with the range of this matrix operator.
const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
//! Returns a reference to the matrix to be preconditioned.
Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > getMatrix() const
{ return matrix_; }
//! Returns the number of flops in the computation phase.
double getComputeFlops() const;
//! Returns the number of flops for the application of the preconditioner.
double getApplyFlops() const;
//! Returns the number of calls to initialize().
int getNumInitialize() const;
//! Returns the number of calls to compute().
int getNumCompute() const;
//! Returns the number of calls to apply().
int getNumApply() const;
//! Returns the time spent in initialize().
double getInitializeTime() const;
//! Returns the time spent in compute().
double getComputeTime() const;
//! Returns the time spent in apply().
double getApplyTime() const;
//@}
//! @name Overridden from Teuchos::Describable
//@{
/** \brief Return a simple one-line description of this object. */
std::string description() const;
/** \brief Print the object with some verbosity level to an FancyOStream object. */
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
//@}
private:
bool isInitialized_;
bool isComputed_;
Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domainMap_;
Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rangeMap_;
Teuchos::RCP<const MatrixType> matrix_;
Teuchos::RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > inversediag_;
mutable int numInitialize_;
mutable int numCompute_;
mutable int numApply_;
double initializeTime_;
double computeTime_;
double applyTime_;
magnitudeType condEst_;
};
/** Function to construct a Diagonal preconditioner with vector input.
* The input vector is assumed to contain the equivalent of the inverted
* diagonal of a matrix.
*
* Example usage:<br>
* typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> TCrsMatrix;<br>
* typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TVector;<br>
* typedef Tpetra::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> TPrec;
*
* Teuchos::RCP<TVector> myvec = ...
*
* Teuchos::RCP<TPrec> prec = Tifpack::createDiagonalPreconditioner<TCrsMatrix,TVector>(myvec);
*
*/
template<class MatrixType,class VectorType>
Teuchos::RCP<Tifpack::Diagonal<MatrixType> >
createDiagonalPreconditioner(const Teuchos::RCP<const VectorType>& invdiag)
{
return Teuchos::rcp(new Tifpack::Diagonal<MatrixType>(invdiag));
}
}//namespace Tifpack
#endif
|