Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

dbinev.C

Go to the documentation of this file.
00001 //
00002 //  mkdouble.C: construct a linked list of unit-mass nodes.
00003 //
00004 //             Simon Portegies Zwart, July 1996
00005 //
00006 
00007 #include "hdyn.h"
00008 #include "single_star.h"
00009 #include "main_sequence.h"
00010 #include "double_star.h"
00011 #include "sstar_to_dyn.h"
00012 #include "dstar_to_dyn.h"
00013 
00014 
00015 void add_secondary(dyn* original, real mass_ratio) {
00016 
00017     dyn* primary = new dyn;
00018     dyn* secondary = new dyn;
00019 
00020     // Add new links.
00021 
00022     original->set_oldest_daughter(primary);
00023 
00024     primary->set_parent(original);
00025     secondary->set_parent(original);
00026 
00027     primary->set_younger_sister(secondary);
00028     secondary->set_elder_sister(primary);
00029 
00030     // Set new masses.
00031 
00032     primary->set_mass(original->get_mass());
00033     secondary->set_mass(mass_ratio*original->get_mass());
00034     original->inc_mass(secondary->get_mass());
00035 
00036     // Naming convention:
00037 
00038     if (original->get_name() == NULL)
00039         if (original->get_index() >= 0) {
00040             char tmp[64];
00041             sprintf(tmp, "%d", original->get_index());
00042             original->set_name(tmp);
00043         }
00044 
00045     primary->set_name(original->get_name());
00046     secondary->set_name(original->get_name());
00047     strcat(primary->get_name(), "a");
00048     strcat(secondary->get_name(), "b");
00049 
00050    }
00051 
00052 void mksecondary(dyn* b, real binary_fraction, real lower_limit) {
00053 
00054     // For now, use a flat distribution in secondary mass ratio.
00055     // Assume that the probability of a star being the primary of
00056     // a binary is independent of mass.
00057 
00058     real sum = 0;
00059     b->set_mass(0);
00060 
00061     for_all_daughters(dyn, b, bi) {
00062         sum += binary_fraction;
00063         if (sum >= 1) {
00064             sum -= 1;
00065 
00066             real mass_ratio = randinter(lower_limit, 1);        // Quick fix...
00067             add_secondary(bi, mass_ratio);
00068 
00069         }
00070         b->inc_mass(bi->get_mass());
00071     }
00072 }
00073 
00074 local void  evolve_binary(dyn* the_binary, real end_time) {
00075 
00076       real time = 0;   
00077       real dt=0;
00078       if (!the_binary->is_root())
00079          if (the_binary->get_parent()->is_root()) {
00080              cerr<<"binary "<<the_binary<<endl;
00081              do {
00082                 dt = the_binary->get_starbase()->get_evolve_timestep();
00083                 time += max(0., min(end_time-time, dt));
00084                 cerr<<"dt, t= " << dt<<" " << time<<endl;
00085                 the_binary->get_starbase()->evolve_element(time);
00086              }
00087              while (time<end_time);
00088          }
00089    }
00090 
00091 local  bool  evolve_the_stellar_system(dyn* b, real time) {
00092 
00093       for_all_nodes(dyn, b, bi) {
00094          cerr<<bi<< " is_root?: "<<bi->is_root()<<endl;
00095          cerr<<bi<< " is_parent?: "<<bi->is_parent()<<endl;
00096          if (!bi->is_root())
00097             if (bi->get_parent()->is_root()) {
00098                 cerr<<"binary "<<bi<<endl;
00099                 bi->get_starbase()->evolve_element(time);
00100             }
00101 
00102      }
00103       return true;
00104    }
00105 
00106 void make_new_kepler_to_dyn(dyn* b, real m_total, real sma, real ecc,
00107                             int planar=0) {
00108 
00109      kepler *johannes = new kepler;
00110 
00111      real peri = 1; // Default value (unimportant unless ecc = 1).
00112 
00113      // For now, binary phase is random.
00114 
00115      real mean_anomaly = randinter(-PI, PI);
00116 
00117      make_standard_kepler(*johannes, 0, m_total, -0.5 * m_total / sma, ecc,
00118                           peri, mean_anomaly);
00119      set_random_orientation(*johannes, planar);
00120 
00121      b->set_kepler(johannes);
00122    }
00123 
00124 void main(int argc, char ** argv) {
00125 
00126     bool m_flag = false;
00127     bool c_flag = false;
00128 
00129     bool reandom_initialization = false;
00130     int  n = 1;
00131     int id=1;
00132     real m_tot=1,r_hm=1, t_hc=1;
00133     binary_type type = Detached;
00134     binary_type bin_type = Detached;
00135     real binary_fraction = 1.0;
00136 //              Initial conditions from Tutukov & Yunglesson 1993.
00137     real sma    = 138;
00138     real ecc    = 0.0;
00139     real m_prim = 13.1;
00140     real m_sec  =  9.8;
00141     real mass_ratio = 0.75;
00142     real lower_limit = 0.0;
00143     int random_seed = 0;
00144     char seedlog[64];
00145     real start_time = 0;
00146     real end_time   = 35;
00147     extern char *poptarg;
00148     int c;
00149     char* comment;
00150     char* param_string = "a:e:M:m:n:q:s:T:t:c:";
00151 
00152     while ((c = pgetopt(argc, argv, param_string)) != -1)
00153         switch(c) {
00154             case 'a': sma = atof(poptarg);
00155                       break;
00156             case 'e': ecc = atof(poptarg);
00157                       break;
00158             case 'M': m_prim = atof(poptarg);
00159                       break;
00160             case 'm': m_flag = true;
00161                       m_sec = atof(poptarg);
00162                       break;
00163             case 'n': n = atoi(poptarg);
00164                       break;
00165             case 'q': mass_ratio = atof(poptarg);
00166                       break;
00167             case 'T': end_time = atof(poptarg);
00168                       break;
00169             case 't': start_time = atof(poptarg);
00170                       break;
00171             case 's': random_seed = atoi(poptarg);
00172                       break;
00173             case 'c': c_flag = TRUE;
00174                       comment = poptarg;
00175                       break;
00176             case '?': params_to_usage(cerr, argv[0], param_string);
00177                       exit(1);
00178         }
00179 
00180     if (n <= 0) err_exit("mkdyn: N > 0 required!");
00181     int actual_seed = srandinter(random_seed);
00182     sprintf(seedlog, "       random number generator seed = %d",actual_seed);
00183 
00184     dyn *b;
00185 
00186     b = get_dyn(cin);
00187     if (c_flag == TRUE)
00188         b->log_comment(comment);
00189     b->log_history(argc, argv);
00190     b->get_starbase()->set_stellar_evolution_scaling(m_tot, r_hm, t_hc);
00191 
00192     adddouble(b, start_time, type);
00193 
00194     put_dyn(cout, *b);
00195 
00196     evolve_binary(b, end_time);
00197 
00198     put_dyn(cout, *b);
00199 }

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