3#ifndef DUNE_PDELAB_SOLVER_TERMINATE_HH
4#define DUNE_PDELAB_SOLVER_TERMINATE_HH
6#include <dune/pdelab/solver/newtonerrors.hh>
11 class TerminateInterface
15 virtual ~TerminateInterface () {}
17 virtual bool terminate() = 0;
19 virtual void setParameters(
const ParameterTree&) = 0;
21 virtual void printParameters()
const
23 std::cout <<
"NewtonMethod::_terminate->printParameters() is not implemented." << std::endl;
28 template <
typename Solver>
29 class DefaultTerminate :
public TerminateInterface
32 using Real =
typename Solver::Real;
34 DefaultTerminate(Solver& solver) : _solver(solver) {}
36 virtual bool terminate()
override
38 if (_force_iteration && _solver.result().iterations == 0)
40 auto converged = _solver.result().defect < _solver.getAbsoluteLimit() || _solver.result().defect < _solver.result().first_defect * _solver.getReduction();
41 _solver.result().converged = converged;
42 if (_solver.result().iterations >= _maxIterations && not _solver.result().converged)
44 "Terminate::terminate(): Maximum iteration count reached");
48 virtual void setParameters(
const ParameterTree& parameterTree)
override
50 _maxIterations = parameterTree.get<
unsigned int>(
"MaxIterations", _maxIterations);
51 _force_iteration = parameterTree.get<
bool>(
"ForceIteration", _force_iteration);
54 virtual void printParameters()
const override
56 std::cout <<
"Terminate.MaxIterations. " << _maxIterations << std::endl;
57 std::cout <<
"Terminate.ForceIteration " << _force_iteration << std::endl;
61 void setMaxIterations(
const unsigned int maxIterations)
63 _maxIterations = maxIterations;
67 void setForceIteration(
const bool forceIteration)
69 _force_iteration = forceIteration;
74 unsigned int _maxIterations = 40;
75 bool _force_iteration =
false;
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216