Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

binev.C

Go to the documentation of this file.
00001 //
00002 //  binev.C: evolves a single binary borrowing the tree structure from node 
00003 //
00004 //             Simon Portegies Zwart, Nov 1996
00005 //
00006 
00007 #include "node.h"
00008 #include "double_star.h"
00009 #include "main_sequence.h"
00010 //#include "dstar_to_dyn.h"
00011 
00012 #ifdef TOOLBOX
00013 
00014 local void  evolve_binary(node* the_binary, real end_time, int n_step) {
00015 
00016       real time = 0;   
00017       real dt=0;
00018       double_star* bin_star = dynamic_cast(double_star*, 
00019                                            the_binary->get_starbase());
00020         bin_star->dump(cerr);
00021         cerr<<"time = "<<time<<endl;
00022         bin_star->put_state();
00023         cerr << "Porb = " << bin_star->get_period() << endl;
00024 
00025         real dt_min = end_time/(real)n_step;
00026         
00027       if (!the_binary->is_root())
00028          if (the_binary->get_parent()->is_root()) {
00029              cerr<<"binary "<<the_binary<<endl;
00030              do {
00031                 dt = min(dt_min,
00032                          the_binary->get_starbase()->get_evolve_timestep());
00033                 time += max(0., min(end_time-time, dt));
00034                 cerr<<"dt, t= " << dt<<" " << time<<endl;
00035                 the_binary->get_starbase()->evolve_element(time);
00036                 //the_binary->get_starbase()->dump(cerr);
00037                 bin_star->dump(cerr);
00038                 cerr<<"time = "<<time<<endl;
00039                 bin_star->put_state();
00040                 cerr << "Porb = " << bin_star->get_period() << endl;
00041             }
00042              while (time<end_time);
00043              // perform evolution until exact end_time.
00044              bin_star->evolve_the_binary(end_time);
00045 
00046          }
00047    }
00048 
00049 void main(int argc, char ** argv) {
00050 
00051     bool m_flag = false;
00052     bool P_flag = false;
00053     int  n = 1;
00054     int id=1;
00055     stellar_type type = Main_Sequence;
00056     binary_type bin_type = Detached;
00057     real binary_fraction = 1.0;
00058 //              Initial conditions from Tutukov & Yunglesson 1993.
00059     real m_tot = 1;
00060     real r_hm = 1;
00061     real t_hc = 1;;
00062     real sma    = 138;
00063     real period = 39.3; // days.
00064     real ecc    = 0.0;
00065     real m_prim = 13.1;
00066     real m_sec  =  9.8;
00067     real mass_ratio = 0.75;
00068     real lower_limit = 0.0;
00069     int random_seed = 0;
00070     char seedlog[64];
00071     real start_time = 0;
00072     real end_time   = 35;
00073     extern char *poptarg;
00074     int c;
00075     char* param_string = "a:P:e:M:m:n:q:s:T:R:";
00076 
00077     while ((c = pgetopt(argc, argv, param_string)) != -1)
00078         switch(c) {
00079             case 'a': sma = atof(poptarg);
00080                       break;
00081             case 'P': P_flag = true;
00082                       period = atof(poptarg);
00083                       break;
00084             case 'e': ecc = atof(poptarg);
00085                       break;
00086             case 'M': m_prim = atof(poptarg);
00087                       break;
00088             case 'm': m_flag = true;
00089                       m_sec = atof(poptarg);
00090                       break;
00091             case 'n': n = atoi(poptarg);
00092                       break;
00093             case 'q': mass_ratio = atof(poptarg);
00094                       break;
00095             case 'R': r_hm = atof(poptarg);
00096                       break;
00097             case 'T': end_time = atof(poptarg);
00098                       break;
00099             case 's': random_seed = atoi(poptarg);
00100                       break;
00101             case '?': params_to_usage(cerr, argv[0], param_string);
00102                       exit(1);
00103         }
00104 
00105     int actual_seed = srandinter(random_seed);
00106     sprintf(seedlog, "       random number generator seed = %d",actual_seed);
00107 
00108     if (m_flag) 
00109        mass_ratio = m_sec / m_prim;
00110     else
00111        m_sec = mass_ratio*m_prim;
00112     m_tot = m_prim;// + m_sec;
00113 
00114     if (P_flag)
00115       sma = period_to_semi(period, m_prim, m_sec);
00116     
00117     cerr.precision(INT_PRECISION);
00118     // Create flat tree 
00119     node *root  = mknode(1);
00120     root->log_history(argc, argv);
00121     root->log_comment(seedlog);
00122     root->get_starbase()->set_stellar_evolution_scaling(m_tot, r_hm, t_hc);
00123 
00124     node* the_binary = root->get_oldest_daughter();
00125 
00126 //              Add the stars and secondary.
00127     add_secondary(the_binary, mass_ratio);
00128 
00129     int i = 0;
00130     for_all_leaves(node, the_binary, bi)
00131       bi->set_index(i++);
00132                   
00133     addstar(root, start_time, type);
00134     double_star* new_double = 
00135                  new_double_star(the_binary, sma, ecc, 
00136                                  start_time, id, bin_type);
00137 
00138     root->get_starbase()->set_use_hdyn(false);
00139     put_node(cout, *root);
00140 
00141 //      Test pointer structure
00142     node *b = root->get_oldest_daughter();
00143     starbase *s = b->get_starbase();
00144     star *st     = (star*)b->get_starbase();
00145    
00146     evolve_binary(the_binary, end_time, n);
00147     double_star* bin_star = dynamic_cast(double_star*, 
00148                                          the_binary->get_starbase());
00149     bin_star->dump(cerr);
00150     put_node(cout, *root);
00151 }
00152 
00153 #endif

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