black_box_newton_solver.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2024 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 
27 
28 // Include guard to prevent multiple inclusions of the header
29 #ifndef OOMPH_BLACK_BOX_NEWTON_SOLVER_HEADER
30 #define OOMPH_BLACK_BOX_NEWTON_SOLVER_HEADER
31 
32 // Config header generated by autoconfig
33 #ifdef HAVE_CONFIG_H
34 #include <oomph-lib-config.h>
35 #endif
36 
37 
38 #include "Vector.h"
39 #include "matrices.h"
40 
41 namespace oomph
42 {
43  /// ///////////////////////////////////////////////////////////////
44  /// ///////////////////////////////////////////////////////////////
45  /// ///////////////////////////////////////////////////////////////
46 
47 
48  //======================================================================
49  // Namespace for black-box FD Newton solver.
50  //======================================================================
51  namespace BlackBoxFDNewtonSolver
52  {
53  // Function pointer for function that specifies residuals: The arguments
54  // are: Parameters, unknowns, residuals
55  typedef void (*ResidualFctPt)(const Vector<double>& parameters,
56  const Vector<double>& unknowns,
57  Vector<double>& residuals);
58 
59  // Function pointer for Jacobian function: Parameters, unknowns, Jacobian
60  typedef void (*JacobianFctPt)(const Vector<double>&,
61  const Vector<double>&,
62  DenseDoubleMatrix& jacobian);
63 
64  // Maximum number of Newton iterations
65  extern unsigned Max_iter;
66 
67  // Number of Newton iterations taken in most recent invocation
68  extern unsigned N_iter_taken;
69 
70  // Flag to indicate if progress of Newton iteration is to be documented
71  // (defaults to false)
72  extern bool Doc_Progress;
73 
74  // Size of increment used in finite-difference calculations
75  extern double FD_step;
76 
77  // Tolerance (maximum allowed value of an single residual at convergence)
78  extern double Tol;
79 
80  // Use steplength control do make globally convergent (default false)
81  extern bool Use_step_length_control;
82 
83  // Black-box FD Newton solver:
84  // Calling sequence for residual function is
85  // \code residual_fct(parameters,unknowns,residuals) \endcode
86  // where all arguments are double Vectors.
87  // unknowns.size() = residuals.size().
88  // Final optional argument specifies function that computes
89  // analytical Jacobian (yes, despite the name of the namespace and the
90  // function -- it is optional!).
91  extern void black_box_fd_newton_solve(ResidualFctPt residual_fct,
92  const Vector<double>& params,
93  Vector<double>& unknowns,
94  JacobianFctPt jacobian_fct = 0);
95 
96 
97  // Line search helper for globally convergent Newton method
98  extern void line_search(const Vector<double>& x_old,
99  const double half_residual_squared_old,
100  const Vector<double>& gradient,
101  ResidualFctPt residual_fct,
102  const Vector<double>& params,
103  Vector<double>& newton_dir,
104  Vector<double>& x,
105  double& half_residual_squared,
106  const double& stpmax);
107 
108  } // namespace BlackBoxFDNewtonSolver
109 
110 
111 } // namespace oomph
112 
113 #endif
Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functiona...
Definition: matrices.h:1271
unsigned Max_iter
Max. # of Newton iterations.
unsigned N_iter_taken
Number of Newton iterations taken in most recent invocation.
void line_search(const Vector< double > &x_old, const double half_residual_squared_old, const Vector< double > &gradient, ResidualFctPt residual_fct, const Vector< double > &params, Vector< double > &newton_dir, Vector< double > &x, double &half_residual_squared, const double &stpmax)
Line search helper for globally convergent Newton method.
void(* JacobianFctPt)(const Vector< double > &, const Vector< double > &, DenseDoubleMatrix &jacobian)
bool Doc_Progress
Flag to indicate if progress of Newton iteration is to be documented (defaults to false)
void black_box_fd_newton_solve(ResidualFctPt residual_fct, const Vector< double > &params, Vector< double > &unknowns, JacobianFctPt jacobian_fct)
Black-box FD Newton solver: Calling sequence for residual function is.
void(* ResidualFctPt)(const Vector< double > &parameters, const Vector< double > &unknowns, Vector< double > &residuals)
bool Use_step_length_control
Use steplength control do make globally convergent (default false)
//////////////////////////////////////////////////////////////////// ////////////////////////////////...