Skip to content
Snippets Groups Projects
Commit 743a15fc authored by Patrick Jaap's avatar Patrick Jaap
Browse files

LoopSolver: Add getter for the current convergence rate

parent 85705ebb
No related branches found
No related tags found
1 merge request!56LoopSolver: Add getter for the current convergence rate
...@@ -98,7 +98,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -98,7 +98,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve()
// Please don't replace this call to 'diff' by computing the norm of the difference. // Please don't replace this call to 'diff' by computing the norm of the difference.
// In some nonlinear DD applications the 'diff' method may be nonlinear. // In some nonlinear DD applications the 'diff' method may be nonlinear.
real_type normOfCorrection = this->errorNorm_->diff(oldSolution,this->iterationStep_->getSol()); real_type normOfCorrection = this->errorNorm_->diff(oldSolution,this->iterationStep_->getSol());
real_type convRate = (normOfOldCorrection > 0) convRate_ = (normOfOldCorrection > 0)
? normOfCorrection / normOfOldCorrection : 0.0; ? normOfCorrection / normOfOldCorrection : 0.0;
error = normOfCorrection; error = normOfCorrection;
normOfOldCorrection = normOfCorrection; normOfOldCorrection = normOfCorrection;
...@@ -107,7 +107,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -107,7 +107,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve()
if (referenceSolution_) if (referenceSolution_)
{ {
normOfError = this->errorNorm_->diff(this->iterationStep_->getSol(), *referenceSolution_); normOfError = this->errorNorm_->diff(this->iterationStep_->getSol(), *referenceSolution_);
convRate = (normOfOldError > 0) ? normOfError / normOfOldError : 0.0; convRate_ = (normOfOldError > 0) ? normOfError / normOfOldError : 0.0;
error = normOfError; error = normOfError;
normOfOldError = normOfError; normOfOldError = normOfError;
} }
...@@ -117,9 +117,9 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -117,9 +117,9 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve()
error = (oldNorm == 0) ? std::numeric_limits<real_type>::max() error = (oldNorm == 0) ? std::numeric_limits<real_type>::max()
: error / oldNorm; : error / oldNorm;
if (!std::isinf(convRate) && !std::isnan(convRate) && i>0) if (!std::isinf(convRate_) && !std::isnan(convRate_) && i>0)
{ {
totalConvRate *= convRate; totalConvRate *= convRate_;
this->maxTotalConvRate_ = std::max(this->maxTotalConvRate_, std::pow(totalConvRate, 1/((real_type)convRateCounter+1))); this->maxTotalConvRate_ = std::max(this->maxTotalConvRate_, std::pow(totalConvRate, 1/((real_type)convRateCounter+1)));
convRateCounter++; convRateCounter++;
} }
...@@ -151,7 +151,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() ...@@ -151,7 +151,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve()
std::cout << " "; std::cout << " ";
else else
std::cout << std::fixed std::cout << std::fixed
<< std::setw(9) << std::setprecision(5) << convRate; << std::setw(9) << std::setprecision(5) << convRate_;
std::cout << std::setprecision(oldPrecision); std::cout << std::setprecision(oldPrecision);
std::cout.flags(oldFormatFlags); std::cout.flags(oldFormatFlags);
......
...@@ -107,6 +107,16 @@ public: ...@@ -107,6 +107,16 @@ public:
return iter_; return iter_;
} }
/**
* \brief Get current convergence rate
*/
auto convergenceRate() const
{
return convRate_;
}
virtual void preprocess(); virtual void preprocess();
/** \brief Loop, call the iteration procedure /** \brief Loop, call the iteration procedure
...@@ -119,6 +129,8 @@ protected: ...@@ -119,6 +129,8 @@ protected:
std::vector<Dune::Solvers::Criterion> criteria_; std::vector<Dune::Solvers::Criterion> criteria_;
int iter_; int iter_;
real_type convRate_;
}; };
} // namespace Solvers } // namespace Solvers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment