00001 #include "SeBa_hist.h"
00002
00003 bool scenarios_identical(SeBa_hist* hi, SeBa_hist* ha) {
00004
00005 bool the_same = true;
00006 if(*hi->get_last() != *ha->get_last())
00007 the_same = false;
00008 else {
00009 SeBa_hist *SeBa_hist_hi, *SeBa_hist_hj;
00010 for (SeBa_hist_hi = hi->get_first(),
00011 SeBa_hist_hj = ha->get_first();
00012 (SeBa_hist_hi != NULL && SeBa_hist_hj != NULL);
00013 SeBa_hist_hi = SeBa_hist_hi->get_future(),
00014 SeBa_hist_hj = SeBa_hist_hj->get_future()) {
00015
00016 if(*SeBa_hist_hi != *SeBa_hist_hj)
00017 the_same = false;
00018
00019 }
00020 }
00021
00022 return the_same;
00023 }
00024
00025 bool SeBa_hist::operator == (SeBa_hist& ha) const {
00026
00027 bool the_same = false;
00028 if(bin_tpe == ha.get_binary_type()) {
00029 if(bin_tpe == Merged && tpe_prim == ha.get_primary_type()) {
00030
00031 the_same = true;
00032 }
00033 else if(tpe_prim == ha.get_primary_type() &&
00034 tpe_sec == ha.get_secondary_type()) {
00035
00036 the_same = true;
00037 }
00038 }
00039
00040 return the_same;
00041 }
00042
00043 bool SeBa_hist::operator != (SeBa_hist& ha) const {
00044
00045 bool different = true;
00046 if (*this == ha)
00047 different = false;
00048
00049 return different;
00050 }
00051
00052
00053 ostream& operator<<(ostream& s, SeBa_hist& hi) {
00054
00055 s << hi.number << " "<< hi.time;
00056
00057
00058 s << "\t" << hi.semi << " " << hi.ecc;
00059 s << "\t" << hi.label_prim << " " << hi.tpe_prim
00060
00061 << " " << hi.m_prim << " " << hi.r_prim;
00062 s << "\t" << hi.label_sec << " " << hi.tpe_sec
00063
00064 << " " << hi.m_sec << " " << hi.r_sec;
00065 s << endl;
00066
00067 return s;
00068
00069 }
00070
00071
00072 void SeBa_hist::put_history(ostream& s, bool verbose=false) {
00073
00074 if (verbose) {
00075 s << "\nnumber= " << number <<"\tTime= "<< time;
00076 s << "\t" << type_string(bin_tpe)
00077 << "\t a= " << semi << " e= " << ecc << endl;
00078 s << "\t" << type_string(tpe_prim)
00079 << "\tM= " << m_prim << " R= " << r_prim << endl;
00080 s << "\t" << type_string(tpe_sec)
00081 << "\tm= " << m_sec << " r= " << r_sec << endl;
00082 }
00083 else {
00084 s << *this;
00085 }
00086
00087 if (future!=NULL)
00088 future->put_history(s, verbose);
00089 }
00090
00091
00092 void SeBa_hist::put_single_reverse(ostream& s) {
00093
00094 s << number << " "<< time;
00095 s << "\t" << semi << " " << ecc;
00096 s << "\t" << label_sec << " " << tpe_sec << " "
00097
00098 << m_sec << " " << r_sec;
00099 s << "\t" << label_prim << " " <<tpe_prim << " "
00100
00101 << m_prim << " " << r_prim;
00102 s << endl;
00103 }
00104
00105 real SeBa_hist::get_parameter(binary_parameter param) {
00106
00107 switch(param) {
00108 case identity: return number;
00109 break;
00110 case bin_type: return bin_tpe;
00111 break;
00112 case current_time: return time;
00113 break;
00114 case primary_mass: return m_prim;
00115 break;
00116 case primary_radius: return r_prim;
00117 break;
00118 case secondary_mass: return m_sec;
00119 break;
00120 case secondary_radius: return r_sec;
00121 break;
00122 case semi_major_axis: return semi;
00123 break;
00124 case eccentricity: return ecc;
00125 break;
00126 case mass_ratio: return m_sec/m_prim;
00127 break;
00128 }
00129 }
00130
00131
00132 real SeBa_hist::set_stellar_radius(bool primary = true) {
00133
00134 real r = 1.e6;
00135 real q = m_prim/m_sec;
00136 real rl_r = r_prim;
00137 if (!primary) {
00138 rl_r = r_sec;
00139 q = 1/q;
00140 }
00141
00142 if (rl_r >= 0) {
00143 real q1_3 = pow(q, cnsts.mathematics(one_third));
00144 real q2_3 = pow(q1_3, 2);
00145
00146 r = semi*0.49*q2_3/(0.6*q2_3 + log(1 + q1_3)) - rl_r;
00147 }
00148
00149 return r;
00150 }
00151
00152 bool SeBa_hist::read_SeBa_hist(istream& s) {
00153
00154 int tpe_1, tpe_2;
00155
00156 s >> number >> time
00157 >> semi >> ecc
00158
00159
00160 >> label_prim >> tpe_1 >> m_prim >> r_prim
00161 >> label_sec >> tpe_2 >> m_sec >> r_sec;
00162
00163 if(s.eof()) return false;
00164
00165
00166 tpe_prim = (stellar_type)tpe_1;
00167 tpe_sec = (stellar_type)tpe_2;
00168
00169
00170
00171
00172
00173
00174 if (ecc>=1) {
00175 bin_tpe = Disrupted;
00176 }
00177 else if (semi<=0) {
00178 bin_tpe = Merged;
00179 if(m_prim<=0) {
00180 m_prim = m_sec;
00181 tpe_prim = tpe_sec;
00182 r_prim = r_sec;
00183 }
00184 }
00185 else if (r_prim<=0 && r_sec<=0 && semi<100000)
00186 bin_tpe = Contact;
00187 else if(r_prim<=0 || r_sec<=0 && semi<100000)
00188 bin_tpe = Semi_Detached;
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 return true;
00199
00200 }
00201
00202 void SeBa_hist::move_SeBa_hist_to(SeBa_hist *next_hi) {
00203
00204 next_hi = this;
00205 next_hi->future = NULL;
00206 next_hi->past = NULL;
00207 }
00208
00209 bool SeBa_hist::binary_contains(char *prim_string,
00210 char *sec_string,
00211 binary_type bt = Detached) {
00212
00213
00214 if (bin_tpe== bt &&
00215 (!strcmp(prim_string, type_string(tpe_prim)) ||
00216 !strcmp(prim_string, type_short_string(tpe_prim)) ||
00217 !strcmp(prim_string, type_string(summarize_stellar_type(tpe_prim))) ||
00218 !strcmp(prim_string, "any"))
00219 &&
00220 (!strcmp(sec_string, type_string(tpe_sec)) ||
00221 !strcmp(sec_string, type_short_string(tpe_sec)) ||
00222 !strcmp(sec_string, type_string(summarize_stellar_type(tpe_sec))) ||
00223 !strcmp(sec_string, "any"))) {
00224
00225 return true;
00226 }
00227
00228 #if 0
00229 PRC(number);
00230 PRC(prim_string);PRL(type_string(tpe_prim));
00231 PRC(!strcmp(prim_string, type_string(tpe_prim)));
00232 PRC(!strcmp(prim_string, type_short_string(tpe_prim)));
00233 PRL(!strcmp(prim_string, type_string(summarize_stellar_type(tpe_prim))));
00234
00235 PRC(sec_string);PRL(type_string(tpe_sec));
00236 PRC(!strcmp(sec_string, type_string(tpe_sec)));
00237 PRC(!strcmp(sec_string, type_short_string(tpe_sec)));
00238 PRL(!strcmp(sec_string, type_string(summarize_stellar_type(tpe_sec))));
00239 #endif
00240
00241 return false;
00242
00243 }
00244
00245 void SeBa_hist::put_first_formed_left(char *string_type, real dt) {
00246
00247
00248
00249 for_all_SeBa_hist(SeBa_hist, get_first(), hi) {
00250
00251
00252
00253
00254 if (!strcmp(string_type, type_string(hi->tpe_prim)) ||
00255 !strcmp(string_type, type_short_string(hi->tpe_prim)) ||
00256 !strcmp(string_type,
00257 type_string(summarize_stellar_type(hi->tpe_prim)))) {
00258
00259 if ((get_time() - hi->get_time()) < dt) {
00260 cout << *get_first();
00261 cout << *this;
00262 }
00263 break;
00264 }
00265 else if (!strcmp(string_type, type_string(hi->tpe_sec)) ||
00266 !strcmp(string_type, type_short_string(hi->tpe_sec)) ||
00267 !strcmp(string_type,
00268 type_string(summarize_stellar_type(hi->tpe_sec))) &&
00269 ((get_time() - hi->get_time()) < dt)) {
00270
00271 if ((get_time() - hi->get_time()) < dt) {
00272 get_first()->put_single_reverse(cout);
00273 put_single_reverse(cout);
00274 }
00275 break;
00276 }
00277 }
00278
00279 }
00280
00281 bool SeBa_hist::binary_limits(binary_parameter param,
00282 real lower, real upper) {
00283
00284
00285 if (get_parameter(param) >= lower &&
00286 get_parameter(param) < upper)
00287 return true;
00288
00289 return false;
00290
00291 }
00292
00293 SeBa_hist* SeBa_hist::get_SeBa_hist_at_time(real snap_time) {
00294
00295 if (snap_time>get_last()->get_time())
00296 return NULL;
00297
00298 for_all_SeBa_hist(SeBa_hist, get_future(), hi) {
00299 if (hi->get_past()->get_time()<= snap_time &&
00300 snap_time<hi->get_time()) {
00301 return hi->get_past();
00302 }
00303 }
00304
00305 err_exit("SeBa_hist::SeBa_hist_at_time(real time): time not found");
00306 }
00307
00308
00309 SeBa_hist* get_history(SeBa_hist *hi, istream& is) {
00310
00311 while (hi->get_number()==hi->get_last()->get_number()) {
00312
00313 if (is.eof())
00314 return NULL;
00315
00316 new SeBa_hist(hi->get_last());
00317
00318 hi->get_last()->read_SeBa_hist(is);
00319
00320 };
00321
00322 SeBa_hist *next_hi;
00323
00324 next_hi = hi->get_last();
00325 next_hi->get_past()->set_future(NULL);
00326 next_hi->set_past(NULL);
00327
00328 return next_hi;
00329
00330 }
00331
00332 void SeBa_hist::add_to_SeBa_hist(SeBa_hist *next_hi) {
00333
00334 cerr << "add: ";
00335 next_hi->put_state(cerr);
00336 cerr << "\nto ";
00337 put_state(cerr);
00338 cerr << endl;
00339
00340 SeBa_hist *last = get_last();
00341 last->set_future(next_hi);
00342 next_hi->set_past(last);
00343 }
00344
00345
00346
00347
00348
00349
00350 void SeBa_hist::put_state(ostream & s) {
00351
00352 switch (bin_tpe) {
00353 case Merged:
00354 s << "{" << type_short_string(tpe_prim) << "}";
00355 break;
00356 case Disrupted:
00357 s << ")";
00358 s << type_short_string(tpe_prim) << ",";
00359 s << type_short_string(tpe_sec);
00360 s << "(";
00361 break;
00362 case Detached:
00363 s << "(";
00364 s << type_short_string(tpe_prim) << ",";
00365 s << type_short_string(tpe_sec);
00366 s << ")";
00367 break;
00368 case Contact:
00369 s << "[";
00370 s << type_short_string(tpe_prim) << ",";
00371 s << type_short_string(tpe_sec);
00372 s << "]";
00373 break;
00374 case Semi_Detached:
00375 if (r_prim<=0 && semi<100000) {
00376 s << "[";
00377 s << type_short_string(tpe_prim) << ",";
00378 s << type_short_string(tpe_sec);
00379 s << ")";
00380 }
00381 else {
00382 s << "(";
00383 s << type_short_string(tpe_prim) << ",";
00384 s << type_short_string(tpe_sec);
00385 s << "]";
00386 }
00387 break;
00388 default:
00389 cerr << "Unknown binary type in SeBa_hist->put_state() "<< endl;
00390 }
00391 s << ";";
00392 }
00393
00394 void put_state(SeBa_hist * hi, ostream & s) {
00395
00396 for_all_SeBa_hist(SeBa_hist, hi, ha) {
00397 ha->put_state(s);
00398 }
00399
00400 s << endl;
00401 }
00402