/usr/include/trilinos/Tifpack_Relaxation_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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | /*@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_RELAXATION_DECL_HPP
#define TIFPACK_RELAXATION_DECL_HPP
#include "Tifpack_ConfigDefs.hpp"
#include "Tifpack_Preconditioner.hpp"
#include "Tifpack_Condest.hpp"
#include "Tifpack_Parameters.hpp"
#include <Tpetra_Vector.hpp>
#include <Teuchos_TestForException.hpp>
#include <Teuchos_RCP.hpp>
#include <Teuchos_Time.hpp>
#include <Teuchos_TypeNameTraits.hpp>
#include <Teuchos_ScalarTraits.hpp>
#include <string>
#include <iostream>
#include <sstream>
namespace Teuchos {
// forward declaration
class ParameterList;
}
namespace Tifpack {
enum RelaxationType {
JACOBI,
GS,
SGS
};
//! Tifpack::Relaxation: defines relaxation preconditioners for Tpetra::RowMatrix objects.
/*!
The Tifpack::Relaxation class enables the construction of relaxation
preconditioners for Tpetra::RowMatrix. Tifpack::Relaxation
is derived from Tifpack::Preconditioner, which is itself derived
from Tpetra::Operator.
Therefore this object can be used as preconditioner everywhere an
apply() method is required in the preconditioning step.
This class enables the construction of the following simple preconditioners:
- Jacobi;
- Gauss-Seidel;
- Symmetric Gauss-Seidel.
<P>We now briefly describe the main features of the above preconditioners.
Consider a linear system of type
\f[
A x = b,
\f]
where \f$A\f$ is a square, real matrix, and \f$x, b\f$ are two real
vectors. We begin with the decomposition
\f[
A = D - E - F
\f]
where \f$D\f$ is the diagonal of A, \f$-E\f$ is the strict lower part, and
\f$-F\f$ is the strict upper part. It is assumed that the diagonal entries
of \f$A\f$ are different from zero.
<P>Given an starting solution \f$x_0\f$, an iteration of the (damped) Jacobi
method can be written in matrix form as follows:
\f[
x_{k+1} = \omega D^{-1}(E + F) x_k + D_{-1}b,
\f]
for \f$k < k_{max}\f$, and \f$\omega \f$ a damping parameter.
Using Tifpack::Jacobi, the user can apply the specified number of sweeps
(\f$k_{max}\f$), and the damping parameter. If only one sweep is used, then
the class simply applies the inverse of the diagonal of A to the input
vector.
<P>Given a starting solution \f$x_0\f$, an iteration of the (damped) GaussSeidel
method can be written in matrix form as follows:
\f[
(D - E) x_{k+1} = \omega F x_k + b,
\f]
for \f$k < k_{max}\f$, and \f$\omega \f$ a damping parameter. Equivalently,
the Gauss-Seidel preconditioner can be defined as
\f[
P_{GS}^{-1} = (D - E)^{-1}.
\f]
Clearly, the role of E and F can be interchanged. However,
Tifpack::GaussSeidel does not consider backward Gauss-Seidel methods.
<P>For a list of supported parameters, please refer to the Relaxation::setParameters method.
\author Michael Heroux, SNL 9214.
\date Last modified on 22-Jan-05.
*/
template<class MatrixType>
class Relaxation : 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;
// \name Constructors and Destructors
//@{
//! Relaxation constructor with given Tpetra::RowMatrix input.
explicit Relaxation(const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& Matrix);
//! Relaxation Destructor.
virtual ~Relaxation();
//@}
//@{ \name Preconditioner computation methods
//! Sets all the parameters for the preconditioner
/**
Valid parameters include the following:
<ul>
<li> "relaxation: type"<br>
Valid values (string):<br>
<ul>
<li> "Jacobi"
<li> "Gauss-Seidel"
<li> "Symmetric Gauss-Seidel"
</ul>
<li> "relaxation: sweeps" (int)
<li> "relaxation: damping factor" (floating-point)
<li> "relaxation: min diagonal value" (floating-point)
<li> "relaxation: zero starting solution" (bool)
<li> "relaxation: backward mode" (bool)
</ul>
*/
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 for the specified matrix, diagonal perturbation thresholds and relaxation parameters.
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;
//! Returns the Tpetra::Map object associated with the range of this operator.
const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& getRangeMap() const;
bool hasTransposeApply() const;
//! 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;
//! 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;
//! 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:
// @{ Internal methods
//! Copy constructor (should never be used)
Relaxation(const Relaxation<MatrixType>& RHS);
//! operator= (should never be used)
Relaxation<MatrixType>& operator=(const Relaxation<MatrixType>& RHS);
//! Applies the Jacobi preconditioner to X, returns the result in Y.
void ApplyInverseJacobi(
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
//! Applies the Gauss-Seidel preconditioner to X, returns the result in Y.
void ApplyInverseGS(
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
void ApplyInverseGS_RowMatrix(
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
void ApplyInverseGS_CrsMatrix(
const MatrixType& A,
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
//! Applies the symmetric Gauss-Seidel preconditioner to X, returns the result in Y.
void ApplyInverseSGS(
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
void ApplyInverseSGS_RowMatrix(
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
void ApplyInverseSGS_CrsMatrix(
const MatrixType& A,
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
//@}
// @{ Internal data and parameters
//! reference to the matrix to be preconditioned
const Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > A_;
//! Reference to the communicator object
const Teuchos::RCP<const Teuchos::Comm<int> > Comm_;
//! Time object to track timing.
Teuchos::RCP<Teuchos::Time> Time_;
//! Importer for parallel GS and SGS
Teuchos::RCP<Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> > Importer_;
//! Contains the diagonal elements of \c Matrix.
mutable Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > Diagonal_;
//! Number of application of the preconditioner (should be greater than 0).
int NumSweeps_;
//! Which type of point relaxation approach to use
int PrecType_;
//! Minimum diagonal value
Scalar MinDiagonalValue_;
//! Damping factor.
double DampingFactor_;
//! If \c true, more than 1 processor is currently used.
bool IsParallel_;
//! If \c true, the starting solution is always the zero vector.
bool ZeroStartingSolution_;
//! Backward-Mode Gauss Seidel
bool DoBackwardGS_;
//! Condition number estimate
magnitudeType Condest_;
//! If \c true, the preconditioner has been computed successfully.
bool IsInitialized_;
//! If \c true, the preconditioner has been computed successfully.
bool IsComputed_;
//! Contains the number of successful calls to initialize().
int NumInitialize_;
//! Contains the number of successful call to compute().
int NumCompute_;
//! Contains the number of successful call to apply().
mutable int NumApply_;
//! Contains the time for all successful calls to initialize().
double InitializeTime_;
//! Contains the time for all successful calls to compute().
double ComputeTime_;
//! Contains the time for all successful calls to apply().
mutable double ApplyTime_;
//! Contains the number of flops for compute().
double ComputeFlops_;
//! Contain sthe number of flops for apply().
mutable double ApplyFlops_;
//! Number of local rows.
size_t NumMyRows_;
//! Number of global rows.
global_size_t NumGlobalRows_;
//! Number of global nonzeros.
global_size_t NumGlobalNonzeros_;
//@}
}; //class Relaxation
}//namespace Tifpack
#endif // TIFPACK_RELAXATION_DECL_HPP
|