NewtonMethod should support in-place parameter changes of TerminateInterface and LineSearchInterface
Description
The new NewthonMethod
replacing the old Newton
solver implementation is a great improvement in terms of code readability. It is also much more extensible now that termination and line search have their own interfaces that can be supplied by the user. However, the new implementations lacks some nice features of the old Newton
.
Most prominently, the TerminateInterface
and LineSearchInterface
cannot be accessed, but only set. This makes changing their parameters cumbersome. Specifically, I want to make use of the old setMaxIterations()
method. To manually alter them with the new NewtonMethod
requires a lot of code:
// OLD
Dune::PDELab::Newton<GO, LS, U> newton_old(go, ls, u);
newton_old.setParameters(config.sub("newton"));
// One-liner!
newton_old.setMaxIterations(iter);
// NEW
using Newton = Dune::PDELab::NewtonMethod<GO, LS>
Newton newton_new(go, ls, config.sub("newton"));
// Need to define a new parameter tree or manipulate an existing one
Dune::ParameterTree cfg_terminate;
cfg_terminate["max_iterations"] = std::to_string(iter);
// Initialize and set terminate object
auto term = std::make_shared<Dune::PDELab::DefaultTerminate<Newton>>(cfg_terminate);
newton_new.setTerminate(term);
Proposal
The default implementations of TerminateInterface
and LineSearchInterface
are useful, especially because the NewtonMethod
builds them automatically. However, they should also be retrievable from the NewtonMethod
interface through getter functions. Additionally, it is cumbersome that their parameters can only be set through a ParameterTree
object. They should also be accessible through specific setter functions like setMaxIterations()
. But these setters would even be redundant if the interface parameters were public. I actually see no reason why the default terminate settings (apart from the solver reference) would need to be private, as manipulating them at any time is safe.
In short:
- Add getters for
TerminateInterface
andLineSearchInterface
toNewtonMethod
. - Add option to manipulate
DefaultTerminate
andDefaultLineSearch
withoutParameterTree
object, either by- adding specific setter functions, OR...
- making the parameters public