00001 #include "dstar_to_dyn.h"
00002 #include "double_star.h"
00003 #include "dyn.h"
00004
00005 #ifndef TOOLBOX
00006
00007
00008
00009 void print_binary_dstars(dyn* bi) {
00010
00011
00012
00013 if (bi->n_leaves() == 2) {
00014 double_state bst = make_state(bi);
00015 if(bst.type != Unknown_Binary_Type) {
00016 cerr << " ";
00017 put_state(bst);
00018 }
00019 }
00020 }
00021
00022 double_state make_state(dyn* b) {
00023
00024 double_state bst;
00025
00026
00027
00028
00029
00030
00031 if (has_dstar(b->get_oldest_daughter())) {
00032 bst = make_state(dynamic_cast(double_star*,
00033 b->get_starbase()));
00034 }
00035 else if (b->get_oldest_daughter()->get_star_story()!=NULL &&
00036 b->get_oldest_daughter()->get_binary_sister()
00037 ->get_star_story()!=NULL) {
00038
00039
00040
00041 dyn *bi = b->get_oldest_daughter();
00042 dyn *bj = b->get_oldest_daughter()->get_binary_sister();
00043 real M = bi->get_mass() + bj->get_mass();
00044 vector dx = bj->get_pos() - bi->get_pos();
00045 vector dv = bj->get_vel() - bi->get_vel();
00046 real mu = (bi->get_mass() * bj->get_mass()) / M;
00047 real E = mu*(0.5*dv*dv - M / abs(dx));
00048
00049 kepler k;
00050 k.set_time(0);
00051 k.set_total_mass(M);
00052 k.set_rel_pos(dx);
00053 k.set_rel_vel(dv);
00054
00055 k.set_circular_binary_limit(MAX_CIRC_ECC);
00056
00057 k.initialize_from_pos_and_vel(true, false);
00058
00059 real time = b->get_system_time();
00060 if (time > -VERY_LARGE_NUMBER)
00061 time = b->get_starbase()->conv_t_dyn_to_star(time);
00062 else
00063 time = 0;
00064 real sma = b->get_starbase()->
00065 conv_r_dyn_to_star(k.get_semi_major_axis());
00066 real ecc = k.get_eccentricity();
00067 real sma_c = sma*(1-pow(ecc, 2));
00068
00069 dyn *pi=bi;
00070 dyn *si=bj;
00071 if (si->get_mass() > pi->get_mass()) {
00072 pi = bj;
00073 si = bi;
00074 }
00075 real q = si->get_mass()/pi->get_mass();
00076 real Rl1 = 0.46*sma_c/pow(1+q, cnsts.mathematics(one_third));
00077 real Rl2 = 0.46*sma_c*pow(q/(1+q), cnsts.mathematics(one_third));
00078
00079 star_state primary = make_star_state(pi);
00080 star_state secondary= make_star_state(si);
00081
00082 binary_type type = Detached;
00083
00084 if(ecc==0) type = Synchronized;
00085
00086 if (primary.radius>=Rl1) {
00087 primary.class_spec[Rl_filling] = 1;
00088 type = Semi_Detached;
00089 }
00090 if(secondary.radius>=Rl2) {
00091 secondary.class_spec[Rl_filling] = 1;
00092 if(!primary.class_spec[Rl_filling])
00093 type = Semi_Detached;
00094 else
00095 type = Contact;
00096 }
00097
00098 bst.identity = b->get_index();
00099 bst.time = time;
00100 bst.type = type;
00101 bst.semi = sma;
00102 bst.ecc = ecc;
00103 bst.velocity = 0;
00104 bst.total_mass = primary.mass + secondary.mass;
00105
00106 bst.primary = primary;
00107 bst.secondary = secondary;
00108
00109 }
00110 else {
00111
00112 b->pretty_print_node(cerr);
00113 return bst;
00114 }
00115
00116 return bst;
00117 }
00118
00119 #else
00120
00121
00122 main() {
00123 cerr <<"Hello"<<endl;
00124 }
00125
00126
00127 #endif
00128