Dune Core Modules (2.5.2)

solver.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_ISTL_SOLVER_HH
5#define DUNE_ISTL_SOLVER_HH
6
7#include <iomanip>
8#include <ostream>
9
10namespace Dune
11{
32 {
35 {
36 clear();
37 }
38
40 void clear ()
41 {
42 iterations = 0;
43 reduction = 0;
44 converged = false;
45 conv_rate = 1;
46 elapsed = 0;
47 }
48
51
53 double reduction;
54
57
59 double conv_rate;
60
62 double elapsed;
63 };
64
65
66 //=====================================================================
78 template<class X, class Y>
80 public:
82 typedef X domain_type;
83
85 typedef Y range_type;
86
88 typedef typename X::field_type field_type;
89
102 virtual void apply (X& x, Y& b, InverseOperatorResult& res) = 0;
103
117 virtual void apply (X& x, Y& b, double reduction, InverseOperatorResult& res) = 0;
118
120 virtual ~InverseOperator () {}
121
122 protected:
123 // spacing values
124 enum { iterationSpacing = 5 , normSpacing = 16 };
125
127 void printHeader(std::ostream& s) const
128 {
129 s << std::setw(iterationSpacing) << " Iter";
130 s << std::setw(normSpacing) << "Defect";
131 s << std::setw(normSpacing) << "Rate" << std::endl;
132 }
133
135 template <typename CountType, typename DataType>
136 void printOutput(std::ostream& s,
137 const CountType& iter,
138 const DataType& norm,
139 const DataType& norm_old) const
140 {
141 const DataType rate = norm/norm_old;
142 s << std::setw(iterationSpacing) << iter << " ";
143 s << std::setw(normSpacing) << norm << " ";
144 s << std::setw(normSpacing) << rate << std::endl;
145 }
146
148 template <typename CountType, typename DataType>
149 void printOutput(std::ostream& s,
150 const CountType& iter,
151 const DataType& norm) const
152 {
153 s << std::setw(iterationSpacing) << iter << " ";
154 s << std::setw(normSpacing) << norm << std::endl;
155 }
156 };
157
161}
162
163#endif
Abstract base class for all solvers.
Definition: solver.hh:79
void printHeader(std::ostream &s) const
helper function for printing header of solver output
Definition: solver.hh:127
virtual ~InverseOperator()
Destructor.
Definition: solver.hh:120
void printOutput(std::ostream &s, const CountType &iter, const DataType &norm) const
helper function for printing solver output
Definition: solver.hh:149
void printOutput(std::ostream &s, const CountType &iter, const DataType &norm, const DataType &norm_old) const
helper function for printing solver output
Definition: solver.hh:136
virtual void apply(X &x, Y &b, double reduction, InverseOperatorResult &res)=0
apply inverse operator, with given convergence criteria.
Y range_type
Type of the range of the operator to be inverted.
Definition: solver.hh:85
X domain_type
Type of the domain of the operator to be inverted.
Definition: solver.hh:82
virtual void apply(X &x, Y &b, InverseOperatorResult &res)=0
Apply inverse operator,.
X::field_type field_type
The field type of the operator.
Definition: solver.hh:88
Dune namespace.
Definition: alignment.hh:11
Statistics about the application of an inverse operator.
Definition: solver.hh:32
InverseOperatorResult()
Default constructor.
Definition: solver.hh:34
double elapsed
Elapsed time in seconds.
Definition: solver.hh:62
int iterations
Number of iterations.
Definition: solver.hh:50
double reduction
Reduction achieved: .
Definition: solver.hh:53
void clear()
Resets all data.
Definition: solver.hh:40
double conv_rate
Convergence rate (average reduction per step)
Definition: solver.hh:59
bool converged
True if convergence criterion has been met.
Definition: solver.hh:56
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)