Commit 5bd3116f authored by Carsten Gräser's avatar Carsten Gräser
Browse files

Adapt to changed addCriterion interface

parent 49f206a3
......@@ -8,6 +8,7 @@
// dune-common includes
#include <dune/common/bitsetvector.hh>
#include <dune/common/stringutility.hh>
// dune-istl includes
#include <dune/istl/bcrsmatrix.hh>
......@@ -133,7 +134,7 @@ struct DirectionalBisection
template<class MatrixType, class VectorType, class BitVector>
void solveProblem(const MatrixType& mat, VectorType& x, const VectorType& rhs, const BitVector& ignore, int maxIterations=100, double tolerance=1.0e-10)
void solveProblem(const MatrixType& mat, VectorType& x, const VectorType& rhs, const BitVector& ignore, int maxIterations=100, double tolerance=1.0e-8)
{
typedef VectorType Vector;
typedef MatrixType Matrix;
......@@ -148,44 +149,43 @@ void solveProblem(const MatrixType& mat, VectorType& x, const VectorType& rhs, c
auto stepRule = DownHillBisection();
auto gradientStep = GradientStep(J, x, std::ref(stepRule));
auto norm = EnergyNorm<Matrix, Vector>(mat);
auto solver = Solver(&gradientStep, maxIterations, tolerance, &norm, Solver::FULL);
auto solver = Solver(&gradientStep, 1e9, 0, &norm, Solver::FULL);
Vector temp(x.size());
solver.addMonitor(
auto gradientCriterion = Dune::Solvers::Criterion(
[&](){
temp = 0;
J.addGradient(x, temp);
return temp.two_norm();
auto err = temp.two_norm();
return std::make_tuple(err<tolerance, Dune::formatString(" % 12.5e", err));
},
" % 12.5e",
" |gradient| ");
solver.addMonitor(
[&](){return J(x);},
" % 12.5e",
solver.addCriterion(
[&](){return Dune::formatString(" % 12.5e", J(x));},
" energy ");
double initialEnergy = J(x);
solver.addMonitor(
solver.addCriterion(
[&](){
static double oldEnergy=initialEnergy;
double currentEnergy = J(x);
double decrease = currentEnergy - oldEnergy;
oldEnergy = currentEnergy;
return decrease;
return Dune::formatString(" % 12.5e", decrease);
},
" % 12.5e",
" decrease ");
solver.addMonitor(
[&](){return stepRule.x_;},
" % 12.5e",
solver.addCriterion(
[&](){return Dune::formatString(" % 12d", stepRule.evaluations_);},
" evaluations ");
solver.addCriterion(
[&](){return Dune::formatString(" % 12.5e", stepRule.x_);},
" step size ");
solver.addMonitor(
[&](){return stepRule.evaluations_;},
" % 12d",
" evaluations ");
solver.addCriterion(Dune::Solvers::maxIterCriterion(solver, maxIterations) | gradientCriterion);
solver.solve();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment