Skip to content
Snippets Groups Projects
Commit 71d5e497 authored by Oliver Sander's avatar Oliver Sander
Browse files

LinearSolver is now called IterativeSolver

[[Imported from SVN: r1053]]
parent 14c7fcb0
No related branches found
No related tags found
No related merge requests found
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
template <class OperatorType, class DiscFuncType>
inline
void Dune::IterativeSolver<OperatorType, DiscFuncType>::solve()
{
int i;
if (verbosity_ != QUIET)
std::cout << "--- LinearSolver ---\n";
double error = std::numeric_limits<double>::max();
double normOfOldCorrection = 0;
// Loop until desired tolerance or maximum number of iterations is reached
for (i=0; i<numIt && (error>tolerance_ || isnan(error)); i++) {
// Backup of the current solution for the error computation later on
DiscFuncType oldSolution = iterationStep->getSol();
// Perform one iteration step
iterationStep->iterate();
// Compute error
double oldNorm = errorNorm_->compute(oldSolution, iterationStep->level());
oldSolution -= iterationStep->getSol();
double normOfCorrection = errorNorm_->compute(oldSolution, iterationStep->level());
error = normOfCorrection / oldNorm;
double convRate = normOfCorrection / normOfOldCorrection;
normOfOldCorrection = normOfCorrection;
// Output
if (verbosity_ != QUIET) {
std::cout << "||u^{n+1} - u^n||: " << error << ", "
<< "convrate " << convRate << "\n";
}
}
if (verbosity_ != QUIET) {
std::cout << i << " iterations performed\n";
std::cout << "--------------------\n";
}
}
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_ITERATIVE_SOLVER_HH__
#define __DUNE_ITERATIVE_SOLVER_HH__
#include <dune/solver/common/solver.hh>
#include <dune/fem/norms/norm.hh>
namespace Dune {
/** \brief A generic iterative solver
*
* This class basically implements a loop that calls
* an iteration procedure (which is to be supplied be
* the user). It also monitors convergence. */
template <class OperatorType, class DiscFuncType>
class IterativeSolver : public Solver
{
public:
/** \brief Loop, call the iteration procedure
* and monitor convergence */
virtual void solve();
//! The maximum number of iterations
int numIt;
//! The iteration step used by the algorithm
IterationStep<OperatorType,DiscFuncType>* iterationStep;
//! The norm used to measure convergence
Norm<DiscFuncType>* errorNorm_;
};
}
#include "common/iterativesolver.cc"
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment