Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

makedouble.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 "node.h"
00008 #include "double_star.h"
00009 #include "main_sequence.h"
00010 #include "dstar_to_dyn.h"
00011 
00012 #ifndef TOOLBOX
00013 
00014 void add_secondary(node* original, real mass_ratio) {
00015 
00016     node* primary = new node;
00017     node* secondary = new node;
00018 
00019     // Add new links.
00020 
00021     original->set_oldest_daughter(primary);
00022 
00023     primary->set_parent(original);
00024     secondary->set_parent(original);
00025 
00026     primary->set_younger_sister(secondary);
00027     secondary->set_elder_sister(primary);
00028 
00029     // Set new masses.
00030 
00031     primary->set_mass(original->get_mass());
00032     secondary->set_mass(mass_ratio*original->get_mass());
00033     original->inc_mass(secondary->get_mass());
00034 
00035     // Naming convention:
00036 
00037     if (original->get_name() == NULL)
00038         if (original->get_index() >= 0) {
00039             char tmp[64];
00040             sprintf(tmp, "%d", original->get_index());
00041             original->set_name(tmp);
00042         }
00043 
00044     primary->set_name(original->get_name());
00045     secondary->set_name(original->get_name());
00046     strcat(primary->get_name(), "a");
00047     strcat(secondary->get_name(), "b");
00048 
00049    }
00050 
00051 void mksecondary(node* b, real binary_fraction, real lower_limit) {
00052 
00053     // For now, use a flat distribution in secondary mass ratio.
00054     // Assume that the probability of a star being the primary of
00055     // a binary is independent of mass.
00056 
00057     real sum = 0;
00058     b->set_mass(0);
00059 
00060     for_all_daughters(node, b, bi) {
00061         sum += binary_fraction;
00062         if (sum >= 1) {
00063             sum -= 1;
00064 
00065             real mass_ratio = randinter(lower_limit, 1);        // Quick fix...
00066             add_secondary(bi, mass_ratio);
00067 
00068         }
00069         b->inc_mass(bi->get_mass());
00070     }
00071 }
00072 
00073 #else
00074 
00075 local void  evolve_the_stellar_system(node* b, real time) {
00076 
00077       for_all_nodes(node, b, bi) {
00078          cerr<<bi<< " is_root?: "<<bi->is_root()<<endl;
00079          cerr<<bi<< " is_parent?: "<<bi->is_parent()<<endl;
00080          if (!bi->is_root())
00081             if (bi->get_parent()->is_root()) {
00082                 cerr<<"binary "<<bi<<endl;
00083                 bi->get_starbase()->evolve_element(time);
00084             }
00085          
00086       }
00087    }
00088 
00089 void main(int argc, char ** argv) {
00090 
00091     bool A_flag = false;
00092     bool a_flag = false;
00093     bool E_flag = false;
00094     bool e_flag = false;
00095     bool reandom_initialization = false;
00096     int  n = 1;
00097 
00098     int id=1;
00099     real a_min = 1;
00100     real a_max = 1.e+6;
00101     real e_min = 0;
00102     real e_max = 1;
00103     real m_tot=1,r_hm=1, t_hc=1;
00104     stellar_type type = Main_Sequence;
00105     binary_type bin_type = Detached;
00106     real binary_fraction = 1.0;
00107     real lower_limit = 0.0;
00108     int random_seed = 0;
00109     char seedlog[64];
00110     real t_start = 0;
00111     real t_end   = 100;
00112     extern char *poptarg;
00113     int c;
00114     char* param_string = "A:a:E:e:f:l:M:n:R:S:s:T:t:";
00115 
00116     while ((c = pgetopt(argc, argv, param_string)) != -1)
00117         switch(c) {
00118             case 'A': A_flag = true;
00119                       a_max = atof(poptarg);
00120                       break;
00121             case 'a': a_flag = true;
00122                       a_min = atof(poptarg);
00123                       break;
00124             case 'E': E_flag = true;
00125                       e_max = atof(poptarg);
00126                       break;
00127             case 'e': e_flag = true;
00128                       a_min = atof(poptarg);
00129                       break;
00130             case 'M': m_tot = atof(poptarg);
00131                       break;
00132             case 'n': n = atoi(poptarg);
00133                       break;
00134             case 'r': r_hm = atof(poptarg);
00135                       break;
00136             case 't': t_hc = atof(poptarg);
00137                       break;
00138             case 'T': t_end = atof(poptarg);
00139                       break;
00140             case 'S': type = (stellar_type)atoi(poptarg);
00141                       break;
00142             case 'f': binary_fraction = atof(poptarg);
00143                       break;
00144             case 'l': lower_limit = atof(poptarg);
00145                       break;
00146             case 's': random_seed = atoi(poptarg);
00147                       break;
00148             case '?': params_to_usage(cerr, argv[0], param_string);
00149                       exit(1);
00150         }
00151 
00152     if (n <= 0) err_exit("mknodes: N > 0 required!");
00153     int actual_seed = srandinter(random_seed);
00154     sprintf(seedlog, "       random number generator seed = %d",actual_seed);
00155 
00156     if (A_flag || a_flag || E_flag || E_flag)
00157        reandom_initialization = true;
00158 
00159     // Create flat tree 
00160 //    node *root  = mkstar(n, t_start, type, mf);
00161     node *root  = mknode(n);
00162     root->log_history(argc, argv);
00163     root->log_comment(seedlog);
00164     root->get_starbase()->set_stellar_evolution_scaling(m_tot, r_hm, t_hc);
00165     mksecondary(root, binary_fraction, lower_limit);
00166     addstar(root, t_start, type);
00167 
00168     cerr<<"calling adddouble...\n";
00169     adddouble(root, t_start, bin_type, reandom_initialization, 
00170               a_min, a_max, e_min, e_max);
00171 
00172     put_node(cout, *root);
00173 //      Test pointer structure
00174     cerr<<"est pointer structure"<<endl;
00175     node *b = root->get_oldest_daughter();
00176     starbase *s = b->get_starbase();
00177     star *st     = (star*)b->get_starbase();
00178     cerr<<"binary+s:" << b<<" "<<s<<" " <<st<<endl;
00179     cerr<<"a e m"<<s->get_effective_radius() <<" "
00180                <<s->get_total_mass()<<endl;
00181     cerr<<"p, s"<< st->get_primary()<<" "<<st->get_secondary() <<endl;
00182     cerr<<"M R, m r"<<st->get_primary()->get_total_mass() << " " 
00183                 <<st->get_primary()->get_effective_radius() << " "
00184                 <<st->get_secondary()->get_total_mass() << " " 
00185                 <<st->get_secondary()->get_effective_radius()<< endl;
00186     cerr<<"companion p, s: "<< 
00187          st->get_secondary()->get_companion()<<" " 
00188        <<st->get_primary()->get_companion()<<endl;
00189    cerr<<"companion p, s: "<<st->get_companion(st->get_secondary())<<" "
00190                            <<st->get_companion(st->get_primary())<< endl; 
00191    
00192     evolve_the_stellar_system(root, t_end);
00193     put_node(cout, *root);
00194 }
00195 
00196 #endif
00197 
00198 /* end of: mkbinaries.c */

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