IntegrateGeodesic.hpp

00001 
00002 //
00003 // $Id: IntegrateGeodesic.hpp,v 1.1 2004/08/12 16:21:33 werner Exp $
00004 //
00005 // $Log: IntegrateGeodesic.hpp,v $
00006 // Revision 1.1  2004/08/12 16:21:33  werner
00007 // Integration of numerical geodesics now compiles. Working is not yet satisfying.
00008 //
00009 //
00011 #ifndef __INTEGRATE_GEODESIC_HPP
00012 #define __INTEGRATE_GEODESIC_HPP "Created 20.07.2004 00:19:45 by werner benger"
00013 
00014 #include <spacetime/Geodesic853.hpp>
00015 #include <spacetime/EulerGeodesic.hpp>
00016 #include <spacetime/RungeKutta.hpp>
00017 #include <spacetime/AdamsStoermer.hpp>
00018 
00019 namespace Traum
00020 {
00021 using namespace VecAl;
00022 
00023 class   GeodesicIntegratorBase
00024 {
00025 public:
00026 
00027         enum IntegratorType
00028         {
00029                 Euler,
00030                 RungeKutta,
00031                 AdamsStoermer,
00032                 DOP853
00033         };
00034         const IntegratorType myType;
00035 
00036         GeodesicIntegratorBase(IntegratorType t)
00037         : myType(t)
00038         {}
00039 };
00040 
00046 template <class TangentialSpaceType>
00047 class   GeodesicIntegrator : public GeodesicIntegratorBase
00048 {
00049 public:
00050         typedef typename TangentialSpaceType::Point_t  Point_t;
00051         typedef typename TangentialSpaceType::Vector_t Vector_t;
00052 
00053         enum { Dims = TangentialSpaceType::Dims };
00054 
00055         GeodesicIntegrator(IntegratorType t)
00056         : GeodesicIntegratorBase(t)
00057         {}
00058 
00059         virtual success_code advance(bool bk=false) = 0;
00060         virtual void restart(const Point_t&x0, const Vector_t&v0) = 0;
00061         virtual Point_t  position() const = 0;
00062         virtual Vector_t velocity() const = 0;
00063 };
00064 
00080 template <class Acceleration>
00081 class IntegrateGeodesic : public GeodesicIntegrator<typename Acceleration::TangentialSpace_t>
00082 {
00083 public:
00085         typedef typename Acceleration::TangentialSpace_t TangentialSpace_t;
00086         typedef GeodesicIntegrator<TangentialSpace_t>    Base_t;
00087 
00089         typedef typename Base_t::Point_t  Point_t;
00091         typedef typename Base_t::Vector_t Vector_t;
00092 
00094         typedef typename Acceleration::Point_t  GenericPoint_t;
00096         typedef typename Acceleration::Vector_t GenericVector_t;
00097 
00098         enum { Dims = Acceleration::Dims };
00099 
00100         EulerGeodesic<Acceleration>             E;
00101         RungeKuttaGeodesic<Acceleration>        RK;
00102         AdamsStoermerGeodesic<Acceleration>     AS;
00103         Geodesic853<Acceleration>               DP853;
00104 
00105         IntegrateGeodesic(const Acceleration&A, IntegratorType t)
00106         : Base_t(t)
00107         , E(A)
00108         , RK(A)
00109         , AS(A)
00110         , DP853(A)
00111         {}
00112 
00113         override success_code advance(bool bk=false)
00114         {
00115                 switch(myType)
00116                 {
00117                 case Euler:         return E.advance(bk);
00118                 case RungeKutta:    return RK.advance(bk);
00119                 case AdamsStoermer: return AS.advance(bk);
00120                 case DOP853:        return DP853.advance(bk);
00121                 }
00122         }
00123 
00124         void setStepSize(double ds)
00125         {
00126                 E.ds  = ds;
00127                 RK.ds = ds;
00128                 AS.ds = ds;
00129         }
00130 
00131         override void restart(const Point_t&x0, const Vector_t&v0)      
00132         {
00133                 switch(myType)
00134                 {
00135                 case Euler:         E    .x = x0; 
00136                                     E    .v = v0; 
00137                                     break;
00138 
00139                 case RungeKutta:    RK   .x = x0; 
00140                                     RK   .v = v0; 
00141                                     break;
00142 
00143                 case AdamsStoermer: AS.reset_step();
00144                                     AS   .x = x0; 
00145                                     AS   .v = v0; 
00146                                     break;
00147 
00148                 case DOP853:        DP853.restart1(0, x0, v0); 
00149                                     break;
00150                 }
00151         }
00152 
00153 
00154         override Point_t  position() const
00155         {
00156                 switch(myType)
00157                 {
00158                 case Euler:         return E.x;
00159                 case RungeKutta:    return RK.x;
00160                 case AdamsStoermer: return AS.x;
00161                 case DOP853:        return DP853.position();
00162                 }
00163         }
00164 
00165         override Vector_t velocity() const
00166         {
00167                 switch(myType)
00168                 {
00169                 case Euler:         return E.v;
00170                 case RungeKutta:    return RK.v;
00171                 case AdamsStoermer: return AS.v;
00172                 case DOP853:        return DP853.velocity();
00173                 }
00174         }
00175 };
00176 
00177 } // namespace Vecal
00178 
00179 #endif // __INTEGRATE_GEODESIC_HPP