Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

makesphere.C

Go to the documentation of this file.
00001 
00017 
00018 #include "dyn.h"
00019 
00020 #ifndef TOOLBOX
00021 
00022 void  mksphere(dyn * root, int n,
00023                int u_flag)                      // default = false
00024 {
00025     real radius, costheta, sintheta, phi;
00026     dyn  * bi;
00027 
00028     root->set_mass(1);
00029     real pmass = 1.0 / n;
00030 
00031     for (bi = root->get_oldest_daughter(); bi != NULL;
00032          bi = bi->get_younger_sister()) {
00033         bi->set_mass(pmass);
00034 
00035         radius = pow(randinter(0, 1), 1.0/3.0);
00036         costheta = randinter(-1.0, 1.0);
00037         sintheta = 1 - costheta*costheta;
00038         if (sintheta > 0) sintheta = sqrt(sintheta);
00039         phi = randinter(0.0, TWO_PI);
00040         bi->set_pos(vector(radius * sintheta * cos(phi),
00041                            radius * sintheta * sin(phi),
00042                            radius * costheta));
00043 
00044         bi->set_vel(vector(randinter(-1,1),
00045                            randinter(-1,1),
00046                            randinter(-1,1)));
00047     }
00048 
00049 //  Transform to center-of-mass coordinates and optionally
00050 //  scale to standard parameters.
00051 
00052     root->to_com();
00053     putrq(root->get_log_story(), "initial_mass", 1.0);
00054 
00055     if (!u_flag && n > 1) {
00056 
00057         real kinetic, potential;
00058 
00059         get_top_level_energies(root, 0.0, potential, kinetic);
00060         scale_virial(root, -0.5, potential, kinetic);   // scales kinetic
00061         real energy = kinetic + potential;
00062         scale_energy(root, -0.25, energy);              // scales energy
00063         putrq(root->get_dyn_story(), "total_energy", -0.25);
00064         putrq(root->get_log_story(), "initial_rvirial", 1.0);
00065     }
00066 }
00067 
00068 #else
00069 
00070 #define  SEED_STRING_LENGTH  60
00071 
00072 #define  FALSE  0
00073 #define  TRUE   1
00074 
00075 main(int argc, char ** argv) {
00076     int  i;
00077     int  n;
00078     int  input_seed, actual_seed;
00079     int  c_flag = FALSE;
00080     int  i_flag = FALSE;
00081     int  n_flag = FALSE;
00082     int  o_flag = FALSE;
00083     int  s_flag = FALSE;
00084     int  u_flag = FALSE;
00085 
00086     char  *comment;
00087     char  seedlog[SEED_STRING_LENGTH];
00088 
00089     check_help();
00090 
00091     extern char *poptarg;
00092     int c;
00093     char* param_string = "c:in:os:u";
00094 
00095     while ((c = pgetopt(argc, argv, param_string)) != -1)
00096         switch(c)
00097             {
00098             case 'c': c_flag = TRUE;
00099                       comment = poptarg;
00100                       break;
00101             case 'i': i_flag = TRUE;
00102                       break;
00103             case 'n': n_flag = TRUE;
00104                       n = atoi(poptarg);
00105                       break;
00106             case 'o': o_flag = TRUE;
00107                       break;
00108             case 's': s_flag = TRUE;
00109                       input_seed = atoi(poptarg);
00110                       break;
00111             case 'u': u_flag = TRUE;
00112                       break;
00113             case '?': params_to_usage(cerr, argv[0], param_string);
00114                       get_help();
00115                       exit(1);
00116             }            
00117     
00118     if (n_flag == FALSE) {
00119         cerr << "makesphere: must specify the number # of";
00120         cerr << " particles with -n#\n";
00121         exit(1);
00122     }
00123     
00124     if (n < 1) {
00125         cerr << "mksphere: n < 1 not allowed\n";
00126         exit(1);
00127     }
00128 
00129     dyn *b, *by, *bo;
00130     b = new dyn();
00131     bo = new dyn();
00132     if (i_flag) bo->set_label(1);
00133     b->set_oldest_daughter(bo);
00134     bo->set_parent(b);
00135 
00136     for (i = 1; i < n; i++) {
00137         by = new dyn();
00138         if (i_flag) by->set_label(i+1);
00139         bo->set_younger_sister(by);
00140         by->set_elder_sister(bo);
00141         bo = by;
00142     }
00143 
00144     if (c_flag == TRUE) b->log_comment(comment);
00145 
00146     b->log_history(argc, argv);
00147 
00148     if (s_flag == FALSE) input_seed = 0;
00149     actual_seed = srandinter(input_seed);
00150 
00151     if (o_flag) cerr << "mksphere: random seed = " << actual_seed << endl;
00152 
00153     sprintf(seedlog, "       random number generator seed = %d",actual_seed);
00154     b->log_comment(seedlog);
00155 
00156     if (n > 0) mksphere(b, n, u_flag);
00157 
00158     put_node(cout, *b);
00159     rmtree(b);
00160 }
00161 
00162 #endif
00163 
00164 /* end of: mksphere.c */

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