00001
00002
00003
00004
00005 #include "proto_star.h"
00006 #include "dyn.h"
00007 #include "kepler.h"
00008
00009 local void add_secondary(dyn* original, real mass_ratio)
00010 {
00011 dyn* primary = new dyn;
00012 dyn* secondary = new dyn;
00013
00014
00015
00016 original->set_oldest_daughter(primary);
00017
00018 primary->set_parent(original);
00019 secondary->set_parent(original);
00020
00021 primary->set_younger_sister(secondary);
00022 secondary->set_elder_sister(primary);
00023
00024
00025
00026 primary->set_mass(original->get_mass());
00027 secondary->set_mass(mass_ratio*original->get_mass());
00028 original->inc_mass(secondary->get_mass());
00029
00030
00031
00032 if (original->get_name() == NULL)
00033 if (original->get_index() >= 0) {
00034 char tmp[64];
00035 sprintf(tmp, "%d", original->get_index());
00036 original->set_name(tmp);
00037 }
00038
00039 if (original->get_name() != NULL) {
00040
00041
00042
00043 primary->set_name(original->get_name());
00044 secondary->set_name(original->get_name());
00045 strcat(primary->get_name(), "a");
00046 strcat(secondary->get_name(), "b");
00047
00048
00049
00050 char tmp[256];
00051 sprintf(tmp, "(%s,%s)", primary->get_name(), secondary->get_name());
00052 original->set_name(tmp);
00053 }
00054 }
00055
00056 #if 0
00057
00058 local void set_kepler_orientation_from_aml(kepler *k,
00059 vector angular_momentum) {
00060
00061
00062 vector n = angular_momentum/abs(angular_momentum);
00063
00064 vector temp = vector(1, 0, 0);
00065 if (abs(n[0]) > .5) temp = vector(0, 1, 0);
00066 if (n[2] < 0) temp = -temp;
00067
00068 vector b = n ^ temp;
00069 b /= abs(b);
00070 vector a = b ^ n;
00071 if (n[2] < 0) a = -a;
00072
00073
00074
00075
00076 vector l = cos(psi)*a + sin(psi)*b;
00077 vector t = n ^ l;
00078
00079 k.set_orientation(l, t, n);
00080 }
00081 #endif
00082
00083 local void add_dynamics(dyn* cm, real ecc, real energy)
00084
00085 {
00086 dyn* primary = cm->get_oldest_daughter();
00087 dyn* secondary = primary->get_younger_sister();
00088
00089 real m_total = cm->get_mass();
00090 real m1 = primary->get_mass();
00091 real m2 = secondary->get_mass();
00092
00093 PRC(m_total);PRC(m1);PRL(m2);
00094
00095
00096
00097 kepler k;
00098
00099 real peri = 1;
00100 if (ecc == 1) peri = 0;
00101
00102
00103
00104 real mean_anomaly = randinter(-PI, PI);
00105
00106
00107
00108
00109 energy = -energy;
00110
00111 make_standard_kepler(k, 0, m_total, energy, ecc,
00112 peri, mean_anomaly);
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 int planar = 0;
00124 set_random_orientation(k, planar);
00125
00126 k.initialize_from_shape_and_phase();
00127
00128 k.print_elements(cerr);
00129
00130
00131
00132 primary->set_pos(-m2 * k.get_rel_pos() / m_total);
00133 primary->set_vel(-m2 * k.get_rel_vel() / m_total);
00134
00135 cerr << primary->get_pos() << endl;
00136 cerr << primary->get_vel() << endl;
00137
00138 secondary->set_pos(m1 * k.get_rel_pos() / m_total);
00139 secondary->set_vel(m1 * k.get_rel_vel() / m_total);
00140
00141 cerr << secondary->get_pos() << endl;
00142 cerr << secondary->get_vel() << endl;
00143 }
00144
00145 void proto_star::create_binary_from_proto_star() {
00146
00147
00148
00149
00150
00151 real m_tot = core_mass;
00152 real q = randinter(0, 1);
00153 real mprim = m_tot/(1+q);
00154 real msec = mprim*q;
00155
00156
00157
00158 real am = 1;
00159
00160
00161 real a_min = pow(am, 2)/m_tot;
00162 real two_r = 2*core_radius;
00163 real ecc_min = max(0., 1 - pow(am/(two_r*m_tot), 2));
00164 real ecc_max = min(1., 1 - two_r/a_min);
00165
00166
00167
00168
00169
00170 PRC(am);PRC(q);PRC(mprim);PRC(msec);PRC(a_min);PRL(two_r);
00171 PRC(ecc_min);PRL(ecc_max);
00172
00173
00174
00175
00176 star_transformation_story(Main_Sequence);
00177 new main_sequence(*this);
00178 return;
00179
00180
00181 star_transformation_story(Double);
00182
00183
00184 ecc_min = sqrt(ecc_min);
00185
00186 real ecc = sqrt(randinter(ecc_min, ecc_max));
00187 real sma = pow(am, 2) / (m_tot*(1-pow(ecc, 2)));
00188 real energy = 0.5 * (mprim+msec) / sma;
00189
00190 dump(cerr, false);
00191 PRC(ecc);PRC(sma);PRL(energy);
00192
00193 relative_mass = mprim;
00194 get_node()->set_mass(conv_m_star_to_dyn(mprim));
00195
00196 add_secondary(dynamic_cast(dyn*, get_node()), q);
00197 cerr << "Secondary added"<<endl;
00198
00199 addstar(((dyn*)get_node())->get_parent(), 0., Main_Sequence);
00200 cerr << "star added"<<endl;
00201
00202 add_dynamics(dynamic_cast(dyn*, get_node()->get_parent()),
00203 ecc, energy);
00204
00205 cerr << "dynamics double created" << endl;
00206
00207 for_all_leaves(dyn, ((dyn*)get_node())->get_root(), si) {
00208 cerr << si->format_label() << " ";
00209 PRL(si->get_starbase()->get_element_type());
00210 cerr << "pos: " << si->get_pos() << endl;
00211 }
00212 }
00213
00214
00215
00216
00217
00218