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

worldline.h

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00012 //
00013 //  version 1:  Oct 2000   Steve McMillan
00014 //  version 2:
00015 //
00016 //  This file includes:
00017 //  1) definition of classes segment, worldline, and worldbundle
00018 
00019 #ifndef  STARLAB_WORLD_H
00020 #  define  STARLAB_WORLD_H
00021 
00022 #include "tdyn.h"
00023 
00024 // Define id data type:
00025 
00026 #define NEW_UNIQUE_ID_T                 // remove to restore old version
00027 
00028 #ifndef NEW_UNIQUE_ID_T
00029     typedef real unique_id_t;           // old
00030 #else
00031     typedef int unique_id_t;            // new
00032 #endif
00033 
00034 unique_id_t unique_id(int index);
00035 unique_id_t unique_id(char *name);
00036 unique_id_t unique_id(node *b);
00037 
00038 // Class definitions:
00039 
00040 // A worldline is an indexed pointer to the start of a linked list of
00041 // worldline segments.  Each segment consists of a series of events
00042 // (tdyns) along a particle trajectory.  Tree changes result in new
00043 // worldline segments for all particles involved.  The full worldline
00044 // is the entirety of all such segments.
00045 //
00046 // There is presently considerable redundancy in the data stored.
00047 // We will refine the data structures as the package evolves...
00048 
00050 
00051 class segment {
00052 
00053     private:
00054 
00055         unique_id_t id;                 
00056         tdyn *first_event;              
00057         tdyn *last_event;               
00058         real t_start;                   
00059         real t_end;                     
00060         segment *next;                  
00061 
00062     public:
00063 
00064         segment() {                     // empty segment
00065             id = -1;
00066             first_event = last_event = NULL;
00067             t_start = t_end = 0;
00068             next = NULL;
00069         }
00070 
00071         segment(tdyn *b) {              // segment containing a single event
00072             id = unique_id(b);
00073             first_event = last_event = b;
00074             t_start = t_end = b->get_time();
00075             next = NULL;
00076         }
00077 
00078         unique_id_t get_id()            {return id;}
00079         tdyn *get_first_event()         {return first_event;}
00080         tdyn *get_last_event()          {return last_event;}
00081         real get_t_start()              {return t_start;}
00082         real get_t_end()                {return t_end;}
00083 
00084         segment *get_next()             {return next;}
00085         void set_next(segment *s)       {next = s;}
00086 
00087         void add_event(tdyn *b, bool accept = false) {
00088 
00089             if (accept                          // id check is often redundant
00090                 || unique_id(b) == id) {        // and may cause problems if
00091                                                 // optimization is turned on
00092                 if (last_event)
00093                     last_event->set_next(b);
00094                 b->set_prev(last_event);
00095 
00096                 last_event = b;
00097                 t_end = b->get_time();
00098             }
00099         }
00100 
00101         void print(char *label = NULL);
00102 };
00103 
00105 
00111 
00112 class worldline {
00113 
00114     private:
00115 
00116         unique_id_t id;                 
00117         segment *first_segment;         
00118         segment *last_segment;          
00119         real t_start;                   
00120         real t_end;                     
00121 
00122         int start_esc_flag;             
00123         int end_esc_flag;               
00124         real t_esc;                     
00125 
00126         // Management of tree traversal:
00127 
00128         real t_curr;                    
00129         tdyn *current_event;            
00130         segment *current_segment;       
00131 
00132         pdyn *tree_node;                
00133                                         // in the interpolated tree at time t
00134 
00135     public:
00136 
00137         worldline() {                   // empty worldline
00138             id = -1;
00139             first_segment = last_segment = NULL;
00140             t_start = t_end = 0;
00141 
00142             t_curr = 0;
00143             current_event = NULL;
00144             current_segment = NULL;
00145 
00146             tree_node = NULL;
00147 
00148             start_esc_flag = end_esc_flag = 0;
00149             t_esc = VERY_LARGE_NUMBER;
00150         }
00151 
00152         worldline(segment *s) {         // worldline of a single segment
00153             id = s->get_id();
00154             first_segment = last_segment = s;
00155             t_start = s->get_t_start();
00156             t_end = s->get_t_end();
00157 
00158             t_curr = 0;
00159             current_event = NULL;
00160             current_segment = NULL;
00161 
00162             tree_node = NULL;
00163 
00164             start_esc_flag = end_esc_flag = 0;
00165             t_esc = VERY_LARGE_NUMBER;
00166         }
00167 
00168         worldline(tdyn *b) {            // worldline of a single event
00169             segment *s = new segment(b);
00170             id = s->get_id();
00171             first_segment = last_segment = s;
00172             t_start = s->get_t_start();
00173             t_end = s->get_t_end();
00174 
00175             t_curr = -VERY_LARGE_NUMBER;
00176             current_event = NULL;
00177             current_segment = NULL;
00178 
00179             tree_node = NULL;
00180 
00181             // Note:  We use the prev and next pointers in tdyn to carry
00182             // temporary information from scan_dyn_story() about cluster
00183             // membership, to avoid adding more data to the class.  At
00184             // this stage, all prev and next pointers should be NULL.
00185             // Restore those settings here and transfer the membership
00186             // information to the worldline, where it belongs.
00187             //
00188             // NOTE:  The default (no esc_flag set via prev) is esc_flag = 0.
00189 
00190             start_esc_flag = end_esc_flag = 0;
00191             t_esc = VERY_LARGE_NUMBER;
00192 
00193             if (b->get_prev()) {                // escape flag is set
00194                 b->set_prev(NULL);
00195                 start_esc_flag = end_esc_flag = 1;
00196                 t_esc = b->get_time();          // should be overwritten
00197             }
00198 
00199             if (b->get_next()) {                // t_esc is specified
00200                 real *x = (real*) b->get_next();
00201                 b->set_next(NULL);
00202                 t_esc = *x;
00203                 delete x;
00204             }
00205         }
00206 
00207         unique_id_t get_id()            {return id;}
00208         segment *get_first_segment()    {return first_segment;}
00209         segment *get_last_segment()     {return last_segment;}
00210         real get_t_start()              {return t_start;}
00211 
00212         real get_t_end()                {return t_end;}
00213         void set_t_end(real t)          {t_end = t;}
00214 
00215         inline void set_start_esc_flag(int f)   {start_esc_flag = f;}
00216         inline int get_start_esc_flag() {return start_esc_flag;}
00217         inline bool is_member(real t)   {
00218             if (start_esc_flag == 1)
00219                 return false;
00220             else if (end_esc_flag == 0)
00221                 return true;
00222             else
00223                 return (t < t_esc);
00224         }
00225 
00226         inline void set_end_esc_flag(int f)     {end_esc_flag = f;}
00227         inline int get_end_esc_flag()   {return end_esc_flag;}
00228 
00229         real get_t_esc()                {return t_esc;}
00230         void set_t_esc(real t)          {t_esc = t;}
00231 
00232         real get_t_curr()               {return t_curr;}
00233         void set_t_curr(real t)         {t_curr = t;}
00234 
00235         tdyn *get_current_event()       {return current_event;}
00236         void set_current_event(tdyn* b) {current_event = b;}
00237 
00238         segment *get_current_segment()  {return current_segment;}
00239         void set_current_segment(segment* s)    {current_segment = s;}
00240 
00241         pdyn *get_tree_node()           {return tree_node;}
00242         void set_tree_node(pdyn* b)     {tree_node = b;}
00243         void clear_tree_node()          {tree_node = NULL;}
00244 
00245         void add_segment(segment *s, bool accept = false) {
00246             if (accept                          // id check is often redundant
00247                 || s->get_id() == id) {         // and may cause problems if
00248                                                 // optimization is turned on
00249                 last_segment->set_next(s);
00250                 last_segment = s;
00251                 t_end = s->get_t_end();
00252             }
00253         }
00254 
00255         void dump(int offset = 0, real t1 = 0, real t2 = VERY_LARGE_NUMBER);
00256         void check(int i = -1);
00257 };
00258 
00259 typedef worldline *worldlineptr;        // convenient...
00260 
00262 // Also includes structures for data management purposes.
00263 
00264 class worldbundle {
00265 
00266     private:
00267 
00268         worldlineptr *bundle;           
00269         int          nw;                
00270         int          nw_max;            
00271         real         t_min;             
00272         real         t_max;             
00273         real         t_int;             
00274         pdyn         *root;             
00275 
00276     public:
00277 
00278         worldbundle() {
00279             bundle = NULL;
00280             nw = nw_max = 0;
00281             t_min = VERY_LARGE_NUMBER;
00282             t_max = -VERY_LARGE_NUMBER;
00283             t_int = -VERY_LARGE_NUMBER;
00284             root = NULL;
00285         }
00286 
00287         worldbundle(tdyn *b);
00288 
00289         worldlineptr *get_bundle()      {return bundle;}
00290         worldline *get_worldline(int i) {return bundle[i];}
00291 
00292         int get_nw()                    {return nw;}
00293         real get_t_min()                {return t_min;}
00294         real get_t_max()                {return t_max;}
00295 
00296         void set_t_int(real t)          {t_int = t;}
00297         real get_t_int()                {return t_int;}
00298 
00299         void set_pdyn_root(pdyn *p)     {root = p;}
00300         pdyn *get_pdyn_root()           {return root;}
00301 
00302         int find_index(unique_id_t id);
00303         int find_index(char *name);
00304         int find_index(_pdyn_ *b);
00305 
00306         worldline *find_worldline(unique_id_t id);
00307         worldline *find_worldline(char *name);
00308         worldline *find_worldline(_pdyn_ *b);
00309 
00310         void attach(tdyn *b, int verbose = 0);
00311 
00312         void print();
00313         void print_worldline(char *name, real dt = 0);
00314         void dump(int offset = 0);
00315         void check();
00316         int get_n_daughters();
00317 };
00318 
00319 typedef worldbundle *worldbundleptr;
00320 
00321 // Globally visible functions:
00322 
00324 
00325 void print_id(void *id, char *label = NULL);
00326 
00328 
00329 worldbundle *read_bundle(istream &s, int verbose = 0);
00330 
00332 
00333 void read_bundles(istream &s, worldbundleptr wh[], int& nh,
00334                   int verbose = 0);
00335 
00337 
00338 int count_segments(worldbundle *wb);
00339 
00341 
00342 int count_events(worldbundle *wb);
00343 
00345 
00346 tdyn *find_event(worldline *w, tdyn *bn, real t);
00347 
00349 
00350 void print_event(worldline *w, tdyn *bn, real t);
00351 
00352 // Old:
00353 
00355 
00356 vec interpolate_pos(tdyn *p, real t, tdyn *bn = NULL);
00357 
00358 // New:
00359 
00361 
00362 void interpolate_pos(tdyn *p, real t, vec& pos, bool inc, tdyn *bn);
00363 
00365 
00366 void set_interpolated_pos(tdyn *p, real t, vec& pos,
00367                           tdyn *bn = NULL);
00369 
00370 void set_interpolated_pos(tdyn *p, real t, pdyn *curr,
00371                           tdyn *bn = NULL);
00372 
00374 
00375 void inc_interpolated_pos(tdyn *p, real t, vec& pos,
00376                           tdyn *bn = NULL);
00377 
00379 
00380 vec interpolate_vel(tdyn *p, real t, tdyn *bn = NULL);
00381 
00383 
00384 real mass_scale_factor();
00385 
00387 
00388 pdyn *create_interpolated_tree(worldbundle *wb, real t, bool vel = false);
00389 
00391 
00392 pdyn *create_interpolated_tree2(worldbundle *wb, real t, bool vel = false);
00393 
00395 
00396 void preload_pdyn(worldbundleptr wh[], int nh,
00397                   bool verbose = false, bool vel = false);
00398 
00400 
00401 char *set_center(worldbundleptr wh[], int nh, int center_number,
00402                  bool verbose = false);
00403 
00405 
00406 int get_n_center();
00407 
00409 
00410 int get_center();
00411 
00413 
00414 char *get_center_id(int center_number = -1);
00415 
00417 
00418 vec get_center_pos();
00419 
00421 
00422 vec get_center_vel();
00423 
00425 
00426 bool is_member(worldbundle *wb, pdyn *p);
00427 
00429 
00430 int id_n_clump(unique_id_t id);
00431 
00432 #endif

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