Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

rs_snapshot.C

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 //----------------------------------------------------------------------------
00008 //   version 1:  Sept 1998   Simon Portegies Zwart   spz@grape.c.u-tokyo.ac.jp
00009 //                                                   University of Tokyo
00010 //   version 2:  July 2000  Simon Portegies Zwart   spz@mit.edu
00011 //                          Gijs Nelemans           gijsn@astro.uva.nl
00012 //............................................................................
00013 //   non-local functions: 
00014 //----------------------------------------------------------------------------
00015 
00016 
00017 #include "SeBa_hist.h"
00018 
00019 #ifdef TOOLBOX
00020 
00021 real **mkrarray(int rows, int cols) {
00022     real ** ret = new real *[rows];
00023     for (int i=0; i<cols; i++)
00024         ret[i] = new real[cols];
00025 
00026     for (int i=0; i<rows; i++)
00027         for (int j=0; j<cols; j++)
00028         ret[i][j] = 0;
00029 
00030     return ret;
00031 }
00032 
00033 void print_binary_matric(real **population) {
00034 
00035     real N_row = 0; 
00036     cerr << "    ";
00037     for (int j=0; j<no_of_stellar_type-1; j++) {
00038       cerr << " " << type_short_string((stellar_type)j);
00039       if(j==(int)Main_Sequence || 
00040          j==(int)Super_Giant   || 
00041          j==(int)Thorn_Zytkow)
00042         cerr << "  "; 
00043     }
00044     cerr << endl;
00045       
00046     for (int k = 0; k < no_of_stellar_type-1; k++) {
00047       N_row = 0;
00048       for (int i = 0; i < no_of_stellar_type-1; i++)
00049         N_row += population[i][k];
00050       
00051       if(N_row>0) {
00052         cerr << "   " << type_short_string((stellar_type)k);
00053           
00054         for (int i = 0; i < no_of_stellar_type-1; i++) {
00055           cerr << " " << population[i][k];
00056           if(i==(int)Main_Sequence || 
00057              i==(int)Super_Giant   || 
00058              i==(int)Thorn_Zytkow)
00059             cerr << "  "; 
00060         }
00061         cerr << endl;
00062       }
00063     }
00064   }
00065 
00066 void print_binary_array(real **population) {
00067 
00068     real N_row = 0;
00069 
00070     int n_all = no_of_star_type_summ*no_of_star_type_summ;
00071     real *pri_sec = new real[n_all];
00072     for (int j=0; j<n_all; j++)
00073       pri_sec[j] = 0;
00074 
00075     int js, ks, ts;
00076     for (int j=0; j<no_of_stellar_type-1; j++)
00077       for (int k = 0; k < no_of_stellar_type-1; k++) {
00078         js = (int)summarize_stellar_type((stellar_type)j);
00079         ks = (int)summarize_stellar_type((stellar_type)k);
00080         if(js>ks) {
00081           ts = js;
00082           js=ks;
00083           ks = ts;
00084         }
00085         pri_sec[js + no_of_star_type_summ*ks] += population[j][k];
00086       }
00087 
00088     for (js=0; js<no_of_star_type_summ-1; js++)
00089       for (ks = 0; ks < no_of_star_type_summ-1; ks++) {
00090         if(pri_sec[js + no_of_star_type_summ*ks]>0)
00091           cerr << " (" << type_short_string((stellar_type_summary)js)
00092                << ", " << type_short_string((stellar_type_summary)ks) <<")\t"
00093                << pri_sec[js + no_of_star_type_summ*ks] << endl;
00094       }
00095 
00096     delete []pri_sec;
00097   }
00098 
00099 
00100 
00101 local real extract_snapshot(SeBa_hist *hi, real snap_time,
00102                            bool normalize) {
00103 
00104     real binaries_read = 0;
00105 
00106     real ** detached_population;
00107     real** contact_population;
00108     real* single_population;
00109     real* blue_straggler_population;
00110     bool p_bss, s_bss, tb;
00111     int N_detached=0, N_contact=0, N_single=0;
00112     binary_type tpe_bin;
00113     stellar_type prim_type, sec_type, ts;
00114     real prim_mass, sec_mass;
00115     real m_to;
00116       m_to = turn_off_mass(snap_time);
00117 
00118       detached_population = mkrarray((int)no_of_stellar_type, 
00119                                     (int)no_of_stellar_type);
00120       contact_population = mkrarray((int)no_of_stellar_type, 
00121                                    (int)no_of_stellar_type);
00122       single_population = new real[(int)no_of_stellar_type];
00123       blue_straggler_population = new real[(int)no_of_stellar_type];
00124       for(int i=0; i<(int)no_of_stellar_type; i++) {
00125         single_population[i]=0;
00126         blue_straggler_population[i] = 0;
00127       }
00128 
00129 
00130     int mergers = 0;    
00131     SeBa_hist* next_hi = get_history(hi, cin);
00132     do {
00133 
00134       binaries_read++;
00135 
00136       if (hi->get_last()->get_time() < snap_time) {
00137         cerr << "ERROR: snap_time not reached" << endl;
00138         exit(-1);
00139       }
00140 
00141       if (hi->get_last()->get_binary_type() == Merged) 
00142         mergers++;
00143 //      cerr << hi->get_parameter(identity) << endl;
00144 
00145         SeBa_hist *hj = hi->get_SeBa_hist_at_time(snap_time);
00146 
00147 //      tpe_bin     = hi->binary_type_at_time(snap_time);
00148 //      prim_type   = hi->primary_type_at_time(snap_time, p_bss);
00149 //      sec_type    = hi->secondary_type_at_time(snap_time, s_bss);
00150         if(hj) {
00151           tpe_bin     = hj->get_binary_type();
00152           prim_type   = hj->get_primary_type();
00153           prim_mass   = hj->get_parameter(primary_mass);
00154           sec_type    = hj->get_secondary_type();
00155           sec_mass    = hj->get_parameter(secondary_mass);
00156           if(prim_type==Main_Sequence && prim_mass>m_to)
00157             p_bss = true;
00158           else
00159             p_bss = false;
00160           if(sec_type==Main_Sequence && sec_mass>m_to)
00161             s_bss = true;
00162           else
00163             s_bss = false;
00164           if (prim_mass<sec_mass) {
00165             ts = prim_type;
00166             prim_type = sec_type;
00167             sec_type = ts;
00168             tb = p_bss;
00169             p_bss=s_bss;
00170             s_bss=tb;
00171           }
00172 
00173           if(prim_type>=0 && sec_type>=0) {
00174             if(tpe_bin==Detached) {
00175               N_detached++;
00176               if (p_bss)
00177                 blue_straggler_population[(int)sec_type]++; 
00178               else if (s_bss)
00179                 blue_straggler_population[(int)prim_type]++; 
00180               else
00181                 detached_population[(int)prim_type][(int)sec_type]++; 
00182             }
00183             else if(tpe_bin==Semi_Detached ||
00184                     tpe_bin==Contact) {
00185               N_contact++;
00186               if (p_bss)
00187                 blue_straggler_population[(int)sec_type]++; 
00188               else if (s_bss)
00189                 blue_straggler_population[(int)prim_type]++; 
00190               else
00191                 contact_population[(int)prim_type][(int)sec_type]++; 
00192             }
00193             else {
00194               N_single++;
00195               single_population[(int)prim_type]++; 
00196               if (p_bss)
00197                 blue_straggler_population[Proto_Star]++; 
00198               
00199               if(tpe_bin==Disrupted) {
00200                 N_single++;
00201                 single_population[(int)sec_type]++; 
00202                 if (p_bss)
00203                   blue_straggler_population[Disintegrated]++; 
00204               }
00205             }
00206           }
00207         }
00208 
00209 
00210       delete hi;
00211       
00212       hi = next_hi;
00213       next_hi = get_history(hi, cin);
00214     }
00215     while (next_hi);
00216 
00217     PRL(binaries_read);
00218     if(normalize) {
00219         int p = cerr.precision(LOW_PRECISION);
00220         cerr << "Normalized to 100%"<<endl;
00221         binaries_read /= 100;
00222 
00223         for (int j = 0; j<no_of_stellar_type-1; j++)  {
00224 
00225             single_population[j] /= binaries_read;
00226             blue_straggler_population[j] /= binaries_read;
00227 
00228             for (int i = 0; i < no_of_stellar_type-1; i++) {
00229                 detached_population[i][j] /= binaries_read;
00230                 contact_population[i][j] /= binaries_read;
00231             }
00232         }
00233         cerr.precision(p);
00234     }
00235 
00236     if (N_detached>0) {
00237         cerr << "     Detached population"<<endl;
00238         print_binary_matric(detached_population);
00239         cerr << "\n     Summary:" << endl;
00240         print_binary_array(detached_population);
00241     }
00242     else
00243         cerr << "     ---No detached binaries---" <<endl;
00244 
00245     cerr <<  endl;
00246 
00247     if (N_contact>0) {
00248         cerr << "     Semi-detached/contact population"<<endl;
00249         print_binary_matric(contact_population);
00250         cerr << "\n     Summary:" << endl;
00251         print_binary_array(contact_population);
00252     }
00253     else
00254         cerr << "     ---No contact Binaries---" <<endl;
00255 
00256     cerr <<  endl;
00257 
00258     cerr << "     Single population"<<endl;
00259     cerr << "    ";
00260     for (int j=0; j<no_of_stellar_type-1; j++) {
00261         cerr << " " << type_short_string((stellar_type)j);
00262         if(j==(int)Main_Sequence || 
00263            j==(int)Super_Giant   || 
00264            j==(int)Thorn_Zytkow)
00265             cerr << "  "; 
00266     }
00267 
00268     cerr <<  endl;
00269 
00270     cerr << endl << "     ";
00271     for (int j = 0; j<no_of_stellar_type-1; j++) {
00272         cerr << " " << single_population[j];
00273         if(j==(int)Main_Sequence || 
00274            j==(int)Super_Giant   || 
00275            j==(int)Thorn_Zytkow)
00276             cerr << "  "; 
00277     }
00278     cerr << "\n     Blue straggler population (pl=merged, di=dissrupted)"
00279          << endl;
00280     cerr << endl << "     ";
00281     for (int j = 0; j<no_of_stellar_type-1; j++) {
00282         cerr << " " << blue_straggler_population[j];
00283         if(j==(int)Main_Sequence || 
00284            j==(int)Super_Giant   || 
00285            j==(int)Thorn_Zytkow)
00286             cerr << "  "; 
00287     }
00288     cerr << endl;
00289 
00290     return binaries_read;
00291   }
00292 //----------------------------------------------------------------------------
00293 //  main  --  driver to reduce SeBa short dump data
00294 //----------------------------------------------------------------------------
00295 
00296 main(int argc, char ** argv) {
00297 
00298   bool normalize = false;
00299     real snap_time = 0;
00300 
00301     char  *comment;
00302     check_help();
00303 
00304     extern char *poptarg;
00305     int c;
00306     char* param_string = "Nt:";
00307 
00308     while ((c = pgetopt(argc, argv, param_string)) != -1)
00309         switch(c)
00310             {
00311             case 't': snap_time = atof(poptarg);
00312                       break;
00313             case 'N': normalize = !normalize;
00314                       break;
00315             case '?': params_to_usage(cerr, argv[0], param_string);
00316                       get_help();
00317                       exit(1);
00318             }            
00319 
00320 
00321     SeBa_hist* hi = new SeBa_hist;
00322     if (!hi->read_SeBa_hist(cin))
00323       exit(-1);
00324 
00325     cerr << "Time = " << snap_time << " [Myr]" << endl << endl;
00326     
00327 
00328     real binaries_read = extract_snapshot(hi, snap_time, normalize);
00329 
00330     cerr << "Total number of binaries read: " << binaries_read << endl;
00331 }
00332 
00333 #endif // endof: TOOLBOX
00334 
00335 
00336 

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