Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Iteration.h

Go to the documentation of this file.
00001 // Copyright (C) 2003 Johan Hoffman and Anders Logg.
00002 // Licensed under the GNU GPL Version 2.
00003 //
00004 // - Updates by Johan Jansson (2004)
00005 
00006 #ifndef __ITERATION_H
00007 #define __ITERATION_H
00008 
00009 #include <dolfin/dolfin_log.h>
00010 #include <dolfin/constants.h>
00011 
00012 namespace dolfin
00013 {
00014   class Solution;
00015   class RHS;
00016   class TimeSlab;
00017   class Element;
00018   class ElementGroup;
00019   class ElementGroupList;
00020   class FixedPointIteration;
00021 
00023 
00024   class Iteration
00025   {
00026   public:
00027 
00028     // Type of iteration
00029     enum State {nonstiff, stiff1, stiff2, stiff3, stiff, newton};
00030 
00031     // Element residuals
00032     struct Residuals
00033     {
00034       Residuals() : r0(0), r1(0), r2(0) {}
00035       void operator=(real r) { r1 = r2; r2 = r; }
00036       void reset() { r0 = 0.0; r1 = 0.0; r2 = 0.0; }
00037       friend LogStream& operator<<(LogStream& stream, const Residuals& r)
00038       { stream << "residual: " << r.r1 << " --> " << r.r2; return stream; }
00039       real r0, r1, r2;
00040     };
00041 
00042     // Increments
00043     struct Increments
00044     {
00045       Increments() : d0(0), d1(0), d2(0), dtot(0) {}
00046       void operator=(real d) { d0 = d1; d1 = d2; d2 = d; dtot = std::max(dtot, d); }
00047       void reset() { d0 = 0.0; d1 = 0.0; d2 = 0.0; dtot = 0.0; }
00048       friend LogStream& operator<<(LogStream& stream, const Increments& d)
00049       { stream << "increment: " << d.d0 << " --> " << d.d1 << " --> " << d.d2; return stream; }
00050       real d0, d1, d2, dtot;
00051     };
00052 
00054     Iteration(Solution& u, RHS& f, FixedPointIteration& fixpoint,
00055               unsigned int maxiter, real tol, real maxdiv, real maxconv,
00056               unsigned int depth);
00057     
00059     virtual ~Iteration();
00060 
00062     virtual State state() const = 0;
00063 
00064     // Start iteration on group list
00065     virtual void start(ElementGroupList& list) = 0;
00066 
00067     // Start iteration on element group
00068     virtual void start(ElementGroup& group) = 0;
00069     
00070     // Start iteration on element
00071     virtual void start(Element& element) = 0;
00072 
00074     virtual void update(ElementGroupList& list, Increments& d) = 0;
00075 
00077     virtual void update(ElementGroup& group, Increments& d) = 0;
00078 
00080     virtual void update(Element& element, Increments& d) = 0;
00081 
00083     virtual void stabilize(ElementGroupList& list, const Increments& d,
00084                            unsigned int n) = 0;
00085     
00087     virtual void stabilize(ElementGroup& group, const Increments& d,
00088                            unsigned int n) = 0;
00089     
00091     virtual void stabilize(Element& element, const Increments& d,
00092                            unsigned int n) = 0;
00093     
00095     virtual bool converged(ElementGroupList& list, const Increments& d, unsigned int n) = 0;
00096 
00098     virtual bool converged(ElementGroup& group, const Increments& d, unsigned int n) = 0;
00099 
00101     virtual bool converged(Element& element, const Increments& d, unsigned int n) = 0;
00102 
00104     virtual bool diverged(ElementGroupList& list, const Increments& d, unsigned int n, State& newstate) = 0;
00105     
00107     virtual bool diverged(ElementGroup& group, const Increments& d, unsigned int n, State& newstate) = 0;
00108 
00110     virtual bool diverged(Element& element, const Increments& d, unsigned int n, State& newstate) = 0;
00111 
00113     virtual void report() const = 0;
00114 
00116     void stabilization(real& alpha, unsigned int& m) const;
00117 
00119     unsigned int depth() const;
00120 
00122     void down();
00123 
00125     void up();
00126 
00128     void init(ElementGroup& group);
00129 
00130     // Update initial data for element
00131     void init(Element& element);
00132 
00134     void reset(ElementGroupList& list);
00135 
00137     void reset(ElementGroup& group);
00138 
00139     // Reset element
00140     void reset(Element& element);
00141 
00142     // Compute L2 norm of element residual for group list
00143     real residual(ElementGroupList& list);
00144 
00145     // Compute L2 norm of element residual for element group
00146     real residual(ElementGroup& group);
00147 
00148     // Compute absolute value of element residual for element
00149     real residual(Element& element);
00150     
00151     // Check if latest iteration was accepted
00152     bool accept() const;
00153 
00154   protected:
00155 
00156     // An array of values used for Gauss-Jacobi iteration
00157     struct Values
00158     {
00159       Values();
00160       ~Values();
00161 
00162       void init(unsigned int size);
00163 
00164       real* values;
00165       unsigned int size;
00166       unsigned int offset;
00167     };
00168 
00169     // Stabilization for adaptive iteration
00170     bool stabilize(const Increments& d, unsigned int n, real r);
00171     
00172     // Compute divergence
00173     real computeDivergence(ElementGroupList& list);
00174 
00175     // Compute divergence
00176     real computeDivergence(ElementGroup& group);
00177 
00178     // Unstabilized update
00179     void updateUnstabilized(ElementGroupList& list, Increments& d);
00180 
00181     // Unstabilized update
00182     void updateUnstabilized(ElementGroup& group, Increments& d);
00183 
00184     // Compute alpha
00185     real computeAlpha(real rho) const;
00186 
00187     // Compute number of damping steps
00188     unsigned int computeSteps(real rho) const;
00189     
00190     // Initialize data for propagation of initial values
00191     void initInitialData(real t0);
00192 
00193     // Initialize data to new size
00194     void initData(Values& values, unsigned int size);
00195 
00196     // Compute size of data
00197     unsigned int dataSize(ElementGroupList& list);
00198 
00199     // Compute size of data
00200     unsigned int dataSize(ElementGroup& group);
00201 
00202     // Copy data from group list
00203     void copyData(ElementGroupList& list, Values& values);
00204 
00205     // Copy data to group list
00206     void copyData(Values& values, ElementGroupList& list);
00207 
00208     // Copy data from element group
00209     void copyData(ElementGroup& group, Values& values);
00210     
00211     // Copy data to element group
00212     void copyData(Values& values, ElementGroup& group);
00213 
00214     // Check if the number is between 0 and inf
00215     bool positive(real number) const;
00216 
00217     //--- Iteration data ---
00218 
00219     Solution& u;
00220     RHS& f;
00221     FixedPointIteration& fixpoint;
00222 
00223     unsigned int maxiter;
00224 
00225     real maxdiv;
00226     real maxconv;
00227     real tol;
00228 
00229     // Stabilization parameter
00230     real alpha;
00231 
00232     // Angle of sector, gamma = cos(theta)
00233     real gamma;
00234 
00235     // Increment at start of stabilizing iterations
00236     real d0;
00237 
00238     // Number of stabilizing iterations
00239     unsigned int m;
00240 
00241     // Number of remaining stabilizing iterations
00242     unsigned int j;
00243 
00244     // Depth of iteration (0,1,2,3)
00245     unsigned int _depth;
00246 
00247     // Temporary data used to restore element values after iteration
00248     Values x0;
00249 
00250     // Temporary data used for Gauss-Jacobi iteration
00251     Values x1;
00252 
00253     // Temporary data used for propagation of initial values
00254     Values u0;
00255 
00256     // True if we should keep the new values
00257     bool _accept;
00258 
00259   };
00260 
00261 }
00262 
00263 #endif


Documentation automatically generated with Doxygen on 10 Sep 2004.