testIntegration.cpp

Go to the documentation of this file.
00001 #include "Time.h"
00002 #include "RungeKuttaFehlbergIntegrator.h"
00003 #include "RungeKuttaIntegrator.h"
00004 #include "Matrix.h"
00005 #include <iostream>
00006 
00007 using namespace std;
00008 using namespace O_SESSAME;
00009 // Torque function that will be called each timestep
00010 Vector NullFunctor(const ssfTime& _pSSFTime, const OrbitState& _pOrbitState, const AttitudeState& _pAttitudeState)
00011 {
00012     return Vector(3);
00013 }
00014 
00015 Vector testRKFunc(const ssfTime &_time, const Vector& _integratingState, Orbit *_Orbit, Attitude *_Attitude, const Matrix &_parameters, const Functor &_forceFunctorPtr)
00016 {
00017     static Vector returnVal(1);
00018     returnVal(1) = _integratingState(1) - pow(_time.GetSeconds(),2) + 1;
00019     return returnVal;
00020 }
00021 Vector testRKFunc2(const ssfTime &_time, const Vector& _integratingState, Orbit *_Orbit, Attitude *_Attitude, const Matrix &_parameters, const Functor &_forceFunctorPtr)
00022 {
00023     static Vector returnVal(1);
00024     returnVal(1) = _integratingState(1) - pow(_time.GetSeconds(),3) + 1;
00025     return returnVal;
00026 }
00027 int main()
00028 {
00030     // Setup an integrator and any special parameters
00031     RungeKuttaIntegrator myRK4Integrator; 
00032     myRK4Integrator.SetNumSteps(10);
00033     
00034     // Integration times
00035     vector<ssfTime> integrationTimes;
00036     ssfTime begin(0);
00037     ssfTime end(begin + 2);
00038     integrationTimes.push_back(begin);
00039     integrationTimes.push_back(end);
00040 
00041     SpecificFunctor NothingFunctor(&NullFunctor);
00042     Matrix Parameters(1,1);
00043     
00044     Vector initConditions(1);
00045     initConditions(1) = 0.5;
00046         
00048     // Setup an integrator and any special parameters
00049     RungeKuttaFehlbergIntegrator myRK5Integrator; 
00050     myRK5Integrator.SetTolerance(0.0001);
00051 
00052     // Integration times
00053     
00055     // Integrate over the desired time interval
00056     tick();
00057     Matrix RK5History = myRK5Integrator.Integrate(
00058                             integrationTimes,           // seconds
00059                             &testRKFunc, 
00060                             initConditions,
00061                             NULL,
00062                             NULL,
00063                             Parameters,
00064                             NothingFunctor
00065                         );
00066     cout << "finished propagating in " << tock() << " seconds." << endl;
00067                             
00068                         
00069                         
00070     cout << "RK-4(5) output: " << endl << setprecision(15) <<RK5History;
00071     
00072     
00073     
00075     // Integrate over the desired time interval
00076     tick();
00077     Matrix RK4History = myRK4Integrator.Integrate(
00078                             integrationTimes,           // seconds
00079                             &testRKFunc, 
00080                             initConditions,
00081                             NULL,
00082                             NULL,
00083                             Parameters,
00084                             NothingFunctor
00085                         );
00086     cout << "finished propagating in " << tock() << " seconds." << endl;
00087                             
00088                         
00090     // Integrate over the desired time interval
00091     tick();
00092     Matrix RK4History2 = myRK4Integrator.Integrate(
00093                             integrationTimes,           // seconds
00094                             &testRKFunc2, 
00095                             initConditions,
00096                             NULL,
00097                             NULL,
00098                             Parameters,
00099                             NothingFunctor
00100                         );
00101     cout << "finished propagating in " << tock() << " seconds." << endl;                       
00102     cout << "RK-4 output: " << endl << setprecision(15) << RK4History;
00103     cout << "RK-4 output2: " << endl << setprecision(15) << RK4History2;
00104 
00105     return;
00106 }
00107 

Generated on Wed Aug 6 12:58:53 2003 for Open-Sessame Framework by doxygen1.3