00001
00002
00003
00004
00005
00006
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
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
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
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
00069 OrbitState myOrbit;
00070 myOrbit.SetStateRepresentation(new PositionVelocity);
00071 myOrbit.SetOrbitFrame(new OrbitFrameIJK);
00072 Vector initPV(6);
00073 initPV(VectorIndexBase+0) = -5776.6;
00074 initPV(VectorIndexBase+1) = -157;
00075 initPV(VectorIndexBase+2) = 3496.9;
00076 initPV(VectorIndexBase+3) = -2.595;
00077 initPV(VectorIndexBase+4) = -5.651;
00078 initPV(VectorIndexBase+5) = -4.513;
00079 myOrbit.GetStateRepresentation()->SetPositionVelocity(initPV);
00080
00081 SpecificFunctor OrbitForcesFunctor(&OrbitForcesWithDragFunctor);
00082
00083
00084
00085 Matrix Parameters(1,1);
00086 Parameters(MatrixIndexBase,MatrixIndexBase) = 398600.4418;
00087
00088
00089
00090 cout << "PropTime = " << begin.GetSeconds() << " s -> " << end.GetSeconds() << " s" << endl;
00091 cout << "Orbit State: " << ~myOrbit.GetStateRepresentation()->GetPositionVelocity() << endl;
00092
00093
00094 tick();
00095 Matrix history = myIntegrator.Integrate(
00096 integrationTimes,
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
00109
00110 Matrix plotting = history(_,_(MatrixIndexBase+1,MatrixIndexBase+3));
00111
00112 Plot3D(plotting);
00113
00114
00115
00116 ofstream ofile;
00117 ofile.open("OrbitHistory.dat");
00118 ofile << history;
00119 ofile.close();
00120
00121
00122
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
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
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167