Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

kira_escape.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00011 // Functions associated with escapers.
00012 //
00013 // Externally visible functions:
00014 //
00015 //      void check_and_remove_escapers
00016 
00017 #include "hdyn.h"
00018 #include <star/dstar_to_kira.h>
00019 
00020 local bool remove_escapers(hdyn* b,
00021                            real rmax,
00022                            vector center_pos,
00023                            vector center_vel)
00024 {
00025     bool correct_dynamics = false;
00026     real rmax2 = rmax*rmax;
00027     int n_esc = 0;
00028 
00029     for_all_daughters(hdyn, b, bi)
00030         if (square(bi->get_pos()- center_pos) > rmax2)
00031             n_esc++;
00032 
00033     if (n_esc <= 0) {
00034         cerr << "\n  No escapers\n";
00035         return false;
00036     }
00037 
00038     cerr << endl << n_esc << " escaper(s):\n";
00039 
00040     hdyn** esc_list = new hdynptr[n_esc];
00041 
00042     real epot0, ekin0, etot0;
00043     calculate_energies_with_external(b, epot0, ekin0, etot0);
00044 
00045     n_esc = 0;
00046     for_all_daughters(hdyn, b, bj) {
00047 
00048         // Escape criterion (note that we do NOT check E > 0):
00049         
00050         if (square(bj->get_pos()- center_pos) > rmax2) {
00051         
00052             cerr << "    " << bj->format_label() << " " << bj->get_mass()
00053                  << endl;
00054             cerr << "    pos: " << bj->get_pos()- center_pos << "   |pos| = "
00055                  << abs(bj->get_pos()- center_pos) << endl;
00056             cerr << "    vel: " << bj->get_vel()- center_vel << "   |vel| = "
00057                  << abs(bj->get_vel()- center_vel) << endl;
00058 
00059             if (b->get_use_sstar())
00060                 if (has_sstar(bj)) {
00061                     cerr << "    ";
00062                     put_state(make_star_state(bj));
00063                     cerr << endl;
00064                 }
00065         
00066 //          if (bj->get_starbase() != NULL) {
00067 //              bj->get_starbase()->print_star_story(cerr);
00068 //          }
00069 
00070             for_all_daughters(hdyn, b, bb) {
00071                 if (bb->get_nn() == bj) {
00072                     cerr << "    reset NB for " << bb->format_label()<<endl;
00073                     bb->set_nn(NULL);
00074                 }
00075             }
00076 
00077             // Correct the list of perturbed top_level binaries.
00078 
00079             if (bj->is_perturbed_cm())
00080                 bj->remove_from_perturbed_list();
00081 
00082             esc_list[n_esc++] = bj;
00083             detach_node_from_general_tree(*bj);
00084 
00085             b->inc_mass(-bj->get_mass());       // Not done by detach_node...
00086         }
00087     }
00088 
00089     // Note from Steve (7/01):  Used to reset the CM because of the
00090     // chance we might compute escapers relative to the origin of
00091     // coordinates (rather than, say, the density center).  Without
00092     // resetting, recoil would eventually carry the entire system
00093     // beyond the tidal radius!  Now we should *never* use the
00094     // coordinate origin in determining escapers, so there is no need
00095     // to correct here.
00096 
00097     // b->to_com();
00098 
00099     // Correct all perturber lists.
00100 
00101     correct_perturber_lists(b, esc_list, n_esc);
00102 
00103     // Should possibly recompute accs and jerks on top-level nodes here too.
00104     // Not necessary if we are going to reinitialize next.
00105 
00106 #if 0
00107     calculate_acc_and_jerk_on_all_top_level_nodes(b);
00108 #endif
00109 
00110     if (b->n_leaves() > 1) {
00111 
00112         real epot = 0, ekin = 0, etot = 0;
00113         calculate_energies_with_external(b, epot, ekin, etot);
00114 
00115         cerr << endl;
00116         PRI(2); PRC(epot0); PRC(ekin0); PRL(etot0);
00117         PRI(2); PRC(epot); PRC(ekin); PRL(etot);
00118 
00119         // pp3(cm, cerr);
00120 
00121         real de_total = etot - etot0;
00122 
00123         PRI(2); PRL(de_total);
00124 
00125         // Update statistics on energy change components:
00126 
00127         b->get_kira_counters()->de_total += de_total;
00128 
00129         predict_loworder_all(b, b->get_system_time());  // Unnecessary?
00130 
00131         cerr << "initialize_system_phase2 called from remove_escapers\n";
00132         initialize_system_phase2(b, 4);
00133     }
00134 
00135     return true;
00136 }
00137 
00138 
00139 
00140 void check_and_remove_escapers(hdyn* b,
00141                                xreal& ttmp, hdyn** next_nodes,
00142                                int& n_next, bool& tree_changed)
00143 {
00144     if (b->get_scaled_stripping_radius() <= 0) return;
00145 
00146     // Note: Definition of scaled_stripping_radius
00147     //   incorporates initial mass factor.
00148 
00149     real stripping_radius = b->get_scaled_stripping_radius()
00150                                 * pow(total_mass(b), 1.0/3.0);
00151 
00152     // Note also that this scaling ensures that omega
00153     // remains constant as the system evolves if the Jacobi
00154     // radius is identified with the stripping radius.
00155 
00156     real mass0 = total_mass(b);
00157 
00158     vector center_pos, center_vel;
00159     get_std_center(b, center_pos, center_vel);
00160 
00161     // Note from Steve (7/01):  If we have a tidal field, we should
00162     // probably determine the center self-consistently as the center
00163     // of mass of particles within the Jacobi surface.
00164     //
00165     // To do...  (See also refine_cluster_mass().)
00166 
00167     if (remove_escapers(b, stripping_radius, center_pos, center_vel)) {
00168 
00169         PRI(2); PRC(b->get_scaled_stripping_radius());
00170         PRL(stripping_radius);
00171 
00172         tree_changed = true;
00173         fast_get_nodes_to_move(b, next_nodes, n_next,
00174                                ttmp, tree_changed);
00175         tree_changed = true;
00176 
00177         cerr << "\n  New N = " << b->n_leaves()
00178              <<  "  mass = " << total_mass(b) << endl;
00179         PRI(2); print_recalculated_energies(b);
00180 
00181         // Update statistics.
00182 
00183         b->get_kira_counters()->dm_escapers += mass0 - total_mass(b);
00184     }
00185 }

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