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

testEnvironment.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file testEnvironment.cpp
00003 *  \brief Sample of an orbit integration and an Environment object using components of the SSF.
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 #include "orbitmodels/TwoBodyDynamics.h"
00012 #include "Matrix.h"
00013 #include "RungeKuttaIntegrator.h"
00014 #include "PositionVelocity.h"
00015 #include "Plot.h"
00016 #include "Environment.h"
00017 #include "OrbitStateRepresentation.h"
00018 #include "EarthCentralBody.h"
00019 #include "OrbitState.h"
00020 #include "orbitframes/OrbitFrameIJK.h"
00021 
00022 // Force function that will be called each timestep
00023 Vector GravityForceFunction(ssfTime* _currentTime, OrbitState* _currentOrbitState, AttitudeState* _currentAttitudeState, EnvFuncParamaterType _parameterList)
00024 {
00025     Vector state = _currentOrbitState->GetState();
00026     Vector Forces(3);
00027     Vector Position(3); Position(_) = state(_(VectorIndexBase,VectorIndexBase+2));
00028     Forces = -398600.441 / pow(norm2(Position),3) * Position;
00029     return Forces;
00030 }
00031 
00032 Vector DragForceFunction(ssfTime* _currentTime, OrbitState* _currentOrbitState, AttitudeState* _currentAttitudeState, EnvFuncParamaterType _parameterList)
00033 {
00034     Vector Forces(3);
00035     double BC = *(reinterpret_cast<double*>(_parameterList[1]));
00036     Vector Vrel(3); Vrel = _currentOrbitState->GetState()(_(VectorIndexBase+3,VectorIndexBase+5));
00037     double Vrel_mag = norm2(Vrel);
00038     Forces = -1/2 *1 / BC * pow(Vrel_mag,2) * Vrel / Vrel_mag; 
00039     return Forces;
00040 }
00041 
00042 int main()
00043 {
00044     // Setup an integrator and any special parameters
00045     RungeKuttaIntegrator myIntegrator; 
00046         int numOrbits = 10;
00047         int numSteps = 100;
00048   
00049     cout << "Number of Orbits: " << flush;
00050     cin >> numOrbits;
00051     cout << "Number of Integration Steps: "<< flush;
00052     cin >> numSteps;
00053 
00054     myIntegrator.SetNumSteps(numSteps);
00055     
00056     // Create & initialize an orbit type
00057     OrbitState myOrbit;
00058     myOrbit.SetStateRepresentation(new PositionVelocity);
00059     myOrbit.SetOrbitFrame(new OrbitFrameIJK);
00060     Vector initPV(6);
00061         initPV(VectorIndexBase+0) = -5776.6; // km/s
00062         initPV(VectorIndexBase+1) = -157; // km/s        
00063         initPV(VectorIndexBase+2) = 3496.9; // km/s    
00064         initPV(VectorIndexBase+3) = -2.595;  // km/s
00065         initPV(VectorIndexBase+4) = -5.651;  // km/s        
00066         initPV(VectorIndexBase+5) = -4.513; // km/s
00067     myOrbit.SetState(initPV);
00068     
00069     AttitudeState myAttitude;
00070     myAttitude.SetRotation(Rotation(Quaternion(0,0,0,1)));
00071     
00072     // Create the matrix of parameters needed for the RHS
00073     Matrix Parameters(1,1);
00074     Parameters(MatrixIndexBase,MatrixIndexBase) = 398600.441; //km / s^2
00075 
00076     
00077     // ENVIRONMENT TESTING
00078     Environment* pEarthEnv = new Environment;
00079     EarthCentralBody *pCBEarth = new EarthCentralBody;
00080     pEarthEnv->SetCentralBody(pCBEarth);
00081     cout << "Filling Parameters" << endl;
00082     EnvFunction TwoBodyGravity(&GravityForceFunction);
00083     pEarthEnv->AddForceFunction(TwoBodyGravity);
00084     EnvFunction DragForce(&DragForceFunction);
00085     double BC = 200;
00086     DragForce.AddParameter(reinterpret_cast<void*>(&BC), 1);
00087     pEarthEnv->AddForceFunction(DragForce);
00088     cout << "Finished Setting up Earth Environment" << endl;
00089 
00090 
00091     vector<ssfTime> integrationTimes;
00092     ssfTime begin(Now());
00093     ssfTime end(begin + 92*60*numOrbits);
00094     integrationTimes.push_back(begin);
00095     integrationTimes.push_back(end);
00096     cout << "PropTime = " << begin.GetSeconds() << " s -> " << end.GetSeconds() << " s" << endl;
00097     cout << "Orbit State: " << ~myOrbit.GetState() << endl;
00098 
00099     ObjectFunctor<Environment> OrbitForcesFunctor(pEarthEnv, &Environment::GetForces);
00100     // Integrate over the desired time interval
00101     tick();
00102     Matrix history = myIntegrator.Integrate(
00103                             integrationTimes,           // seconds
00104                             &TwoBodyDynamics, 
00105                             myOrbit.GetState(),
00106                             NULL,
00107                             NULL,
00108                             Parameters,
00109                             OrbitForcesFunctor
00110                         );
00111 
00112     cout << "finished propagating in " << tock() << " seconds." << endl;                                 
00113     // Output the flight history
00114     //cout << history;
00115     Matrix plotting = history(_,_(MatrixIndexBase+1,MatrixIndexBase+3));
00116 
00117     Plot3D(plotting);
00118     delete pEarthEnv;
00119     
00120     return 0;
00121                             
00122 }
00123 
00124 // Do not change the comments below - they will be added automatically by CVS
00125 /*****************************************************************************
00126 *       $Log: testEnvironment.cpp,v $
00127 *       Revision 1.1.1.1  2005/04/26 17:41:00  cakinli
00128 *       Adding OpenSESSAME to DSACSS distrib to capture fixed version.
00129 *       
00130 *       Revision 1.2  2003/08/24 20:59:13  nilspace
00131 *       Updated.
00132 *       
00133 *       Revision 1.1  2003/04/08 23:06:26  nilspace
00134 *       Initial Submission.
00135 *       
00136 *
00137 ******************************************************************************/
00138 
00139                         

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