Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

set_com.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00025 
00026 //   version 1:  Aug/Sep 2001   Steve McMillan
00027 
00028 #include "dyn.h"
00029 
00030 #ifndef TOOLBOX
00031 
00032 void dyn::set_com(vector pos, vector vel)       // defaults = 0
00033 {
00034     vector com_pos;
00035     vector com_vel;
00036 
00037     compute_com(this, com_pos, com_vel); 
00038 
00039     vector dpos = pos - com_pos;
00040     vector dvel = vel - com_vel;
00041 
00042     // Adjust only top-level nodes; don't touch the root node.
00043 
00044     for_all_daughters(dyn, this, bb) {
00045         bb->inc_pos(dpos);
00046         bb->inc_vel(dvel);
00047     }
00048 
00049     // Correct entries in the dyn story.
00050 
00051     putvq(get_dyn_story(), "com_pos", pos);
00052     putvq(get_dyn_story(), "com_vel", vel);
00053 
00054     // Note: Do not modify the "center" of any external field.
00055     // This function adjusts only the N-body center of mass.
00056 }
00057 
00058 #else
00059 
00060 main(int argc, char ** argv)
00061 {
00062     bool  c_flag = FALSE;
00063     char  *comment;
00064     vector r = 0;
00065     vector v = 0;
00066 
00067     bool n_flag = false;
00068 
00069     check_help();
00070 
00071     extern char *poptarg;
00072     extern char *poparr[];
00073     int c;
00074     char* param_string = "c:nr:::v:::";
00075 
00076     while ((c = pgetopt(argc, argv, param_string)) != -1)
00077         switch(c) {
00078             case 'c':   c_flag = TRUE;
00079                         comment = poptarg;
00080                         break;
00081             case 'n':   n_flag = true;
00082                         break;
00083 
00084             case 'r':   r = vector(atof(poparr[0]),
00085                                    atof(poparr[1]),
00086                                    atof(poparr[2]));
00087                         break;
00088             case 'v':   v = vector(atof(poparr[0]),
00089                                    atof(poparr[1]),
00090                                    atof(poparr[2]));
00091                         break;
00092 
00093             case '?':   params_to_usage(cerr, argv[0], param_string);
00094                         get_help();
00095                         exit(1);
00096         }            
00097 
00098     dyn *b;
00099 
00100     while (b = get_dyn(cin)) {
00101 
00102         if (c_flag == TRUE)
00103             b->log_comment(comment);
00104         b->log_history(argc, argv);
00105 
00106         // Check if we have to reinterpret r and v in light of possible
00107         // external fields and physical parameters.
00108 
00109         real mass, length, time;
00110         bool phys = get_physical_scales(b, mass, length, time);
00111 
00112         // If phys, we are using physical units.  Mass, length, and time are
00113         // the physical equivalents of 1 N-body unit, in Msun, pc, and Myr.
00114 
00115         check_set_external(b, false);
00116         bool ext = (b->get_external_field() != 0);
00117 
00118         // If ext, we have an external field, assumed attractive.  Note
00119         // that this function doesn't make much sense if ext = false...
00120         // If ext, the external field has already been converted to
00121         // N-body units, regardless of phys.
00122 
00123         // Possibilities:
00124         //
00125         // no ext field, no physical units:     set r, v as is in N-body units
00126         // no ext field, physical units:        convert r, v to N-body and set
00127         // ext field, no physical units:        use N-body units, but use v/vc
00128         // ext field, physical units:           convert to N-body and use v/vc
00129 
00130         if (phys && !n_flag) {
00131 
00132             cerr << "set_com:  converting input physical parameters"
00133                  << " to N-body units" << endl;
00134             cerr << "          r = (" << r << ") pc,  v = ("
00135                  << v << ") v_circ" << endl;
00136             cerr << "          N-body length scale = " << length << " pc"
00137                  << endl;
00138 
00139             // Convert r and v to N-body units.
00140 
00141             r /= length;
00142             if (!ext) {
00143 
00144                 // Input v is in km/s; length/time is the velocity unit
00145                 // in pc/Myr = 3.086e13/3.156e13 km/s = 0.978 km/s.
00146 
00147                 real vunit = 0.978*length/time;
00148                 v /= vunit;
00149             }
00150 
00151         } else
00152 
00153             cerr << "set_com:  interpreting input parameters"
00154                  << " as N-body units" << endl;
00155 
00156         if (ext) {
00157 
00158             // Convert v from units of vcirc into N-body units.
00159 
00160             real vc = vcirc(b, r);
00161 
00162             if (vc > 0) {
00163                 v *= vc;
00164                 cerr << "          circular orbit speed = " << vc;
00165                 if (phys && !n_flag) cerr << " (N-body)";
00166                 cerr << ",  period = " << 2*M_PI*abs(r)/vc
00167                      << endl;
00168             }
00169         }
00170 
00171         // Now r and v are in N-body units, appropriately scaled.
00172 
00173         b->set_com(r, v);
00174         cerr << "          r = (" << r << "),  v = (" << v << ")"
00175              << endl;
00176 
00177         put_dyn(cout, *b);      
00178         rmtree(b);
00179     }
00180 }
00181 
00182 #endif

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