/usr/include/dune/istl/solver.hh is in libdune-istl-dev 2.4.1-1.
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 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_SOLVER_HH
#define DUNE_ISTL_SOLVER_HH
#include <iomanip>
#include <ostream>
namespace Dune
{
/**
* @addtogroup ISTL_Solvers
* @{
*/
/** \file
\brief Define general, extensible interface for inverse operators.
Implementation here covers only inversion of linear operators,
but the implementation might be used for nonlinear operators
as well.
*/
/**
\brief Statistics about the application of an inverse operator
The return value of an application of the inverse
operator delivers some important information about
the iteration.
*/
struct InverseOperatorResult
{
/** \brief Default constructor */
InverseOperatorResult ()
{
clear();
}
/** \brief Resets all data */
void clear ()
{
iterations = 0;
reduction = 0;
converged = false;
conv_rate = 1;
elapsed = 0;
}
/** \brief Number of iterations */
int iterations;
/** \brief Reduction achieved: \f$ \|b-A(x^n)\|/\|b-A(x^0)\|\f$ */
double reduction;
/** \brief True if convergence criterion has been met */
bool converged;
/** \brief Convergence rate (average reduction per step) */
double conv_rate;
/** \brief Elapsed time in seconds */
double elapsed;
};
//=====================================================================
/*!
\brief Abstract base class for all solvers.
An InverseOperator computes the solution of \f$ A(x)=b\f$ where
\f$ A : X \to Y \f$ is an operator.
Note that the solver "knows" which operator
to invert and which preconditioner to apply (if any). The
user is only interested in inverting the operator.
InverseOperator might be a Newton scheme, a Krylov subspace method,
or a direct solver or just anything.
*/
template<class X, class Y>
class InverseOperator {
public:
//! \brief Type of the domain of the operator to be inverted.
typedef X domain_type;
//! \brief Type of the range of the operator to be inverted.
typedef Y range_type;
/** \brief The field type of the operator. */
typedef typename X::field_type field_type;
/**
\brief Apply inverse operator,
\warning Note: right hand side b may be overwritten!
\param x The left hand side to store the result in.
\param b The right hand side
\param res Object to store the statistics about applying the operator.
*/
virtual void apply (X& x, Y& b, InverseOperatorResult& res) = 0;
/*!
\brief apply inverse operator, with given convergence criteria.
\warning Right hand side b may be overwritten!
\param x The left hand side to store the result in.
\param b The right hand side
\param reduction The minimum defect reduction to achieve.
\param res Object to store the statistics about applying the operator.
*/
virtual void apply (X& x, Y& b, double reduction, InverseOperatorResult& res) = 0;
//! \brief Destructor
virtual ~InverseOperator () {}
protected:
// spacing values
enum { iterationSpacing = 5 , normSpacing = 16 };
//! helper function for printing header of solver output
void printHeader(std::ostream& s) const
{
s << std::setw(iterationSpacing) << " Iter";
s << std::setw(normSpacing) << "Defect";
s << std::setw(normSpacing) << "Rate" << std::endl;
}
//! helper function for printing solver output
template <typename CountType, typename DataType>
void printOutput(std::ostream& s,
const CountType& iter,
const DataType& norm,
const DataType& norm_old) const
{
const DataType rate = norm/norm_old;
s << std::setw(iterationSpacing) << iter << " ";
s << std::setw(normSpacing) << norm << " ";
s << std::setw(normSpacing) << rate << std::endl;
}
//! helper function for printing solver output
template <typename CountType, typename DataType>
void printOutput(std::ostream& s,
const CountType& iter,
const DataType& norm) const
{
s << std::setw(iterationSpacing) << iter << " ";
s << std::setw(normSpacing) << norm << std::endl;
}
};
/**
* @}
*/
}
#endif
|