00001
00007
00008
00009
00010
00011 #include "dyn.h"
00012
00013 #ifdef TOOLBOX
00014
00015 #define MFRAC_DEFAULT 0.999
00016 #define RFRAC_DEFAULT 22.8042468
00017
00018 #define SEED_STRING_LENGTH 60
00019
00020 local void addplummer(dyn * b, real mfrac, real rfrac)
00021 {
00022 real radius;
00023 real velocity;
00024 real theta, phi;
00025 real x, y;
00026 real scalefactor;
00027 real inv_scalefactor;
00028 real sqrt_scalefactor;
00029 real m_min, m_max;
00030
00031 scalefactor = 16.0 / (3.0 * PI);
00032 inv_scalefactor = 1.0 / scalefactor;
00033 sqrt_scalefactor = sqrt(scalefactor);
00034
00035
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
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