Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

dstar_to_kira.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00011 // dstar_to_kira.C 
00012 //
00013 // Set of dstar functions referenced by dstar_kira (and associated
00014 // hdyn functions).
00015 //
00016 // Externally visible functions:
00017 //
00018 //      bool create_or_delete_binary
00019 //      bool binary_is_merged
00020 //      bool binary_evolution
00021 //      void update_kepler_from_binary_evolution
00022 //
00023 // An interesting mixture of dyn.h and hdyn.h references!
00024 //
00025 // SPZ+SMcM July 1998
00026 //
00027 // Globally visible functions:
00028 //
00029 //      binary_is_merged                bool function
00030 //      create_or_delete_binary         switch:  calls adddouble
00031 //                                               or delete_double
00032 //                                      called from:
00033 //                                          binary_evolution (this file)
00034 //                                          integrate_unperturbed_motion
00035 //                                                      (hdyn_unpert.C)
00036 //                                          dissociate_binary
00037 //                                                      (kira_stellar.C)
00038 //      binary_evolution                evolve a binary node
00039 //                                      called from evolve_stars
00040 //                                                      (kira_stellar.C)
00041 //      update_kepler_from_binary_evolution     what it says...
00042 //
00043 // Local functions:
00044 //
00045 //      need_dstar
00046 //      binary_wants_to_be_updated
00047 //      evolve_an_unperturbed_binary    called by delete_double and
00048 //                                      binary_evolution
00049 //      initial_binary_period
00050 //      delete_double
00051 //      delete_double                   delete double_star part of a node
00052 //                                      called by create_or_delete_binary
00053 //
00054 // Functions delete_double() and binary_evolution() use the function
00055 // hdyn::merge_nodes().  This may be OK because the only way to get to
00056 // the reference in this file is via a call that originated in kira.
00057 
00058 #include "dstar_to_kira.h"
00059 
00060 #define REPORT_ADD_DOUBLE        false
00061 #define REPORT_DEL_DOUBLE        false
00062 #define REPORT_EVOLVE_DOUBLE     false
00063 
00064 local bool need_dstar(hdyn* bi)
00065 {
00066     if (bi->is_low_level_node() && (bi->get_elder_sister() == NULL)
00067         && (bi->get_kepler() != NULL) && bi->get_fully_unperturbed()) {
00068         return true;
00069     } else {
00070         return false;
00071     }
00072 }
00073 
00074 // safety function, but not used in practice.
00075 bool other_urgent_binary_matters(hdyn *bi)              // bi is binary CM
00076 {
00077     bool update_binary = false;
00078      
00079     starbase *cm = bi->get_starbase();
00080     starbase *ps = ((star*)cm)->get_primary();
00081     starbase *ss = ((star*)cm)->get_secondary();
00082 
00083     real pericenter = cm->get_semi()*(1-cm->get_eccentricity());
00084 
00085     real rp = ps->get_effective_radius();
00086     real rs = ss->get_effective_radius();
00087 
00088     if(pericenter <= rp * cnsts.parameters(tidal_circularization_radius) ||
00089        pericenter <= rs * cnsts.parameters(tidal_circularization_radius)) {
00090 
00091       update_binary = true;
00092     }
00093    
00094     return update_binary;
00095 }
00096 
00097 
00098 local bool binary_wants_to_be_updated(hdyn *b)          // b is binary CM
00099 {
00100     bool update_binary = false;
00101      
00102     hdyn* od = b->get_oldest_daughter();
00103     real stellar_time = b->get_starbase()
00104                          ->conv_t_dyn_to_star(od->get_time());
00105                                       // 3/99 was get_system_time()
00106     real current_age  = b->get_starbase()->get_current_time();
00107     real dt_max       = b->get_starbase()->get_evolve_timestep();
00108 
00109     //if (stellar_time >= current_age + dt_max)
00110     if (stellar_time >= current_age 
00111                       + cnsts.star_to_dyn(binary_update_time_fraction)*dt_max)
00112         update_binary = true;
00113 
00114 //    (SPZ: 21 Mar 2001) safety switched off.
00115 //    if(other_urgent_binary_matters(b))
00116 //      update_binary = true;
00117 
00118     return update_binary;
00119 }
00120 
00121 local void evolve_an_unperturbed_binary(hdyn *bi,       // bi is binary CM
00122                                         bool& check_binary_mass,
00123                                         bool& check_binary_sma,
00124                                         bool& check_binary_merger,
00125                                         bool force_evolve=false)
00126 { 
00127     check_binary_mass = check_binary_sma = check_binary_merger = false;
00128 
00129     real old_dyn_mass, old_dyn_sma;
00130     real new_dyn_mass_from_star, new_dyn_sma_from_star;
00131 
00132     hdyn* od = bi->get_oldest_daughter();
00133     real stellar_evolution_time = bi->get_starbase()
00134                                     ->conv_t_dyn_to_star(od->get_time());
00135                                                  // 3/99 was get_system_time()
00136 
00137     kepler * p_kep = od->get_kepler();
00138     old_dyn_mass = bi->get_mass();
00139     old_dyn_sma  = p_kep->get_semi_major_axis();
00140 
00141     if (REPORT_EVOLVE_DOUBLE) {
00142         cerr << "Before evolution:"
00143              << " sma= " << bi->get_starbase()->get_semi()
00144              << " ecc= " << bi->get_starbase()->get_eccentricity() 
00145              << " Time = "<<stellar_evolution_time <<"      ";
00146         put_state(make_state(dynamic_cast(double_star*, bi->get_starbase())));
00147         cerr << endl;
00148         ((double_star*) (bi->get_starbase()))->dump(cerr);
00149         cerr << endl;
00150     }
00151 
00152     if (!force_evolve) {
00153         if (binary_wants_to_be_updated(bi)) 
00154             bi->get_starbase()->evolve_element(stellar_evolution_time);
00155         else
00156             ((double_star*)(bi->get_starbase()))->try_zero_timestep();
00157     }
00158     else 
00159         bi->get_starbase()->evolve_element(stellar_evolution_time);
00160       
00161     new_dyn_mass_from_star = get_total_mass(bi);
00162     new_dyn_sma_from_star = bi->get_starbase()->
00163                             conv_r_star_to_dyn(bi->get_starbase()->get_semi());
00164 
00165     // Relative position and velocity should be changed also
00166     // for the upper parent nodes!!!
00167 
00168     if (abs(new_dyn_mass_from_star-old_dyn_mass)/old_dyn_mass
00169         >=cnsts.star_to_dyn(stellar_mass_update_limit)) {  // MASS_UPDATE_LIMIT
00170         check_binary_mass=true;
00171     }
00172     if (abs(new_dyn_sma_from_star-old_dyn_sma)/old_dyn_sma
00173         >=cnsts.star_to_dyn(semi_major_axis_update_limit)) { //SMA_UPDATE_LIMIT
00174         check_binary_sma=true;
00175     }
00176     if (binary_is_merged(od)) {
00177         cerr << endl << "evolve_an_unperturbed_binary:  binary "
00178              << bi->format_label()
00179              << " is apparently merged" << endl;
00180         check_binary_merger = true;
00181     }
00182       
00183     star * primary = ((star*) (bi->get_starbase()))->get_primary();
00184     star * secondary = ((star*) (bi->get_starbase()))->get_secondary();
00185     real m1 = primary->get_total_mass();
00186     real m2 = secondary->get_total_mass();
00187     real semi = bi->get_starbase()->get_semi();
00188     real ecc = bi->get_starbase()->get_eccentricity();
00189     char * t1 = type_string(primary->get_element_type());
00190     char * t2 = type_string(secondary->get_element_type());
00191 
00192     if (REPORT_EVOLVE_DOUBLE) 
00193         if (check_binary_sma || check_binary_mass || check_binary_merger) {
00194             cerr << " check: "
00195                  <<check_binary_mass<<" "
00196                  <<check_binary_sma<<" "
00197                  <<check_binary_merger<<endl;
00198             bi->pretty_print_node(cerr); PRC(bi->get_time());
00199             PRL(od->get_time());
00200             PRC(bi->get_system_time()); PRL(stellar_evolution_time);
00201             PRC(t1); PRC(m1); PRC(t2); PRC(m2); PRC(semi); PRL(ecc);
00202             cerr << "After evolution:"
00203                  << " sma= " << semi
00204                  << " ecc= " << ecc 
00205                  << " Time = "<<stellar_evolution_time <<"      ";
00206             put_state(make_state(dynamic_cast(double_star*,
00207                                               bi->get_starbase())));
00208             cerr << endl;
00209             ((double_star*) (bi->get_starbase()))->dump(cerr);
00210             cerr << endl;
00211         }
00212 
00213     //bi->get_starbase()->get_seba_counters()->step_dstar++;
00214 }
00215 
00216 local real initial_binary_period(double_star * ds)
00217 {
00218     double_init *di = ds->get_initial_conditions();
00219 
00220     real pdays = 2*PI*sqrt(pow(di->semi*cnsts.parameters(solar_radius), 3.)
00221                            / (cnsts.physics(G)*di->mass_prim
00222                               *(1+di->q)*cnsts.parameters(solar_mass)))
00223                            /  cnsts.physics(days);
00224                            return pdays;
00225 }
00226 
00227 // Helper version of delete_double -- overloaded!
00228 
00229 local void delete_double(hdyn *b)                       // b is binary CM
00230 {
00231     if (REPORT_DEL_DOUBLE) {
00232         cerr << "Unsafe double_star deletion: "<<endl;
00233         b->pretty_print_node(cerr); cerr << endl;
00234         ((star*)(b->get_starbase()))->dump(cerr);
00235     }
00236     double_star *the_binary = dynamic_cast(double_star*, b->get_starbase());
00237 
00238     // First make sure that the binary is evolved to exact time.
00239 
00240     // Individual time of internal binary motion should be used here,
00241     // NOT the system time!!!
00242 
00243     hdyn* od = b->get_oldest_daughter();
00244     real stellar_time = b->get_starbase()
00245                          ->conv_t_dyn_to_star(od->get_time());
00246                                       // 3/99 was get_system_time()
00247     the_binary->evolve_the_binary(stellar_time);
00248     the_binary->set_node(NULL);
00249 
00250     story* old_story = the_binary->get_star_story();
00251     the_binary->set_star_story(NULL);
00252 
00253     if (old_story)
00254         delete old_story;
00255       
00256     // (Keep the story if we want to add a story chapter about the
00257     // binary evolution.)
00258 
00259     // Now safely delete the binary.
00260 
00261     delete the_binary;
00262       
00263     // Create a new starbase to the dyn.  See note in other delete_double.
00264 
00265     // b->set_starbase(new starbase(b));
00266 
00267     b->set_starbase(new starbase());
00268     b->get_starbase()->set_node(b);
00269 }
00270 
00271 //-----------------------------------------------------------------------------
00272 //
00273 // delete_double  -- the real "delete double()"
00274 //
00275 // Delete the double_star attached to the parent of the leaves.
00276 // Does not check whether or not a double_star indeed exists.
00277 //
00278 // May set two "update_dynamics" flags:
00279 //              0:      binary mass or semimajor axis changed during
00280 //                      the final binary evolution step
00281 //              1:      binary orbit has changed significantly since
00282 //                      the dynamical binary became unperturbed
00283 //
00284 // Called only by create_or_delete_binary.
00285 //
00286 //-----------------------------------------------------------------------------
00287 
00288 local void delete_double(hdyn *b,                   // b is binary CM
00289                          bool * update_dynamics,
00290                          bool allow_evolution_before_termination,
00291                          int full_dump = 0)
00292 {
00293     if (b->get_oldest_daughter()->get_kepler() == NULL) {
00294         cerr << "Deleting double without a kepler pointer"<<endl;
00295         delete_double(b);
00296         return;
00297     }
00298 
00299     // cerr << endl << "in delete_double" << endl;
00300   
00301     bool kepler_created = false;
00302 
00303     hdyn* od = b->get_oldest_daughter();
00304     if (!od->get_kepler()) {
00305 
00306         // This cannot occur -- already tested above...
00307 
00308         cerr << "No Kepler in delete_double; create one."<<endl;
00309         new_child_kepler(b, od->get_time(), MAX_CIRC_ECC); 
00310         kepler_created = true;     // 3/99 was get_system_time()
00311     }
00312     else {
00313         od->get_kepler()->
00314             set_circular_binary_limit(MAX_CIRC_ECC);    // Probably unnecessary
00315         dyn_to_child_kepler(b, od->get_time()); // 3/99 was get_system_time()
00316     }
00317 
00318     if (REPORT_DEL_DOUBLE) {
00319         cerr << "kepler created in delete_double ";
00320         cerr << "at address " << od->get_kepler() 
00321              << endl;
00322     }
00323   
00324     kepler* johannes = od->get_kepler();
00325   
00326     if (REPORT_DEL_DOUBLE) {
00327         cerr << "delete double star "; b->pretty_print_node(cerr);
00328         cerr<<endl;
00329         ((double_star*)(b->get_starbase()))->dump(cerr);
00330     }
00331     
00332     double_star *the_binary = dynamic_cast(double_star*, b->get_starbase());
00333 
00334     if (REPORT_DEL_DOUBLE) 
00335         put_state(make_state(the_binary));
00336 
00337     // First make sure that the binary is evolved to exact time.
00338 
00339     real stellar_time = b->get_starbase()
00340                          ->conv_t_dyn_to_star(od->get_time());
00341                                       // 3/99 was get_system_time()
00342 
00343     bool change_mass = false, change_sma = false, check_merger = false;
00344     bool force_evolve = true;
00345 
00346     // Optionally evolve the binary (to its current dynamical time)
00347     // before deleting it.  If no evolution occurs, all dynamics
00348     // flags will be false on return.
00349 
00350     if (allow_evolution_before_termination) {
00351 
00352         evolve_an_unperturbed_binary(b,
00353                                      change_mass,
00354                                      change_sma,
00355                                      check_merger,
00356                                      force_evolve);
00357     }
00358 
00359     update_dynamics[0] |= (change_mass || change_sma);
00360 
00361     if (REPORT_DEL_DOUBLE) {
00362         PRL(update_dynamics[0]);
00363         the_binary->dump(cerr);
00364         put_state(make_state(the_binary));
00365     }
00366 
00367     if (check_merger) {
00368 
00369         hdyn* bcoll = od->get_binary_sister();
00370 
00371         cerr <<"delete_double:  merger within "
00372              << b->format_label()
00373              << " triggered by ";
00374         cerr << bcoll->format_label();
00375         int p = cerr.precision(INT_PRECISION);
00376         cerr << " at time (tsys)" << b->get_system_time()
00377              << "(binary: "<< od->get_time() <<")"<< endl; 
00378         cerr.precision(p);
00379 
00380 //      cerr << "merging nodes(1)..." << endl << flush;
00381 
00382         od->merge_nodes(bcoll, full_dump);
00383         update_dynamics[0] = true;
00384 
00385 //      cerr << "...done" << endl << flush;
00386       
00387         // Components are not deleted in merge_nodes.  Do this now.
00388         // Also, if unperturbed binaries are resolved in perturber lists,
00389         // must check and correct the lists now.
00390 
00391         if (RESOLVE_UNPERTURBED_PERTURBERS) {
00392             hdynptr del[2];
00393             del[0] = od;
00394             del[1] = bcoll;
00395             correct_perturber_lists(b->get_root(), del, 2, b);
00396         }
00397 
00398         if (kepler_created) delete johannes;
00399 
00400         delete od;
00401         delete bcoll;
00402 
00403         delete the_binary;
00404 
00405         return; 
00406     }
00407     else {
00408 
00409         // Unperturbed motion is about to be terminated.  If the final
00410         // orbit is radically different from the initial one, we will
00411         // have to recompute the time step on returning to kira...
00412 
00413         if (the_binary->get_period()
00414             / initial_binary_period(the_binary) < 0.9) {
00415             real dm_fast = sudden_mass_loss(b); 
00416             update_kepler_from_binary_evolution(b, dm_fast);
00417             update_dynamics[1] = true;
00418             if (REPORT_DEL_DOUBLE) 
00419                 PRL(update_dynamics[1]);
00420         }
00421 
00422         // Could keep the story, possibly to be added to the root or
00423         // component stories, or we might add a story chapter about
00424         // the binary evolution.  However, for now, any story text in
00425         // the parent node is simply discarded.
00426 
00427         story* old_story = the_binary->get_star_story();
00428         the_binary->set_star_story(NULL);
00429 
00430         if (old_story)
00431             delete old_story;
00432       
00433 //       cerr << "before deleting the_binary" << endl;
00434 //       PRL(b);
00435 //       PRL(b->get_starbase());
00436 //       PRL(b->get_starbase()->get_star_story());
00437 
00438         the_binary->set_node(NULL);
00439         delete the_binary;
00440       
00441         // Create a new starbase to the dyn.
00442 
00443         // Note from Steve to Simon, 8/27/98.  Deleting the_binary here
00444         // has the effect of corrupting the star_story pointer associated
00445         // with b (see commented lines before and after the deletion).
00446         // However, "new starbase(b)" uses any existing (i.e. non-null)
00447         // star_story pointer it finds, so it propogates the corruption into
00448         // the newly created starbase.  This can have disastrous effects
00449         // much later when we come to print or delete b!
00450         //
00451         // (It took me a day to find this bug!)
00452 
00453 //       cerr << "after deleting the_binary" << endl;
00454 //       PRL(b);
00455 //       PRL(b->get_starbase());
00456 //       PRL(b->get_starbase()->get_star_story());
00457 
00458 //       b->set_starbase(new starbase(b));
00459 
00460         b->set_starbase(new starbase());
00461         b->get_starbase()->set_node(b);
00462 
00463         // This creates a new starbase with an empty star story.
00464         // Actually, adddouble sets star_story = NULL, so NULL should
00465         // be OK here too...
00466 
00467         // If we want to preserve the old_story, don't delete above,
00468         // and do this:
00469         // 
00470         //      b->get_starbase()->set_star_story(old_story);
00471     }
00472       
00473     if (kepler_created) {
00474         if (od->get_kepler()) {
00475             od->set_kepler(NULL);
00476             od->get_binary_sister()->set_kepler(NULL);
00477             delete johannes;
00478         }
00479     }
00480 }
00481 
00482 
00483 
00484 //------------------------------------------------------------------------
00485 //
00486 // Global functions:
00487 //
00488 //------------------------------------------------------------------------
00489 
00490 bool create_or_delete_binary(hdyn *bi,                // pointer to parent node
00491                              bool * update_dynamics,
00492                              int full_dump /*= 0*/ )  // default = false
00493 {
00494 // Two "update_dynamics" flags may be modified (by delete_double):
00495 //
00496 //              0:      binary mass or semimajor axis changed during
00497 //                      the final binary evolution step
00498 //              1:      binary orbit has changed significantly since
00499 //                      the dynamical binary became unperturbed
00500 //
00501 // They are *not* initialized by this function.
00502 
00503     if (REPORT_ADD_DOUBLE || REPORT_DEL_DOUBLE )
00504         cerr << "create_or_delete_binary" << endl;
00505   
00506     if (has_dstar(bi->get_oldest_daughter())) {
00507         if (REPORT_DEL_DOUBLE )
00508             cerr << "Delete existing binary from "
00509                  << bi->format_label()<<endl;
00510 
00511         // Setting this flag false means that the binary will not
00512         // be allowed to evolve before its dstar is deleted.  In that
00513         // case, update_dynamics will be set false on return.
00514 
00515         bool allow_evolution_before_termination = false;
00516 
00517         delete_double(bi, update_dynamics,
00518                       allow_evolution_before_termination,
00519                       full_dump);
00520 
00521         //bi->get_starbase()->get_seba_counters()->del_dstar++;
00522 
00523         return true;
00524     }
00525     else {
00526         if (REPORT_ADD_DOUBLE)
00527             cerr << "Create new binary to "
00528                  << bi->format_label()<<endl;
00529 
00530         adddouble(bi, bi->get_oldest_daughter()->get_time());
00531                                      // 3/99 was get_system_time()
00532 
00533         //bi->get_starbase()->get_seba_counters()->add_dstar++;
00534 
00535         return true;
00536     }
00537 
00538     return false;
00539 }
00540 
00541 bool binary_is_merged(dyn* bi)
00542 {
00543     starbase * p_star = bi->get_parent()->get_starbase();
00544     if (bi->get_kepler()
00545         && p_star->get_element_type()==Double) {      
00546         if (p_star->get_bin_type()==Merged)
00547             return true;
00548     }
00549     return false;
00550 }
00551 
00552 bool binary_evolution(hdyn *b,          // root node
00553                       int full_dump)    // default = 0
00554 
00555 // Return value is true iff a system reinitialization will be needed
00556 // after returning to kira.
00557 
00558 {
00559     bool update_dynamics[2] = {false, false};
00560                 
00561     // int p = cerr.precision(HIGH_PRECISION);
00562     // cerr << "entering binary_evolution at time "
00563     //      << b->get_system_time() << endl;
00564     // cerr.precision(p);
00565 
00566     for_all_leaves(hdyn, b, bi) {
00567 
00568         if (need_dstar(bi) && (! has_dstar(bi))) {
00569 
00570             hdyn *  parent = bi->get_parent();
00571 
00572             create_or_delete_binary(bi->get_parent(),
00573                                     update_dynamics, full_dump);
00574 
00575             if (REPORT_ADD_DOUBLE) {
00576                 cerr << "new double star created at time "
00577                      << bi->get_time()<<endl;
00578                 pp3(parent, cerr);
00579             }
00580         }
00581 
00582         if (has_dstar(bi)) {                        // bi is binary component
00583 
00584             if (need_dstar(bi)) {
00585 
00586                 if (binary_wants_to_be_updated(bi->get_parent())) {
00587 
00588                     if (REPORT_EVOLVE_DOUBLE) 
00589                         cerr << "\nEvolving binary " << bi->format_label()
00590                              << endl;
00591 
00592                     // The procedure below is effectively similar to that
00593                     // followed in delete_double.
00594 
00595                     bool change_mass, change_sma, check_merger;
00596                     bool force_evolve = false;
00597                 
00598                     evolve_an_unperturbed_binary(bi->get_parent(),
00599                                                  change_mass,
00600                                                  change_sma,
00601                                                  check_merger,
00602                                                  force_evolve);
00603                   
00604                     update_dynamics[0] |= (change_mass || change_sma);
00605 
00606                     if (REPORT_DEL_DOUBLE)
00607                         PRL(update_dynamics[0]);
00608 
00609                     if (check_merger) {
00610 
00611                         hdyn* par = bi->get_parent();
00612                         hdyn* bcoll = bi->get_binary_sister();
00613 
00614                         cerr << "binary_evolution:  merger within "
00615                              << par->format_label()
00616                              << " triggered by ";
00617                         cerr << bcoll->format_label();
00618                         int p = cerr.precision(INT_PRECISION);
00619                         cerr << " at time " << b->get_time() << endl;
00620                         cerr.precision(p);
00621 
00622 //                      cerr << endl << "computing energies before merger:"
00623 //                           << endl << flush;
00624 //                      real epot0, ekin0, etot0;
00625 //                      calculate_energies_with_external(b, epot0,
00626 //                                                       ekin0, etot0);
00627 //                      cerr << "OK" << endl << endl << flush;
00628 //                      cerr << "merging nodes(2)..." << endl;
00629 
00630                         bi->merge_nodes(bcoll, full_dump);
00631 
00632 //                      cerr << "...done" << endl << flush;
00633 //                      cerr << endl << "computing energies after merger (#1):"
00634 //                           << endl << flush;
00635 //                      calculate_energies_with_external(b, epot0,
00636 //                                                       ekin0, etot0);
00637 //                      cerr << "OK" << endl << endl << flush;
00638 
00639                         // Components are not deleted by merge_nodes.  Do this
00640                         // here, and adjust perturber lists if necessary.
00641                     
00642                         if (RESOLVE_UNPERTURBED_PERTURBERS) {
00643                             hdynptr del[2];
00644                             del[0] = bi;
00645                             del[1] = bcoll;
00646                             cerr << "correcting perturber lists"
00647                                  << endl << flush;
00648                             correct_perturber_lists(par->get_root(),
00649                                                     del, 2, par);
00650                         }
00651 
00652                         delete bi;
00653                         delete bcoll;
00654 
00655 //                      cerr << endl << "computing energies after merger (#2):"
00656 //                           << endl << flush;
00657 //                      calculate_energies_with_external(b, epot0,
00658 //                                                       ekin0, etot0);
00659 //                      cerr << "OK" << endl << endl << flush;
00660 
00661                         // Looks as though everything is now taken care of
00662                         // in case of a merger.  The binary is replaced by
00663                         // its center of mass node and all stellar information
00664                         // is updated.  Dynamics will be corrected on return.
00665                         // Should be safe to continue the tree traversal at
00666                         // the parent node...
00667 
00668                         // *Don't* return immediately.  Set update_dynamics
00669                         // true because binary evolution has changed the tree.
00670 
00671                         // return true;
00672 
00673                         update_dynamics[0] = true;
00674                         bi = par;
00675                     }
00676                 }
00677 
00678             } else {
00679                 
00680                 if (REPORT_DEL_DOUBLE) {
00681                     cerr << "delete double star  at time "
00682                          << bi->get_time() << endl;
00683                     pp3(bi->get_parent(), cerr);
00684                     PRL(bi->is_low_level_node());PRL(bi->get_elder_sister());
00685                     PRL(bi->get_kepler());PRL(bi->get_fully_unperturbed());
00686                     PRL(need_dstar(bi));PRL(has_dstar(bi));
00687                 }
00688 
00689                 // This is not very safe.
00690                 // double_star needs to be updated before kepler is deleted.
00691                 // Do it now in delete_double, not very pretty.
00692                 // (SPZ:8/02/1998)
00693                 // delete_double(bi->get_parent());
00694 
00695                 create_or_delete_binary(bi->get_parent(),
00696                                         update_dynamics, full_dump);
00697             }
00698         }
00699     }
00700 
00701     return update_dynamics[0];
00702 }
00703 
00704 void update_kepler_from_binary_evolution(hdyn* the_binary_node, 
00705                                          real dm_fast)
00706 {
00707     if (REPORT_EVOLVE_DOUBLE)
00708         ((double_star*)(the_binary_node->get_starbase()))->dump(cerr);
00709 
00710     kepler *johannes = the_binary_node->get_oldest_daughter()->get_kepler();
00711     real sma = the_binary_node->get_starbase()->conv_r_star_to_dyn(
00712                 the_binary_node->get_starbase()->get_semi());
00713     real ecc = the_binary_node->get_starbase()->get_eccentricity();
00714 
00715     real m_total = get_total_mass(the_binary_node) - dm_fast;
00716 
00717     real mean_anomaly = johannes->get_mean_anomaly();
00718 
00719     // real peri = johannes->get_periastron();
00720     real peri = sma * (1-ecc);
00721     hdyn * b = the_binary_node->get_oldest_daughter();
00722     johannes->transform_to_time(b->get_time());
00723 
00724     real time = johannes->get_time();
00725     if (REPORT_EVOLVE_DOUBLE) {
00726         PRC(time); PRC(sma); PRL(m_total); PRC(mean_anomaly); PRL(peri);
00727     }
00728 
00729     make_standard_kepler(*johannes, time, m_total, -0.5 * m_total / sma, ecc,
00730                          peri, mean_anomaly, 0);
00731 
00732     // Note from Steve, 10/9/98: make_standard_kepler creates a new
00733     // kepler with the specified properties.  However, the default
00734     // action is to aligh the orbit with the coordinate axes, placing
00735     // the binary in the x-y plane and losing orientation information.
00736     // The trailing "0" here retains the old orientation vectors.
00737 
00738     // Feb 26, 1998.
00739     // I believe pred_advance must be called here to
00740     // set the periastron time
00741 
00742     johannes->pred_advance_to_periastron();
00743 
00744     if (johannes->get_pred_time() < b->get_time()) {
00745         cerr << "update_kepler_from_binary, time went backwards"<<endl;
00746         PRC(the_binary_node->format_label());  
00747         PRC(johannes->get_pred_time()); PRL(b->get_time());
00748     }
00749 }

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