Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

scat_helper3.C

Go to the documentation of this file.
00001 
00002 // scat_helper3.C: Helper functions to aid in setting up and manipulating 
00003 //                 three-body scattering experiments.
00004 
00005 // Starlab library function.
00006 
00007 #include "scatter3.h"
00008 
00009 // Translate enum states into strings:
00010 
00011 char * state_string(intermediate_descriptor3 s)
00012 {
00013     switch(s) {
00014         case non_resonance:          return "non_resonance";
00015         case hierarchical_resonance: return "hierarchical_resonance";
00016         case democratic_resonance:   return "democratic_resonance";
00017         case unknown_intermediate:   return "unknown_intermediate";
00018     }
00019 }
00020 
00021 char * state_string(final_descriptor3 s)
00022 {
00023     switch(s) {
00024         case preservation:      return "preservation";
00025         case exchange_1:        return "exchange_1";
00026         case exchange_2:        return "exchange_2";
00027         case ionization:        return "ionization";
00028         case merger_binary_1:   return "merger_binary_1";
00029         case merger_binary_2:   return "merger_binary_2";
00030         case merger_binary_3:   return "merger_binary_3";
00031         case merger_escape_1:   return "merger_escape_1";
00032         case merger_escape_2:   return "merger_escape_2";
00033         case merger_escape_3:   return "merger_escape_3";
00034         case triple_merger:     return "triple_merger";
00035         case error:             return "error";
00036         case stopped:           return "stopped";
00037         case unknown_final:     return "unknown_final";
00038     }
00039 }
00040 
00041 // Pretty-print a body array:
00042 
00043 void print_bodies(ostream & s, body * system, int prec)
00044 {
00045     s.precision(prec);
00046 
00047     s << "  body structure:" << endl;
00048     for (int k = 0; k < 3; k++) {
00049         s << "    " << system[k].index << "  "   << system[k].mass;
00050         for (int kp = 0; kp < 3; kp++) s << "  "   << system[k].pos[kp];
00051         for (int kv = 0; kv < 3; kv++) s << "  "   << system[k].vel[kv];
00052         s << endl;
00053     }
00054 }
00055 
00056 // Pretty-print an initial state:
00057 
00058 void print_initial(ostream & s, initial_state3 & i,
00059                    int bod_flag, int prec)
00060 {
00061     s.precision(prec);
00062 
00063     s << "initial_state:" << endl;
00064     s << "  m1 = " << 1 - i.m2 << "  m2 = " << i.m2
00065       << "  m3 = " << i.m3
00066       << "  r1 = " << i.r1 << "  r2 = " << i.r2 << "  r3 = " << i.r3 << endl;
00067     s << "  a_binary = " << i.sma << "  e_binary = " << i.ecc << endl;
00068     s << "  v_inf = " << i.v_inf << "  rho = " << i.rho
00069       << "  r_init = " << i.r_init;
00070     if (i.r_stop < VERY_LARGE_NUMBER)
00071         s << "  r_stop = " << i.r_stop;
00072     else
00073         s << "  tidal_tol_factor = " << i.tidal_tol_factor;
00074     s << endl;
00075     s << "  phase = " << acos(i.phase.cos_theta) << "  "
00076                       << i.phase.phi << "  " << i.phase.psi << "  "
00077                       << i.phase.mean_anomaly << endl;
00078 
00079     if (bod_flag) print_bodies(s, i.system, prec);
00080 }
00081 
00082 // Pretty-print an intermediate state:
00083 
00084 void print_intermediate(ostream & s, intermediate_state3 & i,
00085                         int bod_flag, int prec)
00086 {
00087     s.precision(prec);
00088 
00089     s << "intermediate_state:" << endl;
00090     s << "  " << state_string(i.descriptor)
00091       << "  n_osc = " << i.n_osc
00092       << "  n_kepler = " << i.n_kepler
00093       << endl;
00094 
00095     if (i.r_min_min * i.r_min_min < 0.9 * VERY_LARGE_NUMBER)
00096         {
00097         s << "  r_min = ";
00098         for (int k = 0; k < i.n_stars; k++)
00099             s << "(" << i.index[k] << ") " << i.r_min[k] << "  ";
00100         s << "r_min_min = " << i.r_min_min << endl;
00101         }
00102 
00103     if (bod_flag) print_bodies(s, i.system, prec);
00104     
00105 }
00106 
00107 // Pretty-print a final state:
00108 
00109 void print_final(ostream & s, final_state3 & f,
00110                  int bod_flag, int prec)
00111 {
00112     s.precision(prec);
00113 
00114     s << "final_state:" << endl;
00115     s << "  " << state_string(f.descriptor);
00116 
00117     if (f.sma > 0) s << "  a_binary = " << f.sma << "  e_binary = " << f.ecc;
00118     s << endl;
00119 
00120     s << "  escaper = " << f.escaper ;
00121 
00122     if (f.outer_separation > 0)
00123       s << "  outer_separation = " << f.outer_separation 
00124         << "  outer_virial_ratio = " << f.virial_ratio;
00125     s << endl;
00126 
00127     s << "  time = " << f.time << "  n_steps = " << f.n_steps
00128       << "  dE = " << f.error << endl;
00129 
00130     if (bod_flag) print_bodies(s, f.system, prec);
00131 
00132 }
00133 
00134 // Pretty-print scattering outcomes:
00135 
00136 void print_scatter3_outcome(intermediate_state3& inter,
00137                             final_state3& final,
00138                             ostream& s)
00139 {
00140     s << state_string(inter.descriptor) << " "
00141       << state_string(final.descriptor) << endl;
00142 }
00143 
00144 void print_scatter3_summary(intermediate_state3& inter,
00145                             final_state3& final,
00146                             real cpu,
00147                             ostream& s)
00148 {
00149     int p = s.precision(STD_PRECISION);
00150     s << "  time = " << final.time
00151       << "  n_steps = " << final.n_steps
00152       << "  n_osc = " << inter.n_osc
00153       << "  n_kepler = " << inter.n_kepler
00154       << endl
00155       << "  error = " << final.error
00156       << "  total CPU time = " << cpu << " s"
00157       << endl;
00158     s.precision(p);
00159 }
00160 
00161 void print_scatter3_report(initial_state3& init,
00162                            intermediate_state3& inter,
00163                            final_state3& final,
00164                            real cpu,
00165                            bool b_flag,
00166                            ostream& s)
00167 {
00168     print_initial(s, init, b_flag);
00169     print_intermediate(s, inter, b_flag);
00170     print_final(s, final, b_flag);
00171     if (cpu > 0) s << "  CPU time = " << cpu << endl;
00172 }
00173 
00174 // Set up a random phase structure:
00175 
00176 void randomize_angles(phase3 &p) // Establish random angles for scattering
00177 {
00178     p.cos_theta = randinter(-1, 1);
00179     p.phi = randinter(0, TWO_PI);
00180     p.psi = randinter(0, TWO_PI);
00181     p.mean_anomaly = randinter(-PI, PI);
00182 }
00183 
00184 // System consists of "non-particles" until properly initialized
00185 
00186 void initialize_bodies(body * system)
00187 {
00188     for (int k = 0; k < 3; k++) {
00189         system[k].index = 0;
00190         system[k].mass = -1;
00191     }
00192 }
00193 
00194 // Set up a template initial state:
00195 
00196 void make_standard_init(initial_state3 & init)
00197 {
00198     init.m2 = 0.5;              // mass of secondary in target binary
00199     init.m3 = 0.5;              // mass of projectile (m1 + m2 = 1)
00200     init.r1 = 0;                // radius of star #1
00201     init.r2 = 0;                // radius of star #2
00202     init.r3 = 0;                // radius of star #3
00203     init.sma = 1;
00204     init.ecc = 0;               // inner binary eccentricity
00205 
00206     init.v_inf = 1;             // velocity at infinity, in units of v_crit
00207     init.rho = 0;               // impact parameter
00208 
00209     // Not used (for bound systems):
00210 
00211     init.a_out = 0;
00212     init.e_out = 0;
00213 
00214     init.r_init_min = MIN_INITIAL_SEPARATION;
00215     init.r_init_max = MAX_INITIAL_SEPARATION;
00216     init.r_stop
00217           = VERY_LARGE_NUMBER;  // final separation
00218     init.tidal_tol_factor = DEFAULT_TIDAL_TOL_FACTOR;
00219     init.eta
00220           = DEFAULT_ETA;        // accuracy parameter
00221 
00222     initialize_bodies(init.system);
00223     init.id = get_initial_seed() + get_n_rand();
00224 }

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