00001 ////////////////////////////////////////////////////////////////////////////////////////////////// 00002 /*! \file Integrator.h 00003 * \brief Abstract interface to the Integrator Strategy. 00004 * \author $Author: jayhawk_hokie $ 00005 * \version $Revision: 1.2 $ 00006 * \date $Date: 2005/06/10 12:53:29 $ 00007 *////////////////////////////////////////////////////////////////////////////////////////////////// 00008 /* 00009 */ 00010 ////////////////////////////////////////////////////////////////////////////////////////////////// 00011 00012 #ifndef __SSF_INTEGRATOR_H__ 00013 #define __SSF_INTEGRATOR_H__ 00014 00015 #include <matrix/Matrix.h> 00016 #include <utils/Functor.h> 00017 #include <utils/Time.h> 00018 #include <vector.h> 00019 using namespace std; 00020 namespace O_SESSAME { 00021 class Orbit; 00022 class Attitude; 00023 00024 ////////////////////////////////////////////////////////////////////////////////////////////////// 00025 /*! @defgroup IntegrationLibrary Integration Library */ 00026 /* @{ */ 00027 00028 /*! \brief A generalized pointer to a function that takes a vector as a parameter and returns a vector */ 00029 typedef Vector (*vectorFuncPtr)(const Vector& _vectorFuncPtrParams); 00030 00031 /*! \brief defines a pointer to an integrator's right-hand side (RHS) function */ 00032 typedef Vector (*odeFunc)(const double& _time, const Vector& _state, const Matrix& _parameters, vectorFuncPtr _funcPtr); 00033 //typedef Vector(*odeFunc)(const double& _time, const Vector& _states, const Matrix& _params); 00034 00035 /*! \brief defines a pointer to an integrator's right-hand side (RHS) function using a functor for the arbitrary vector function 00036 * 00037 * @param _time This is the time at this step of the integration 00038 * @param _integratingState This is the current state at the time of integration. The state can be any vector 00039 of values the user desires to integrate, such as quaternions, angular momentum, energy, or position. These values 00040 are the result of the time derivative values being combined through the integration. 00041 * @param _pOrbit This is a pointer to an Orbit object. It is only necessary if the RHS function needs to inspect values of 00042 the orbit (OrbitHistory, OrbitState, etc.). If the user does not need to use the orbit object, the integration function will 00043 have passed in a NULL value (pointer to nothing), and the orbit object should not be used. 00044 * @param _pAttitude This is a pointer to an Attitude object. It is only necessary if the RHS function needs to inspect values of 00045 the attitude (AttitudeHistory, AttitudeState, etc.). If the user does not need to use the attitude object, the integration function will 00046 have passed in a NULL value (pointer to nothing), and the attitude object should not be used. 00047 * @param _parameters This is a matrix of constants that is passed to the RHS function for the user to store constants throughout 00048 the integration. Examples include the Moment of Inertia matrix, mass, ballistic coefficient, etc. The matrix can be any size, but the 00049 user needs to note how values were stored into the matrix in order to correctly extract them. (ex the first 3x3 sub-matrix is the MOI, 00050 while element (4,1) is the mass, and element (4,2) is the drag area). 00051 * @param _forceFunctorPtr This is a call-back function meant for use in calculating disturbance functions. By setting this reference to a 00052 force or torque disturbance function, the user can call this function within the RHS function, giving the current (integrated) states 00053 as parameters to calculate the instantaneous disturbance vector. (see Functor) 00054 * The right-hand side (RHS) is the function that calculates the time derivatives of the state: \f$\dot{\bf x}=f(t,{\bf x})\f$. 00055 The type @em odeFunctor is a definition of the interface to the RHS function, which requires the calculation time, state at that time, 00056 a possible pointer to an Orbit and Attitude Object, a matrix of parameter constants, and a call-back function pointer that can be used to 00057 evaluate any function of OrbitState and AttitudeState. An Example of a RHS function for 2-body orbital dynamics is: 00058 \code 00059 static Vector TwoBodyDynamics(const ssfTime &_time, const Vector& _integratingState, Orbit *_pOrbit, Attitude *_pAttitude, const Matrix &_parameters, const Functor &_forceFunctorPtr) 00060 { 00061 static Vector Forces(3); 00062 static Vector Velocity(3); 00063 static Vector stateDot(6); 00064 static OrbitState orbState 00065 (new PositionVelocity); 00066 00067 orbState.GetStateRepresentation()->SetPositionVelocity(_integratingState); 00068 00069 Forces = _forceFunctorPtr.Call(_time, orbState, _Attitude->GetStateObject()); 00070 Velocity(_) = _integratingState(_(VectorIndexBase+3,VectorIndexBase+5)); 00071 00072 stateDot(_(VectorIndexBase, VectorIndexBase+2)) = Velocity(_); 00073 stateDot(_(VectorIndexBase+3, VectorIndexBase+5)) = Forces(_); 00074 return stateDot; 00075 } 00076 \endcode 00077 */ 00078 typedef Vector (*odeFunctor)(const ssfTime& _time, const Vector& _integratingState, Orbit *_pOrbit, Attitude *_pAttitude, const Matrix& _parameters, const Functor& _forceFunctorPtr); 00079 /** @} */ 00080 00081 /*! \class Integrator 00082 * \brief Interface class to the Integrator algorithm strategies. 00083 * \ingroup IntegrationLibrary 00084 * 00085 * This class defines the functions that are required for all Integrator types (ie \sa RungeKuttaIntegrator, 00086 \sa AdamsBashfourthIntegrator, etc). 00087 00088 \par 00089 Integration in the Open-Sessame Framework is modeled after integration in <a href="http://www.mathworks.com" target=_new>MatLab</a>. 00090 To integrate, a user must specify a Right-Hand Side (RHS) function that has the form \f$\dot{\bf x} = f\left(t,{\bf x}, {\bf P}, T(t, {\bf x})\right)\f$, 00091 where \f$t\f$ is the time (in seconds), \f${\bf x}\f$ is the vector of states being integrated, \f${\bf P}\f$ is a matrix of constants, and 00092 \f$T(t, {\bf x})\f$ is a reference to an external function which can be used to evaluate other parameters necessary 00093 for the RHS equation. The integration strategy will then evaluate the function \f$f\f$ at various timesteps, depending on the 00094 integration algorithm, and combine the results together to approximate the integrated solution. 00095 00096 \par 00097 Integration is specifically useful in the Open-Sessame Framework for numerically evaluating the equations of motion (EOM) 00098 of a spacecraft. The attitude \& orbit EOM are usually defined as the time rate of change of the states (rotations, angular 00099 velocities, position, angular momentum, energy, etc) which can be integrated to determine the 00100 state of the spacecraft at some future time. For example, to evaluate the quaternion at some time \f$T\f$: 00101 \f[\frac{d\bar{\bf q}}{dt} = \dot{\bar{\bf q}} \Rightarrow d\bar{\bf q} = \dot{\bar{\bf q}} dt\f] 00102 \f[ \bar{\bf q}(T) = \int^{T}_{0}{\dot{\bar{\bf q}}(t, \bar{\bf q}(T)) dt} \f] 00103 00104 \example testAttitudeIntegration.cpp 00105 \example testOrbitIntegration.cpp 00106 */ 00107 class Integrator 00108 { 00109 public: 00110 /*! Standard Integration Function */ 00111 // virtual Matrix Integrate(const Vector& _propTime, odeFunc _FuncPtr, const Vector& _initialConditions, const Matrix& _constants, vectorFuncPtr _vectorFuncPtr) = 0; 00112 00113 00114 /*! Interface to the Orbit \& Attitude integration function. 00115 * 00116 * This function defines just the interface to any of the derived integration strategies. Because it 00117 * is pure virtual (virtual ... = 0;), it is not actually implemented, but defines a member function that 00118 * is required to be implemented by all derived classes. Therefore, the user can be assured this integration 00119 * function will exist for all derived classes. 00120 * 00121 * @param _propTime This input variable specifies the list of integration times, from the starting value (first time) to the ending integration (last time) with the specified intervals. 00122 * This vector is built by creating ssfTime object, and "push_back" them onto the vector list: 00123 * \code 00124 * vector<ssfTime> integrationTimes; 00125 * ssfTime begin(0); 00126 * ssfTime end(begin + 20); 00127 * integrationTimes.push_back(begin); 00128 * integrationTimes.push_back(end); 00129 * \endcode 00130 * @param _FunctorPtr This is the reference (see odeFunctor) to the Right-Hand side (RHS) of the integration equation. It should be a single function that computes the time derivative 00131 * of the state given the time, current state, and other parameters. 00132 * @param _initialConditions The vector of initial conditions of the state being integrated. It can be any sized. And should be in the order specified by the user. 00133 (ex. \f$[q_1, q_2, q_3, q_4, \omega_1, \omega_2, \omega_3]^{T}\f$) 00134 * @param _Orbit This is a pointer to an Orbit object. It will be passed directly to the RHS and may be used for evaluating the dynamics or disturbance torque/forces. 00135 * However, if no orbit is required, or used, the user should only pass a NULL pointer and the orbit object shouldn't be used in the user's RHS function. 00136 * @param _Attitude This is a pointer to an Attitude object. It behaves much the same way as _Orbit above. It will be passed directly to the RHS function for use in 00137 * evaluation, but if not used, the user should only pass a NULL pointer, and the attitude object not used in the RHS function. 00138 * @param _constants This is a matrix of constants that is required by the RHS function. The constants are passed to each evaluation of the RHS, and may be any size, and 00139 * store any values the user requires. Examples include Moments of Inertia, ballistic coefficients, mass, etc. 00140 Example: \f[\begin{bmatrix} I_{11} & I_{12} & I_{13} \\ I_{21} & I_{22} & I_{23} \\ I_{31} & I_{32} & I_{33} \\ mass & drag area & 0 \end{bmatrix}\f] 00141 * @param _functorPtr The Functor is a call-back function that the RHS can use to evaluate an external function call. The prototype of the _functorPtr must correspond to the Functor 00142 * definition, but other than that, may perform any calculations required by the user in the RHS function. 00143 * @return The output of the integration function is a matrix of calculated integration times (meshpoints), and integrated state values at each of the meshpoints. 00144 * \f[ 00145 * \begin{bmatrix} 00146 * t_0 & x_{1,0} & x_{2,0} & ...\\ 00147 * t_1 & x_{1,1} & x_{2,1} & ...\\ 00148 * t_2 & x_{1,2} & x_{2,2} & ...\\ 00149 * . & . & . & . \\ 00150 * t_{final} & x_{1,f} & x_{2,f} & ... 00151 * \end{bmatrix} 00152 * \f] 00153 * where \f$t_T\f$ is the time at step T, and \f$x_{i,T}\f$ is the state value of element i, at time step T. 00154 */ 00155 virtual Matrix Integrate(const vector<ssfTime>& _propTime, odeFunctor _FunctorPtr, const Vector& _initialConditions, Orbit* _pOrbit, Attitude* _pAttitude, const Matrix& _constants, const Functor& _functorPtr) = 0; 00156 protected: 00157 // Integrator() {}; 00158 }; 00159 00160 } // close namespace O_SESSAME 00161 00162 #endif 00163 // Do not change the comments below - they will be added automatically by CVS 00164 /***************************************************************************** 00165 * $Log: Integrator.h,v $ 00166 * Revision 1.2 2005/06/10 12:53:29 jayhawk_hokie 00167 * Changed header file format to make it easier to link to the spacecraft code by only having to specify dsacss/dep/spacecraft/src (ex. "file.h" changed to <dir/file.h> where dir is a folder in src). 00168 * 00169 * Revision 1.1.1.1 2005/04/26 17:41:00 cakinli 00170 * Adding OpenSESSAME to DSACSS distrib to capture fixed version. 00171 * 00172 * Revision 1.10 2003/10/18 21:37:28 rsharo 00173 * Removed "../utils" from all qmake project paths. Prepended "utils 00174 * /" to all #include directives for utils. Removed ".h" extensions from STL header 00175 * s and referenced STL components from "std::" namespace. Overall, changed to be 00176 * more portable. 00177 * 00178 * Revision 1.9 2003/05/22 21:03:52 nilspace 00179 * Updated comments. 00180 * 00181 * Revision 1.8 2003/05/22 02:59:38 nilspace 00182 * Changed to pass pointers instead of references of Orbit & Attitude objects. 00183 * 00184 * Revision 1.7 2003/05/21 19:45:01 nilspace 00185 * Updated documentation. 00186 * 00187 * Revision 1.6 2003/05/20 17:44:21 nilspace 00188 * Updated comments. 00189 * 00190 * Revision 1.5 2003/05/13 18:58:27 nilspace 00191 * Cleaned up comments. 00192 * 00193 * Revision 1.4 2003/04/27 22:04:34 nilspace 00194 * Created the namespace O_SESSAME. 00195 * 00196 * Revision 1.3 2003/04/25 13:45:55 nilspace 00197 * const'd Get() functions. 00198 * 00199 * Revision 1.2 2003/04/23 16:30:59 nilspace 00200 * Various bugfixes & uploading of all changed code for new programmers. 00201 * 00202 * Revision 1.1 2003/04/08 22:32:20 nilspace 00203 * Initial submission. 00204 * 00205 * 00206 ******************************************************************************/