libMesh
diff_solver.h
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 
20 #ifndef LIBMESH_DIFF_SOLVER_H
21 #define LIBMESH_DIFF_SOLVER_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/reference_counted_object.h"
26 #include "libmesh/parallel_object.h"
27 
28 // C++ includes
29 #include <vector>
30 #include <memory>
31 
32 namespace libMesh
33 {
34 
35 // Forward Declarations
36 class ImplicitSystem;
37 template <typename T> class NumericVector;
38 
43 {
44 public:
45  virtual void operator() (const NumericVector<Number> & delta_u,
46  const Real & norm_delta_u,
47  const NumericVector<Number> & u,
48  const Real & norm_u,
49  const NumericVector<Number> & res,
50  const Real & norm_res,
51  const unsigned int iteration) = 0;
52  virtual ~LinearSolutionMonitor() = default;
53 };
54 
68 class DiffSolver : public ReferenceCountedObject<DiffSolver>,
69  public ParallelObject
70 {
71 public:
76 
81  DiffSolver (sys_type & s);
82 
89  static std::unique_ptr<DiffSolver> build(sys_type & s);
90 
94  virtual ~DiffSolver () = default;
95 
100  virtual void init ();
101 
106  virtual void reinit ();
107 
113  virtual unsigned int solve () = 0;
114 
119  unsigned int total_outer_iterations() { return _outer_iterations; }
120 
125  unsigned int total_inner_iterations() { return _inner_iterations; }
126 
130  unsigned int solve_result() { return _solve_result; }
131 
135  const sys_type & system () const { return _system; }
136 
140  sys_type & system () { return _system; }
141 
146  unsigned int max_linear_iterations;
147 
155 
160  bool quiet;
161 
166  bool verbose;
167 
173 
179 
191 
203 
209 
214 
220  enum SolveResult {
226 
232 
238 
244 
250 
256 
262 
269 
275 
281  };
282 
286  std::unique_ptr<LinearSolutionMonitor> linear_solution_monitor;
287 
302  virtual void set_exact_constraint_enforcement(bool enable)
303  {
305  }
306 
308  {
310  }
311 
312 protected:
313 
319 
325 
332 
336  unsigned int _outer_iterations;
337 
341  unsigned int _inner_iterations;
342 
347 
354  unsigned int _solve_result;
355 };
356 
357 
358 } // namespace libMesh
359 
360 
361 #endif // LIBMESH_DIFF_SOLVER_H
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
bool exact_constraint_enforcement()
Definition: diff_solver.h:307
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
unsigned int solve_result()
Definition: diff_solver.h:130
Functor for use as callback in solve of nonlinear solver.
Definition: diff_solver.h:42
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
The DiffSolver achieved the desired absolute step size tolerance.
Definition: diff_solver.h:249
ImplicitSystem sys_type
The type of system.
Definition: diff_solver.h:75
virtual void reinit()
The reinitialization function.
Definition: diff_solver.C:63
virtual void operator()(const NumericVector< Number > &delta_u, const Real &norm_delta_u, const NumericVector< Number > &u, const Real &norm_u, const NumericVector< Number > &res, const Real &norm_res, const unsigned int iteration)=0
The libMesh namespace provides an interface to certain functionality in the library.
static std::unique_ptr< DiffSolver > build(sys_type &s)
Factory method.
Definition: diff_solver.C:56
The linear solver used by the DiffSolver failed to find a solution.
Definition: diff_solver.h:280
virtual ~DiffSolver()=default
Destructor.
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
unsigned int total_outer_iterations()
Definition: diff_solver.h:119
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
The DiffSolver achieved the desired relative step size tolerance.
Definition: diff_solver.h:255
sys_type & _system
A reference to the system we are solving.
Definition: diff_solver.h:346
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:146
virtual unsigned int solve()=0
This method performs a solve.
The DiffSolver achieved the desired relative residual tolerance.
Definition: diff_solver.h:243
const sys_type & system() const
Definition: diff_solver.h:135
virtual void set_exact_constraint_enforcement(bool enable)
Enable (or disable; it is true by default) exact enforcement of constraints at the solver level...
Definition: diff_solver.h:302
This class implements reference counting.
An object whose state is distributed along a set of processors.
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
The solver converged but no particular reason is specified.
Definition: diff_solver.h:231
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
SolveResult
Enumeration return type for the solve() function.
Definition: diff_solver.h:220
unsigned int _outer_iterations
The number of outer iterations used by the last solve.
Definition: diff_solver.h:336
virtual ~LinearSolutionMonitor()=default
sys_type & system()
Definition: diff_solver.h:140
The DiffSolver failed to find a descent direction by backtracking (See newton_solver.C)
Definition: diff_solver.h:274
The DiffSolver diverged but no particular reason is specified.
Definition: diff_solver.h:261
A default or invalid solve result.
Definition: diff_solver.h:225
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
DiffSolver(sys_type &s)
Constructor.
Definition: diff_solver.C:30
unsigned int total_inner_iterations()
Definition: diff_solver.h:125
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
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...