petsc_nonlinear_solver.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_PETSC_NONLINEAR_SOLVER_H 00021 #define LIBMESH_PETSC_NONLINEAR_SOLVER_H 00022 00023 #include "libmesh/libmesh_config.h" 00024 00025 // Petsc include files. 00026 #ifdef LIBMESH_HAVE_PETSC 00027 00028 // Local includes 00029 #include "libmesh/nonlinear_solver.h" 00030 #include "libmesh/petsc_macro.h" 00031 00032 // PETSc includes 00033 EXTERN_C_FOR_PETSC_BEGIN 00034 # include <petscsnes.h> 00035 EXTERN_C_FOR_PETSC_END 00036 00037 // C++ includes 00038 00039 namespace libMesh 00040 { 00041 // Allow users access to these functions in case they want to reuse them. Note that users shouldn't 00042 // need access to these most of the time as they are used internally by this object. 00043 extern "C" 00044 { 00045 PetscErrorCode __libmesh_petsc_snes_monitor (SNES, PetscInt its, PetscReal fnorm, void *); 00046 PetscErrorCode __libmesh_petsc_snes_residual (SNES, Vec x, Vec r, void *ctx); 00047 PetscErrorCode __libmesh_petsc_snes_jacobian (SNES, Vec x, Mat *jac, Mat *pc, MatStructure *msflag, void *ctx); 00048 } 00049 00058 template <typename T> 00059 class PetscNonlinearSolver : public NonlinearSolver<T> 00060 { 00061 public: 00065 typedef NonlinearImplicitSystem sys_type; 00066 00070 explicit 00071 PetscNonlinearSolver (sys_type& system); 00072 00076 ~PetscNonlinearSolver (); 00077 00081 virtual void clear (); 00082 00086 virtual void init (); 00087 00091 SNES snes() { this->init(); return _snes; } 00092 00097 virtual std::pair<unsigned int, Real> solve (SparseMatrix<T>&, // System Jacobian Matrix 00098 NumericVector<T>&, // Solution vector 00099 NumericVector<T>&, // Residual vector 00100 const double, // Stopping tolerance 00101 const unsigned int); // N. Iterations 00102 00107 virtual void print_converged_reason(); 00108 00114 SNESConvergedReason get_converged_reason(); 00115 00119 virtual int get_total_linear_iterations(); 00120 00126 virtual unsigned get_current_nonlinear_iteration_number() const { return _current_nonlinear_iteration_number; } 00127 00133 void set_current_nonlinear_iteration_number(unsigned num) { _current_nonlinear_iteration_number = num; } 00134 00138 SNES _snes; 00139 00147 SNESConvergedReason _reason; 00148 00152 int _n_linear_iterations; 00153 00157 unsigned _current_nonlinear_iteration_number; 00158 00159 private: 00160 #if !PETSC_VERSION_LESS_THAN(3,3,0) 00161 void build_mat_null_space(NonlinearImplicitSystem::ComputeVectorSubspace* computeSubspaceObject, 00162 void (*)(std::vector<NumericVector<Number>*>&, sys_type&), 00163 MatNullSpace*); 00164 #endif 00165 }; 00166 00167 00168 00169 } // namespace libMesh 00170 00171 00172 #endif // #ifdef LIBMESH_HAVE_PETSC 00173 #endif // LIBMESH_PETSC_NONLINEAR_SOLVER_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: