Documentation


odeSolver.h

Go to the documentation of this file.
00001 #ifndef OdeSolver_h_________________________________
00002 #define OdeSolver_h_________________________________
00003 
00004 #include <animal/integrator.h>
00005 
00006 namespace animal {
00007 
00019 template<
00020     class t_Positions,
00021     class t_Vector,
00022     class t_Real>
00023 class OdeSolver
00024 {
00025 public:
00026     typedef t_Positions Positions;  
00027     typedef t_Vector Vector; 
00028     typedef t_Real Real;     
00029   static const int EULER          = 0; 
00030   static const int RK2            = 1; 
00031   static const int RK4            = 2; 
00032   static const int MODMID         = 3; 
00033   static const int VVERLET        = 4; 
00034 
00036     OdeSolver();
00037 
00039     virtual ~OdeSolver(){}
00040     
00042     virtual void solveODE( Positions& pos, Vector& vel, Real dt );
00043 
00045     void setMethod( int m );
00046     
00048     int method() const;
00049 
00051     void setMMIDsteps( int n ){ _MMIDsteps = n; }
00052 
00054     int MMIDsteps() const { return _MMIDsteps; }
00055 
00056     int _method;  
00057     int _MMIDsteps;      
00058 protected:
00059     
00065     virtual void computeAccelerations( Vector& acceleration, const Positions& pos, const Vector& vel )=0;
00066     
00067 
00068     typedef Derivs<Vector,Vector> Der;  
00069     
00070     Vector dv1;  
00071     Vector da1;  
00072     Der d1; 
00073     
00074     Vector dv2;  
00075     Vector da2;  
00076     Der d2; 
00077     
00078     Vector dv3;  
00079     Vector da3;  
00080     Der d3; 
00081     
00082     Vector dv4;  
00083     Vector da4;  
00084     Der d4; 
00085     
00086     
00087     typedef States<Positions,Vector> Sta;  
00088 
00089     Positions sp1;   
00090     Vector sv1;   
00091     Sta s1;        
00092 
00093     Positions sp2;   
00094     Vector sv2;   
00095     Sta s2;        
00096 
00097     Positions sp3;   
00098     Vector sv3;   
00099     Sta s3;        
00100 
00101     Vector velHalf;  // auxilliary variable for half step velocities - used in velocity verlet scheme
00102 
00104     void computeDerivative( Der& d, const Sta& s, Real );
00105 
00112     void euler(Positions& pos, Vector& vel, Real h, Real t=0);
00113 
00120     void rk2(Positions& pos, Vector& vel, Real h, Real t=0);
00121 
00128     void rk4(Positions& pos, Vector& vel, Real h, Real t=0);
00129 
00137     void modmid(Positions& pos, Vector& vel, Real h, int n, Real t=0);
00138 
00139     // velocity verlet scheme
00140     void velocityVerlet(Positions& pos, Vector& vel, Real h);
00141 
00142     //=======================================================================
00143     // The following methods perform time integration given initial conditions and all necessary auxiliary containers
00144 
00152     void integrate_euler
00153     (
00154         Sta& s,
00155         Real h,
00156         Real t,
00157         Der& d
00158     );
00159     
00168     void integrate_rk2
00169     ( 
00170         Sta& s, 
00171         Real h, 
00172         Real t,
00173         Der& d, 
00174         Sta& s1 
00175     );
00176     
00188     void integrate_rk4
00189     (
00190         Sta& s,
00191         Real h,
00192         Real t,
00193         Der& d1,
00194         Der& d2,
00195         Der& d3,
00196         Der& d4,
00197         Sta& s1
00198     );
00199 
00211     void integrate_modmid
00212     (
00213         Sta& s,
00214         Real h,
00215         Real t,
00216         int n,
00217         Der& d1,
00218         Sta& s1,
00219         Sta& s2,
00220         Sta& s3
00221     );
00222 
00223      // perform velocity verlet integration on given states
00224     void integrate_VVerlet(
00225         Sta& s,
00226         Real h,
00227         Der& d  );
00228 
00229 
00230 };
00235 }//animal
00236 
00237 
00238 #endif

Generated on Thu Dec 23 13:52:26 2004 by doxygen 1.3.6