Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

Environment.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file Environment.cpp
00003 *  \brief Implementation of the Environment encapsulation object.
00004 *  \author $Author: cakinli $
00005 *  \version $Revision: 1.1.1.1 $
00006 *  \date    $Date: 2005/04/26 17:40:56 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /* 
00009 *
00010 */
00011 //////////////////////////////////////////////////////////////////////////////////////////////////
00012 
00013 #include "Environment.h"
00014 #include "CentralBody/CentralBody.h"
00015 namespace O_SESSAME {
00016     
00017 /*! \brief Create an instance of Environment */
00018 Environment::Environment() : m_CalculatedForces(3), 
00019                              m_CalculatedTorques(3), 
00020                              m_ForcesFunctor(const_cast<Environment*>(this), &Environment::GetForces),
00021                              m_TorquesFunctor(const_cast<Environment*>(this), &Environment::GetTorques)
00022 {
00023     m_pCB = NULL;
00024 }
00025     
00026 /*! \brief Default Deconstructor */
00027 Environment::~Environment()
00028 {
00029     if(m_pCB)
00030         m_pCB->ReleaseReference();
00031 }
00032 
00033     /*! \brief Evaluate the current disturbance torques given a state. 
00034         * @param _currentTime current time to evaluate at.
00035         * @param _currentOrbitState current orbital state.
00036         * @param _currentAttitudeState current attitude state.
00037         * @return 3-element vector of disturbance torques in the body frame (N).
00038         */
00039 Vector Environment::GetTorques(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00040 {
00041     m_CalculatedTorques.setToValue(0);
00042     m_funcIterator = m_TorqueFunctions.begin();
00043     while (m_funcIterator != m_TorqueFunctions.end())
00044     {
00045         m_CalculatedTorques += (*m_funcIterator).Evaluate(_currentTime, _currentOrbitState, _currentAttitudeState);
00046         ++m_funcIterator;
00047     }
00048     return m_CalculatedTorques;
00049 }
00050 
00051     /*! \brief Evaluate the current disturbance forces given a state. 
00052         * @param _currentTime current time to evaluate at.
00053         * @param _currentOrbitState current orbital state.
00054         * @param _currentAttitudeState current attitude state.
00055         * @return 3-element vector of disturbance forces in the body frame (N).
00056         */
00057 Vector Environment::GetForces(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00058 {
00059     m_CalculatedForces.setToValue(0);
00060     m_funcIterator = m_ForceFunctions.begin();
00061     while (m_funcIterator != m_ForceFunctions.end())
00062     {
00063         m_CalculatedForces += (*m_funcIterator).Evaluate(_currentTime, _currentOrbitState, _currentAttitudeState);
00064         ++m_funcIterator;
00065     }
00066     return m_CalculatedForces;
00067 }
00068     
00069     /*! \brief Set the pointer to the central body to use for modeling the environment.
00070         * @param _pCB pointer to the CentralBody object.
00071         */
00072 void Environment::SetCentralBody(CentralBody *_pCB)
00073 {
00074     m_pCB = _pCB;
00075     return;
00076 }
00077 
00078     /*! \brief Get the pointer to the environment's central body.
00079         * @return pointer to the CentralBody object.
00080         */
00081 const CentralBody* Environment::GetCentralBody() const
00082 {
00083     return m_pCB;
00084 }
00085     
00086     /*! \brief Add a force disturbance function to the list of force functions
00087         * @param _forceFunc Pointer to a force function that matches the EnvFunction prototype.
00088         */
00089 void Environment::AddForceFunction(const EnvFunction &_forceFunc)
00090 {
00091     // iterate through the set of Force Functions to prevent duplication.
00092     /** \todo Check to prevent overlapping force functions *//*
00093     m_funcIterator = m_ForceFunctions.begin();
00094     while (m_funcIterator != m_ForceFunctions.end())
00095     {
00096         if(*m_funcIterator == _forceFunc)
00097             return;
00098     }*/
00099     m_ForceFunctions.push_back(_forceFunc);
00100     return;
00101 }
00102     /*! \brief Add a torque disturbance function to the list of force functions
00103         * @param _forceFunc Pointer to a torque function that matches the EnvFunction prototype.
00104         */
00105 void Environment::AddTorqueFunction(const EnvFunction &_torqueFunc)
00106 {
00107     // iterate through the set of Torque Functions to prevent duplication.
00108     /** \todo Check to prevent overlapping torque functions *//*
00109     m_funcIterator = m_TorqueFunctions.begin();
00110     while (m_funcIterator != m_TorqueFunctions.end())
00111     {
00112         if(*m_funcIterator == _torqueFunc)
00113             return;
00114     }*/
00115     m_TorqueFunctions.push_back(_torqueFunc);
00116     return;
00117 }
00118     
00119     /*! \brief Get the reference to the Environment::GetForces() function.
00120         * @return reference to the environment's GetForces() function.
00121         */
00122 const Functor& Environment::GetForceFunction() const
00123 {
00124     return m_ForcesFunctor;
00125 }
00126 
00127     /*! \brief Get the reference to the Environment::GetTorques() function.
00128         * @return reference to environment's GetTorques() function.
00129         */
00130 const Functor& Environment::GetTorqueFunction() const
00131 {
00132     return m_TorquesFunctor;
00133 }
00134 //////////////////////////////////////////////////////
00135 // EnvFunction Member Functions
00136 //////////////////////////////////////////////////////
00137     /*! \brief Create a disturbance function. 
00138         *
00139         *  Example: EnvFunction DragForce(&myDisturbanceFunction);
00140         * @param _EnvFuncPtr pointer to an environmental disturbance function. 
00141         */
00142 EnvFunction::EnvFunction(pt2EnvFunc _EnvFuncPtr) : m_NumParameters(0) , m_EnvFuncParameters(m_NumParameters)
00143 {
00144     m_EnvFuncPtr = _EnvFuncPtr;
00145 }
00146     /*! \brief Create a disturbance function with a set number of parameters.
00147         *
00148         *  Example: EnvFunction DragForce(&myDisturbanceFunction, 2);
00149         * @param _EnvFuncPtr pointer to an environmental disturbance function. 
00150         * @param _numParameters number of parameters that are passed to the disturbance function.
00151         */
00152 EnvFunction::EnvFunction(pt2EnvFunc _EnvFuncPtr, const int &_numParameters) : m_NumParameters(_numParameters) , m_EnvFuncParameters(m_NumParameters)
00153 {
00154     m_EnvFuncPtr = _EnvFuncPtr;
00155 }
00156     /*! \brief Evaluate the disturbance function at a specific state.
00157         *  Used to calculate the actual force or torque disturbance given the time, orbit state and attitude state.
00158         * @param _currentTime current time to evaluate at.
00159         * @param _currentOrbitState current orbital state.
00160         * @param _currentAttitudeState current attitude state.
00161         * @return 3-element vector of forces (N) or torques (Nm) from the disturbance at the specified state. 
00162         */
00163 Vector EnvFunction::Evaluate(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00164 {
00165     return m_EnvFuncPtr(_currentTime, _currentOrbitState, _currentAttitudeState, m_EnvFuncParameters);
00166 }
00167 
00168     /*! \brief Add a parameter to the parameter list.
00169         *
00170         *  The parameter is inserted in the specified position in the list of parameters, pushing any other parameters back. The list of parameters is passed into the disturbance function (ie mass, ballistic coefficient, magnetic dipole)
00171         *       <h4>Example:</h4> MagneticForce.AddParameter(reinterpret_cast<void*>(Spacecraft.GetDipole(), 2); where the GetDipole() function returns by reference.
00172         *       <p>If a parameter position is given that is beyond the last position, the parameter will be put in the last position, the intermediate parameters will be filled with empty parameters.
00173         * \warning Make sure the variable that you are passing in as a parameter will stay in scope during the disturbance function calls.
00174         * @param _parameter pointer to the data where the pertinent variable is stored. 
00175         * @param _paramNumber Position in the list of parameters. If none is specified, the parameter is put at the end.
00176         */
00177 void EnvFunction::AddParameter(void* _parameter, int _paramNumber)
00178 {
00179     if (_paramNumber > m_NumParameters)
00180     {    
00181         // Calculate the number of parameters "missing" to be temporarily filled
00182         int delta = _paramNumber - m_NumParameters;
00183         if(delta > 1)
00184         {
00185             for(int ii = 1; ii < delta; ++ii)
00186             {
00187                 m_EnvFuncParameters.push_back(0);
00188             }
00189         }
00190         m_EnvFuncParameters.push_back(_parameter);
00191     }
00192     else
00193         m_EnvFuncParameters.insert(m_EnvFuncParameters.begin() + _paramNumber - 1, _parameter);
00194     
00195     m_NumParameters = _paramNumber;
00196 
00197 }
00198     
00199     /*! \brief Changes what a parameter in the list points to.
00200         *  
00201         * @param _parameter pointer to the data where the pertinent variable is stored. 
00202         * @param _paramNumber Position in the list of parameters. If none is specified, the parameter is put at the end.
00203         */
00204 void EnvFunction::ChangeParameter(void* _parameter, int _paramNumber)
00205 {
00206     RemoveParameter(_paramNumber);
00207     AddParameter(_parameter, _paramNumber);
00208 }
00209 
00210     /*! \brief Removes a parameter from the parameter list.
00211         *
00212         *  the parameters following the removed parameters will all move down one step to "fill the spot".
00213         *       <p>If no position is specified, the last parameter in the list is removed.
00214         *       <p>If a position is given that is greater than the number of parameters, nothing happens to the list.
00215         *       <h4>Example:</h4> ParameterList = [Area, Dipole, Mass], RemoveParameter(2); ParameterList = [Area, Mass]
00216         * @param _paramNumber Position of the parameter to be removed. If none is specified, remove the last parameter in the list.
00217         */
00218 void EnvFunction::RemoveParameter(int _paramNumber)
00219 {
00220     if(_paramNumber <= m_NumParameters)
00221         m_EnvFuncParameters.erase(m_EnvFuncParameters.begin()+_paramNumber);
00222     else if(_paramNumber == -1)
00223         m_EnvFuncParameters.pop_back();
00224     else
00225         return;
00226     
00227     --m_NumParameters;
00228 }
00229 } // close namespace O_SESSAME
00230 
00231 // Do not change the comments below - they will be added automatically by CVS
00232 /*****************************************************************************
00233 *       $Log: Environment.cpp,v $
00234 *       Revision 1.1.1.1  2005/04/26 17:40:56  cakinli
00235 *       Adding OpenSESSAME to DSACSS distrib to capture fixed version.
00236 *       
00237 *       Revision 1.8  2003/06/12 18:06:35  nilspace
00238 *       .
00239 *       
00240 *       Revision 1.7  2003/06/10 15:58:52  nilspace
00241 *       GetTorques now incrementes the function iterator.
00242 *       
00243 *       Revision 1.6  2003/05/22 03:42:32  nilspace
00244 *       Moved documentation to the implementation file.
00245 *       
00246 *       Revision 1.5  2003/05/13 18:59:16  nilspace
00247 *       Fixed some comments.
00248 *       
00249 *       Revision 1.4  2003/05/05 20:45:46  nilspace
00250 *       Changed the pass-by-address parameters to pass-by-reference.
00251 *       
00252 *       Revision 1.3  2003/05/02 02:16:29  nilspace
00253 *       Documented the API.
00254 *       Added a GetTorquesFunction().
00255 *       
00256 *       Revision 1.2  2003/04/27 22:04:33  nilspace
00257 *       Created the namespace O_SESSAME.
00258 *       
00259 *       Revision 1.1  2003/04/08 22:37:22  nilspace
00260 *       Initial Submission.
00261 *       
00262 *
00263 ******************************************************************************/

Generated on Wed Sep 5 12:54:20 2007 for DSACSS Operational Code by  doxygen 1.3.9.1