orsa_universe.h

Go to the documentation of this file.
00001 /* 
00002    ORSA - Orbit Reconstruction, Simulation and Analysis
00003    Copyright (C) 2002-2004 Pasquale Tricarico
00004    
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009    
00010    As a special exception, Pasquale Tricarico gives permission to
00011    link this program with Qt commercial edition, and distribute the
00012    resulting executable, without including the source code for the Qt
00013    commercial edition in the source distribution.
00014    
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019    
00020    You should have received a copy of the GNU General Public License
00021    along with this program; if not, write to the Free Software
00022    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef _ORSA_UNIVERSE_H_
00026 #define _ORSA_UNIVERSE_H_
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include "orsa_body.h"
00032 #include "orsa_integrator.h"
00033 #include "orsa_common.h"
00034 #include "orsa_frame.h"
00035 #include "orsa_error.h"
00036 
00037 namespace orsa {
00038   
00039   //! This class collects all the Frames of an integration, sampled at a fixed sample_period
00040   class Evolution : protected std::vector<Frame> {
00041   public:
00042     Evolution();
00043     Evolution(const Evolution &);
00044     virtual ~Evolution();
00045     
00046   public:
00047     virtual unsigned int size() const { return std::vector<Frame>::size(); }
00048     virtual void push_back(const Frame &f) { std::vector<Frame>::push_back(f); }
00049     virtual reference operator[](size_type n) { return std::vector<Frame>::operator[](n); }
00050     virtual const_reference operator[](size_type n) const { return std::vector<Frame>::operator[](n); }
00051     virtual void clear() { std::vector<Frame>::clear(); }
00052     
00053   public:
00054     using std::vector<Frame>::iterator;
00055     using std::vector<Frame>::const_iterator;
00056     
00057   public:
00058     virtual iterator begin() { return std::vector<Frame>::begin(); }
00059     virtual iterator end()   { return std::vector<Frame>::end(); }
00060     virtual iterator erase(iterator position) { return std::vector<Frame>::erase(position); }
00061     //
00062     virtual const_iterator begin() const { return std::vector<Frame>::begin(); }
00063     virtual const_iterator end()   const { return std::vector<Frame>::end(); }
00064     
00065   public:
00066     void Integrate(const UniverseTypeAwareTime &time_stop, const bool save_last_anyway=false);
00067     void Integrate(const Frame&, const UniverseTypeAwareTime&, const UniverseTypeAwareTime&);
00068     
00069   public:
00070     // virtual void step_done(double,double,double,Frame&,bool &continue_integration) { 
00071     virtual void step_done(const UniverseTypeAwareTime &,
00072                            const UniverseTypeAwareTime &,
00073                            const UniverseTypeAwareTimeStep &,
00074                            const Frame &,
00075                            bool & continue_integration) { 
00076       if (bool_stop_integration) continue_integration=false;
00077     }
00078     
00079     virtual void integration_started()  { _integrating=true;  bool_stop_integration=false; };
00080     virtual void integration_finished() { _integrating=false; };
00081     
00082   public:
00083     void SetMaxUnsavedSubSteps(unsigned int m) {
00084       max_unsaved_substeps = m;
00085       max_unsaved_substeps_active = true;
00086     }
00087     
00088   public:
00089     std::vector<BodyWithEpoch> start_bodies;
00090     std::vector<JPL_planets>   start_JPL_bodies; // used only in Real Universe mode
00091     
00092     // public:
00093   private:
00094     Integrator  * integrator;
00095     Interaction * interaction;
00096     UniverseTypeAwareTimeStep sample_period;
00097     
00098   public:
00099     void SetIntegrator(const IntegratorType);
00100     void SetIntegrator(const Integrator *);
00101     const Integrator * GetIntegrator() const { return integrator; }
00102     //
00103     void SetIntegratorTimeStep(const UniverseTypeAwareTimeStep);
00104     const UniverseTypeAwareTimeStep & GetIntegratorTimeStep() const;
00105     //
00106     void SetIntegratorAccuracy(const double);
00107     double GetIntegratorAccuracy() const;
00108     // 
00109     void SetInteraction(const InteractionType);
00110     void SetInteraction(const Interaction *);
00111     const Interaction * GetInteraction() const { return interaction; }
00112     //
00113     void SetSamplePeriod(const UniverseTypeAwareTimeStep &);
00114     const UniverseTypeAwareTimeStep & GetSamplePeriod() const { return sample_period; }
00115     
00116   public:
00117     bool integrating() const { return _integrating; }
00118     virtual void stop_integration() const { bool_stop_integration=true; }
00119     
00120   private:
00121     mutable bool bool_stop_integration;
00122     
00123   private:
00124     bool _integrating;
00125     
00126   private:
00127     unsigned int max_unsaved_substeps;
00128     bool         max_unsaved_substeps_active;
00129     
00130   public:
00131     std::string name;
00132     
00133   private:
00134     static unsigned int used_evolution_id;
00135     
00136   public:
00137     unsigned int Id() const { return id; }
00138     
00139   private:
00140     const unsigned int id;
00141   };
00142   
00143   //! This enum is used to classify the Universes: a Real Universe is composed
00144   // exclusively by the JPL planets and massless bodies, while the Simulated
00145   // Universe is composed by an arbitrary number of massive and massless objects.
00146   // Another big difference is the following one: in the Real Universe each body
00147   // can be defined at a different epoch, while in the Simulated all the bodies
00148   // are defined at the same epoch.
00149   enum UniverseType {
00150     Real=1,
00151     Simulated=2
00152   };
00153   
00154   inline void convert(UniverseType &ut, const unsigned int i)  {
00155     switch(i) {
00156     case 1: ut = Real;      break;
00157     case 2: ut = Simulated; break;
00158       //
00159     default:
00160       ORSA_ERROR("conversion problem: i = %i",i);
00161       break;       
00162     }
00163   }
00164   
00165   class Universe : protected std::vector<Evolution*> { 
00166   public:
00167     Universe();
00168     Universe(length_unit,mass_unit,time_unit,UniverseType=Simulated,ReferenceSystem=ECLIPTIC,TimeScale=ET);
00169     
00170     virtual ~Universe();
00171     
00172   private:
00173     void common_init(const length_unit, const mass_unit, const time_unit);
00174     
00175   public:
00176     virtual unsigned int size() const { return std::vector<Evolution*>::size(); }
00177     virtual void push_back(Evolution * const e) { std::vector<Evolution*>::push_back(e); }
00178     virtual reference operator[](size_type n) { return std::vector<Evolution*>::operator[](n); }
00179     virtual const_reference operator[](size_type n) const { return std::vector<Evolution*>::operator[](n); }
00180     virtual void clear() { std::vector<Evolution*>::clear(); }
00181     
00182   public:
00183     typedef std::vector<Evolution*>::iterator             iterator;
00184     typedef std::vector<Evolution*>::const_iterator const_iterator;
00185     
00186   public:
00187     virtual iterator begin() { return std::vector<Evolution*>::begin(); }
00188     virtual iterator end()   { return std::vector<Evolution*>::end(); }
00189     virtual iterator erase(iterator position) { return std::vector<Evolution*>::erase(position); }
00190     //
00191     virtual const_iterator begin() const { return std::vector<Evolution*>::begin(); }
00192     virtual const_iterator end()   const { return std::vector<Evolution*>::end(); }
00193     
00194   public:
00195     inline UniverseType GetUniverseType() const { return type; }
00196     inline ReferenceSystem GetReferenceSystem() const { return sys; }
00197     inline TimeScale GetTimeScale() const { return timescale; }
00198     
00199   public:
00200     std::string name;
00201     std::string description;
00202     
00203   public:
00204     bool modified;
00205     
00206   private:
00207     const UniverseType    type;
00208     const ReferenceSystem sys;
00209     const TimeScale       timescale; // sync with default_Date_timescale
00210   };
00211   
00212   //! The active universe
00213   extern Universe * universe;
00214   
00215   //! A good frame to start an integration with 
00216   Frame StartFrame(const std::vector<BodyWithEpoch> &, std::vector<JPL_planets> &, const Interaction *, const Integrator *, const UniverseTypeAwareTime &);
00217 } 
00218 // namespace orsa
00219 
00220 #endif // _ORSA_UNIVERSE_H_

Generated on Thu Jul 13 06:45:23 2006 for liborsa by  doxygen 1.4.7