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