$extrastylesheet
diff_solver.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 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_DIFF_SOLVER_H
00021 #define LIBMESH_DIFF_SOLVER_H
00022 
00023 // Local includes
00024 #include "libmesh/auto_ptr.h"
00025 #include "libmesh/libmesh_common.h"
00026 #include "libmesh/reference_counted_object.h"
00027 #include "libmesh/parallel_object.h"
00028 
00029 // C++ includes
00030 #include <vector>
00031 
00032 namespace libMesh
00033 {
00034 
00035 // Forward Declarations
00036 class ImplicitSystem;
00037 template <typename T> class NumericVector;
00038 
00042 class LinearSolutionMonitor {
00043 public:
00044   virtual void operator() (const NumericVector<Number>& delta_u, const double &norm_delta_u,
00045                            const NumericVector<Number>& u, const double &norm_u,
00046                            const NumericVector<Number>& res, const double &norm_res,
00047                            const unsigned int iteration) = 0;
00048   virtual ~LinearSolutionMonitor();
00049 };
00050 
00051 inline LinearSolutionMonitor::~LinearSolutionMonitor() {}
00052 
00066 // ------------------------------------------------------------
00067 // Solver class definition
00068 class DiffSolver : public ReferenceCountedObject<DiffSolver>,
00069                    public ParallelObject
00070 {
00071 public:
00075   typedef ImplicitSystem sys_type;
00076 
00081   DiffSolver (sys_type& s);
00082 
00087   static UniquePtr<DiffSolver> build(sys_type& s);
00088 
00092   virtual ~DiffSolver () {}
00093 
00098   virtual void init ();
00099 
00104   virtual void reinit ();
00105 
00111   virtual unsigned int solve () = 0;
00112 
00117   unsigned int total_outer_iterations() { return _outer_iterations; }
00118 
00123   unsigned int total_inner_iterations() { return _inner_iterations; }
00124 
00128   unsigned int solve_result() { return _solve_result; }
00129 
00133   const sys_type & system () const { return _system; }
00134 
00138   sys_type & system () { return _system; }
00139 
00144   unsigned int max_linear_iterations;
00145 
00152   unsigned int max_nonlinear_iterations;
00153 
00158   bool quiet;
00159 
00164   bool verbose;
00165 
00170   bool continue_after_max_iterations;
00171 
00176   bool continue_after_backtrack_failure;
00177 
00187   Real absolute_residual_tolerance;
00188   Real relative_residual_tolerance;
00189 
00199   Real absolute_step_tolerance;
00200   Real relative_step_tolerance;
00201 
00206   Real initial_linear_tolerance;
00207 
00211   Real minimum_linear_tolerance;
00212 
00218   enum SolveResult {
00223     INVALID_SOLVE_RESULT = 0,
00224 
00229     CONVERGED_NO_REASON = 1,
00230 
00235     CONVERGED_ABSOLUTE_RESIDUAL = 2,
00236 
00241     CONVERGED_RELATIVE_RESIDUAL = 4,
00242 
00247     CONVERGED_ABSOLUTE_STEP = 8,
00248 
00253     CONVERGED_RELATIVE_STEP = 16,
00254 
00259     DIVERGED_NO_REASON = 32,
00260 
00266     DIVERGED_MAX_NONLINEAR_ITERATIONS = 64,
00267 
00272     DIVERGED_BACKTRACKING_FAILURE = 128,
00273 
00278     DIVERGED_LINEAR_SOLVER_FAILURE = 256
00279   };
00280 
00284   UniquePtr<LinearSolutionMonitor> linear_solution_monitor;
00285 
00286 protected:
00287 
00292   Real max_solution_norm;
00293 
00299   Real max_residual_norm;
00300 
00304   unsigned int _outer_iterations;
00305 
00309   unsigned int _inner_iterations;
00310 
00314   sys_type& _system;
00315 
00322   unsigned int _solve_result;
00323 };
00324 
00325 
00326 } // namespace libMesh
00327 
00328 
00329 #endif // LIBMESH_DIFF_SOLVER_H