Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

kepler.h

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00011 
00013 
00014 //  version 1:  Nov 1993   Piet Hut & Steve McMillan
00015 //  version 2:
00016 //
00017 //  This file includes:
00018 //  1) definition of class kepler
00019 //  2) declarations of kepler-related functions that do not know about the
00020 //     dyn class
00021 
00022 #ifndef  STARLAB_KEPLER_H
00023 #  define  STARLAB_KEPLER_H
00024 
00025 #include  "starlab_vector.h"
00026 #include  "story.h"
00027 
00029 
00030 //             Introduced to deal with tidal problems in unperturbed motion,
00031 //             but no longer needed.  Retain the class as an example, and
00032 //             keep the pointer (not used, as of 8/03) in the kepler class.
00033 //
00034 //                                                      Steve, 8/03
00035 
00036 class kep_config                            // for possible use with
00037 {                                           // unperturbed motion
00038     public:
00039         real time;                          // unperturbed start time
00040         void *nn;                           // CM nn at startup
00041         real de;                            // tidal error at startup
00042         real energy;                        // initial energy of the nn orbit
00043 
00044         kep_config() {time = de = energy = 0, nn = NULL;}
00045 };
00046 
00048 
00049 class  kepler
00050 {
00051     protected:
00052 
00053         // Constants of the orbit:
00054 
00055         real  total_mass;                    
00056 
00057         real  energy;                        
00058         real  angular_momentum;              
00059 
00060         real  mean_motion;                   // keep these separate to
00061         real  period;                        // handle special cases
00062 
00063         vec  normal_unit_vector;             
00064         vec  longitudinal_unit_vector;       
00065                                              //   pointing from the focus
00066                                              //   to the pericenter
00067         vec  transverse_unit_vector;         
00068                                              //   pointing from the focus to
00069                                              //   a true anomaly of 90 degrees
00070 
00071         real  semi_major_axis;
00072         real  eccentricity;
00073         real  periastron;
00074 
00076 
00077         real  time_of_periastron_passage;    
00078 
00079         // Dynamical variables:
00080 
00081         real  time;                          
00082 
00083         vec  rel_pos;                        
00084         vec  rel_vel;                        
00085 
00086         real  separation;                    
00087                                              //   NOTE: ALWAYS update separation
00088                                              //   when updating rel_pos.
00089 
00090         real  true_anomaly;                  // helpful when starting with a
00091                                              //   prescribed separation.
00092         real  mean_anomaly;                  // helpful when starting with a
00093                                              //   prescribed time.
00094         // Predicted quantities:
00095 
00096         real pred_time;                      
00097         vec  pred_rel_pos;                   
00098         vec  pred_rel_vel;                   
00099         real pred_separation;                
00100         real pred_true_anomaly;              
00101         real pred_mean_anomaly;              
00102 
00103 
00104         real circular_binary_limit;          // Use to allow parts of code to
00105                                              // make nearly circular binaries
00106                                              // exactly circular, but don't
00107                                              // force it on other functions.
00108 
00109         // Bookkeeping (not currently used, as of 8/03 -- Steve)
00110 
00111         kep_config *kep_init;                
00112 
00113         // Local functions:
00114 
00115         void fast_to_pred_rel_pos_vel(real r_cos_true_an,
00116                                       real r_sin_true_an);
00117         void fast_pred_mean_anomaly_to_pos_and_vel();   // (Steve, 6/01)
00118 
00119         void to_pred_rel_pos_vel(real, real);
00120         void to_pred_rel_pos_vel_linear(real);
00121         void pred_true_to_mean_anomaly();
00122         void mean_anomaly_to_periastron_passage();      // to be pred_ified ??
00123         void update_time_of_periastron();
00124         void set_real_from_pred();
00125         void pred_mean_anomaly_to_pos_and_vel();
00126 
00127     public:
00128 
00129         kepler();
00130 
00131         virtual ~kepler() {if (kep_init) delete kep_init;}
00132 
00134 
00135         void kep_to_dyn_story(story *);
00136 
00137         void set_time(const real new_time)        {time = new_time;}
00138 
00140 
00141         void offset_time(const real dt) {
00142             time += dt;
00143             time_of_periastron_passage += dt;
00144         }
00145         void set_total_mass(const real new_mass) {total_mass = new_mass;}
00146         void set_rel_pos(const vec& new_pos)  {rel_pos = new_pos;
00147                                                    separation = abs(rel_pos);}
00148         void set_rel_vel(const vec& new_vel)  {rel_vel = new_vel;}
00149 
00150         void set_energy(const real E)             {energy = E;}
00151         void set_semi_major_axis(const real a)    {semi_major_axis = a;}
00152         void set_angular_momentum(const real h)   {angular_momentum = h;}
00153         void set_eccentricity(const real e)       {eccentricity = e;}
00154         void set_periastron(const real q)         {periastron = q;}
00155 
00156         void set_mean_anomaly(const real M)       {mean_anomaly = M;}
00157 
00159 
00160         void set_orientation(vec& l, vec& t, vec& n) {
00161             longitudinal_unit_vector = l;
00162             transverse_unit_vector = t;
00163             normal_unit_vector = n;
00164         }
00165 
00167 
00168         void  align_with_axes(int);
00169 
00170         real get_circular_binary_limit()        {return circular_binary_limit;}
00171         void set_circular_binary_limit(real e)  {circular_binary_limit = e;}
00172 
00173         kep_config *get_kep_init()              {return kep_init;}
00174         void set_kep_init(kep_config *k)        {kep_init = k;}
00175 
00176         void initialize_from_pos_and_vel(bool minimal = false,
00177                                          bool verbose = true);
00178         void initialize_from_shape_and_phase();
00179 
00180         real get_time()                           {return time;}
00181         real get_pred_time()                      {return pred_time;}
00182         real get_total_mass()                     {return total_mass;}
00183         vec  get_rel_pos()                        {return rel_pos;}
00184         vec  get_rel_vel()                        {return rel_vel;}
00185 
00186         real get_energy()                         {return energy;}
00187         real get_semi_major_axis()                {return semi_major_axis;}
00188         real get_angular_momentum()               {return angular_momentum;}
00189         real get_eccentricity()                   {return eccentricity;}
00190         real get_periastron()                     {return periastron;}
00191         real get_apastron()                       {return semi_major_axis
00192                                                        * (1 + eccentricity);}
00193         real get_period()                         {return period;}
00194 
00195         real get_mean_motion()                    {return mean_motion;}
00196 
00197         vec  get_normal_unit_vector()             {return normal_unit_vector;}
00198         vec  get_longitudinal_unit_vector()
00199                     {return longitudinal_unit_vector;}
00200         vec  get_transverse_unit_vector()
00201                     {return transverse_unit_vector;}
00202 
00203         real get_separation()                     {return separation;}
00204         real get_true_anomaly()                   {return true_anomaly;}
00205         real get_mean_anomaly()                   {return mean_anomaly;}
00206         real get_time_of_periastron_passage()
00207                   {return time_of_periastron_passage;}
00208 
00209         // The following functions transform the relative position and
00210         // velocity, as well as the other internal variables (`radius'
00211         // is the separation between the two stars).
00212 
00213         real advance_to_radius(real);           
00214         real return_to_radius(real);            
00215 
00216         real advance_to_periastron();
00217         real return_to_periastron();
00218         real advance_to_apastron();
00219         real return_to_apastron();
00220 
00221         real transform_to_time(real);
00222 
00223         // The following functions transform only the predicted relative
00224         // position and velocity, and predicted mean and true anomaly, but
00225         // leave all other internal variables unchanged.
00226 
00227         real pred_transform_to_radius(real, int);
00228         real pred_advance_to_radius(real);      
00229         real pred_return_to_radius(real);       
00230 
00231         real pred_advance_to_periastron();
00232         real pred_return_to_periastron();
00233         real pred_advance_to_apastron();
00234         real pred_return_to_apastron();
00235 
00236         real pred_transform_to_time(real);
00237 
00238         //  Simple print routines:
00239 
00240         void print_all(ostream & s = cerr);
00241         void print_dyn(ostream & s = cerr);
00242         void print_elements(ostream & s = cerr);
00243 };
00244 
00245 void set_kepler_tolerance(int);  //     0: quit on any trig error
00246                                  //     1: quit on large trig error
00247                                  //     2: force to periastron or apastron on
00248                                  //        trig error
00249 
00250 void set_kepler_print_trig_warning(bool);
00251 
00252 void make_standard_kepler(kepler &k, real t, real mass,
00253                           real energy, real eccentricity,
00254                           real q, real mean_anomaly,
00255                           int align_axis = 0);
00256 
00257 void set_random_orientation(kepler &k, int planar = 0);
00258 
00259 //  The following functions allow the user to access the "fast" solver
00260 //  for the elliptical Kepler's equation:
00261 
00262 void set_kepler_fast_flag(bool flag = true);
00263 void clear_kepler_fast_flag();
00264 bool get_kepler_fast_flag();
00265 
00266 void set_kepler_fast_tol(real tol = 1.e-6);
00267 void reset_kepler_fast_tol();
00268 real get_kepler_fast_tol();
00269 
00270 void set_kepler_print_trig_warning(bool p);
00271 
00272 
00273 #endif

Generated on Wed Jul 20 12:43:35 2005 for Starlab by  doxygen 1.4.3