RungeKuttaIntegrator.cpp

Go to the documentation of this file.
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 Matrix RungeKuttaIntegrator::Integrate(const Vector &_propTime, odeFunc _FuncPtr, const Vector &_initialConditions, const Matrix &_constants, vectorFuncPtr _vectorFuncPtr)
00026 {
00027         double timeInitial = _propTime(VectorIndexBase);
00028         double t = timeInitial;
00029         double h = (_propTime(VectorIndexBase + 1) - t) / m_NumSteps;
00030 
00031         int numEqs = _initialConditions.getIndexCount();
00032         Vector inputs = _initialConditions;
00033         Vector K1(numEqs);
00034         Vector K2(numEqs);
00035         Vector K3(numEqs);
00036         Vector K4(numEqs);
00037 
00038         Matrix output(m_NumSteps + 1, numEqs + 1);
00039 
00040         output(MatrixIndexBase,MatrixIndexBase) = timeInitial;
00041         output(MatrixIndexBase,_(MatrixIndexBase+1,MatrixIndexBase+numEqs)) = ~_initialConditions;
00042 
00043         Vector temp(numEqs);
00044         for (int ii = 1; ii <= m_NumSteps; ++ii)
00045         {
00046             K1 = h * _FuncPtr(t, inputs, _constants, _vectorFuncPtr);
00047             temp = inputs + K1 / 2.0;
00048             K2 = h * _FuncPtr(t + h/2, temp, _constants, _vectorFuncPtr);
00049             temp = inputs + K2 / 2.0;
00050             K3 = h * _FuncPtr(t + h/2, temp, _constants, _vectorFuncPtr);
00051             temp = inputs + K3;
00052             K4 = h * _FuncPtr(t + h, temp, _constants, _vectorFuncPtr);
00053             for (int jj = MatrixIndexBase; jj < MatrixIndexBase + numEqs; ++jj)
00054             {
00055                 inputs(jj) += (K1(jj)
00056                                  + 2.0 * K2(jj)
00057                                  + 2.0 * K3(jj)
00058                                  + K4(jj)) / 6.0;
00059             }
00060             t = timeInitial + ii * h;
00061             output(MatrixIndexBase + ii,MatrixIndexBase) = t;
00062             output(MatrixIndexBase + ii,_(MatrixIndexBase+1,MatrixIndexBase+numEqs)) = ~inputs; 
00063         }
00064         return output;
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; // need to create copy to prevent the stl .begin() and .end() from discarding the const-ness
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; // Calculation step size (seconds)
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 } // close namespace O_SESSAME
00152 
00153 // Do not change the comments below - they will be added automatically by CVS
00154 /*****************************************************************************
00155 *       $Log: RungeKuttaIntegrator.cpp,v $
00156 *       Revision 1.7  2003/05/22 02:59:15  nilspace
00157 *       Updated comments. Changed to pass in pointers to Orbit & Attitude objects.
00158 *       
00159 *       Revision 1.6  2003/05/13 18:58:27  nilspace
00160 *       Cleaned up comments.
00161 *       
00162 *       Revision 1.5  2003/04/27 22:04:34  nilspace
00163 *       Created the namespace O_SESSAME.
00164 *       
00165 *       Revision 1.4  2003/04/25 14:15:06  nilspace
00166 *       Created a temporary vectro<ssfTime> to prevent the STL .begin() and .end() functions from discarding the const-ness of _propTime in Integrate().
00167 *       
00168 *       Revision 1.3  2003/04/25 13:45:55  nilspace
00169 *       const'd Get() functions.
00170 *       
00171 *       Revision 1.2  2003/04/23 16:30:59  nilspace
00172 *       Various bugfixes & uploading of all changed code for new programmers.
00173 *       
00174 *       Revision 1.1  2003/04/08 22:29:55  nilspace
00175 *       Initial submission. Made a subclass of Integrator.
00176 *       
00177 *       
00178 *
00179 ******************************************************************************/

Generated on Wed Aug 6 12:58:52 2003 for Open-Sessame Framework by doxygen1.3