Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

makeblack_hole.C

Go to the documentation of this file.
00001 
00008 
00009 //                 Simon Portegies Zwart, MIT November 2000
00010 
00011 #include "dyn.h"
00012 
00013 #define  SEED_STRING_LENGTH  256
00014 char  tmp_string[SEED_STRING_LENGTH];
00015 
00016 #ifdef TOOLBOX
00017 
00018 local void mkblack_hole(dyn* b, int id, real m_bh) {
00019 
00020     b->to_com();
00021 
00022     real r_min = VERY_LARGE_NUMBER;
00023     dyn *bh = NULL;
00024     if(id<0) {
00025       for_all_daughters(dyn, b, bi) {
00026         if(abs(bi->get_pos()) < r_min) {
00027           r_min = abs(bi->get_pos());
00028           bh = bi;
00029         }
00030       }
00031     }
00032     else {
00033       for_all_daughters(dyn, b, bi) {
00034         if(bi->get_index() == id) {
00035           bh = bi;
00036           break;
00037         }
00038       }
00039     }
00040 
00041     PRL(m_bh);
00042     if(m_bh<=1) {
00043         cerr << "fractional bh mass" << endl;
00044         m_bh *= b->get_mass()-bh->get_mass();
00045         PRL(m_bh);
00046     }
00047 
00048     real prev_mass; 
00049     if(bh) {
00050         prev_mass = bh->get_mass();
00051         bh->set_mass(m_bh);
00052         bh->set_vel(bh->get_vel() * sqrt(prev_mass/m_bh));
00053     }
00054     else 
00055         err_exit("mkblack_hole: selected star not found");
00056 
00057     putiq(bh->get_log_story(), "black_hole", 1);
00058 
00059     real m_sum = 0;
00060     for_all_leaves(dyn, b, bi) {
00061         m_sum += bi->get_mass();
00062     }
00063 
00064     b->set_mass(m_sum);
00065 
00066     sprintf(tmp_string,
00067             "         black hole added, total mass = %8.2f", m_sum); 
00068     b->log_comment(tmp_string);
00069     cerr << "Black hole mass is " << m_bh << endl;
00070 }
00071 
00072 void main(int argc, char ** argv) {
00073 
00074     real m_bh = 0;
00075     int id = -1;    // most central particle is selected
00076 
00077     check_help();
00078 
00079     extern char *poptarg;
00080     int c;
00081     char* param_string = "i:M:";
00082 
00083     while ((c = pgetopt(argc, argv, param_string)) != -1)
00084         switch(c) {
00085             case 'M': m_bh = atof(poptarg);
00086                       break;
00087             case 'i': id = atoi(poptarg);
00088                       break;
00089             case '?': params_to_usage(cerr, argv[0], param_string);
00090                       exit(1);
00091         }
00092 
00093     dyn* b;
00094     b = get_dyn(cin);
00095     b->log_history(argc, argv);
00096 
00097     if (id>b->n_leaves())
00098       err_exit("selected id exceeds particle number");
00099 
00100     mkblack_hole(b, id, m_bh);
00101 
00102     real initial_mass = getrq(b->get_log_story(), "initial_mass");
00103 
00104     if (initial_mass > -VERY_LARGE_NUMBER)
00105         putrq(b->get_log_story(), "initial_mass", b->get_mass(),
00106               HIGH_PRECISION);
00107 
00108     real m_sum = b->get_mass();
00109     real old_mtot = b->get_starbase()->conv_m_dyn_to_star(1);
00110     if(old_mtot!=m_sum) {
00111         real old_r_vir= b->get_starbase()->conv_r_star_to_dyn(1);
00112         real old_t_vir= b->get_starbase()->conv_t_star_to_dyn(1);
00113         b->get_starbase()->set_stellar_evolution_scaling(m_sum,
00114                                                          old_r_vir,
00115                                                          old_t_vir);
00116     }
00117 
00118     put_dyn(cout, *b);
00119     rmtree(b);
00120 
00121 }
00122 #endif

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