00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 local inline void update_nn_coll(hdyn *this_node, int id,
00030 real d_to_b_sq, hdyn *b,
00031 real &d_nn_sq, hdyn *&nn,
00032 real sum_of_radii,
00033 real &d_coll_sq, hdyn *&coll)
00034
00035
00036
00037
00038 {
00039 if (d_to_b_sq < d_nn_sq) {
00040
00041 #if 0
00042 hdyn *old_nn = nn;
00043 real old_d_nn_sq = d_nn_sq;
00044 #endif
00045
00046 d_nn_sq = d_to_b_sq;
00047 nn = b;
00048
00049 #if 0
00050 if (this_node->get_real_system_time() > 13.62265) {
00051 cerr << "update_nn_coll(" << id << "): ";
00052 PRL(this_node->format_label());
00053 PRI(4); PRC(old_nn); PRL(sqrt(old_d_nn_sq));
00054 if (old_d_nn_sq < 0.5*VERY_LARGE_NUMBER) {
00055 PRI(4); cerr << "old: " << flush;
00056 if (old_nn->is_valid()) {
00057 PRC(old_nn->format_label());
00058 }
00059 if (old_d_nn_sq > 0) {
00060 PRC(sqrt(old_d_nn_sq));
00061 }
00062 cerr << endl << flush;
00063 }
00064 PRI(4); PRC(nn->format_label()); PRL(sqrt(d_nn_sq));
00065 }
00066 #endif
00067
00068 }
00069
00070 real coll_dist = d_to_b_sq - sum_of_radii*sum_of_radii;
00071
00072 if (coll_dist < d_coll_sq) {
00073 d_coll_sq = coll_dist;
00074 coll = b;
00075 }
00076 }
00077
00078
00079
00080
00081
00082
00083 #define PERTURBER_CRITERION 2 // For determination of perturbers
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 local real binary_scale(hdyn* cm)
00139 {
00140 static hdyn *last_cm = NULL;
00141 static xreal last_time = 0;
00142 static real last_scale = 0;
00143
00144 xreal time = cm->get_time();
00145
00146 if (cm == last_cm
00147 && time == last_time)
00148 return last_scale;
00149
00150 hdyn *d1 = cm->get_oldest_daughter();
00151 if (!d1) return 0;
00152
00153 hdyn *d2 = d1->get_younger_sister();
00154 if (!d2) return 0;
00155
00156 real sep = abs(d1->get_pos() - d2->get_pos());
00157 real energy = 0.5 * square(d1->get_vel() - d2->get_vel())
00158 - cm->get_mass() / sep;
00159 real sma = 0.5 * cm->get_mass() / abs(energy);
00160
00161 last_cm = cm;
00162 last_time = time;
00163 last_scale = max(sma, sep);
00164
00165
00166
00167
00168
00169 return last_scale;
00170 }
00171
00172
00173
00174
00175 local inline real define_perturbation_radius_factor(hdyn *b,
00176 real pert_factor_sq)
00177 {
00178 int perturber_criterion = b->get_kira_options()->perturber_criterion;
00179
00180 real r_bin = binary_scale(b);
00181 real m_bin = b->get_mass();
00182
00183
00184
00185
00186
00187
00188 if (perturber_criterion == 0) {
00189
00190
00191
00192
00193 return pert_factor_sq * r_bin * r_bin;
00194
00195 } else if (perturber_criterion == 1) {
00196
00197
00198
00199 real rp2 = pert_factor_sq * r_bin * r_bin;
00200
00201
00202 return 2 * rp2 * sqrt(rp2) / m_bin;
00203
00204 } else if (perturber_criterion == 2) {
00205
00206
00207
00208
00209
00210
00211 real rp2 = pert_factor_sq * r_bin * r_bin;
00212
00213
00214 return rp2 * sqrt(rp2);
00215 }
00216 }
00217
00218
00219
00220
00221 local inline real perturbation_scale_sq(hdyn *b,
00222 real pert_factor_sq)
00223 {
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 if (!b->get_oldest_daughter()) return 0;
00235
00236 real r_bin = binary_scale(b);
00237 return pert_factor_sq * r_bin * r_bin;
00238 }
00239
00240
00241
00242 local inline bool is_perturber(hdyn *b,
00243 real m_pert,
00244 real distance_squared,
00245 real perturbation_radius_factor)
00246 {
00247 int perturber_criterion = b->get_kira_options()->perturber_criterion;
00248 real m_bin = b->get_mass();
00249
00250 if (perturber_criterion == 0) {
00251
00252
00253
00254 return (distance_squared < perturbation_radius_factor);
00255
00256 } else if (perturber_criterion == 1) {
00257
00258
00259
00260 return (distance_squared * sqrt(distance_squared)
00261 < m_pert * perturbation_radius_factor);
00262
00263 } else if (perturber_criterion == 2) {
00264
00265
00266
00267
00268 real d3 = distance_squared * sqrt(distance_squared);
00269
00270 if (m_pert <= 0.5*m_bin)
00271 return (d3 < perturbation_radius_factor);
00272
00273 return (0.5*m_bin*d3
00274 < m_pert * perturbation_radius_factor);
00275
00276 }
00277 }
00278
00279
00280
00281
00282 local inline real crit_separation_cubed(hdyn *b,
00283 real m_pert,
00284 real r_bin,
00285 real gamma)
00286 {
00287 real m_bin = b->get_mass();
00288 real d_min_sq = b->get_d_min_sq();
00289 int perturber_criterion = b->get_kira_options()->perturber_criterion;
00290
00291 real d2 = min(d_min_sq, r_bin * r_bin);
00292 real d3 = d2 * sqrt(d2) / gamma;
00293
00294 if (perturber_criterion == 0
00295 || (perturber_criterion == 2 && m_pert <= 0.5 * m_bin))
00296
00297 return d3;
00298
00299 else
00300
00301 return 2 * (m_pert / m_bin) * d3;
00302 }
00303
00304 local inline real time_to_radius(real dr,
00305 real vr,
00306 real ar)
00307 {
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 if (dr <= 0) return 0;
00320
00321 real dt = VERY_LARGE_NUMBER;
00322
00323 if (vr < 0) dt = -dr / vr;
00324 if (ar < 0) dt = min(dt, sqrt (-2 * dr / ar));
00325
00326 return dt;
00327 }