Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

flatten.C

Go to the documentation of this file.
00001 
00006 
00007 //   version 1:  March 1994   Piet Hut
00008 
00009 #include "dyn.h"
00010 
00011 #ifndef TOOLBOX
00012 
00013 //-----------------------------------------------------------------------------
00014 //  unbundle_node  --  ...
00015 //                 note:
00016 //                      the positions and velocities of the daughters of the
00017 //                      node-to-be-unbundled are increased by the values of the
00018 //                      corresponding quantities of the node-to-be-unbundled;
00019 //                      the other physical quantities of the daughters remain
00020 //                      unchanged, while those of the node-to-be-unbundled are
00021 //                      be discarded.
00022 //                 note:
00023 //                      the parent, daughter and grand daughters really should
00024 //                      be synchronized in time; to be implemented.
00025 //-----------------------------------------------------------------------------
00026 
00027 local void  unbundle_node(dyn * ud)
00028     {
00029     dyn * parent;
00030     parent = ud->get_parent();
00031 
00032     if (parent == NULL)
00033         err_exit("unbundle() : no parent for this node");
00034 
00035     dyn * od;
00036     od = ud->get_oldest_daughter();
00037 
00038     if (od == NULL)
00039         return;                         // nothing left to unbundle
00040 
00041     vector pos = ud->get_pos();
00042     vector vel = ud->get_vel();
00043 
00044     for_all_daughters(dyn, ud, dd)
00045         {
00046         dd->inc_pos(pos);
00047         dd->inc_vel(vel);
00048         }
00049 
00050     // pointer adjustments:
00051 
00052     dyn * elder_sister;
00053     elder_sister = ud->get_elder_sister();
00054 
00055     if (elder_sister == NULL)
00056         parent->set_oldest_daughter(od);
00057     else
00058         {
00059         elder_sister->set_younger_sister(od);
00060         od->set_elder_sister(elder_sister);
00061         }
00062 
00063     dyn * d = od;
00064     dyn * pd;
00065 
00066     while (d)
00067         {
00068         d->set_parent(parent);
00069         pd = d;
00070         d = d->get_younger_sister();
00071         }
00072     
00073     dyn * younger_sister;
00074     younger_sister = ud->get_younger_sister();
00075 
00076     if (younger_sister)
00077         {
00078         younger_sister->set_elder_sister(pd);
00079         pd->set_younger_sister(younger_sister);
00080         }
00081 
00082     delete ud;
00083     }
00084 
00085 /*-----------------------------------------------------------------------------
00086  *  flatten_node  --  
00087  *-----------------------------------------------------------------------------
00088  */
00089 void  dyn::flatten_node()
00090     {
00091     for_all_daughters(dyn, this, d)
00092         {
00093         if (d->is_grandparent())
00094             d->flatten_node();
00095 
00096         unbundle_node(d);
00097         }
00098     }
00099 
00100 /*===========================================================================*/
00101 
00102 #else
00103 
00104 //-----------------------------------------------------------------------------
00105 //  main  --  driver to use  flatten_node() as a tool.
00106 //-----------------------------------------------------------------------------
00107 
00108 main(int argc, char ** argv)
00109 {
00110     bool  c_flag = FALSE;
00111     char  *comment;
00112 
00113     check_help();
00114 
00115     extern char *poptarg;
00116     int c;
00117     char* param_string = "c:";
00118 
00119     while ((c = pgetopt(argc, argv, param_string)) != -1)
00120         switch(c) {
00121 
00122             case 'c': c_flag = TRUE;
00123                       comment = poptarg;
00124                       break;
00125             case '?': params_to_usage(cerr, argv[0], param_string);
00126                       get_help();
00127                       exit(1);
00128         }            
00129 
00130     dyn *b;
00131 
00132     while (b = get_dyn(cin)) {
00133 
00134         if (c_flag == TRUE)
00135             b->log_comment(comment);
00136         b->log_history(argc, argv);
00137 
00138         b->flatten_node();
00139         put_dyn(cout, *b);      
00140         delete b;
00141     }
00142 }
00143 
00144 #endif
00145 
00146 // endof: flatten.C
00147 

Generated at Sun Feb 24 09:57:00 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001