Dune Core Modules (2.3.1)

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
99 virtual void apply (X& x, Y& b, InverseOperatorResult& res) = 0;
100
111 virtual void apply (X& x, Y& b, double reduction, InverseOperatorResult& res) = 0;
112
114 virtual ~InverseOperator () {}
115
116 protected:
117 // spacing values
118 enum { iterationSpacing = 5 , normSpacing = 16 };
119
121 void printHeader(std::ostream& s) const
122 {
123 s << std::setw(iterationSpacing) << " Iter";
124 s << std::setw(normSpacing) << "Defect";
125 s << std::setw(normSpacing) << "Rate" << std::endl;
126 }
127
129 template <class DataType>
130 void printOutput(std::ostream& s,
131 const double iter,
132 const DataType& norm,
133 const DataType& norm_old) const
134 {
135 const DataType rate = norm/norm_old;
136 s << std::setw(iterationSpacing) << iter << " ";
137 s << std::setw(normSpacing) << norm << " ";
138 s << std::setw(normSpacing) << rate << std::endl;
139 }
140
142 template <class DataType>
143 void printOutput(std::ostream& s,
144 const double iter,
145 const DataType& norm) const
146 {
147 s << std::setw(iterationSpacing) << iter << " ";
148 s << std::setw(normSpacing) << norm << std::endl;
149 }
150 };
151
155}
156
157#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:121
virtual ~InverseOperator()
Destructor.
Definition: solver.hh:114
void printOutput(std::ostream &s, const double iter, const DataType &norm, const DataType &norm_old) const
helper function for printing solver output
Definition: solver.hh:130
void printOutput(std::ostream &s, const double iter, const DataType &norm) const
helper function for printing solver output
Definition: solver.hh:143
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:14
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 (Jul 15, 22:36, 2024)