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

dyn.h

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00011 
00013 
00014 //  version 1:  Dec 1992   Piet Hut, Steve McMillan, Jun Makino
00015 //  version 2:
00016 //
00017 //  This file includes:
00018 //  1) definition of class dyn
00019 
00020 #ifndef  STARLAB_DYN_H
00021 #  define  STARLAB_DYN_H
00022 
00023 #include <vector>
00024 #include  "util_math.h"
00025 #include  "node.h"
00026 #include  "kepler.h"
00027 
00028 #define BIN_INDENT      21      // for print_pert() and print_binary_params()
00029 
00030 static const real rnull = 0.0;
00031 
00032 //#include  "dyn_kepler.h"   NOTE: this file is included at the end instead,
00033 //                           because it needs to know about the dyn class
00034 
00036 
00037 class  dyn : public node
00038 {
00039     protected:
00040 
00041         // Global variables:
00042 
00043         static xreal system_time;       
00044         static real real_system_time;   
00045 
00046         static bool use_sstar;          
00047 
00049 
00050         static bool ignore_internal;
00051 
00052         //------------------------------------------------------------
00053 
00055 
00056         // (Moved from hdyn to dyn by Steve, 7/01):
00057 
00058         static unsigned int external_field;
00059                                         // 0 ==> none
00060                                         // 1 ==> tidal (bit 0)
00061                                         // 2 ==> Plummer (bit 1)
00062                                         // 3 ==> Plummer+tidal (bits 0+1)
00063                                         // 4 ==> power-law (bit 2)
00064                                         // etc.
00065 
00067 
00072 
00073         // (Changed by Steve, 6/99)
00074         // Note that alpha and omega are in general independent.
00075 
00076         static int  tidal_type;
00077 
00078         static real omega;              
00079         static real omega_sq;           // omega squared (probably not needed)
00080 
00081         static real alpha1;             
00082         static real alpha3;             
00083 
00084         static vec tidal_center;        
00085                                         //                              (7/01)
00086 
00087         // Confining Plummer model parameters (Steve, 7/01):
00088 
00089         static real p_mass;             
00090         static real p_scale_sq;         
00091 
00092         static vec p_center;            
00093         static bool p_friction;         
00094                                         // (currently for Plummer only)
00095 
00096         // Confining power-law model parameters (Steve, 7/01).
00097         // New implementation (Steve, 2/04) means that Plummer is
00098         // no longer a special case (with exponent = 0).
00099 
00100         static real pl_coeff;           
00101         static real pl_scale;           
00102         static real pl_exponent;        
00103 
00104         static vec pl_center;           
00105 
00106         static FILE *ifp;  
00107         static FILE *ofp;  
00108 
00109         static bool col_output;         
00110 
00111         //------------------------------------------------------------
00112 
00113         vec  pos;                       
00114         vec  vel;                       
00115         vec  acc;                       
00116         kepler * kep;                   
00117 
00118     public:
00119 
00120         static FILE* set_ifp(FILE* p)           {return ifp = p;}
00121         static FILE* get_ifp()                  {return ifp;}
00122         void clear_ifp()                        {ifp = NULL;}
00123         static FILE* set_ofp(FILE* p)           {return ofp = p;}
00124         static FILE* get_ofp()                  {return ofp;}
00125         void clear_ofp()                        {ofp = NULL;}
00126 
00128 
00129         static bool set_col_output(bool b = true)       {return col_output = b;}
00130         static bool get_col_output()                    {return col_output;}
00131 
00133 
00134         inline void dyn_init() {
00135             pos = vel = acc = 0.0;
00136             kep = NULL;
00137         }
00138 
00139         dyn(hbpfp the_hbpfp = new_hydrobase, sbpfp the_sbpfp = new_starbase,
00140             bool use_stories = true)
00141            : node(the_hbpfp, the_sbpfp, use_stories)    {dyn_init();}
00142  
00144 
00145         inline void rmkepler() {
00146             if (kep) {
00147                 dyn* s = get_binary_sister();
00148 
00149                 if (s && s->kep == kep)
00150                     s->kep = NULL;
00151 
00152                 // changed (unsigned int) to unsigned long
00153                 if ((unsigned long) kep != 1 && (unsigned long) kep != 2)
00154                     delete kep;         // in case kep is used as a flag
00155 
00156                 kep = NULL;
00157             }
00158         }
00159 
00160         virtual ~dyn() {
00161 
00162             // Note added by Steve 7/7/98:
00163             //
00164             // Some care is required when deleting the kepler structure,
00165             // as binary components in kira share a kepler.  In that case,
00166             // when the kepler of the first component is deleted, the
00167             // kepler pointer of the other component must also be set
00168             // NULL.  Otherwise, an attempt will be made to delete a
00169             // nonexistent structure.  Do this via another function so
00170             // that the same procedure can be used from other classes.
00171 
00172             rmkepler();
00173         }
00174 
00175         inline xreal get_system_time()  const   {return system_time;}
00176         inline real get_real_system_time() const {return real_system_time;}
00177         void set_system_time(xreal t)           {system_time = t;
00178                                                  real_system_time = t;}
00179 
00180         void set_ignore_internal(bool i = true) {ignore_internal = i;}
00181         bool get_ignore_internal()      const   {return ignore_internal;}
00182 
00183         //-----------------------------------------------------------------
00184         // External field:
00185   
00186         inline unsigned int get_external_field() const {return external_field;}
00187         inline void set_external_field(unsigned int e) {external_field = e;}
00188 
00190 
00191         inline void set_tidal_field(int t)      {tidal_type = t;
00192                                                  if (t > 0)
00193                                                      SETBIT(external_field, 0);
00194                                                  else
00195                                                      CLRBIT(external_field, 0);}
00196         inline int get_tidal_field()    const   {return tidal_type;}
00197         inline void unset_tidal_field(int t)    {set_tidal_field(0);}
00198 
00199         void set_omega(real o)                  {omega = o;
00200                                                  omega_sq = o*o;}
00201         inline real get_omega()         const   {return omega;}
00202         inline real get_omega_sq()      const   {return omega_sq;}
00203 
00204         void set_alpha(real a1, real a3)        {alpha1 = a1;
00205                                                  alpha3 = a3;}
00206         inline real get_alpha1()        const   {return alpha1;}
00207         inline real get_alpha3()        const   {return alpha3;}
00208         inline void set_tidal_center(vec c)     {tidal_center = c;}
00209         inline vec get_tidal_center()   const   {return tidal_center;}
00210 
00212 
00213         void set_tidal_field(real alpha1, real alpha3,
00214                              int type = 0, real omega = 0, vec c = 0.0) {
00215             if (type > 0) set_tidal_field(type);
00216             set_alpha(alpha1, alpha3);
00217             set_tidal_center(c);
00218         }
00219 
00221 
00222         inline void set_plummer()               {SETBIT(external_field, 1);}
00223         inline bool get_plummer()       const   {return (GETBIT(external_field,
00224                                                                 1) > 0);}
00225         inline void unset_plummer()             {CLRBIT(external_field, 1);}
00226 
00227         inline real get_p_mass()        const   {return p_mass;}
00228         inline void set_p_mass(real m)          {p_mass = m;}
00229         inline real get_p_scale_sq()    const   {return p_scale_sq;}
00230         inline void set_p_scale_sq(real r2)     {p_scale_sq = r2;}
00231         inline void set_p_center(vec c)         {p_center = c;}
00232         inline vec  get_p_center()      const   {return p_center;}
00233         inline bool get_p_friction()    const   {return p_friction;}
00234         inline void set_p_friction(bool f)      {p_friction = f;}
00235 
00237 
00238         inline void set_plummer(real m, real r2,
00239                                 vec c = 0.0, bool f = false) {  // all in one
00240             set_plummer();
00241             p_mass = m;
00242             p_scale_sq = r2;
00243             p_center = c;
00244             p_friction = f;
00245         }
00246 
00248 
00249         inline void set_pl()                    {SETBIT(external_field, 2);}
00250         inline bool get_pl()            const   {return (GETBIT(external_field,
00251                                                                 2) > 0);}
00252         inline void unset_pl()                  {CLRBIT(external_field, 2);}
00253 
00254         inline real get_pl_coeff()      const   {return pl_coeff;}
00255         inline void set_pl_coeff(real c)        {pl_coeff = c;}
00256         inline real get_pl_scale()      const   {return pl_scale;}
00257         inline void set_pl_scale(real r)        {pl_scale = r;}
00258         inline real get_pl_exponent()   const   {return pl_exponent;}
00259         inline void set_pl_exponent(real e)     {pl_exponent = e;}
00260         inline void set_pl_center(vec c)        {pl_center = c;}
00261         inline vec get_pl_center()      const   {return pl_center;}
00262 
00264 
00265         inline void set_pl(real A, real a,
00266                            real e, vec c = 0.0) {         // all in one
00267 
00268             set_pl();
00269 
00270             pl_coeff = A;
00271             pl_scale = a;
00272             pl_exponent = e;
00273             pl_center = c;
00274         }
00275 
00277 
00278         real get_external_scale_sq();
00279 
00281 
00282         vec get_external_center();
00283 
00284         //-----------------------------------------------------------------
00285 
00286         void  set_pos(const vec& new_pos)      {pos = new_pos;}
00287         void  set_vel(const vec& new_vel)      {vel = new_vel;}
00288         void  set_acc(const vec& new_acc)      {acc = new_acc;}
00289 
00290         void  clear_pos()                         {pos = 0.0;}  
00291         void  clear_vel()                         {vel = 0.0;}  
00292         void  clear_acc()                         {acc = 0.0;}  
00293 
00294         inline void  inc_pos(const vec& d_pos) {pos += d_pos;}  
00295         inline void  inc_vel(const vec& d_vel) {vel += d_vel;}  
00296         inline void  inc_acc(const vec& d_acc) {acc += d_acc;}  
00297 
00299 
00300         inline void  scale_pos(const real scale_factor)  {pos *= scale_factor;}
00301 
00303 
00304         inline void  scale_vel(const real scale_factor)  {vel *= scale_factor;}
00305 
00307 
00308         inline void  scale_acc(const real scale_factor)  {acc *= scale_factor;}
00309 
00310         inline vec  get_pos()           const   {return pos;}
00311         inline vec  get_vel()           const   {return vel;}
00312         inline vec  get_acc()           const   {return acc;}
00313 
00314         inline dyn * get_parent() const
00315             {return (dyn*) node::get_parent();}
00316         inline dyn * get_oldest_daughter() const
00317             {return (dyn*)node::get_oldest_daughter();}
00318         inline dyn * get_younger_sister() const
00319             {return (dyn*) node::get_younger_sister();}
00320         inline dyn * get_elder_sister() const
00321             {return (dyn*) node::get_elder_sister();}
00322 
00324 
00325         inline dyn * get_root() const
00326             {return (dyn*) node::get_root();}
00327 
00329 
00330         inline dyn * get_top_level_node() const
00331             {return static_cast<dyn*>(node::get_top_level_node());}
00332 
00334 
00335         inline dyn * get_binary_sister()
00336             {return (dyn*) node::get_binary_sister();}
00337 
00339 
00340         void  calculate_acceleration(dyn *, real);
00341 
00342         inline kepler * get_kepler()    const       {return kep;}
00343         void  set_kepler(kepler * new_kep)          {kep = new_kep;}
00344 
00345         virtual void null_pointers();
00346         virtual void print_static(ostream &s = cerr);
00347 
00348         virtual istream& scan_dyn_story(istream&);
00349         virtual bool check_and_correct_node(bool verbose = true);
00350 
00351         virtual ostream& print_dyn_story(ostream &s,
00352                                          bool print_xreal = true,
00353                                          int short_output = 0);
00354 
00355         void to_com();          
00356         void set_com(vec r = 0.0, vec v = 0.0);
00357 
00360 
00361         void offset_com();
00362 
00365 
00366         void reset_com();
00367         int flatten_node();     
00368 
00369         // Declaration of member function defined in dyn_tt.C
00370 
00371         virtual real get_radius();
00372         virtual void set_radius(real) {};
00373 
00374         bool get_use_sstar()                    {return use_sstar;}
00375         void set_use_sstar(bool u)              {use_sstar = u;}
00376 
00377         // Placeholders (~null in dyn, realized in hdyn)
00378 
00379         virtual bool nn_stats(real energy_cutoff, real kT,
00380                               vec center, bool verbose,
00381                               bool long_binary_output = true,
00382                               int which = 0);
00383         virtual real print_pert(bool long_binary_output = true,
00384                                 int indent = BIN_INDENT);
00385 };
00386 
00387 typedef dyn * dynptr;  // to enable dynamic array declarations such as
00388                        //    dyn** dyn_ptr_array = new dynptr[n];
00389                        // (note that the following expression is illegal:
00390                        //    dyn** dyn_ptr_array = new (dyn *)[n];)
00391 
00392 typedef vec (dyn::*dyn_VMF_ptr)(void) const;    // vec member function pointer
00393 typedef void (dyn::*dyn_MF_ptr)(const vec &);   // member function pointer
00394 
00395 inline  node * new_dyn(hbpfp the_hbpfp,
00396                        sbpfp the_sbpfp,
00397                        bool use_stories)
00398     {return (node *) new dyn(the_hbpfp, the_sbpfp, use_stories);}
00399 
00400 inline  dyn * mkdyn(int n, hbpfp the_hbpfp = new_hydrobase,
00401                            sbpfp the_sbpfp = new_starbase)
00402     {return  (dyn *) mk_flat_tree(n, new_dyn, the_hbpfp, the_sbpfp);}
00403 
00405 
00406 dyn *get_col(istream& s = cin,
00407              npfp the_npfp = new_dyn,
00408              hbpfp the_hbpfp = new_hydrobase,
00409              sbpfp the_sbpfp = new_starbase,
00410              bool use_stories = true);
00411 
00413 
00414 void put_col(dyn*, ostream& s = cout);
00415 
00417 
00418 dyn *get_dyn(istream & s = cin,
00419              hbpfp the_hbpfp = new_hydrobase,
00420              sbpfp the_sbpfp = new_starbase,
00421              bool use_stories = true);
00422 
00424 
00425 inline void put_dyn(dyn *b,                     // note: not put_node, now!!
00426                     ostream &s = cout,
00427                     bool print_xreal = true,
00428                     int short_output = 0) {
00429     return dyn::get_col_output() ? put_col(b, s) :
00430         put_node(b, s, print_xreal, short_output);
00431 }
00432 
00434 
00435 dyn* fget_dyn(FILE* fp = dyn::get_ifp()?:stdin);
00436 
00438 
00439 inline dyn * common_ancestor(dyn * bi, dyn * bj)
00440     {return (dyn*) common_ancestor((node*)bi, (node*)bj);}
00441 
00443 
00444 vec something_relative_to_root(dyn * b, dyn_VMF_ptr mf);
00445 
00446 void dbg_message(char*, dyn*);
00447 void dbg_message(char*, dyn*, dyn*);
00448 
00449 // From dyn/init (used in sdyn3/evolve/bound3.C):
00450 
00452 
00453 void  makesphere(dyn * root, int n, real R = 1, int u_flag = 0);
00454 
00455 // From dyn/util:
00456 
00458 
00459 real pot_on_general_node(dyn * bj, dyn * bi, real eps2, bool cm);
00460 
00462 
00463 void calculate_energies(dyn * root, real eps2,
00464                         real & epot, real & ekin, real & etot,
00465                         bool cm = false);
00466 
00468 
00469 void print_recalculated_energies(dyn *, int mode = 0,
00470                                  real eps2 = 0, real e_corr = 0);
00471 
00473 
00474 void initialize_print_energies(dyn *, real eps2 = 0);
00475 
00477 
00478 void compute_density(dyn* b,
00479                      int k = 12,
00480                      bool use_mass = false,
00481                      dyn** list = NULL,
00482                      int n_list = 0);
00483 
00485 
00486 void merge_low_level_nodes(dyn* b, real frac = 1, int option = 1);
00487 
00488 // Special-case functions (superceded):
00489 
00490 vector<real>& get_radial_densities(dyn *, vec, vector<real>&,
00491                                    bool (*)(dyn*) = 0);
00492 
00493 vector<real>& get_radial_numdensities(dyn *, vec, vector<real>&,
00494                                       bool (*)(dyn*) = 0);
00495 
00497 
00498 int get_radial_vdisp(dyn *b, vec cpos, vec cvel,
00499                      int n_zones, real r[], real v2[]);
00500 
00502 
00503 int get_density_profile(dyn *b, vec cpos,
00504                         int n_zones, real r[], real rho[],
00505                         bool (*select)(dyn*) = NULL);
00507 
00508 int get_profile(dyn *b, vec cpos,
00509                 int n_zones, real r[], real q[],
00510                 real (*Q)(dyn*));
00511 
00512 // Overloaded functions:
00513 
00514 void compute_com(dyn*, vec&, vec&);     
00515 void compute_com(dyn*);                 
00516 
00518 
00519 void compute_mcom(dyn*, vec&, vec&, real f = 0.9, int n_iter = 2);
00520 
00522 
00523 void compute_mcom(dyn*, real f = 0.9, int n_iter = 2);
00524 
00526 
00527 int  get_std_center(dyn*, vec&, vec&, bool verbose = false);
00528 
00530 
00531 int  get_std_center(dyn*, bool verbose = false);
00532 
00534 
00535 void compute_max_cod(dyn*, vec&, vec&);
00536 
00538 
00539 void compute_max_cod(dyn*);
00540 
00542 
00543 void compute_mean_cod(dyn*, vec&, vec&);
00544 
00546 
00547 void compute_mean_cod(dyn*);
00548 
00549 // From lagrad.C:
00550 
00552 
00553 void compute_mass_radii(dyn*);
00554 
00556 
00557 void compute_mass_radii_percentiles(dyn*);
00558 
00560 
00561 void compute_mass_radii_quartiles(dyn*);
00562 
00564 
00565 void set_lagr_cutoff_mass(dyn *b, real frac_low, real frac_high = 1.0);
00566 
00568 
00569 void reset_lagr_cutoff_mass(dyn *b, real frac_low, real frac_high = 1.0);
00570 
00572 
00573 real get_lagr_cutoff_mass();
00574 
00576 
00577 real get_lagr_cutoff_mass_low();
00578 
00580 
00581 real get_lagr_cutoff_mass_high();
00582 
00584 
00585 real print_lagrangian_radii(dyn* b,
00586                             int which_lagr = 2,
00587                             bool verbose = true,
00588                             int which_star = 0,
00589                             bool print = true);
00591 
00592 real compute_lagrangian_radii(dyn* b,
00593                               int which_lagr = 2,
00594                               bool verbose = true,
00595                               int which_star = 0);
00597 
00598 real compute_lagrangian_radii(dyn* b,
00599                               real *arr, int narr,
00600                               bool verbose = true,
00601                               int which_star = 0);
00603 
00604 real compute_lagrangian_radii(dyn* b,
00605                               real r,
00606                               bool verbose = true,
00607                               int which_star = 0);
00608 
00610 
00611 typedef bool boolfn(dyn*);
00612 bool compute_general_mass_radii(dyn*, int,
00613                                 bool nonlin = false,
00614                                 boolfn *bf = NULL,
00615                                 bool verbose = true);
00616 
00617 // From sys_stats.C:
00618 
00620 
00621 void search_for_binaries(dyn* b, real energy_cutoff = 0, real kT = 0,
00622                          vec center = 0, bool verbose = true,
00623                          bool long_binary_output = true);
00624 
00626 
00627 bool parse_sys_stats_main(int argc, char *argv[],
00628                           int  &which_lagr,
00629                           bool &binaries,
00630                           bool &short_output,
00631                           bool &B_flag,
00632                           bool &calc_e,
00633                           bool &n_sq,
00634                           bool &out,
00635                           bool &verbose,
00636                           char *cvs_id, char *source);
00637 void check_addstar(dyn* b);
00638 
00640 
00641 void sys_stats(dyn* root,
00642                real energy_cutoff = 1,
00643                bool verbose = true,
00644                bool binaries = true,
00645                bool long_binary_output = false,
00646                int which_lagr = 2,
00647                bool print_time = false,
00648                bool compute_energy = false,
00649                bool allow_n_sq_ops = false,
00650                void (*compute_energies)(dyn*, real, real&, real&, real&, bool)
00651                         = calculate_energies,
00652                void (*dstar_params)(dyn*) = NULL,
00653                bool (*print_dstar_stats)(dyn*, bool, vec, bool) = NULL);
00654 
00656 
00657 void refine_cluster_mass(dyn *b, int verbose = 0);
00658 
00660 
00661 void refine_cluster_mass2(dyn *b, int verbose = 0);
00662 
00663 // From dyn_stats.C:
00664 
00666 
00667 real print_binary_params(kepler* k, real m1, real kT,
00668                          real dist_from_cod,
00669                          bool verbose = true,
00670                          bool long_output = true,
00671                          int init_indent = 0,
00672                          int indent = BIN_INDENT);
00673 
00675 
00676 real get_total_energy(dyn* bi, dyn* bj);
00677 
00679 
00680 real get_semi_major_axis(dyn* bi, dyn* bj);
00681 
00683 
00684 real get_period(dyn* bi, dyn* bj);
00685 
00687 
00688 void get_total_energy_and_period(dyn* bi, dyn* bj, real& E, real& P);
00689 
00691 
00692 void initialize_kepler_from_dyn_pair(kepler& k, dyn* bi, dyn* bj,
00693                                      bool minimal = false);
00694 
00696 
00697 void print_binary_from_dyn_pair(dyn* bi, dyn* bj,
00698                                 real kT = 0,
00699                                 vec center = vec(0,0,0),
00700                                 bool verbose = true,
00701                                 bool long_output = true);
00702 
00704 
00705 real print_structure_recursive(dyn* b,
00706                                void (*dstar_params)(dyn*),
00707                                int& n_unp, real& e_unp,
00708                                real kT = 0.0,
00709                                vec center = vec(0,0,0),
00710                                bool verbose = true,
00711                                bool long_output = true,
00712                                int indent = 0);
00713 
00715 
00716 real print_structure_recursive(dyn* b,
00717                                real kT = 0.0,
00718                                vec center = vec(0,0,0),
00719                                bool verbose = true,
00720                                bool long_output = true,
00721                                int indent = 2);
00722 
00724 
00725 void compute_core_parameters(dyn* b, int k,
00726                              bool allow_n_sq_ops,
00727                              vec& center,
00728                              real& rcore, int& ncore, real& mcore);
00729 
00730 
00731 // From plot_stars.C:
00732 
00734 
00735 void plot_stars(dyn * bi,
00736                 int n = 5,
00737                 int k = 3);
00738 
00739 // From scale.C:
00740 
00742 
00743 real get_mass(dyn *b);
00744 
00746 
00747 void scale_mass(dyn *b, real mscale);
00748 
00750 
00751 void scale_pos(dyn *b, real rscale, vec com_pos = 0.0);
00752 
00754 
00755 void scale_vel(dyn *b, real vscale, vec com_vel = 0.0);
00756 
00758 
00759 real get_top_level_kinetic_energy(dyn *b);
00760 
00762 
00763 real get_kinetic_energy(dyn *b);
00764 
00766 
00767 void get_top_level_energies(dyn *b, real eps2, real &potential, real &kinetic);
00768 
00770 
00771 void scale_virial(dyn *b, real q, real potential, real& kinetic,
00772                   vec com_vel = 0.0);
00773 
00775 
00776 real scale_energy(dyn *b, real e, real& energy,
00777                   vec com_pos = 0.0,
00778                   vec com_vel = 0.0);
00779 
00781 
00782 bool parse_scale_main(int argc, char *argv[],
00783                       real& eps, bool& c_flag,
00784                       bool& e_flag, real& e,
00785                       bool& m_flag, real& m,
00786                       bool& q_flag, real& q,
00787                       bool& r_flag, real& r,
00788                       bool& debug,
00789                       char *cvs_id, char *source);
00790 
00792 
00793 void scale(dyn *b, real eps,
00794            bool c_flag,
00795            bool e_flag, real e,
00796            bool m_flag, real m,
00797            bool q_flag, real q,
00798            bool r_flag, real r,
00799            bool debug = false,
00800            void (*top_level_energies)(dyn*, real, real&, real&)
00801                         = get_top_level_energies);
00802 
00803 // From dyn_external.C:
00804 
00806 
00807 void get_external_acc(dyn * b,
00808                       vec pos,
00809                       vec vel,
00810                       real& pot,
00811                       vec& acc,
00812                       vec& jerk,
00813                       bool pot_only = false);
00814 
00816 
00817 real get_external_pot(dyn * b,
00818                       void (*pot_func)(dyn *, real) = NULL);
00819 
00821 
00822 real vcirc(dyn *b, vec r);
00823 
00824 // Return the potential due to an external tidal field.
00825 
00826 real get_tidal_pot(dyn *b);
00827 
00828 // Return the potential due to an external Plummer field.
00829 
00830 real get_plummer_pot(dyn *b);
00831 
00832 // Return the potential due to an external power-law field.
00833 
00834 real get_power_law_pot(dyn *b);
00835 
00836 // Return the virial term due to an external field.
00837 
00838 real get_external_virial(dyn * b);
00839 
00840 // Print the properties of an external tidal field.
00841 
00842 void print_external(unsigned int ext, bool shortbits = false);
00843 
00845 
00846 void set_new_rhalf(bool s = true);
00847 
00848 void set_friction_beta(real b); 
00849 void set_friction_mass(real m); 
00850 void set_friction_vel(vec v);   
00851 void set_friction_acc(dyn *b, real r);  
00852 
00853 // From add_plummer.C and add_power_law.C:
00854 
00856 
00857 bool get_physical_scales(dyn *b, real& mass, real& length, real& time);
00858 
00860 
00861 void add_plummer(dyn *b,
00862                  real coeff, real scale,
00863                  vec center = 0.0,
00864                  bool n_flag = false,
00865                  bool verbose = false,
00866                  bool fric_flag = false);
00867 
00869 
00870 void toggle_plummer_friction(dyn *b);
00871 
00873 
00874 void add_power_law(dyn *b,
00875                    real coeff, real exponent, real scale,
00876                    vec center = 0.0,
00877                    bool n_flag = false,
00878                    bool verbose = false,
00879                    bool G_flag = false);
00880 
00881 // From dyn_story.C:
00882 
00884 
00885 real get_initial_mass(dyn* b,
00886                       bool verbose = false,
00887                       bool mass_set = false,
00888                       real input_mass = 0);
00889 
00891 
00892 real get_initial_virial_radius(dyn* b,
00893                                bool verbose = false,
00894                                bool r_virial_set = false,
00895                                real input_r_virial = 0);
00896 
00898 
00899 real get_initial_jacobi_radius(dyn* b,
00900                                real r_virial,
00901                                bool verbose = false,
00902                                bool r_jacobi_set = false,
00903                                real input_r_jacobi = 0);
00904 
00906 
00907 void set_tidal_params(dyn* b,
00908                       bool verbose,
00909                       real initial_r_jacobi,
00910                       real initial_mass,
00911                       int& tidal_field_type);
00912 
00914 
00915 void test_tidal_params(dyn* b,
00916                        bool verbose,
00917                        real initial_r_jacobi,
00918                        real initial_r_virial,
00919                        real initial_mass);
00920 
00922 
00923 int check_set_tidal(dyn *b, bool verbose = false);
00924 
00925 // Check for and set Plummer parameters from input snapshot.
00926 
00927 void check_set_plummer(dyn *b, bool verbose = false);
00928 
00929 // Check for and set power-law parameters from input snapshot.
00930 
00931 void check_set_power_law(dyn *b, bool verbose = false);
00932 
00933 // Check for and set external field parameters from input snapshot.
00934 
00935 void check_set_external(dyn *b, bool verbose = false, int fric_int = -1);
00936 
00937 // Check for and set ignore_internal flag from input snapshot.
00938 
00939 void check_set_ignore_internal(dyn *b, bool verbose = false);
00940 
00941 //----------------------------------------------------------------------
00942 //
00943 // Standard wrappers (for starcluster).
00944 // See dyn/util/wrappers.C for functions not specified inline.
00945 
00946 // "System" quantities (b is root node):
00947 
00948 int  bound_number(dyn *b);      
00949 real bound_mass(dyn *b);        
00950 
00952 
00953 vec  total_angular_momentum(dyn *b, vec x = 0, vec v = 0);
00954 real total_energy(dyn *b);      
00955 real core_radius(dyn *b);       
00956 real core_mass(dyn *b);         
00957 int  core_number(dyn *b);       
00958 real virial_radius(dyn *b);     
00959 real tidal_radius(dyn *b);      
00960 real core_density(dyn *b);      
00961 
00962 // Quantities defined (mainly) for individual nodes:
00963 
00964 inline real     mass(dyn *b)
00965                 {
00966                     if (b->get_oldest_daughter()) {
00967                         if (b->get_mass() > 0)
00968                             return b->get_mass();       // assume OK
00969                         else
00970                             return get_mass(b); // recompute
00971                     } else
00972                         return b->get_mass();
00973                 }
00974 
00975 inline vec      pos(dyn *b, vec x = 0)  {return b->get_pos()-x;}
00976 inline vec      vel(dyn *b, vec v = 0)  {return b->get_vel()-v;}
00977 
00979 inline real     distance(dyn *b, vec x = 0)
00980                                         {return abs(b->get_pos()-x);}
00982 inline real     distance_sq(dyn *b, vec x = 0)
00983                                         {return square(b->get_pos()-x);}
00985 inline real     speed(dyn *b, vec v = 0)
00986                                         {return abs(b->get_vel()-v);}
00988 inline real     speed_sq(dyn *b, vec v = 0)
00989                                         {return square(b->get_vel()-v);}
00990 
00992 
00993 inline real     v_rad_sq(dyn *b, vec x = 0, vec v = 0)
00994                                         {
00995                                             vec dx = b->get_pos()-x;
00996                                             vec dv = b->get_vel()-v;
00997                                             real dr2 = square(dx);
00998                                             if (dr2 > 0)
00999                                                 return square(dx*dv)/dr2;
01000                                             else
01001                                                 return 0;
01002                                         }
01004 
01005 inline real     v_rad(dyn *b, vec x = 0, vec v = 0)
01006                                         {return sqrt(v_rad_sq(b, x, v));}
01007 
01009 
01010 inline real     v_trans_sq(dyn *b, vec x = 0, vec v = 0)
01011                                         {
01012                                             vec dx = b->get_pos()-x;
01013                                             vec dv = b->get_vel()-v;
01014                                             real dr2 = square(dx);
01015                                             if (dr2 > 0)
01016                                                 return dv*dv
01017                                                          - square(dx*dv)/dr2;
01018                                             else
01019                                                 return 0;
01020                                         }
01021 
01023 
01024 inline real     v_trans(dyn *b, vec x = 0, vec v = 0)
01025                                         {return sqrt(v_trans_sq(b, x, v));}
01026 
01028 
01029 inline real     energy(dyn *b, vec v = 0)
01030                                         {
01031                                             if (find_qmatch(b->get_dyn_story(),
01032                                                             "pot")) {
01033                                                 if (!b->get_parent())   // root
01034                                                     return total_energy(b);
01035                                                 else {
01036                                                     real pot =
01037                                                       getrq(b->get_dyn_story(),
01038                                                             "pot");
01039                                                     vec dv = b->get_vel()-v;
01040                                                     return b->get_mass()
01041                                                              *(pot+0.5*dv*dv);
01042                                                 }
01043                                             } else
01044                                                 return 0;
01045                                         }
01046 
01048 
01049 inline vec      angular_momentum(dyn *b, vec x = 0, vec v = 0)
01050                                         {
01051                                             if (b->get_parent()) {
01052                                                 vec dx = b->get_pos()-x;
01053                                                 vec dv = b->get_vel()-v;
01054                                                 return b->get_mass()*dx^dv;
01055                                             } else
01056                                                 return
01057                                                     total_angular_momentum(b);
01058                                         }
01059 
01060 //----------------------------------------------------------------------
01061 
01062 #include  "dyn_kepler.h"
01063 
01064 #endif
01065 
01066 //=======================================================================//
01067 //  +---------------+        _\|/_        +------------------------------\\ ~
01068 //  |  the end of:  |         /|\         |  inc/dyn.h
01069 //  +---------------+                     +------------------------------//
01070 //========================= STARLAB =====================================\\ ~

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