libMesh
diff_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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/auto_ptr.h"
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/reference_counted_object.h"
27 #include "libmesh/parallel_object.h"
28 
29 // C++ includes
30 #include <vector>
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 double & norm_delta_u,
47  const NumericVector<Number> & u,
48  const double & norm_u,
49  const NumericVector<Number> & res,
50  const double & norm_res,
51  const unsigned int iteration) = 0;
52  virtual ~LinearSolutionMonitor();
53 };
54 
56 
70 class DiffSolver : public ReferenceCountedObject<DiffSolver>,
71  public ParallelObject
72 {
73 public:
78 
83  DiffSolver (sys_type & s);
84 
91  static UniquePtr<DiffSolver> build(sys_type & s);
92 
96  virtual ~DiffSolver () {}
97 
102  virtual void init ();
103 
108  virtual void reinit ();
109 
115  virtual unsigned int solve () = 0;
116 
121  unsigned int total_outer_iterations() { return _outer_iterations; }
122 
127  unsigned int total_inner_iterations() { return _inner_iterations; }
128 
132  unsigned int solve_result() { return _solve_result; }
133 
137  const sys_type & system () const { return _system; }
138 
142  sys_type & system () { return _system; }
143 
148  unsigned int max_linear_iterations;
149 
157 
162  bool quiet;
163 
168  bool verbose;
169 
175 
181 
193 
205 
211 
216 
222  enum SolveResult {
227  INVALID_SOLVE_RESULT = 0,
228 
233  CONVERGED_NO_REASON = 1,
234 
239  CONVERGED_ABSOLUTE_RESIDUAL = 2,
240 
245  CONVERGED_RELATIVE_RESIDUAL = 4,
246 
251  CONVERGED_ABSOLUTE_STEP = 8,
252 
257  CONVERGED_RELATIVE_STEP = 16,
258 
263  DIVERGED_NO_REASON = 32,
264 
270  DIVERGED_MAX_NONLINEAR_ITERATIONS = 64,
271 
276  DIVERGED_BACKTRACKING_FAILURE = 128,
277 
282  DIVERGED_LINEAR_SOLVER_FAILURE = 256
283  };
284 
289 
290 protected:
291 
297 
304 
308  unsigned int _outer_iterations;
309 
313  unsigned int _inner_iterations;
314 
318  sys_type & _system;
319 
326  unsigned int _solve_result;
327 };
328 
329 
330 } // namespace libMesh
331 
332 
333 #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:174
Real minimum_linear_tolerance
The tolerance for linear solves is kept above this minimum.
Definition: diff_solver.h:215
virtual ~DiffSolver()
Destructor.
Definition: diff_solver.h:96
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:203
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Definition: diff_solver.h:162
unsigned int solve_result()
Definition: diff_solver.h:132
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:156
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
Definition: diff_solver.h:191
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:296
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:303
ImplicitSystem sys_type
The type of system.
Definition: diff_solver.h:77
The libMesh namespace provides an interface to certain functionality in the library.
Real initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the ...
Definition: diff_solver.h:210
unsigned int _solve_result
Initialized to zero.
Definition: diff_solver.h:326
unsigned int _inner_iterations
The number of inner iterations used by the last solve.
Definition: diff_solver.h:313
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
unsigned int total_outer_iterations()
Definition: diff_solver.h:121
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Definition: diff_solver.h:70
sys_type & _system
A reference to the system we are solving.
Definition: diff_solver.h:318
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:148
const sys_type & system() const
Definition: diff_solver.h:137
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
This class implements reference counting.
This class forms the base class for all other classes that are expected to be implemented in parallel...
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:168
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:180
SolveResult
Enumeration return type for the solve() function.
Definition: diff_solver.h:222
unsigned int _outer_iterations
The number of outer iterations used by the last solve.
Definition: diff_solver.h:308
sys_type & system()
Definition: diff_solver.h:142
UniquePtr< LinearSolutionMonitor > linear_solution_monitor
Pointer to functor which is called right after each linear solve.
Definition: diff_solver.h:288
unsigned int total_inner_iterations()
Definition: diff_solver.h:127
Real relative_residual_tolerance
Definition: diff_solver.h:192
virtual void operator()(const NumericVector< Number > &delta_u, const double &norm_delta_u, const NumericVector< Number > &u, const double &norm_u, const NumericVector< Number > &res, const double &norm_res, const unsigned int iteration)=0
This class provides a specific system class.