petsc_nonlinear_solver.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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_PETSC_NONLINEAR_SOLVER_H
21 #define LIBMESH_PETSC_NONLINEAR_SOLVER_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 // Petsc include files.
26 #ifdef LIBMESH_HAVE_PETSC
27 
28 // Local includes
30 #include "libmesh/petsc_macro.h"
31 
32 // PETSc includes
33 EXTERN_C_FOR_PETSC_BEGIN
34 # include <petscsnes.h>
35 EXTERN_C_FOR_PETSC_END
36 
37 // C++ includes
38 
39 namespace libMesh
40 {
41  // Allow users access to these functions in case they want to reuse them. Note that users shouldn't
42  // need access to these most of the time as they are used internally by this object.
43  extern "C"
44  {
45  PetscErrorCode __libmesh_petsc_snes_monitor (SNES, PetscInt its, PetscReal fnorm, void *);
46  PetscErrorCode __libmesh_petsc_snes_residual (SNES, Vec x, Vec r, void *ctx);
47  PetscErrorCode __libmesh_petsc_snes_jacobian (SNES, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx);
48  }
49 
58 template <typename T>
60 {
61 public:
66 
70  explicit
72 
77 
81  virtual void clear ();
82 
86  virtual void init ();
87 
91  SNES snes() { this->init(); return _snes; }
92 
97  virtual std::pair<unsigned int, Real> solve (SparseMatrix<T>&, // System Jacobian Matrix
98  NumericVector<T>&, // Solution vector
99  NumericVector<T>&, // Residual vector
100  const double, // Stopping tolerance
101  const unsigned int); // N. Iterations
102 
107  virtual void print_converged_reason();
108 
114  SNESConvergedReason get_converged_reason();
115 
119  virtual int get_total_linear_iterations();
120 
127 
131  void set_residual_zero_out(bool state) { _zero_out_residual = state; }
132 
136  void set_jacobian_zero_out(bool state) { _zero_out_jacobian = state; }
137 
141  void use_default_monitor(bool state) { _default_monitor = state; }
142 
143 protected:
147  SNES _snes;
148 
156  SNESConvergedReason _reason;
157 
162 
167 
172 
177 
182 
183  private:
184 #if !PETSC_VERSION_LESS_THAN(3,3,0)
186  void (*)(std::vector<NumericVector<Number>*>&, sys_type&),
187  MatNullSpace*);
188 #endif
189 
190  friend PetscErrorCode __libmesh_petsc_snes_residual (SNES snes, Vec x, Vec r, void *ctx);
191  friend PetscErrorCode __libmesh_petsc_snes_jacobian (SNES snes, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx);
192 };
193 
194 
195 
196 } // namespace libMesh
197 
198 
199 #endif // #ifdef LIBMESH_HAVE_PETSC
200 #endif // LIBMESH_PETSC_NONLINEAR_SOLVER_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo