TangentialDifferentialEquation.hpp

00001 #ifndef __FISH_CEPHALUS_TangentialDifferentialEquation_HPP
00002 #define __FISH_CEPHALUS_TangentialDifferentialEquation_HPP
00003 
00004 #include <aerie/AnalyticFunction.hpp>
00005 #include <ode/dop853def.hpp>
00006 #include <field/Field.hpp>
00007 
00008 namespace Fiber
00009 {
00010 
00011 
00012 struct  TangentialDifferentialEquationAnalytic
00013 {
00014         typedef ::Eagle::tvector3 tvector3;
00015 
00016         typedef Eagle::PhysicalSpace::AnalyticFunction<tvector3> Eqn_t;
00017 
00018         const Eqn_t*Eqn;
00019 
00020         enum { N = 3 };
00021         typedef double real;
00022 
00023         double  Time;
00024         
00025         TangentialDifferentialEquationAnalytic()
00026         : Eqn(0)
00027         , Time(0.0)
00028         {}
00029 
00030         struct RealArray_t : Eagle::FixedArray<real, N> 
00031         {
00032                 void init(int) {}
00033         };
00034         
00035         struct DOPVarsArray_t : Eagle::FixedArray<Traum::dop_vars<real>, N >
00036         {
00037                 void init(int) {}
00038         };
00039         
00040         void DiffEqn(int nEquations, real s, const real *q, real *dq_ds) const
00041         {
00042         Eagle::point3   Q;
00043                 for(int k=0; k<N; k++)
00044                         Q[k] = q[k]; 
00045 
00046                 assert( Eqn ); 
00047         tvector3 DataDir = (*Eqn)(Time, Q);
00048 
00049                 for(int i=0; i<N; i++)
00050                 {
00051                         dq_ds[i] = DataDir[i];
00052                 }
00053         }
00054 };
00055 
00056 typedef Traum::dop853<  TangentialDifferentialEquationAnalytic> LineIntegratorAnalytic;
00057 
00058 
00071 template <class LineIntegratorAnalyticContainer>
00072 bool    setupAnalyticIntegrators(LineIntegratorAnalyticContainer&AnalyticLineIntegrators, const RefPtr<Field>&ToIntegrateField, double Time)
00073 {
00074         if (!ToIntegrateField)
00075                 return false; 
00076 
00077         if (MemCore::InterfacePtr<TangentialDifferentialEquationAnalytic::Eqn_t>
00078                     AnalyticField = *ToIntegrateField)
00079         {
00080                 for(typename LineIntegratorAnalyticContainer::iterator 
00081                             it = AnalyticLineIntegrators.begin(); 
00082                             it != AnalyticLineIntegrators.end(); it++)
00083                 {
00084                 TangentialDifferentialEquationAnalytic::Eqn_t&AF = *AnalyticField;
00085                         (*it).Eqn = &AF; 
00086                         // note: need to set the time at each integration point in the following code 
00087                         (*it).Time = Time;
00088                 } 
00089                 return true;
00090         } 
00091         return false;
00092 }
00093 
00094 
00095 } // namespace Fiber
00096 
00097 #endif // __FISH_CEPHALUS_TangentialDifferentialEquation_HPP