libMesh
newton_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #include "libmesh/diff_system.h"
20 #include "libmesh/dof_map.h"
21 #include "libmesh/libmesh_logging.h"
22 #include "libmesh/linear_solver.h"
23 #include "libmesh/newton_solver.h"
24 #include "libmesh/numeric_vector.h"
25 #include "libmesh/sparse_matrix.h"
26 
27 namespace libMesh
28 {
29 
30 // SIGN from Numerical Recipes
31 template <typename T>
32 inline
33 T SIGN(T a, T b)
34 {
35  return b >= 0 ? std::abs(a) : -std::abs(a);
36 }
37 
39  Real last_residual,
40  Real & current_residual,
41  NumericVector<Number> & newton_iterate,
42  const NumericVector<Number> & linear_solution)
43 {
44  // Take a full step if we got a residual reduction or if we
45  // aren't substepping
46  if ((current_residual < last_residual) ||
48  (!require_finite_residual || !libmesh_isnan(current_residual))))
49  return 1.;
50 
51  // The residual vector
53 
54  Real ax = 0.; // First abscissa, don't take negative steps
55  Real cx = 1.; // Second abscissa, don't extrapolate steps
56 
57  // Find bx, a step length that gives lower residual than ax or cx
58  Real bx = 1.;
59 
60  while (libmesh_isnan(current_residual) ||
61  (current_residual > last_residual &&
63  {
64  // Reduce step size to 1/2, 1/4, etc.
65  Real substepdivision;
66  if (brent_line_search && !libmesh_isnan(current_residual))
67  {
68  substepdivision = std::min(0.5, last_residual/current_residual);
69  substepdivision = std::max(substepdivision, tol*2.);
70  }
71  else
72  substepdivision = 0.5;
73 
74  newton_iterate.add (bx * (1.-substepdivision),
75  linear_solution);
76  newton_iterate.close();
77  bx *= substepdivision;
78  if (verbose)
79  libMesh::out << " Shrinking Newton step to "
80  << bx << std::endl;
81 
82  // We may need to localize a parallel solution
83  _system.update();
84 
85  // Check residual with fractional Newton step
86  _system.assembly(true, false, !this->_exact_constraint_enforcement);
87 
88  rhs.close();
89  current_residual = rhs.l2_norm();
90  if (verbose)
91  libMesh::out << " Current Residual: "
92  << current_residual << std::endl;
93 
94  if (bx/2. < minsteplength &&
95  (libmesh_isnan(current_residual) ||
96  (current_residual > last_residual)))
97  {
98  libMesh::out << "Inexact Newton step FAILED at step "
99  << _outer_iterations << std::endl;
100 
102  {
103  libmesh_convergence_failure();
104  }
105  else
106  {
107  libMesh::out << "Continuing anyway ..." << std::endl;
109  return bx;
110  }
111  }
112  } // end while (current_residual > last_residual)
113 
114  // Now return that reduced-residual step, or use Brent's method to
115  // find a more optimal step.
116 
117  if (!brent_line_search)
118  return bx;
119 
120  // Brent's method adapted from Numerical Recipes in C, ch. 10.2
121  Real e = 0.;
122 
123  Real x = bx, w = bx, v = bx;
124 
125  // Residuals at bx
126  Real fx = current_residual,
127  fw = current_residual,
128  fv = current_residual;
129 
130  // Max iterations for Brent's method loop
131  const unsigned int max_i = 20;
132 
133  // for golden ratio steps
134  const Real golden_ratio = 1.-(std::sqrt(5.)-1.)/2.;
135 
136  for (unsigned int i=1; i <= max_i; i++)
137  {
138  Real xm = (ax+cx)*0.5;
139  Real tol1 = tol * std::abs(x) + tol*tol;
140  Real tol2 = 2.0 * tol1;
141 
142  // Test if we're done
143  if (std::abs(x-xm) <= (tol2 - 0.5 * (cx - ax)))
144  return x;
145 
146  Real d;
147 
148  // Construct a parabolic fit
149  if (std::abs(e) > tol1)
150  {
151  Real r = (x-w)*(fx-fv);
152  Real q = (x-v)*(fx-fw);
153  Real p = (x-v)*q-(x-w)*r;
154  q = 2. * (q-r);
155  if (q > 0.)
156  p = -p;
157  else
158  q = std::abs(q);
159  if (std::abs(p) >= std::abs(0.5*q*e) ||
160  p <= q * (ax-x) ||
161  p >= q * (cx-x))
162  {
163  // Take a golden section step
164  e = x >= xm ? ax-x : cx-x;
165  d = golden_ratio * e;
166  }
167  else
168  {
169  // Take a parabolic fit step
170  d = p/q;
171  if (x+d-ax < tol2 || cx-(x+d) < tol2)
172  d = SIGN(tol1, xm - x);
173  }
174  }
175  else
176  {
177  // Take a golden section step
178  e = x >= xm ? ax-x : cx-x;
179  d = golden_ratio * e;
180  }
181 
182  Real u = std::abs(d) >= tol1 ? x+d : x + SIGN(tol1,d);
183 
184  // Assemble the residual at the new steplength u
185  newton_iterate.add (bx - u, linear_solution);
186  newton_iterate.close();
187  bx = u;
188  if (verbose)
189  libMesh::out << " Shrinking Newton step to "
190  << bx << std::endl;
191 
192  // We may need to localize a parallel solution
193  _system.update();
194  _system.assembly(true, false, !this->_exact_constraint_enforcement);
195 
196  rhs.close();
197  Real fu = current_residual = rhs.l2_norm();
198  if (verbose)
199  libMesh::out << " Current Residual: "
200  << fu << std::endl;
201 
202  if (fu <= fx)
203  {
204  if (u >= x)
205  ax = x;
206  else
207  cx = x;
208  v = w; w = x; x = u;
209  fv = fw; fw = fx; fx = fu;
210  }
211  else
212  {
213  if (u < x)
214  ax = u;
215  else
216  cx = u;
217  if (fu <= fw || w == x)
218  {
219  v = w; w = u;
220  fv = fw; fw = fu;
221  }
222  else if (fu <= fv || v == x || v == w)
223  {
224  v = u;
225  fv = fu;
226  }
227  }
228  }
229 
230  if (!quiet)
231  libMesh::out << "Warning! Too many iterations used in Brent line search!"
232  << std::endl;
233  return bx;
234 }
235 
236 
238  : Parent(s),
239  require_residual_reduction(true),
240  require_finite_residual(true),
241  brent_line_search(true),
242  track_linear_convergence(false),
243  minsteplength(1e-5),
244  linear_tolerance_multiplier(1e-3),
245  _linear_solver(LinearSolver<Number>::build(s.comm()))
246 {
247 }
248 
249 
250 
251 NewtonSolver::~NewtonSolver () = default;
252 
253 
254 
256 {
257  Parent::init();
258 
259  if (libMesh::on_command_line("--solver-system-names"))
260  _linear_solver->init((_system.name()+"_").c_str());
261  else
262  _linear_solver->init();
263 
264  _linear_solver->init_names(_system);
265 }
266 
267 
268 
270 {
271  Parent::reinit();
272 
273  _linear_solver->clear();
274 
275  _linear_solver->init_names(_system);
276 }
277 
278 
279 
280 unsigned int NewtonSolver::solve()
281 {
282  LOG_SCOPE("solve()", "NewtonSolver");
283 
284  // Reset any prior solve result
286 
287  NumericVector<Number> & newton_iterate = *(_system.solution);
288 
289  std::unique_ptr<NumericVector<Number>> linear_solution_ptr = newton_iterate.zero_clone();
290  NumericVector<Number> & linear_solution = *linear_solution_ptr;
291  NumericVector<Number> & rhs = *(_system.rhs);
292 
293  newton_iterate.close();
294  linear_solution.close();
295  rhs.close();
296 
297 #ifdef LIBMESH_ENABLE_CONSTRAINTS
300 #endif
301 
302  SparseMatrix<Number> & matrix = *(_system.matrix);
303 
304  // Set starting linear tolerance
305  double current_linear_tolerance = initial_linear_tolerance;
306 
307  // Start counting our linear solver steps
308  _inner_iterations = 0;
309 
310  // Now we begin the nonlinear loop
313  {
314  // We may need to localize a parallel solution
315  _system.update();
316 
317  if (verbose)
318  libMesh::out << "Assembling the System" << std::endl;
319 
320  _system.assembly(true, true, !this->_exact_constraint_enforcement);
321  rhs.close();
322  Real current_residual = rhs.l2_norm();
323 
324  if (libmesh_isnan(current_residual))
325  {
326  libMesh::out << " Nonlinear solver DIVERGED at step "
328  << " with residual Not-a-Number"
329  << std::endl;
330  libmesh_convergence_failure();
331  continue;
332  }
333 
334  if (current_residual <= absolute_residual_tolerance)
335  {
336  if (verbose)
337  libMesh::out << "Linear solve unnecessary; residual "
338  << current_residual
339  << " meets absolute tolerance "
341  << std::endl;
342 
343  // We're not doing a solve, but other code may reuse this
344  // matrix.
345  matrix.close();
346 
348  if (current_residual == 0)
349  {
352  if (absolute_step_tolerance > 0)
354  if (relative_step_tolerance > 0)
356  }
357 
358  break;
359  }
360 
361  // Prepare to take incomplete steps
362  Real last_residual = current_residual;
363 
364  max_residual_norm = std::max (current_residual,
366 
367  // Compute the l2 norm of the whole solution
368  Real norm_total = newton_iterate.l2_norm();
369 
370  max_solution_norm = std::max(max_solution_norm, norm_total);
371 
372  if (verbose)
373  libMesh::out << "Nonlinear Residual: "
374  << current_residual << std::endl;
375 
376  // Make sure our linear tolerance is low enough
377  current_linear_tolerance =
378  double(std::min (current_linear_tolerance,
379  current_residual * linear_tolerance_multiplier));
380 
381  // But don't let it be too small
382  if (current_linear_tolerance < minimum_linear_tolerance)
383  {
384  current_linear_tolerance = minimum_linear_tolerance;
385  }
386 
387  // If starting the nonlinear solve with a really good initial guess, we dont want to set an absurd linear tolerance
388  current_linear_tolerance =
389  double(std::max(current_linear_tolerance,
390  absolute_residual_tolerance / current_residual
391  / 10.0));
392 
393  // At this point newton_iterate is the current guess, and
394  // linear_solution is now about to become the NEGATIVE of the next
395  // Newton step.
396 
397  // Our best initial guess for the linear_solution is zero!
398  linear_solution.zero();
399 
400  if (verbose)
401  libMesh::out << "Linear solve starting, tolerance "
402  << current_linear_tolerance << std::endl;
403 
404  // Solve the linear system.
405  const std::pair<unsigned int, Real> rval =
406  _linear_solver->solve (matrix, _system.request_matrix("Preconditioner"),
407  linear_solution, rhs, current_linear_tolerance,
409 
411  {
412  LinearConvergenceReason linear_c_reason = _linear_solver->get_converged_reason();
413 
414  // Check if something went wrong during the linear solve
415  if (linear_c_reason < 0)
416  {
417  // The linear solver failed somehow
419  // Print a message
420  libMesh::out << "Linear solver failed during Newton step, dropping out."
421  << std::endl;
422  break;
423  }
424  }
425 
426  // We may need to localize a parallel solution
427  _system.update ();
428  // The linear solver may not have fit our constraints exactly
429 #ifdef LIBMESH_ENABLE_CONSTRAINTS
432  (_system, &linear_solution, /* homogeneous = */ true);
433 #endif
434 
435  const unsigned int linear_steps = rval.first;
436  libmesh_assert_less_equal (linear_steps, max_linear_iterations);
437  _inner_iterations += linear_steps;
438 
439  const bool linear_solve_finished =
440  !(linear_steps == max_linear_iterations);
441 
442  if (verbose)
443  libMesh::out << "Linear solve finished, step " << linear_steps
444  << ", residual " << rval.second
445  << std::endl;
446 
447  // Compute the l2 norm of the nonlinear update
448  Real norm_delta = linear_solution.l2_norm();
449 
450  if (verbose)
451  libMesh::out << "Trying full Newton step" << std::endl;
452  // Take a full Newton step
453  newton_iterate.add (-1., linear_solution);
454  newton_iterate.close();
455 
456  if (this->linear_solution_monitor.get())
457  {
458  // Compute the l2 norm of the whole solution
459  norm_total = newton_iterate.l2_norm();
460  rhs.close();
461  (*this->linear_solution_monitor)(linear_solution, norm_delta,
462  newton_iterate, norm_total,
463  rhs, rhs.l2_norm(), _outer_iterations);
464  }
465 
466  // Check residual with full Newton step, if that's useful for determining
467  // whether to line search, whether to quit early, or whether to die after
468  // hitting our max iteration count
469  if (this->require_residual_reduction ||
470  this->require_finite_residual ||
471  _outer_iterations+1 < max_nonlinear_iterations ||
473  {
474  _system.update ();
475  _system.assembly(true, false, !this->_exact_constraint_enforcement);
476 
477  rhs.close();
478  current_residual = rhs.l2_norm();
479  if (verbose)
480  libMesh::out << " Current Residual: "
481  << current_residual << std::endl;
482 
483  // don't fiddle around if we've already converged
484  if (test_convergence(current_residual, norm_delta,
485  linear_solve_finished &&
486  current_residual <= last_residual))
487  {
488  if (!quiet)
489  print_convergence(_outer_iterations, current_residual,
490  norm_delta, linear_solve_finished &&
491  current_residual <= last_residual);
493  break; // out of _outer_iterations for loop
494  }
495  }
496 
497  // since we're not converged, backtrack if necessary
498  Real steplength =
500  last_residual, current_residual,
501  newton_iterate, linear_solution);
502  norm_delta *= steplength;
503 
504  // Check to see if backtracking failed,
505  // and break out of the nonlinear loop if so...
507  {
509  break; // out of _outer_iterations for loop
510  }
511 
513  {
514  libMesh::out << " Nonlinear solver reached maximum step "
515  << max_nonlinear_iterations << ", latest evaluated residual "
516  << current_residual << std::endl;
518  {
520  libMesh::out << " Continuing..." << std::endl;
521  }
522  else
523  {
524  libmesh_convergence_failure();
525  }
526  continue;
527  }
528 
529  // Compute the l2 norm of the whole solution
530  norm_total = newton_iterate.l2_norm();
531 
532  max_solution_norm = std::max(max_solution_norm, norm_total);
533 
534  // Print out information for the
535  // nonlinear iterations.
536  if (verbose)
537  libMesh::out << " Nonlinear step: |du|/|u| = "
538  << norm_delta / norm_total
539  << ", |du| = " << norm_delta
540  << std::endl;
541 
542  // Terminate the solution iteration if the difference between
543  // this iteration and the last is sufficiently small.
544  if (test_convergence(current_residual, norm_delta / steplength,
545  linear_solve_finished))
546  {
547  if (!quiet)
548  print_convergence(_outer_iterations, current_residual,
549  norm_delta / steplength,
550  linear_solve_finished);
552  break; // out of _outer_iterations for loop
553  }
554  } // end nonlinear loop
555 
556  // The linear solver may not have fit our constraints exactly
557 #ifdef LIBMESH_ENABLE_CONSTRAINTS
560 #endif
561 
562  // We may need to localize a parallel solution
563  _system.update ();
564 
565  // Make sure we are returning something sensible as the
566  // _solve_result, except in the edge case where we weren't really asked to
567  // solve.
569  !max_nonlinear_iterations);
570 
571  return _solve_result;
572 }
573 
574 
575 
576 bool NewtonSolver::test_convergence(Real current_residual,
577  Real step_norm,
578  bool linear_solve_finished)
579 {
580  // We haven't converged unless we pass a convergence test
581  bool has_converged = false;
582 
583  // Is our absolute residual low enough?
584  if (current_residual < absolute_residual_tolerance)
585  {
587  has_converged = true;
588  }
589 
590  // Is our relative residual low enough?
591  if ((current_residual / max_residual_norm) <
593  {
595  has_converged = true;
596  }
597 
598  // For incomplete linear solves, it's not safe to test step sizes
599  if (!linear_solve_finished)
600  {
601  return has_converged;
602  }
603 
604  // Is our absolute Newton step size small enough?
605  if (step_norm < absolute_step_tolerance)
606  {
608  has_converged = true;
609  }
610 
611  // Is our relative Newton step size small enough?
612  if (step_norm / max_solution_norm <
614  {
616  has_converged = true;
617  }
618 
619  return has_converged;
620 }
621 
622 
623 void NewtonSolver::print_convergence(unsigned int step_num,
624  Real current_residual,
625  Real step_norm,
626  bool linear_solve_finished)
627 {
628  // Is our absolute residual low enough?
629  if (current_residual < absolute_residual_tolerance)
630  {
631  libMesh::out << " Nonlinear solver converged, step " << step_num
632  << ", residual " << current_residual
633  << std::endl;
634  }
636  {
637  if (verbose)
638  libMesh::out << " Nonlinear solver current_residual "
639  << current_residual << " > "
640  << (absolute_residual_tolerance) << std::endl;
641  }
642 
643  // Is our relative residual low enough?
644  if ((current_residual / max_residual_norm) <
646  {
647  libMesh::out << " Nonlinear solver converged, step " << step_num
648  << ", residual reduction "
649  << current_residual / max_residual_norm
650  << " < " << relative_residual_tolerance
651  << std::endl;
652  }
654  {
655  if (verbose)
656  libMesh::out << " Nonlinear solver relative residual "
657  << (current_residual / max_residual_norm)
658  << " > " << relative_residual_tolerance
659  << std::endl;
660  }
661 
662  // For incomplete linear solves, it's not safe to test step sizes
663  if (!linear_solve_finished)
664  return;
665 
666  // Is our absolute Newton step size small enough?
667  if (step_norm < absolute_step_tolerance)
668  {
669  libMesh::out << " Nonlinear solver converged, step " << step_num
670  << ", absolute step size "
671  << step_norm
672  << " < " << absolute_step_tolerance
673  << std::endl;
674  }
675  else if (absolute_step_tolerance)
676  {
677  if (verbose)
678  libMesh::out << " Nonlinear solver absolute step size "
679  << step_norm
680  << " > " << absolute_step_tolerance
681  << std::endl;
682  }
683 
684  // Is our relative Newton step size small enough?
685  if (step_norm / max_solution_norm <
687  {
688  libMesh::out << " Nonlinear solver converged, step " << step_num
689  << ", relative step size "
690  << (step_norm / max_solution_norm)
691  << " < " << relative_step_tolerance
692  << std::endl;
693  }
694  else if (relative_step_tolerance)
695  {
696  if (verbose)
697  libMesh::out << " Nonlinear solver relative step size "
698  << (step_norm / max_solution_norm)
699  << " > " << relative_step_tolerance
700  << std::endl;
701  }
702 }
703 
704 } // namespace libMesh
bool continue_after_max_iterations
Defaults to true, telling the DiffSolver to continue rather than exit when a solve has reached its ma...
Definition: diff_solver.h:172
virtual void init() override
The initialization function.
NewtonSolver(sys_type &system)
Constructor.
std::unique_ptr< LinearSolver< Number > > _linear_solver
The LinearSolver defines the interface used to solve the linear_implicit system.
Real absolute_step_tolerance
The DiffSolver should exit after the full nonlinear step norm is reduced to either less than absolute...
Definition: diff_solver.h:201
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Definition: diff_solver.h:160
static constexpr Real TOLERANCE
virtual ~NewtonSolver()
Destructor.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const =0
unsigned int max_nonlinear_iterations
The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_...
Definition: diff_solver.h:154
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
Definition: diff_solver.h:189
Real max_solution_norm
The largest solution norm which the DiffSolver has yet seen will be stored here, to be used for stopp...
Definition: diff_solver.h:324
Real max_residual_norm
The largest nonlinear residual which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_residual_tolerance.
Definition: diff_solver.h:331
bool _exact_constraint_enforcement
Whether we should enforce exact constraints globally during a solve.
Definition: diff_solver.h:318
virtual unsigned int solve() override
This method performs a solve, using an inexact Newton-Krylov method with line search.
The DiffSolver achieved the desired absolute step size tolerance.
Definition: diff_solver.h:249
NumericVector< Number > * rhs
The system matrix.
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).
virtual void reinit()
The reinitialization function.
Definition: diff_solver.C:63
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
The libMesh namespace provides an interface to certain functionality in the library.
The linear solver used by the DiffSolver failed to find a solution.
Definition: diff_solver.h:280
const SparseMatrix< Number > * request_matrix(std::string_view mat_name) const
Definition: system.C:1047
bool libmesh_isnan(T x)
unsigned int _solve_result
Initialized to zero.
Definition: diff_solver.h:354
unsigned int _inner_iterations
The number of inner iterations used by the last solve.
Definition: diff_solver.h:341
double linear_tolerance_multiplier
The tolerance for linear solves is kept below this multiplier (which defaults to 1e-3) times the norm...
virtual void zero()=0
Set all entries to zero.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
virtual void init()
The initialization function.
Definition: diff_solver.C:72
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Definition: diff_solver.h:68
The DiffSolver reached the maximum allowed number of nonlinear iterations before satisfying any conve...
Definition: diff_solver.h:268
This base class can be inherited from to provide interfaces to linear solvers from different packages...
Definition: linear_solver.h:59
The DiffSolver achieved the desired relative step size tolerance.
Definition: diff_solver.h:255
T SIGN(T a, T b)
Definition: newton_solver.C:33
virtual void assembly(bool, bool, bool=false, bool=false)
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
sys_type & _system
A reference to the system we are solving.
Definition: diff_solver.h:346
virtual Real l2_norm() const =0
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:146
bool require_finite_residual
If this is set to true, the solver is forced to test the residual after each Newton step...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1573
libmesh_assert(ctx)
The DiffSolver achieved the desired relative residual tolerance.
Definition: diff_solver.h:243
bool track_linear_convergence
If set to true, check for convergence of the linear solve.
virtual void close()=0
Calls the NumericVector&#39;s internal assembly routines, ensuring that the values are consistent across ...
double minimum_linear_tolerance
The tolerance for linear solves is kept above this minimum.
Definition: diff_solver.h:213
bool verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false...
Definition: diff_solver.h:166
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:493
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool continue_after_backtrack_failure
Defaults to false, telling the DiffSolver to throw an error when the backtracking scheme fails to fin...
Definition: diff_solver.h:178
The DiffSolver achieved the desired absolute residual tolerance.
Definition: diff_solver.h:237
Real minsteplength
If the quasi-Newton step length must be reduced to below this factor to give a residual reduction...
virtual void reinit() override
The reinitialization function.
unsigned int _outer_iterations
The number of outer iterations used by the last solve.
Definition: diff_solver.h:336
OStreamProxy out
SparseMatrix< Number > * matrix
The system matrix.
bool test_convergence(Real current_residual, Real step_norm, bool linear_solve_finished)
bool brent_line_search
If require_residual_reduction is true, the solver may reduce step lengths when required.
The DiffSolver failed to find a descent direction by backtracking (See newton_solver.C)
Definition: diff_solver.h:274
bool require_residual_reduction
If this is set to true, the solver is forced to test the residual after each Newton step...
Definition: newton_solver.h:98
bool on_command_line(std::string arg)
Definition: libmesh.C:924
const std::string & name() const
Definition: system.h:2261
A default or invalid solve result.
Definition: diff_solver.h:225
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.
Real line_search(Real tol, Real last_residual, Real &current_residual, NumericVector< Number > &newton_iterate, const NumericVector< Number > &linear_solution)
This does a line search in the direction opposite linear_solution to try and minimize the residual of...
Definition: newton_solver.C:38
void print_convergence(unsigned int step_num, Real current_residual, Real step_norm, bool linear_solve_finished)
This prints output for the convergence criteria based on by the given residual and step size...
double initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the ...
Definition: diff_solver.h:208
const DofMap & get_dof_map() const
Definition: system.h:2293
Real relative_residual_tolerance
Definition: diff_solver.h:190
std::unique_ptr< LinearSolutionMonitor > linear_solution_monitor
Pointer to functor which is called right after each linear solve.
Definition: diff_solver.h:286
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:2274
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...