00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
00067
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
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());
00086 }
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 correct_perturber_lists(b, esc_list, n_esc);
00102
00103
00104
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
00120
00121 real de_total = etot - etot0;
00122
00123 PRI(2); PRL(de_total);
00124
00125
00126
00127 b->get_kira_counters()->de_total += de_total;
00128
00129 predict_loworder_all(b, b->get_system_time());
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
00147
00148
00149 real stripping_radius = b->get_scaled_stripping_radius()
00150 * pow(total_mass(b), 1.0/3.0);
00151
00152
00153
00154
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
00162
00163
00164
00165
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
00182
00183 b->get_kira_counters()->dm_escapers += mass0 - total_mass(b);
00184 }
00185 }