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
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/** \brief Constructor taking all relevant data */ /** \brief Constructor taking all relevant data */
IterativeSolver(int maxIterations, IterativeSolver(int maxIterations,
double tolerance, double tolerance,
Norm<VectorType>* errorNorm, const Norm<VectorType>* errorNorm,
VerbosityMode verbosity, VerbosityMode verbosity,
bool useRelativeError=true) bool useRelativeError=true)
: Solver(verbosity), : Solver(verbosity),
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
int maxIterations_; int maxIterations_;
//! The norm used to measure convergence //! 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 /** \brief If this string is nonempty it is expected to contain a valid
directory name. All intermediate iterates are then written there. */ directory name. All intermediate iterates are then written there. */
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <limits> #include <limits>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <dune/solvers/solvers/solver.hh>
template <class VectorType, class BitVectorType> template <class VectorType, class BitVectorType>
void ::LoopSolver<VectorType, BitVectorType>::check() const void ::LoopSolver<VectorType, BitVectorType>::check() const
...@@ -16,7 +17,7 @@ void ::LoopSolver<VectorType, BitVectorType>::check() const ...@@ -16,7 +17,7 @@ void ::LoopSolver<VectorType, BitVectorType>::check() const
} }
template <class VectorType, class BitVectorType> template <class VectorType, class BitVectorType>
void ::LoopSolver<VectorType, BitVectorType>::solve() void LoopSolver<VectorType, BitVectorType>::solve()
{ {
int i; int i;
...@@ -70,8 +71,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -70,8 +71,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
int convRateCounter = 0; int convRateCounter = 0;
// Loop until desired tolerance or maximum number of iterations is reached // 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 // Backup of the current solution for the error computation later on
VectorType oldSolution = iterationStep_->getSol(); VectorType oldSolution = iterationStep_->getSol();
...@@ -107,7 +108,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -107,7 +108,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
if (this->useRelativeError_ && !std::isnan(error/oldNorm)) if (this->useRelativeError_ && !std::isnan(error/oldNorm))
error = error / oldNorm; error = error / oldNorm;
if (!isinf(convRate) && !isnan(convRate) && i>0) { if (!isinf(convRate) && !isnan(convRate) && i>0)
{
totalConvRate *= convRate; totalConvRate *= convRate;
this->maxTotalConvRate_ = std::max(this->maxTotalConvRate_, std::pow(totalConvRate, 1/((double)convRateCounter+1))); this->maxTotalConvRate_ = std::max(this->maxTotalConvRate_, std::pow(totalConvRate, 1/((double)convRateCounter+1)));
convRateCounter++; convRateCounter++;
...@@ -155,4 +157,6 @@ void ::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -155,4 +157,6 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
std::cout << "--------------------\n"; std::cout << "--------------------\n";
} }
this->setResult(i,error<=this->tolerance_,totalConvRate);
} }
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
LoopSolver(IterationStep<VectorType, BitVectorType>* iterationStep, LoopSolver(IterationStep<VectorType, BitVectorType>* iterationStep,
int maxIterations, int maxIterations,
double tolerance, double tolerance,
Norm<VectorType>* errorNorm, const Norm<VectorType>* errorNorm,
Solver::VerbosityMode verbosity, Solver::VerbosityMode verbosity,
bool useRelativeError=true, bool useRelativeError=true,
const VectorType* referenceSolution=0) const VectorType* referenceSolution=0)
......
...@@ -3,11 +3,32 @@ ...@@ -3,11 +3,32 @@
#include <dune/solvers/common/numproc.hh> #include <dune/solvers/common/numproc.hh>
/** \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 */ /** \brief The base class for all sorts of solver algorithms */
class Solver : public NumProc class Solver : public NumProc
{ {
public: public:
Solver(VerbosityMode verbosity) Solver(VerbosityMode verbosity=FULL)
: NumProc(verbosity) : NumProc(verbosity)
{} {}
...@@ -24,5 +45,24 @@ ...@@ -24,5 +45,24 @@
* solution algorithm */ * solution algorithm */
virtual void solve() = 0; 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 #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment