Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

testOrbitIntegration.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file testOrbitIntegration.cpp
00003 *  \brief Example of orbit integration using Open-Sessame.
00004 *  \author $Author: cakinli $
00005 *  \version $Revision: 1.1.1.1 $
00006 *  \date    $Date: 2005/04/26 17:41:00 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /*!  
00009 */
00010 //////////////////////////////////////////////////////////////////////////////////////////////////
00011 
00012 #include "orbitmodels/TwoBodyDynamics.h"
00013 #include "Matrix.h"
00014 #include "RungeKuttaFehlbergIntegrator.h"
00015 #include "OrbitState.h"
00016 #include "Plot.h"
00017 #include "orbitframes/OrbitFrameIJK.h"
00018 #include "orbitstaterep/PositionVelocity.h"
00019 #include "LinearInterpolator.h"
00020 
00021 #include <vector.h>
00022 using namespace std;
00023 using namespace O_SESSAME;
00024 
00025 /*! \brief Force function that will be called each timestep */
00026 Vector OrbitForcesFunctor(const ssfTime& _pSSFTime, const OrbitState& _pOrbitState, const AttitudeState& _pAttitudeState)
00027 {
00028     Vector Forces;
00029     Vector Position(3); Position(_) = _pOrbitState.GetStateRepresentation()->GetPositionVelocity()(_(VectorIndexBase,VectorIndexBase+2));
00030     Forces = -398600.4418 / pow(norm2(Position),3) * Position;
00031     return Forces;
00032 }
00033 
00034 Vector OrbitForcesWithDragFunctor(const ssfTime& _pSSFTime, const OrbitState& _pOrbitState, const AttitudeState& _pAttitudeState)
00035 {
00036     Vector Forces;
00037     Vector Position(3); Position(_) = _pOrbitState.GetStateRepresentation()->GetPositionVelocity()(_(VectorIndexBase,VectorIndexBase+2));
00038             
00039     double BC = 0.5;
00040     Vector Vrel(3); Vrel = _pOrbitState.GetStateRepresentation()->GetPositionVelocity()(_(VectorIndexBase+3,VectorIndexBase+5));
00041     double Vrel_mag = norm2(Vrel);
00042     Forces = -398600.4418 / pow(norm2(Position),3) * Position;
00043     
00044     Forces += -1/2 *1/BC * pow(Vrel_mag,2) * Vrel / Vrel_mag; 
00045     return Forces;
00046 }
00047 
00048 int main()
00049 {
00050     /////////////////////////////////////////////////
00051     // Setup an integrator and any special parameters
00052     RungeKuttaFehlbergIntegrator myIntegrator; 
00053         int numOrbits = 1;
00054         int numSteps = 100;
00055     cout << "Number of Orbits: " << flush;
00056     cin >> numOrbits;
00057     cout << "Number of Integration Steps: "<< flush;
00058     cin >> numSteps;
00059     //myIntegrator.SetNumSteps(numSteps);
00060     
00061     vector<ssfTime> integrationTimes;
00062     ssfTime begin(0);
00063     ssfTime end(begin + 92*60*numOrbits);
00064     integrationTimes.push_back(begin);
00065     integrationTimes.push_back(end);
00066     
00067     /////////////////////////////////////////////////
00068     // Create & initialize an orbit type
00069     OrbitState myOrbit;
00070     myOrbit.SetStateRepresentation(new PositionVelocity);
00071     myOrbit.SetOrbitFrame(new OrbitFrameIJK);
00072     Vector initPV(6);
00073         initPV(VectorIndexBase+0) = -5776.6; // km/s
00074         initPV(VectorIndexBase+1) = -157; // km/s        
00075         initPV(VectorIndexBase+2) = 3496.9; // km/s    
00076         initPV(VectorIndexBase+3) = -2.595;  // km/s
00077         initPV(VectorIndexBase+4) = -5.651;  // km/s        
00078         initPV(VectorIndexBase+5) = -4.513; // km/s
00079     myOrbit.GetStateRepresentation()->SetPositionVelocity(initPV);
00080 
00081     SpecificFunctor OrbitForcesFunctor(&OrbitForcesWithDragFunctor);
00082 
00083     /////////////////////////////////////////////////
00084     // Create the matrix of parameters needed for the RHS
00085     Matrix Parameters(1,1);
00086     Parameters(MatrixIndexBase,MatrixIndexBase) = 398600.4418; //km / s^2
00087 
00088 
00089     /////////////////////////////////////////////////
00090     cout << "PropTime = " << begin.GetSeconds() << " s -> " << end.GetSeconds() << " s" << endl;
00091     cout << "Orbit State: " << ~myOrbit.GetStateRepresentation()->GetPositionVelocity() << endl;
00092 
00093     // Integrate over the desired time interval
00094     tick();
00095     Matrix history = myIntegrator.Integrate(
00096                             integrationTimes,           // seconds
00097                             &TwoBodyDynamics, 
00098                             myOrbit.GetStateRepresentation()->GetPositionVelocity(),
00099                             NULL,
00100                             NULL,
00101                             Parameters,
00102                             OrbitForcesFunctor
00103                         );
00104 
00105     cout << "finished propagating in " << tock() << " seconds." << endl;
00106     
00107     /////////////////////////////////////////////////
00108     // Plot the flight history
00109     //cout << history;
00110     Matrix plotting = history(_,_(MatrixIndexBase+1,MatrixIndexBase+3));
00111 
00112     Plot3D(plotting);
00113     
00114     /////////////////////////////////////////////////
00115     // Store the output to file
00116     ofstream ofile;
00117     ofile.open("OrbitHistory.dat");
00118     ofile << history;
00119     ofile.close();
00120     
00121     //////////////////////////////////////////////////////////////
00122     // Create an OrbitHistory object (uses a LinearInterpolator)
00123     OrbitHistory myOrbHistory;
00124     myOrbHistory.SetInterpolator(new LinearInterpolator);
00125     Vector PosVel(6);
00126     for(int jj = 1;jj <= history[MatrixRowsIndex].getIndexBound(); ++jj)
00127     {
00128         PosVel(_) = ~history(jj,_(2,7));
00129         myOrbit.GetStateRepresentation()->SetPositionVelocity(PosVel);
00130         myOrbHistory.AppendHistory(history(jj,1), myOrbit);
00131     }
00132     
00133     ///////////////////////////////////////////////////////////
00134     // Ask the user for a specified time to inspect the state.
00135     double inspectTime;
00136     cout << "Output state at time (s): " << flush;
00137     cin >> inspectTime;
00138     ssfTime myTime(inspectTime);
00139     myOrbHistory.GetState(myTime, myOrbit);
00140     cout << myTime.GetSeconds() << " : " << ~myOrbit.GetStateRepresentation()->GetPositionVelocity() << endl;
00141 
00142     return 0;
00143 }
00144 
00145 
00146 // Do not change the comments below - they will be added automatically by CVS
00147 /*****************************************************************************
00148 *       $Log: testOrbitIntegration.cpp,v $
00149 *       Revision 1.1.1.1  2005/04/26 17:41:00  cakinli
00150 *       Adding OpenSESSAME to DSACSS distrib to capture fixed version.
00151 *       
00152 *       Revision 1.4  2003/08/24 20:59:13  nilspace
00153 *       Updated.
00154 *       
00155 *       Revision 1.3  2003/05/13 18:56:15  nilspace
00156 *       Fixed to work with new integrators, History, and interpolation.
00157 *       
00158 *       Revision 1.2  2003/04/23 16:30:59  nilspace
00159 *       Various bugfixes & uploading of all changed code for new programmers.
00160 *       
00161 *       Revision 1.1  2003/04/08 23:05:58  nilspace
00162 *       Initial submission.
00163 *       
00164 *
00165 ******************************************************************************/
00166 
00167                         

Generated on Wed Sep 5 12:54:26 2007 for DSACSS Operational Code by  doxygen 1.3.9.1