Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

debug3.C

Go to the documentation of this file.
00001 
00002 // debug.C: Perform three-body scattering experiments, with diagnostic output.
00003 //
00004 // Input is an initial state, output is intermediate and final states.
00005 // No reference is made to scatter profiles in this file.
00006 
00007 // Starlab application:  scatter3.
00008 
00009 #include "scatter3.h"
00010 
00011 local real energy(sdyn3 * b)
00012 {
00013     real k = 0, u = 0;
00014 
00015     for_all_daughters(sdyn3, b, bi) {
00016         k += bi->get_mass() * bi->get_vel() * bi->get_vel();
00017         for (sdyn3 * bj = bi->get_younger_sister(); bj != NULL;
00018              bj = bj->get_younger_sister())
00019           u -= bi->get_mass() * bj->get_mass()
00020                / abs(bi->get_pos() - bj->get_pos());
00021     }
00022     return 0.5*k + u;
00023 }
00024 
00025 local void print_debug(sdyn3 *s)
00026 
00027 // Print out information on a scattering experiment.  Control is passed
00028 // to this function at time intervals of dt_print.  Note that, for a flyby,
00029 // the first two sdyn3s below s are the components of the binary.
00030 
00031 {
00032 /*
00033     int p = cout.precision(LOW_PRECISION);
00034     cout.setf(ios::scientific, ios::floatfield);
00035 
00036     sdyn3 *d1, *d2, *d3;
00037 
00038     d1 = s->get_oldest_daughter();
00039     d2 = d1->get_younger_sister();
00040     d3 = d2->get_younger_sister();
00041 
00042     real m1 = d1->get_mass();
00043     real m2 = d2->get_mass();
00044     real m3 = d3->get_mass();
00045 
00046     kepler k;
00047 
00048     k.set_time(s->get_time());
00049     k.set_total_mass(d1->get_mass() + d2->get_mass());
00050     k.set_rel_pos(d2->get_pos() - d1->get_pos());
00051     k.set_rel_vel(d2->get_vel() - d1->get_vel());
00052     k.initialize_from_pos_and_vel();
00053  */
00054 
00055     cout << "ssd = " << s->get_ssd()
00056          << "  n_osc = " << s->get_n_ssd_osc();
00057     cout << "  T = " << s->get_time() + s->get_time_offset();
00058 
00059 //    cout << "  CPU = " << cpu_time() << endl;
00060     cout << "  E = " << energy(s) << endl;
00061 
00062     cout.precision(p);
00063 }
00064 
00065 // The main program is identical to scatter3, except that it takes an
00066 // extra command-line flag (dt_print) and passes print_debug as an
00067 // argument to the scatter3 function.
00068 
00069 main(int argc, char **argv)
00070     {
00071 
00072     initial_state3 init;
00073     make_standard_init(init);
00074 
00075     int  seed       = 0;        // seed for random number generator
00076     int  n_rand = 0;
00077     int  n_experiments = 1;     // default: only one run
00078     real dt_out     =           // output time interval
00079           VERY_LARGE_NUMBER;
00080     real dt_snap    =           // output time interval
00081           VERY_LARGE_NUMBER;
00082     real dt_print    =          // diagnostic print time interval
00083           VERY_LARGE_NUMBER;
00084 
00085     real cpu_time_check = 3600;
00086     real snap_cube_size = 10;
00087 
00088     bool  b_flag = FALSE;
00089     bool  q_flag = FALSE;
00090 
00091     extern char *poptarg;
00092     int c;
00093     char* param_string = "A:bc:C:d:D:e:L:m:M:nN::qp:r:s:U:v:x:y:z:";
00094 
00095     while ((c = pgetopt(argc, argv, param_string)) != -1)
00096         switch(c)
00097             {
00098             case 'A': init.eta = atof(poptarg);
00099                       break;
00100             case 'b': b_flag = 1 - b_flag;
00101                       break;
00102             case 'c': cpu_time_check = 3600*atof(poptarg);// (Specify in hours)
00103                       break;
00104             case 'C': snap_cube_size = atof(poptarg);
00105                       break;
00106             case 'd': dt_out = atof(poptarg);
00107                       break;
00108             case 'D': dt_snap = atof(poptarg);
00109                       break;
00110             case 'e': init.ecc = atof(poptarg);
00111                       break;
00112             case 'L': init.r_init_min = atof(poptarg);
00113                       break;
00114             case 'm': init.m2 = atof(poptarg);
00115                       break;
00116             case 'M': init.m3 = atof(poptarg);
00117                       break;
00118             case 'N': n_rand = atoi(poptarg);
00119                       break;
00120             case 'n': n_experiments = atoi(poptarg);
00121                       break;
00122             case 'p': dt_print = atof(poptarg);
00123                       break;
00124             case 'q': q_flag = 1 - q_flag;
00125                       break;
00126             case 'r': init.rho = atof(poptarg);
00127                       break;
00128             case 's': seed = atoi(poptarg);
00129                       break;
00130             case 'U': init.r_init_max = atof(poptarg);
00131                       break;
00132             case 'v': init.v_inf = atof(poptarg);
00133                       break;
00134             case 'x': init.r1 = atof(poptarg);
00135                       break;
00136             case 'y': init.r2 = atof(poptarg);
00137                       break;
00138             case 'z': init.r3 = atof(poptarg);
00139                       break;
00140             case '?': params_to_usage(cerr, argv[0], param_string);
00141                       exit(1);
00142             }            
00143 
00144     if (init.m2 > 1)
00145         {
00146         cerr << "sigma3: initial.m2 = " << init.m2 << " > 1" << endl;
00147         exit(1);
00148         }
00149 
00150     int random_seed = srandinter(seed, n_rand);
00151 
00152     while (n_experiments--)
00153         {
00154         int initial_seed = get_initial_seed();
00155         int n_rand = get_n_rand();
00156 
00157         randomize_angles(init.phase);
00158 
00159         intermediate_state3 inter;
00160         final_state3 final;
00161 
00162         scatter3(init, inter, final, cpu_time_check,
00163                  dt_out, dt_snap, snap_cube_size,
00164                  dt_print, print_debug);
00165 
00166         cerr << "result:  " << state_string(inter.descriptor) << " "
00167              << state_string(final.descriptor)
00168              << "        Random seed = " << initial_seed
00169              << "  n_rand = " << n_rand << endl;
00170 
00171         if (!q_flag)
00172             {
00173             print_initial(cerr, init, b_flag);
00174             print_intermediate(cerr, inter, b_flag);
00175             print_final(cerr, final, b_flag);
00176             }
00177         }
00178     }
00179 

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