8#include <kernel/solver/base.hpp>
9#include <kernel/solver/iterative.hpp>
10#include <kernel/solver/linesearch.hpp>
11#include <kernel/solver/nlopt_precond.hpp>
41 template<
typename Functional_,
typename Filter_>
57 typedef typename Functional_::DataType
DataType;
105 explicit NLOptLS(
const String& plot_name_, Functional_& functional, Filter_& filter,
106 std::shared_ptr<PrecondType> precond =
nullptr) :
146 Functional_& functional, Filter_& filter, std::shared_ptr<PrecondType> precond =
nullptr) :
147 BaseClass(plot_name, section_name, section, precond),
162 auto tol_fval_p = section->
get_entry(
"tol_fval");
163 if (tol_fval_p.second)
168 auto tol_step_p = section->
get_entry(
"tol_step");
169 if (tol_step_p.second)
186 +
", evals: "+
stringify(_functional.get_num_func_evals())+
" (func) "
279 Statistics::add_solver_expression(
331 bool calc_def =
false;
340 Statistics::add_solver_expression(
A class organizing a tree of key-value pairs.
std::pair< String, bool > get_entry(String key) const
Retrieves a value by its key.
DataType _def_init
initial defect
Status get_status() const
Returns the status.
String get_plot_name() const
Returns the plot name of the solver.
Index _min_iter
minimum number of iterations
Index _iter_digits
iteration count digits for plotting
Index get_num_iter() const
Returns number of performed iterations.
void _set_comm_by_matrix(const Matrix_ &matrix)
Sets the communicator for the solver from a matrix.
void _print_line(const String &line) const
Prints a line.
bool is_diverged() const
checks for divergence
String _plot_name
name of the solver in plots
virtual DataType _calc_def_norm(const VectorType &vec_def, const VectorType &vec_sol)
Computes the defect norm.
Index _num_iter
number of performed iterations
bool _plot_iter(Status st=Status::progress) const
Plot the current iteration?
Index _num_stag_iter
number of consecutive stagnated iterations
DataType _def_cur
current defect
Index _max_iter
maximum number of iterations
bool is_converged() const
checks for convergence
Index _min_stag_iter
minimum number of stagnation iterations
Base class for line search based nonlinear optimizers.
NLOptLS(const String &plot_name, const String §ion_name, const PropertyMap *section, Functional_ &functional, Filter_ &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
Functional_::DataType DataType
Underlying floating point type.
Functional_::GradientType GradientType
Type of the functional's gradient has.
DataType _fval_init
Initial function value.
Solver::Linesearch< Functional_, Filter_ > LinesearchType
Our type of linesearch.
virtual Status _set_initial_defect(const VectorType &vec_def, const VectorType &vec_sol) override
Internal function: sets the initial defect vector.
DataType _fval_prev
Functional value from the previous iteration.
virtual Status _set_new_defect(const VectorType &vec_r, const VectorType &vec_sol) override
Internal function: sets the new defect norm.
DataType _fval
Current functional value.
Index _ls_iter_digits
The number of digits used to plot line search iteration numbers.
Functional_ & _functional
Our nonlinear functional.
virtual void set_tol_fval(DataType tol_fval)
Sets the tolerance for function value improvement.
Functional_::VectorTypeR VectorType
Input type for the gradient.
Functional_ FunctionalType
The nonlinear functional type.
DataType _tol_fval
Tolerance for function improvement.
DataType _tol_step
Tolerance for the length of the update step.
Filter_ FilterType
The filter type.
NLOptLS(const String &plot_name_, Functional_ &functional, Filter_ &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
virtual ~NLOptLS()
Empty virtual destructor.
virtual void set_ls_iter_digits(Index digits)
Sets the number of digits used to plot line search iteration numbers.
Index _ls_its
The number of iterations the linesearch performed in the last iteration of this solver.
virtual void set_tol_step(DataType tol_step)
Sets the tolerance for the linesearch step size.
virtual DataType get_tol_step()
Gets the tolerance for the linesearch step size.
Filter_ & _filter
The filter we apply to the gradient.
DataType _steplength
The last step length of the line search.
virtual String get_summary() const override
Returns a summary string.
NLOptPrecond< typename Functional_::VectorTypeL, Filter_ > PrecondType
Generic preconditioner.
virtual DataType get_tol_fval()
Gets the tolerance for function value improvement.
PreconditionedIterativeSolver< VectorType > BaseClass
Our baseclass.
Abstract base class for preconditioners for nonlinear optimization.
Abstract base-class for preconditioned iterative solvers.
virtual String name() const =0
Returns a descriptive string.
String class implementation.
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
T_ abs(T_ x)
Returns the absolute value.
T_ sqr(T_ x)
Returns the square of a value.
bool isfinite(T_ x)
Checks whether a value is finite.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Status
Solver status return codes enumeration.
@ success
solving successful (convergence criterion fulfilled)
@ progress
continue iteration (internal use only)
@ stagnated
solver stagnated (stagnation criterion fulfilled)
@ max_iter
solver reached maximum iterations
@ diverged
solver diverged (divergence criterion fulfilled)
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
String stringify(const T_ &item)
Converts an item into a String.
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
std::uint64_t Index
Index data type.