46 template<
typename Functional_>
55 typedef typename VectorType::DataType
DataType;
114 BaseClass(
"QPenalty", section_name, section),
123 auto initial_penalty_param_p = section->
query(
"initial_penalty_param");
124 if(initial_penalty_param_p.second)
129 auto tol_penalty_p = section->
query(
"tol_penalty");
130 if(tol_penalty_p.second)
228 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
252 this->
_def_cur = _functional.get_constraint();
314 _functional.set_penalty_param(penalty_param);
344 Statistics::add_solver_expression(std::make_shared<ExpressionDefect>(this->
name(), this->
_def_init, this->
get_num_iter()));
363 if(this->_def_init <= this->
_tol_abs)
391 template<
typename Functional_>
392 inline std::shared_ptr<QPenalty<Functional_>>
new_qpenalty( Functional_& functional,
394 typename Functional_::VectorTypeR::DataType initial_penalty_param =
395 typename Functional_::VectorTypeR::DataType(1))
397 return std::make_shared<QPenalty<Functional_>>(functional, inner_solver, initial_penalty_param);
420 template<
typename Functional_>
425 return std::make_shared<QPenalty<Functional_>>(section_name, section, functional, inner_solver);
#define XASSERT(expr)
Assertion macro definition.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Helper class for iteration statistics collection.
Abstract base-class for iterative solvers.
DataType _def_init
initial defect
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.
Status _status
current status of the solver
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
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
virtual void plot_summary() const
Plot a summary of the last solver run.
Index _max_iter
maximum number of iterations
virtual Status _set_initial_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the initial defect vector.
bool is_converged() const
checks for convergence
DataType _tol_abs
absolute tolerance parameter
Quadratic penalty iteration.
VectorType::DataType DataType
Underlying floating point type.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
Functional_ FunctionalType
The functional type.
FunctionalType & _functional
The functional that takes the penalty parameters and is assembled in the inner solver.
virtual ~QPenalty()
Virtual destructor.
IterativeSolver< VectorType > BaseClass
Our base class.
QPenalty(const String §ion_name, const PropertyMap *section, FunctionalType &functional, std::shared_ptr< IterativeSolver< VectorType > > inner_solver)
Constructor using a PropertyMap.
DataType _tol_penalty
Maximum value the penalty parameter is allowed to take.
virtual void done_symbolic() override
Symbolic initialization method.
void set_initial_penalty_param(DataType initial_penalty_param)
Sets the initial penalty parameter.
virtual String name() const override
Returns a descriptive string.
virtual Status _apply_intern(VectorType &vec_sol, const VectorType &vec_rhs)
Internal function, applies the solver.
Status _set_initial_defect(const DataType def_init_)
Internal function: sets the initial defect.
QPenalty(FunctionalType &functional, std::shared_ptr< IterativeSolver< VectorType > > inner_solver, DataType initial_penalty_param=DataType(1))
Constructor.
virtual void init_symbolic() override
Symbolic initialization method.
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver correction method.
void set_tol_penalty(DataType tol_penalty)
Sets the initial penalty parameter.
Functional_::VectorTypeR VectorType
The input vector type.
std::shared_ptr< IterativeSolver< VectorType > > _inner_solver
The inner solver for the penalized, unconstrained optimization problem.
QPenalty(const QPenalty &)=delete
Explicitly delete the copy constructor.
DataType _initial_penalty_param
We start with this initial penalty parameter.
virtual void init_symbolic()
Symbolic initialization method.
virtual void done_symbolic()
Symbolic finalization method.
String class implementation.
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
T_ sqr(T_ x)
Returns the square of a value.
T_ ilog10(T_ x)
Computes the integral base-10 logarithm of an integer, i.e. its number of non-zero decimal digits.
bool isfinite(T_ x)
Checks whether a value is finite.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
std::shared_ptr< QPenalty< Functional_ > > new_qpenalty(Functional_ &functional, std::shared_ptr< IterativeSolver< typename Functional_::VectorTypeR > > inner_solver, typename Functional_::VectorTypeR::DataType initial_penalty_param=typename Functional_::VectorTypeR::DataType(1))
Creates a new QPenalty object.
Status
Solver status return codes enumeration.
@ success
solving successful (convergence criterion fulfilled)
@ progress
continue iteration (internal use only)
@ undefined
undefined status
@ 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.