Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

addplummer.C

Go to the documentation of this file.
00001 
00007 
00008 // For details on model construction, see notes in mkplummer.C
00009 // Steve McMillan, July 1996
00010 
00011 #include "dyn.h"
00012 
00013 #ifdef TOOLBOX
00014 
00015 #define  MFRAC_DEFAULT  0.999                 /* radial cutoff               */
00016 #define  RFRAC_DEFAULT  22.8042468            /* corresponding radial cutoff */
00017                                               /*   (not used right now)      */
00018 #define  SEED_STRING_LENGTH  60
00019 
00020 local void  addplummer(dyn * b, real mfrac, real rfrac)
00021 {
00022     real  radius;                  /* absolute value of position vector      */
00023     real  velocity;                /* absolute value of velocity vector      */
00024     real  theta, phi;              /* direction angles of above vectors      */
00025     real  x, y;                    /* for use in rejection technique         */
00026     real  scalefactor;             /* for converting between different units */
00027     real  inv_scalefactor;         /* inverse scale factor                   */
00028     real  sqrt_scalefactor;        /* sqare root of scale factor             */
00029     real  m_min, m_max;            /* mass shell limits for quiet start      */
00030 
00031     scalefactor = 16.0 / (3.0 * PI);
00032     inv_scalefactor = 1.0 / scalefactor;
00033     sqrt_scalefactor = sqrt(scalefactor);
00034 
00035     //  Set up positions and velocities for top-level nodes.
00036 
00037     m_max = 0;
00038     for_all_daughters(dyn, b, bi) {
00039 
00040         m_min = m_max;
00041         m_max += mfrac * bi->get_mass() / b->get_mass();
00042         real m = randinter(m_min, m_max);
00043         radius = 1.0 / sqrt( pow (m, -2.0/3.0) - 1.0);
00044 
00045         theta = acos(randinter(-1.0, 1.0));
00046         phi = randinter(0.0, TWO_PI);
00047 
00048         bi->set_pos(vector(radius * sin( theta ) * cos( phi ),
00049                            radius * sin( theta ) * sin( phi ),
00050                            radius * cos( theta )));
00051 
00052         x = 0.0;
00053         y = 0.1;
00054 
00055         while (y > x*x*pow( 1.0 - x*x, 3.5)) {
00056             x = randinter(0.0, 1.0);
00057             y = randinter(0.0, 0.1);
00058         }
00059 
00060         velocity = x * sqrt(2.0) * pow( 1.0 + radius*radius, -0.25);
00061         theta = acos(randinter(-1.0, 1.0));
00062         phi = randinter(0.0, TWO_PI);
00063 
00064         bi->set_vel(vector(velocity * sin( theta ) * cos( phi ),
00065                            velocity * sin( theta ) * sin( phi ),
00066                            velocity * cos( theta )));
00067     }
00068 
00069     //  Transform to center-of-mass coordinates.
00070 
00071     b->to_com();
00072 }
00073 
00074 main(int argc, char ** argv)
00075 {
00076     int  random_seed;
00077     real  mfrac = MFRAC_DEFAULT;
00078     real  rfrac = RFRAC_DEFAULT;
00079 
00080     check_help();
00081 
00082     extern char *poptarg;
00083     int c;
00084     char* param_string = "s:";
00085 
00086     while ((c = pgetopt(argc, argv, param_string)) != -1)
00087         switch(c) {
00088 
00089             case 's': random_seed = atoi(poptarg);
00090                       break;
00091             case '?': params_to_usage(cerr, argv[0], param_string);
00092                       get_help();
00093                       exit(1);
00094         }            
00095     
00096     dyn *b;
00097     b = get_dyn(cin);
00098 
00099     b->log_history(argc, argv);
00100 
00101     int actual_seed = srandinter(random_seed);
00102 
00103     char seedlog[64];
00104     sprintf(seedlog, "       random number generator seed = %d",actual_seed);
00105     b->log_comment(seedlog);
00106 
00107     addplummer(b, mfrac, rfrac);
00108 
00109     put_node(cout, *b);
00110 }
00111 
00112 #endif

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