16 #ifndef dealii_solver_bfgs_h 17 #define dealii_solver_bfgs_h 57 template <
typename VectorType>
64 using Number =
typename VectorType::value_type;
122 boost::signals2::connection
154 boost::signals2::connection
170 boost::signals2::signal<
187 template <
typename VectorType>
189 const unsigned int max_history_size_,
190 const bool debug_output_)
197 template <
typename VectorType>
206 template <
class VectorType>
207 boost::signals2::connection
213 ExcMessage(
"One should not attach more than one line search signal."));
219 template <
class VectorType>
220 boost::signals2::connection
228 "One should not attach more than one preconditioner signal."));
234 template <
typename VectorType>
237 const std::function<
typename VectorType::value_type(
const VectorType &x,
248 bool first_step =
true;
255 const auto default_line_min =
261 "Function does not decrease along the current direction"));
270 Assert(first_step || df >= 0.,
271 ExcMessage(
"Function value is not decreasing"));
275 (first_step ? 1. :
std::min(1., -1.01 * 2. * df / g0));
280 const auto line_func =
281 [&](
const Number &x_line) -> std::pair<Number, Number> {
285 const Number g_line = g * p;
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;
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);
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]);
372 deallog <<
"Line search a=" << alpha <<
" f=" << f << std::endl;
376 const Number g_l2 = g.l2_norm();
382 const Number curvature = s_k * y_k;
384 deallog <<
"Curvature " << curvature << std::endl;
390 rho.
add(1. / curvature);
boost::signals2::signal< Number(Number &f, VectorType &x, VectorType &g, const VectorType &p)> line_search_signal
boost::signals2::connection connect_preconditioner_slot(const std::function< void(VectorType &g, const FiniteSizeHistory< VectorType > &s, const FiniteSizeHistory< VectorType > &y)> &slot)
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType ¤t_iterate), StateCombiner > iteration_status
#define AssertThrow(cond, exc)
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)
unsigned int max_history_size
AdditionalData(const unsigned int max_history_size=5, const bool debug_output=false)
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
const AdditionalData additional_data
#define Assert(cond, exc)
#define DEAL_II_NAMESPACE_CLOSE
boost::signals2::signal< void(VectorType &g, const FiniteSizeHistory< VectorType > &s, const FiniteSizeHistory< VectorType > &y)> preconditioner_signal
SolverBFGS(SolverControl &residual_control, const AdditionalData &data=AdditionalData())
typename VectorType::value_type Number
void add(const T &element)
#define DEAL_II_NAMESPACE_OPEN
T min(const T &t, const MPI_Comm &mpi_communicator)
void solve(const std::function< Number(const VectorType &x, VectorType &g)> &compute, VectorType &x)
boost::signals2::connection connect_line_search_slot(const std::function< Number(Number &f, VectorType &x, VectorType &g, const VectorType &p)> &slot)
T max(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcInternalError()