nonlinear_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_NONLINEAR_SOLVER_H
21 #define LIBMESH_NONLINEAR_SOLVER_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
28 #include "libmesh/libmesh.h"
30 #include "libmesh/auto_ptr.h"
31 
32 // C++ includes
33 #include <cstddef>
34 
35 namespace libMesh
36 {
37 
38 // forward declarations
39 template <typename T> class SparseMatrix;
40 template <typename T> class NumericVector;
41 template <typename T> class Preconditioner;
42 class SolverConfiguration;
43 
51 template <typename T>
52 class NonlinearSolver : public ReferenceCountedObject<NonlinearSolver<T> >,
53  public ParallelObject
54 {
55 public:
60 
64  explicit
65  NonlinearSolver (sys_type & s);
66 
70  virtual ~NonlinearSolver ();
71 
76  static UniquePtr<NonlinearSolver<T> > build(sys_type & s,
77  const SolverPackage solver_package = libMesh::default_solver_package());
78 
83  bool initialized () const { return _is_initialized; }
84 
88  virtual void clear () {}
89 
94  virtual void init (const char * name = libmesh_nullptr) = 0;
95 
99  virtual std::pair<unsigned int, Real> solve (SparseMatrix<T> &, // System Jacobian Matrix
100  NumericVector<T> &, // Solution vector
101  NumericVector<T> &, // Residual vector
102  const double, // Stopping tolerance
103  const unsigned int) = 0; // N. Iterations
104 
109  virtual void print_converged_reason() { libmesh_not_implemented(); }
110 
114  virtual int get_total_linear_iterations() = 0;
115 
123  virtual unsigned get_current_nonlinear_iteration_number() const = 0;
124 
129  void (* residual) (const NumericVector<Number> & X,
131  sys_type & S);
132 
138 
143  void (* jacobian) (const NumericVector<Number> & X,
145  sys_type & S);
146 
152 
160  void (* matvec) (const NumericVector<Number> & X,
163  sys_type & S);
164 
173 
179  sys_type & S);
184 
191  void (* nullspace) (std::vector<NumericVector<Number> *> & sp, sys_type & S);
192 
200 
206  void (* transpose_nullspace) (std::vector<NumericVector<Number> *> & sp, sys_type & S);
207 
214 
220  void (* nearnullspace) (std::vector<NumericVector<Number> *> & sp, sys_type & S);
221 
228 
233  void (* user_presolve)(sys_type & S);
234 
241  void (* postcheck) (const NumericVector<Number> & old_soln,
242  NumericVector<Number> & search_direction,
243  NumericVector<Number> & new_soln,
244  bool & changed_search_direction,
245  bool & changed_new_soln,
246  sys_type & S);
247 
254 
258  const sys_type & system () const { return _system; }
259 
263  sys_type & system () { return _system; }
264 
268  void attach_preconditioner(Preconditioner<T> * preconditioner);
269 
274 
279 
292 
306 
311  unsigned int max_linear_iterations;
312 
318 
323 
328  bool converged;
329 
333  void set_solver_configuration(SolverConfiguration & solver_configuration);
334 
335 protected:
339  sys_type & _system;
340 
345 
350 
356 };
357 
358 
359 
360 
361 /*----------------------- inline functions ----------------------------------*/
362 template <typename T>
363 inline
365  ParallelObject (s),
392  converged(false),
393  _system(s),
394  _is_initialized (false),
397 {
398 }
399 
400 
401 
402 template <typename T>
403 inline
405 {
406  this->clear ();
407 }
408 
409 
410 } // namespace libMesh
411 
412 
413 #endif // LIBMESH_NONLINEAR_SOLVER_H
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
void(* residual)(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)
NonlinearImplicitSystem::ComputeResidualandJacobian * residual_and_jacobian_object
void(* transpose_nullspace)(std::vector< NumericVector< Number > * > &sp, sys_type &S)
unsigned int max_function_evaluations
Preconditioner< T > * _preconditioner
virtual void init(const char *name=libmesh_nullptr)=0
void(* user_presolve)(sys_type &S)
void(* nullspace)(std::vector< NumericVector< Number > * > &sp, sys_type &S)
void attach_preconditioner(Preconditioner< T > *preconditioner)
const class libmesh_nullptr_t libmesh_nullptr
virtual unsigned get_current_nonlinear_iteration_number() const =0
unsigned int max_linear_iterations
SolverConfiguration * _solver_configuration
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
NonlinearImplicitSystem::ComputeResidual * residual_object
void(* jacobian)(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
SolverPackage default_solver_package()
Definition: libmesh.C:995
NonlinearImplicitSystem::ComputeJacobian * jacobian_object
void set_solver_configuration(SolverConfiguration &solver_configuration)
virtual int get_total_linear_iterations()=0
NonlinearImplicitSystem::ComputeBounds * bounds_object
Used for solving nonlinear implicit systems of equations.
static UniquePtr< NonlinearSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
const sys_type & system() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void(* nearnullspace)(std::vector< NumericVector< Number > * > &sp, sys_type &S)
NonlinearImplicitSystem::ComputePostCheck * postcheck_object
virtual void print_converged_reason()
void(* bounds)(NumericVector< Number > &XL, NumericVector< Number > &XU, sys_type &S)
void(* postcheck)(const NumericVector< Number > &old_soln, NumericVector< Number > &search_direction, NumericVector< Number > &new_soln, bool &changed_search_direction, bool &changed_new_soln, sys_type &S)
NonlinearImplicitSystem::ComputeVectorSubspace * nearnullspace_object
NonlinearImplicitSystem sys_type
unsigned int max_nonlinear_iterations
NonlinearImplicitSystem::ComputeVectorSubspace * transpose_nullspace_object
void(* matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
NonlinearImplicitSystem::ComputeVectorSubspace * nullspace_object