Skip to content
Snippets Groups Projects
Commit 74b7b0b0 authored by Uli Sack's avatar Uli Sack Committed by usack
Browse files

introduced rudimentary highly experimental feature of a SolverResult class to...

introduced rudimentary highly experimental feature of a SolverResult class to contain result related information such as for example number of performed iterations, convergence rates etc; NOTE: the implementation and interface will change w/o further notice

[[Imported from SVN: r7084]]
parent e34f2190
Branches
Tags
No related merge requests found
......@@ -26,7 +26,7 @@
/** \brief Constructor taking all relevant data */
IterativeSolver(int maxIterations,
double tolerance,
Norm<VectorType>* errorNorm,
const Norm<VectorType>* errorNorm,
VerbosityMode verbosity,
bool useRelativeError=true)
: Solver(verbosity),
......@@ -54,7 +54,7 @@
int maxIterations_;
//! The norm used to measure convergence
Norm<VectorType>* errorNorm_;
const Norm<VectorType>* errorNorm_;
/** \brief If this string is nonempty it is expected to contain a valid
directory name. All intermediate iterates are then written there. */
......
......@@ -2,6 +2,7 @@
#include <limits>
#include <iostream>
#include <iomanip>
#include <dune/solvers/solvers/solver.hh>
template <class VectorType, class BitVectorType>
void ::LoopSolver<VectorType, BitVectorType>::check() const
......@@ -16,7 +17,7 @@ void ::LoopSolver<VectorType, BitVectorType>::check() const
}
template <class VectorType, class BitVectorType>
void ::LoopSolver<VectorType, BitVectorType>::solve()
void LoopSolver<VectorType, BitVectorType>::solve()
{
int i;
......@@ -70,8 +71,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
int convRateCounter = 0;
// Loop until desired tolerance or maximum number of iterations is reached
for (i=0; i<this->maxIterations_ && (error>this->tolerance_ || std::isnan(error)); i++) {
for (i=0; i<this->maxIterations_ && (error>this->tolerance_ || std::isnan(error)); i++)
{
// Backup of the current solution for the error computation later on
VectorType oldSolution = iterationStep_->getSol();
......@@ -107,7 +108,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
if (this->useRelativeError_ && !std::isnan(error/oldNorm))
error = error / oldNorm;
if (!isinf(convRate) && !isnan(convRate) && i>0) {
if (!isinf(convRate) && !isnan(convRate) && i>0)
{
totalConvRate *= convRate;
this->maxTotalConvRate_ = std::max(this->maxTotalConvRate_, std::pow(totalConvRate, 1/((double)convRateCounter+1)));
convRateCounter++;
......@@ -155,4 +157,6 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
std::cout << "--------------------\n";
}
this->setResult(i,error<=this->tolerance_,totalConvRate);
}
......@@ -19,7 +19,7 @@ public:
LoopSolver(IterationStep<VectorType, BitVectorType>* iterationStep,
int maxIterations,
double tolerance,
Norm<VectorType>* errorNorm,
const Norm<VectorType>* errorNorm,
Solver::VerbosityMode verbosity,
bool useRelativeError=true,
const VectorType* referenceSolution=0)
......
......@@ -3,11 +3,32 @@
#include <dune/solvers/common/numproc.hh>
/** \brief The base class for all sorts of solver algorithms */
class Solver : public NumProc
{
/** \brief struct to store result related information such as for example number of iterations etc.
*
* \warning The interface and implementation is so far highly experimental and will change without further notice!
*/
struct SolverResult
{
size_t iterations;
bool converged;
double conv_rate;
// double reduction;
// double elapsed;
SolverResult(){}
SolverResult(size_t iter, bool conv, double rate):
iterations(iter),
converged(conv),
conv_rate(rate)
{}
};
/** \brief The base class for all sorts of solver algorithms */
class Solver : public NumProc
{
public:
Solver(VerbosityMode verbosity)
Solver(VerbosityMode verbosity=FULL)
: NumProc(verbosity)
{}
......@@ -24,5 +45,24 @@
* solution algorithm */
virtual void solve() = 0;
};
SolverResult& getResult()
{
return result;
}
void setResult(const SolverResult& new_result)
{
result = new_result;
}
void setResult(size_t iter, bool conv, double rate)
{
result.iterations = iter;
result.converged = conv;
result.conv_rate = rate;
}
private:
SolverResult result;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment