00001
00008
00009
00010
00011 #include "dyn.h"
00012
00013 #ifdef TOOLBOX
00014
00015 local void jiggle(dyn * b, real f)
00016 {
00017 if (f >= 1) f = 1;
00018
00019 for_all_daughters(dyn, b, bi) {
00020
00021 vector vel = bi->get_vel(), norm;
00022
00023 while(1) {
00024 real costh = randinter(-1, 1);
00025 real sinth = sqrt(max(0.0, 1-costh*costh));
00026 real phi = randinter(0, 2*M_PI);
00027 vector rvec = vector(sinth*cos(phi), sinth*cos(phi), costh);
00028 norm = rvec ^ vel;
00029 if (abs(norm) > 0.01*abs(vel)) break;
00030
00031 }
00032
00033
00034
00035 real v = abs(vel);
00036 vel = sqrt(1 - f*f) * vel + f * v * norm/abs(norm);
00037
00038 bi->set_vel(vel);
00039 }
00040 }
00041
00042 main(int argc, char ** argv)
00043 {
00044 bool c_flag = false, s_flag = false;
00045 char *comment;
00046 real f = 0.01;
00047 int input_seed, actual_seed;
00048 char seedlog[128];
00049
00050 check_help();
00051
00052 extern char *poptarg;
00053 int c;
00054 char* param_string = "c:f:s:";
00055
00056 while ((c = pgetopt(argc, argv, param_string)) != -1)
00057 switch(c) {
00058
00059 case 'c': c_flag = true;
00060 comment = poptarg;
00061 break;
00062 case 'f': f = atof(poptarg);
00063 break;
00064 case 's': s_flag = true;
00065 input_seed = atoi(poptarg);
00066 break;
00067 case '?': params_to_usage(cerr, argv[0], param_string);
00068 get_help();
00069 exit(1);
00070 }
00071
00072 if (!s_flag) input_seed = 0;
00073 actual_seed = srandinter(input_seed);
00074
00075 cerr << "jiggle: random seed = " << actual_seed << endl;
00076
00077 sprintf(seedlog, " random number generator seed = %d", actual_seed);
00078
00079 dyn *b;
00080
00081 while (b = get_dyn(cin)) {
00082
00083 b->log_history(argc, argv);
00084 if (c_flag) b->log_comment(comment);
00085 b->log_comment(seedlog);
00086
00087 jiggle(b, f);
00088 put_dyn(cout, *b);
00089 rmtree(b);
00090 }
00091 }
00092
00093 #endif