16#ifndef dealii_solver_bfgs_h
17#define dealii_solver_bfgs_h
57template <
typename VectorType>
64 using Number =
typename VectorType::value_type;
111 const std::function<
Number(
const VectorType &
x, VectorType &
g)> &compute,
122 boost::signals2::connection
125 Number(
Number &f, VectorType &
x, VectorType &
g,
const VectorType &p)>
154 boost::signals2::connection
156 const std::function<
void(VectorType &
g,
170 boost::signals2::signal<
171 Number(
Number &f, VectorType &
x, VectorType &
g,
const VectorType &p)>
177 boost::signals2::signal<void(VectorType &
g,
187template <
typename VectorType>
197template <
typename VectorType>
199 const AdditionalData &data)
201 , additional_data(data)
206template <
class VectorType>
207boost::signals2::connection
210 Number(Number &f, VectorType &
x, VectorType &
g,
const VectorType &p)> &
slot)
212 Assert(line_search_signal.empty(),
213 ExcMessage(
"One should not attach more than one line search signal."));
214 return line_search_signal.connect(
slot);
219template <
class VectorType>
220boost::signals2::connection
222 const std::function<
void(VectorType &
g,
226 Assert(preconditioner_signal.empty(),
228 "One should not attach more than one preconditioner signal."));
229 return preconditioner_signal.connect(
slot);
234template <
typename VectorType>
237 const std::function<
typename VectorType::value_type(
const VectorType &
x,
238 VectorType &f)> &compute,
252 if (line_search_signal.empty())
256 [&](Number &f, VectorType &
x, VectorType &
g,
const VectorType &p) {
258 const Number
g0 =
g * p;
261 "Function does not decrease along the current direction"));
271 ExcMessage(
"Function value is not decreasing"));
272 df =
std::max(
df, 100. * std::numeric_limits<Number>::epsilon());
281 [&](
const Number &
x_line) -> std::pair<Number, Number> {
286 return std::make_pair(f,
g_line);
290 const auto res = LineMinimization::line_search<Number>(
294 LineMinimization::poly_fit<Number>,
315 std::vector<Number>
c1;
316 c1.reserve(additional_data.max_history_size);
331 conv = this->iteration_status(
k,
g.l2_norm(),
x);
337 if (additional_data.debug_output)
338 deallog <<
"Iteration " <<
k <<
" history " << m << std::endl
339 <<
"f=" << f << std::endl;
345 for (
unsigned int i = 0; i < m; ++i)
347 c1[i] =
rho[i] * (s[i] * p);
351 if (!preconditioner_signal.empty())
352 preconditioner_signal(p, s,
y);
355 for (
int i = m - 1; i >= 0; --i)
358 const Number
c2 =
rho[i] * (
y[i] * p);
359 p.add(
c1[i] -
c2, s[i]);
366 const Number
alpha = line_search_signal(f,
x,
g, p)
371 if (additional_data.debug_output)
372 deallog <<
"Line search a=" <<
alpha <<
" f=" << f << std::endl;
376 const Number
g_l2 =
g.l2_norm();
383 if (additional_data.debug_output)
386 if (
curvature > 0. && additional_data.max_history_size > 0)
void reinit(value_type *starting_element, const std::size_t n_elements)
typename VectorType::value_type Number
boost::signals2::connection connect_line_search_slot(const std::function< Number(Number &f, VectorType &x, VectorType &g, const VectorType &p)> &slot)
boost::signals2::connection connect_preconditioner_slot(const std::function< void(VectorType &g, const FiniteSizeHistory< VectorType > &s, const FiniteSizeHistory< VectorType > &y)> &slot)
void solve(const std::function< Number(const VectorType &x, VectorType &g)> &compute, VectorType &x)
boost::signals2::signal< void(VectorType &g, const FiniteSizeHistory< VectorType > &s, const FiniteSizeHistory< VectorType > &y)> preconditioner_signal
const AdditionalData additional_data
boost::signals2::signal< Number(Number &f, VectorType &x, VectorType &g, const VectorType &p)> line_search_signal
SolverBFGS(SolverControl &residual_control, const AdditionalData &data=AdditionalData())
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
AdditionalData(const unsigned int max_history_size=5, const bool debug_output=false)
unsigned int max_history_size