00001
00002
00003
00004
00005
00006
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
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
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
00057 OrbitState myOrbit;
00058 myOrbit.SetStateRepresentation(new PositionVelocity);
00059 myOrbit.SetOrbitFrame(new OrbitFrameIJK);
00060 Vector initPV(6);
00061 initPV(VectorIndexBase+0) = -5776.6;
00062 initPV(VectorIndexBase+1) = -157;
00063 initPV(VectorIndexBase+2) = 3496.9;
00064 initPV(VectorIndexBase+3) = -2.595;
00065 initPV(VectorIndexBase+4) = -5.651;
00066 initPV(VectorIndexBase+5) = -4.513;
00067 myOrbit.SetState(initPV);
00068
00069 AttitudeState myAttitude;
00070 myAttitude.SetRotation(Rotation(Quaternion(0,0,0,1)));
00071
00072
00073 Matrix Parameters(1,1);
00074 Parameters(MatrixIndexBase,MatrixIndexBase) = 398600.441;
00075
00076
00077
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
00101 tick();
00102 Matrix history = myIntegrator.Integrate(
00103 integrationTimes,
00104 &TwoBodyDynamics,
00105 myOrbit.GetState(),
00106 NULL,
00107 NULL,
00108 Parameters,
00109 OrbitForcesFunctor
00110 );
00111
00112 cout << "finished propagating in " << tock() << " seconds." << endl;
00113
00114
00115 Matrix plotting = history(_,_(MatrixIndexBase+1,MatrixIndexBase+3));
00116
00117 Plot3D(plotting);
00118 delete pEarthEnv;
00119
00120 return 0;
00121
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139