Integrate4D.hpp

00001 
00002 //
00003 // $Id: Integrate4D.hpp,v 1.6 2007/03/28 22:31:38 georg Exp $
00004 //
00005 // $Log: Integrate4D.hpp,v $
00006 // Revision 1.6  2007/03/28 22:31:38  georg
00007 // dtors adapted for gcc4
00008 //
00009 // Revision 1.5  2007/02/22 17:08:42  werner
00010 // A major revision of the vector/fixed array interface, unifying three independent
00011 // libraries into one. The vecal (Vector Algebra), fish/vector (Multidimensional
00012 // vector arrays) and the Eagle library (Geometric Algebra) thus share a common
00013 // root now.
00014 //
00015 // Revision 1.4  2004/05/11 17:16:24  werner
00016 // *** empty log message ***
00017 //
00018 // Revision 1.3  2004/05/05 15:56:52  werner
00019 // Separation of DOP core routines with dynamic size into the ODE library.
00020 //
00021 // Revision 1.2  2004/05/03 13:33:33  werner
00022 // integration improved
00023 //
00024 // Revision 1.1  2004/04/28 14:06:37  werner
00025 // Integrators may be safely derived from the dop853 template now.
00026 // The template definition does not include the member functions, these
00027 // need to be included explicitely when instantiating the dop853 integrator.
00028 //
00029 //
00031 #ifndef __INTEGRATE4D_HPP
00032 #define __INTEGRATE4D_HPP "Created 25.04.2004 11:02:10 by werner benger"
00033 
00034 #include <ode/Integrator.hpp>
00035 #include <eagle/FixedArray.hpp>
00036 #include <ode/dop853decl.hpp>
00037 
00038 #include "spacetime.h"
00039 
00040 namespace Traum
00041 {
00042         using namespace Eagle;
00043 
00044 template <class real=long double, int Dims=4>
00045         class IntegratePathBase;
00046 
00047 template <class Real, int N>
00048         struct  SecondOrderDiffEquationConstantSize
00049         {
00050                 typedef Real real;
00051 
00052                 struct RealArray_t : FixedArray<real, 2*N>             
00053                 {
00054                         void init(int) {}
00055                 };
00056 
00057                 struct DOPVarsArray_t : FixedArray<dop_vars<real>, 2*N >
00058                 {
00059                         void init(int) {}
00060                 };
00061 
00062                 IntegratePathBase<real, N>*parent;
00063 
00064                 //virtual void Accel(real s, const real *x, const real *v, real *d2x_ds2) = 0;
00065 
00066                 void DiffEqn(int nEquations, real s, const real *q, real *dq_ds)
00067                 {
00068                 const real *x = q;
00069                 const real *v = q + N;
00070                 real       *dx_ds = dq_ds;
00071                 real       *dv_ds = dq_ds + N;
00072 
00073                         for(int i=0; i<N; i++)
00074                         {
00075                                 dx_ds[i] = v[i];
00076                         }
00077                         parent->Accel(s, x, v, dv_ds);
00078                 }
00079         };
00080 
00081 
00082 template <>
00083 class SPACETIME_API IntegratePathBase<long double, 4> : public Integrator<long double>
00084 {
00085         typedef long double real;
00086         enum { n = 4 };
00087 
00088         typedef dop853< SecondOrderDiffEquationConstantSize<real, n> > PathIntegrator;
00089         PathIntegrator*myIntegrator;
00090 
00091 public:
00092         IntegratePathBase<long double, 4>();
00093 //      ~IntegratePathBase<long double, 4>();
00094         ~IntegratePathBase();
00095 
00096         real *initialize(int n, const real&s);
00097         override long  step_nr()      const;
00098         override const real&dx()      const;
00099         override const real&x0()      const;
00100         override const real&x1()      const;
00101         override int   size()         const;
00102         override const real&f(int i)  const;
00103         override       real f(int i, const real&x)  const;
00104 
00105         override success_code  advance(bool backward=false);
00106 
00107         virtual void Accel(real s, const real *x, const real *v, real *d2x_ds2) = 0;
00108 };
00109 
00110 
00111 
00112 
00113 template <class Real, int Dims>
00114 class IntegratePath : public IntegratePathBase<Real, Dims>
00115 {
00116 public:
00117         typedef Real real;
00118 
00119         template <class sValue, class Value>
00120         void init(const sValue&s, const Value*q, const Value*dq)
00121         {
00122         real *x = initialize(2*Dims, s);
00123         real *v = x + Dims;
00124                 for(int i=0; i<Dims; i++)
00125                 {
00126                         x[i] =  q[i];
00127                         v[i] = dq[i];
00128                 }
00129         }
00130 
00131         template <class sValue, class Value>
00132         void init(const sValue&s, const FixedArray<Value, Dims>&q, const FixedArray<Value, Dims>&dq)
00133         {
00134         real *x = initialize(2*Dims, s);
00135         real *v = x + Dims;
00136                 for(int i=0; i<Dims; i++)
00137                 {
00138                         x[i] =  q[i];
00139                         v[i] = dq[i];                   
00140                 }
00141         }
00142 
00144 
00145         virtual void Accel(real s, const real *x, const real *v, real *d2x_ds2) = 0;
00146 
00148 static  unsigned nPaths()
00149         {
00150                 return Dims; 
00151         }
00152 
00154         const real&s0()  const
00155         {
00156                 return this->x0(); 
00157         }
00158 
00159         const real&s1()  const
00160         {
00161                 return this->x1(); 
00162         }
00163 
00164         const real&q(int i)  const
00165         {
00166                 return this->f(i); 
00167         }
00168 
00169         real q(unsigned i, real s) const
00170         {
00171                 return this->f(i, s ); 
00172         }
00173 
00174         const real&dq(int i)  const
00175         {
00176                 return this->f(i+nPaths() ); 
00177         }
00178 
00179         real dq(unsigned i, real s) const
00180         {
00181                 return this->f(i+nPaths(), s ); 
00182         }
00183 };
00184 
00185 typedef IntegratePath<long double, 4> IntegratePath4D;
00186 //typedef IntegratePath<     double, 4> IntegratePath4Dd;
00187 //typedef IntegratePath<     float , 4> IntegratePath4Df;
00188 
00189 
00190 } // namespace Traum
00191 
00192 #endif // __INTEGRATE4D_HPP