orsa_body.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_BODY_H_
00026 #define _ORSA_BODY_H_
00027 
00028 #include <assert.h>
00029 #include <string>
00030 #include <list>
00031 #include <map>
00032 #include <iostream>
00033 
00034 #include "orsa_coord.h"
00035 #include "orsa_common.h"
00036 #include "orsa_file_jpl.h"
00037 
00038 namespace orsa {
00039   
00040   class Date;
00041   class UniverseTypeAwareTime;
00042   
00043   class Body;
00044   class BodyWithEpoch;
00045   class JPLBody;
00046   
00047   
00048   class BodyConstants {
00049   public:
00050     BodyConstants();
00051     BodyConstants(const std::string & name, const double mass);
00052     BodyConstants(const std::string & name, const double mass, const double radius);
00053     BodyConstants(const std::string & name, const double mass, const double radius, const JPL_planets);
00054     BodyConstants(const std::string & name, const double mass, const double radius, const double J2, const double J3, const double J4);
00055     BodyConstants(const std::string & name, const double mass, const double radius, const JPL_planets, const double J2, const double J3, const double J4);
00056     BodyConstants(const std::string & name, const double mass, const double radius, const double J2, const double J3, const double J4, const double C22, const double C31, const double C32, const double C33, const double C41, const double C42, const double C43, const double C44, const double S31, const double S32, const double S33, const double S41, const double S42, const double S43, const double S44);
00057     BodyConstants(const std::string & name, const double mass, const double radius, const JPL_planets, const double J2, const double J3, const double J4, const double C22, const double C31, const double C32, const double C33, const double C41, const double C42, const double C43, const double C44, const double S31, const double S32, const double S33, const double S41, const double S42, const double S43, const double S44);
00058     
00059     ~BodyConstants();
00060     
00061   public:
00062     inline const std::string & name() const { return name_; } 
00063     inline double mass() const { return mass_; }
00064     inline double mu() const { return mu_; }
00065     inline bool has_zero_mass() const { return zero_mass_; }
00066     inline double radius() const { return radius_; }
00067     inline JPL_planets JPLPlanet() const { return planet_; }
00068     inline double J2() const { return J2_; }
00069     inline double J3() const { return J3_; }
00070     inline double J4() const { return J4_; }
00071     inline double C22() const { return C22_; }
00072     inline double C31() const { return C31_; }
00073     inline double C32() const { return C32_; }
00074     inline double C33() const { return C33_; }
00075     inline double C41() const { return C41_; }
00076     inline double C42() const { return C42_; }
00077     inline double C43() const { return C43_; }
00078     inline double C44() const { return C44_; }
00079     inline double S31() const { return S31_; }
00080     inline double S32() const { return S32_; }
00081     inline double S33() const { return S33_; }
00082     inline double S41() const { return S41_; }
00083     inline double S42() const { return S42_; }
00084     inline double S43() const { return S43_; }
00085     inline double S44() const { return S44_; }
00086     
00087   protected:
00088     unsigned int users;
00089     
00090   public:
00091     void AddUser()    { ++users; }
00092     void RemoveUser() { --users; }
00093     unsigned int Users() const { return users; }        
00094     
00095   private:
00096     const std::string name_;
00097     const double mass_;
00098     const double mu_;
00099     const bool zero_mass_;
00100     const double radius_;
00101     const JPL_planets planet_;
00102     const double J2_, J3_, J4_;
00103     const double C22_, C31_, C32_, C33_, C41_, C42_, C43_, C44_; 
00104     const double       S31_, S32_, S33_, S41_, S42_, S43_, S44_;
00105     
00106   private:
00107     static unsigned int used_body_id;
00108     
00109   public:
00110     unsigned int BodyId() const { return id; }
00111     unsigned int     Id() const { return id; }
00112     
00113   private:
00114     const unsigned int id;
00115     
00116   protected:
00117     static std::list<BodyConstants*> list_bc;
00118   };
00119   
00120   
00121   class Body {
00122   public:
00123     // brand new bodies
00124     Body(); 
00125     Body(const double mass);
00126     Body(const std::string & name);
00127     Body(const std::string & name, const double mass);
00128     Body(const std::string & name, const double mass, const double radius);
00129     Body(const std::string & name, const double mass, const double radius, const JPL_planets p);
00130     Body(const std::string & name, const double mass, const Vector & position, const Vector & velocity);
00131     Body(const std::string & name, const double mass, const double radius, const Vector & position, const Vector & velocity);
00132     Body(const std::string & name, const double mass, const double radius, const double J2, const double J3, const double J4);
00133     Body(const std::string & name, const double mass, const double radius, const JPL_planets p, const double J2, const double J3, const double J4);
00134     Body(const std::string & name, const double mass, const double radius, const double J2, const double J3, const double J4, const double C22, const double C31, const double C32, const double C33, const double C41, const double C42, const double C43, const double C44, const double S31, const double S32, const double S33, const double S41, const double S42, const double S43, const double S44);
00135     Body(const std::string & name, const double mass, const double radius, const JPL_planets p, const double J2, const double J3, const double J4, const double C22, const double C31, const double C32, const double C33, const double C41, const double C42, const double C43, const double C44, const double S31, const double S32, const double S33, const double S41, const double S42, const double S43, const double S44);
00136     Body(const std::string & name, const double mass, const Vector & position, const Vector & velocity, const double J2, const double J3, const double J4);
00137     Body(const std::string & name, const double mass, const double radius, const Vector & position, const Vector & velocity, const double J2, const double J3, const double J4);
00138     // copy constructors
00139     Body(const Body &);
00140     Body(const BodyWithEpoch &);
00141     Body(const JPLBody &);
00142     
00143     virtual ~Body();
00144     
00145     Body & operator = (const Body &);
00146     
00147   public:
00148     inline const std::string & name() const { return bc->name(); };
00149     inline double mass() const { return bc->mass(); };
00150     inline double mu() const { return bc->mu(); };
00151     inline bool has_zero_mass() const { return bc->has_zero_mass(); }
00152     inline double radius() const { return bc->radius(); };
00153     inline JPL_planets JPLPlanet() const { return bc->JPLPlanet(); }
00154     inline double J2() const { return bc->J2(); }
00155     inline double J3() const { return bc->J3(); }
00156     inline double J4() const { return bc->J4(); }
00157     inline double C22() const { return bc->C22(); }
00158     inline double C31() const { return bc->C31(); }
00159     inline double C32() const { return bc->C32(); }
00160     inline double C33() const { return bc->C33(); }
00161     inline double C41() const { return bc->C41(); }
00162     inline double C42() const { return bc->C42(); }
00163     inline double C43() const { return bc->C43(); }
00164     inline double C44() const { return bc->C44(); }
00165     inline double S31() const { return bc->S31(); }
00166     inline double S32() const { return bc->S32(); }
00167     inline double S33() const { return bc->S33(); }
00168     inline double S41() const { return bc->S41(); }
00169     inline double S42() const { return bc->S42(); }
00170     inline double S43() const { return bc->S43(); }
00171     inline double S44() const { return bc->S44(); }
00172     
00173     const Vector & position() const { return _position; }   
00174     const Vector & velocity() const { return _velocity; }
00175     
00176     inline void AddToPosition(const Vector & v) { _position += v; }
00177     inline void AddToVelocity(const Vector & v) { _velocity += v; }
00178     
00179     inline void SetPosition(const Vector & v) { _position = v; }
00180     inline void SetPosition(const double x, const double y, const double z) { Vector v(x,y,z); SetPosition(v); }
00181     
00182     inline void SetVelocity(const Vector & v) { _velocity = v; }
00183     inline void SetVelocity(const double x, const double y, const double z) { Vector v(x,y,z); SetVelocity(v); }
00184     
00185     // b position - this position
00186     inline Vector distanceVector(const Body & b) const { return b.position()-position(); }
00187     inline double distance(const Body & b) const { return distanceVector(b).Length(); }
00188     
00189     // alias
00190     inline Vector DistanceVector(const Body & b) const { return distanceVector(b); }
00191     inline double Distance(const Body & b)       const { return distance(b); }
00192     
00193     inline double KineticEnergy() const { return (bc->mass() * _velocity.LengthSquared() / 2.0); }
00194     
00195   public:
00196     unsigned int BodyId() const { return bc->BodyId(); }
00197     
00198   public:
00199     // used to sort bodies by decreasing mass 
00200     inline bool operator < (const Body &b) const { return b.mass() < mass(); }
00201     
00202   protected:
00203     BodyConstants * bc;
00204     
00205   protected:
00206     Vector _position, _velocity;
00207   };
00208   
00209   inline bool operator== (const Body &b1, const Body &b2) {
00210     if (b1.BodyId()             != b2.BodyId())              return false;
00211     if (b1.name()               != b2.name())                return false;
00212     if (b1.mass()               != b2.mass())                return false;
00213     if (b1.position()           != b2.position())            return false;
00214     if (b1.velocity()           != b2.velocity())            return false;
00215     return true;
00216   } 
00217   
00218   inline bool operator!= (const Body &b1, const Body &b2) { return !(b1 == b2); }
00219   
00220   
00221   //! base element for intepolation
00222   class BodyWithParameter : public Body {
00223   public:
00224     double par;
00225   };
00226   
00227   
00228   class BodyWithEpoch : public Body {
00229   public:
00230     inline BodyWithEpoch() : Body() { }
00231     
00232   public:
00233     BodyWithEpoch(const BodyWithEpoch &);
00234     inline BodyWithEpoch(const double mass) : Body(mass), epoch() { }
00235     inline BodyWithEpoch(const std::string & name, const double mass) : Body(name,mass), epoch() { }
00236     inline BodyWithEpoch(const std::string & name, const double mass, const Vector & r, const Vector & v) : Body(name,mass,r,v), epoch() { }
00237     inline BodyWithEpoch(const std::string & name, const double mass, const Vector & r, const Vector & v, const Date & d) : Body(name,mass,r,v), epoch(d) { }
00238     inline BodyWithEpoch(const std::string & name, const double mass, const Vector & r, const Vector & v, const double t) : Body(name,mass,r,v), epoch(t) { }
00239     inline BodyWithEpoch(const std::string & name, const double mass, const Vector & r, const Vector & v, const UniverseTypeAwareTime & t) : Body(name,mass,r,v), epoch(t) { }
00240     inline BodyWithEpoch(const std::string & name, const double mass, const double radius) : Body(name,mass,radius), epoch() { }
00241     inline BodyWithEpoch(const std::string & name, const double mass, const double radius, const JPL_planets p) : Body(name,mass,radius,p), epoch() { }
00242     inline BodyWithEpoch(const std::string & name, const double mass, const double radius, const JPL_planets p, const UniverseTypeAwareTime & t) : Body(name,mass,radius,p), epoch(t) { }
00243     inline BodyWithEpoch(const std::string & name, const double mass, const double radius, const double J2, const double J3, const double J4) : Body(name,mass,radius,J2,J3,J4), epoch() { }
00244     inline BodyWithEpoch(const std::string & name, const double mass, const double radius, const JPL_planets p, const double J2, const double J3, const double J4) : Body(name,mass,radius,p,J2,J3,J4), epoch() { }
00245     inline BodyWithEpoch(const std::string & name, const double mass, const double radius, const JPL_planets p, const UniverseTypeAwareTime & t, const double J2, const double J3, const double J4) : Body(name,mass,radius,p,J2,J3,J4), epoch(t) { }
00246     inline BodyWithEpoch(const std::string & name, const double mass, const double radius, const JPL_planets p, const UniverseTypeAwareTime & t, const double J2, const double J3, const double J4, const double C22, const double C31, const double C32, const double C33, const double C41, const double C42, const double C43, const double C44, const double S31, const double S32, const double S33, const double S41, const double S42, const double S43, const double S44) : Body(name,mass,radius,p,J2,J3,J4,C22,C31,C32,C33,C41,C42,C43,C44,S31,S32,S33,S41,S42,S43,S44), epoch(t) { }
00247     
00248   public:
00249     const UniverseTypeAwareTime & Epoch() const { return epoch; }
00250     const UniverseTypeAwareTime & GetEpoch() const { return epoch; }
00251     
00252   public:
00253     virtual void SetEpoch(const UniverseTypeAwareTime & t) {
00254       epoch = t;
00255     }
00256     
00257   protected:
00258     UniverseTypeAwareTime epoch;
00259   };
00260   
00261   
00262   // JPL planets
00263   class JPLBody : public BodyWithEpoch {
00264   public:
00265     JPLBody();
00266     JPLBody(const JPL_planets p, const Date & epoch);
00267     
00268   public:
00269     void SetEpoch(const UniverseTypeAwareTime &);
00270   };
00271   
00272   void Interpolate(const std::vector < BodyWithParameter > & b_in, const double x, Body &b_out, Body &err_b_out);
00273   
00274   void print(const Body&);
00275   
00276   double KineticEnergy(const Body&);
00277   
00278   // template <class T> void AutoHierarchy(vector<T>&); // T is usually a Body or a BodyWithEpoch
00279   
00280   // template <class T> void PrintHierarchy(const vector<T>&); // T is usually a Body or a BodyWithEpoch
00281   
00282 } // namespace orsa
00283 
00284 #endif // _ORSA_BODY_H_

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