00001
00002
00008
00010
00011
00012
00013 #include "RungeKuttaIntegrator.h"
00014 namespace O_SESSAME {
00015
00018 RungeKuttaIntegrator::RungeKuttaIntegrator()
00019 {
00020 m_NumSteps = 1;
00021 }
00022
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00107 Matrix RungeKuttaIntegrator::Integrate(const vector<ssfTime>& _propTime, odeFunctor _odeFunctorPtr, const Vector& _initialConditions, Orbit* _pOrbit, Attitude* _pAttitude, const Matrix& _constants, const Functor& _functorPtr)
00108 {
00109 vector<ssfTime> propTime = _propTime;
00110 vector<ssfTime>::iterator timeIterator = propTime.begin();
00111
00112 ssfTime timeInitial = (*timeIterator);
00113 ssfTime t = timeInitial;
00114 timeIterator = propTime.end() - 1;
00115 double h = ((*timeIterator).GetSeconds() - timeInitial.GetSeconds()) / m_NumSteps;
00116 int numEqs = _initialConditions.getIndexCount();
00117 Vector inputs = _initialConditions;
00118 Vector K1(numEqs);
00119 Vector K2(numEqs);
00120 Vector K3(numEqs);
00121 Vector K4(numEqs);
00122
00123 Matrix output(m_NumSteps + 1, numEqs + 1);
00124
00125 output(MatrixIndexBase,MatrixIndexBase) = timeInitial.GetSeconds();
00126 output(MatrixIndexBase,_(MatrixIndexBase+1,MatrixIndexBase+numEqs)) = ~_initialConditions;
00127 ssfTime tTemp;
00128 Vector temp(numEqs);
00129 for (int ii = 1; ii <= m_NumSteps; ++ii)
00130 {
00131 K1 = h * _odeFunctorPtr(t, inputs, _pOrbit, _pAttitude, _constants, _functorPtr);
00132 temp = inputs + K1 / 2.0; tTemp = t + h/2;
00133 K2 = h * _odeFunctorPtr(tTemp, temp, _pOrbit, _pAttitude, _constants, _functorPtr);
00134 temp = inputs + K2 / 2.0;
00135 K3 = h * _odeFunctorPtr(tTemp, temp, _pOrbit, _pAttitude, _constants, _functorPtr);
00136 temp = inputs + K3; tTemp = t + h;
00137 K4 = h * _odeFunctorPtr(tTemp, temp, _pOrbit, _pAttitude, _constants, _functorPtr);
00138 for (int jj = MatrixIndexBase; jj < MatrixIndexBase + numEqs; ++jj)
00139 {
00140 inputs(jj) += (K1(jj)
00141 + 2.0 * K2(jj)
00142 + 2.0 * K3(jj)
00143 + K4(jj)) / 6.0;
00144 }
00145 t = timeInitial + ii * h;
00146 output(MatrixIndexBase + ii,MatrixIndexBase) = t.GetSeconds();
00147 output(MatrixIndexBase + ii,_(MatrixIndexBase+1,MatrixIndexBase+numEqs)) = ~inputs;
00148 }
00149 return output;
00150 }
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179