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_NONLINEAR_SOLVER_H 00021 #define LIBMESH_NONLINEAR_SOLVER_H 00022 00023 // Local includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/enum_solver_package.h" 00026 #include "libmesh/reference_counted_object.h" 00027 #include "libmesh/nonlinear_implicit_system.h" 00028 #include "libmesh/libmesh.h" 00029 00030 // C++ includes 00031 #include <cstddef> 00032 00033 namespace libMesh 00034 { 00035 00036 // forward declarations 00037 template <typename T> class AutoPtr; 00038 template <typename T> class SparseMatrix; 00039 template <typename T> class NumericVector; 00040 template <typename T> class Preconditioner; 00041 00042 00043 00044 00053 template <typename T> 00054 class NonlinearSolver : public ReferenceCountedObject<NonlinearSolver<T> > 00055 { 00056 public: 00060 typedef NonlinearImplicitSystem sys_type; 00061 00065 explicit 00066 NonlinearSolver (sys_type& s); 00067 00071 virtual ~NonlinearSolver (); 00072 00077 static AutoPtr<NonlinearSolver<T> > build(sys_type& s, const SolverPackage solver_package = 00078 libMesh::default_solver_package()); 00079 00084 bool initialized () const { return _is_initialized; } 00085 00089 virtual void clear () {} 00090 00094 virtual void init () = 0; 00095 00099 virtual std::pair<unsigned int, Real> solve (SparseMatrix<T>&, // System Jacobian Matrix 00100 NumericVector<T>&, // Solution vector 00101 NumericVector<T>&, // Residual vector 00102 const double, // Stopping tolerance 00103 const unsigned int) = 0; // N. Iterations 00104 00109 virtual void print_converged_reason() { libmesh_not_implemented(); } 00110 00114 virtual int get_total_linear_iterations() = 0; 00115 00121 virtual unsigned get_current_nonlinear_iteration_number() const = 0; 00122 00127 void (* residual) (const NumericVector<Number>& X, 00128 NumericVector<Number>& R, 00129 sys_type& S); 00130 00135 NonlinearImplicitSystem::ComputeResidual *residual_object; 00136 00141 void (* jacobian) (const NumericVector<Number>& X, 00142 SparseMatrix<Number>& J, 00143 sys_type& S); 00144 00149 NonlinearImplicitSystem::ComputeJacobian *jacobian_object; 00150 00157 void (* matvec) (const NumericVector<Number>& X, 00158 NumericVector<Number>* R, 00159 SparseMatrix<Number>* J, 00160 sys_type& S); 00161 00168 NonlinearImplicitSystem::ComputeResidualandJacobian *residual_and_jacobian_object; 00169 00173 void (* bounds) (NumericVector<Number>& XL, 00174 NumericVector<Number>& XU, 00175 sys_type& S); 00179 NonlinearImplicitSystem::ComputeBounds *bounds_object; 00180 00187 void (* nullspace) (std::vector<NumericVector<Number>*>& sp, sys_type& S); 00188 00195 NonlinearImplicitSystem::ComputeVectorSubspace *nullspace_object; 00196 00202 void (* nearnullspace) (std::vector<NumericVector<Number>*>& sp, sys_type& S); 00203 00209 NonlinearImplicitSystem::ComputeVectorSubspace *nearnullspace_object; 00210 00211 00212 void (* user_presolve)(sys_type& S); 00213 00217 const sys_type & system () const { return _system; } 00218 00222 sys_type & system () { return _system; } 00223 00227 void attach_preconditioner(Preconditioner<T> * preconditioner); 00228 00232 unsigned int max_nonlinear_iterations; 00233 00237 unsigned int max_function_evaluations; 00238 00249 Real absolute_residual_tolerance; 00250 Real relative_residual_tolerance; 00251 00263 Real absolute_step_tolerance; 00264 Real relative_step_tolerance; 00265 00270 unsigned int max_linear_iterations; 00271 00276 Real initial_linear_tolerance; 00277 00281 Real minimum_linear_tolerance; 00282 00287 bool converged; 00288 00289 protected: 00293 sys_type& _system; 00294 00298 bool _is_initialized; 00299 00303 Preconditioner<T> * _preconditioner; 00304 }; 00305 00306 00307 00308 00309 /*----------------------- inline functions ----------------------------------*/ 00310 template <typename T> 00311 inline 00312 NonlinearSolver<T>::NonlinearSolver (sys_type& s) : 00313 residual (NULL), 00314 residual_object (NULL), 00315 jacobian (NULL), 00316 jacobian_object (NULL), 00317 matvec (NULL), 00318 residual_and_jacobian_object (NULL), 00319 bounds (NULL), 00320 bounds_object (NULL), 00321 nullspace (NULL), 00322 nullspace_object (NULL), 00323 nearnullspace (NULL), 00324 nearnullspace_object (NULL), 00325 user_presolve (NULL), 00326 max_nonlinear_iterations(0), 00327 max_function_evaluations(0), 00328 absolute_residual_tolerance(0), 00329 relative_residual_tolerance(0), 00330 absolute_step_tolerance(0), 00331 relative_step_tolerance(0), 00332 max_linear_iterations(0), 00333 initial_linear_tolerance(0), 00334 minimum_linear_tolerance(0), 00335 _system(s), 00336 _is_initialized (false), 00337 _preconditioner (NULL) 00338 { 00339 } 00340 00341 00342 00343 template <typename T> 00344 inline 00345 NonlinearSolver<T>::~NonlinearSolver () 00346 { 00347 this->clear (); 00348 } 00349 00350 00351 } // namespace libMesh 00352 00353 00354 #endif // LIBMESH_NONLINEAR_SOLVER_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: