00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef STARLAB_HDYN_H
00023 # define STARLAB_HDYN_H
00024
00025 #define MAX_PERTURBERS 256
00026 #define ALLOW_LOW_LEVEL_PERTURBERS true
00027 #define RESOLVE_UNPERTURBED_PERTURBERS false
00028
00029
00030
00031 #define SMALL_TDYN_PERT_SQ 1.e-4
00032
00033
00034
00035 #include "_dyn_.h"
00036
00037 class kira_counters;
00038 class kira_options;
00039 class kira_diag;
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class hdyn : public _dyn_ {
00051 protected:
00052
00053
00054
00055
00056
00057
00058 static kira_counters *kc;
00059 static kira_options *options;
00060 static kira_diag *diag;
00061
00062
00063
00064 static bool use_dstar;
00065
00066
00067
00068 static real stellar_encounter_criterion_sq;
00069 static real stellar_merger_criterion_sq;
00070 static real stellar_capture_criterion_sq;
00071
00072
00073
00074 static hdyn **perturbed_list;
00075 static int n_perturbed;
00076
00077
00078
00079 static real eta;
00080 static real eps;
00081 static real eps2;
00082
00083 static real d_min_fac;
00084 static real d_min_sq;
00085 static real lag_factor;
00086 static real mbar;
00087
00088 static real gamma2;
00089 static real gamma23;
00090
00091 static real initial_step_limit;
00092 static real step_limit;
00093 static real unpert_step_limit;
00094
00095
00096
00097
00098
00099 static real scaled_stripping_radius;
00100
00101
00102
00103 static int max_slow_factor;
00104 static real max_slow_perturbation;
00105 static real max_slow_perturbation_sq;
00106
00107
00108
00109 static unsigned int config;
00110 static bool restart_grape_flag;
00111
00112
00113
00114
00115
00116
00117 static int n_threads;
00118 static real thread_cpu;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 bool on_integration_list;
00129
00130
00131
00132 real perturbation_squared;
00133 bool fully_unperturbed;
00134 real unperturbed_timestep;
00135
00136
00137
00138 int n_perturbers;
00139 hdyn** perturber_list;
00140 bool valid_perturbers;
00141
00142
00143 real perturbation_radius_factor;
00144
00145 int n_perturbers_low;
00146
00147
00148
00149
00150 bool valid_perturbers_low;
00151
00152 real posvel;
00153
00154 real prev_posvel;
00155
00156
00157
00158 hdyn* nn;
00159 real d_nn_sq;
00160
00161 hdyn* coll;
00162
00163
00164 real d_coll_sq;
00165
00166
00167
00168 int grape_index;
00169
00170 real grape_rnb_sq;
00171
00172 int grape_nb_count;
00173
00174
00175
00176
00177 real steps;
00178 real direct_force;
00179 real indirect_force;
00180
00181
00182
00183 bool is_weakly_perturbed(int& status);
00184 bool is_stable(int& status, bool top_level = true);
00185
00186 public:
00187
00188 hdyn(hbpfp the_hbpfp = new_hydrobase, sbpfp the_sbpfp = new_starbase)
00189 : _dyn_(the_hbpfp, the_sbpfp) {
00190
00191 on_integration_list = false;
00192
00193 perturbation_squared = -1;
00194 unperturbed_timestep = -VERY_LARGE_NUMBER;
00195 fully_unperturbed = false;
00196
00197 n_perturbers = n_perturbers_low = 0;
00198 perturber_list = NULL;
00199 valid_perturbers = valid_perturbers_low = false;
00200 perturbation_radius_factor = -1;
00201
00202 posvel = VERY_LARGE_NUMBER;
00203 prev_posvel = -VERY_LARGE_NUMBER;
00204
00205
00206 nn = NULL;
00207 d_nn_sq = 0;
00208
00209 coll = NULL;
00210 d_coll_sq = 0;
00211
00212 grape_index = 0;
00213 grape_rnb_sq = 0;
00214 grape_nb_count = 0;
00215
00216 steps = direct_force = indirect_force = 0;
00217
00218 }
00219
00220 virtual ~hdyn() {
00221 if (perturber_list)
00222 delete [] perturber_list;
00223 }
00224
00225
00226
00227
00228
00229 inline kira_counters *get_kira_counters() const {return kc;}
00230 void set_kira_counters(kira_counters *k){kc = k;}
00231
00232 inline kira_options *get_kira_options() const {return options;}
00233 void set_kira_options(kira_options *o) {options = o;}
00234
00235 inline kira_diag *get_kira_diag() const {return diag;}
00236 void set_kira_diag(kira_diag *d) {diag = d;}
00237
00238
00239
00240 inline bool get_use_dstar() const {return use_dstar;}
00241 void set_use_dstar(bool u) {use_dstar = u;}
00242
00243
00244
00245 real get_stellar_encounter_criterion_sq() const
00246 {return stellar_encounter_criterion_sq;}
00247 void set_stellar_encounter_criterion_sq(real d_sq)
00248 {stellar_encounter_criterion_sq = d_sq;}
00249 inline real get_stellar_capture_criterion_sq() const
00250 {return stellar_capture_criterion_sq;}
00251 void set_stellar_capture_criterion_sq(real d_sq)
00252 {stellar_capture_criterion_sq = d_sq;}
00253
00254 inline real get_stellar_merger_criterion_sq() const
00255 {return stellar_merger_criterion_sq;}
00256 void set_stellar_merger_criterion_sq(real d_sq)
00257 {stellar_merger_criterion_sq = d_sq;}
00258
00259
00260
00261 inline int get_n_perturbed() const {return n_perturbed;};
00262 inline hdyn** get_perturbed_list() {return perturbed_list;};
00263
00264
00265
00266 void set_eta(real e) {eta = e;}
00267 inline real get_eta() const {return eta;}
00268
00269 void set_eps(real e) {eps = e;
00270 eps2 = e*e;}
00271 real get_eps() const {return eps;}
00272 inline real get_eps2() const {return eps2;}
00273
00274 void set_d_min_fac(real d) {d_min_fac = d;}
00275 inline real get_d_min_fac() const {return d_min_fac;}
00276
00277 void set_d_min_sq(real d) {d_min_sq = d;}
00278 inline real get_d_min_sq() const {return d_min_sq;}
00279
00280 void set_lag_factor(real f) {lag_factor = f;}
00281 inline real get_lag_factor() const {return lag_factor;}
00282
00283 void set_mbar(real m) {mbar = m;}
00284 inline real get_mbar() const {return mbar;}
00285
00286 void set_gamma2(real g2) {gamma2 = g2;
00287 gamma23 = pow(g2, -1.0/3.0);}
00288 inline real get_gamma2() const {return gamma2;}
00289 inline real get_gamma23() const {return gamma23;}
00290
00291 void set_initial_step_limit(real s) {initial_step_limit = s;}
00292 inline real get_initial_step_limit() const {return initial_step_limit;}
00293
00294 void set_step_limit(real s) {step_limit = s;}
00295 inline real get_step_limit() const {return step_limit;}
00296
00297 void set_unpert_step_limit(real s) {unpert_step_limit = s;}
00298 inline real get_unpert_step_limit() const {return unpert_step_limit;}
00299
00300
00301
00302 void set_scaled_stripping_radius(real r)
00303 {scaled_stripping_radius = r;}
00304 inline real get_scaled_stripping_radius() const
00305 {return scaled_stripping_radius;}
00306
00307
00308
00309 void set_max_slow_factor(int f = 1) {max_slow_factor = f;}
00310 inline int get_max_slow_factor() const {return max_slow_factor;}
00311
00312 void set_max_slow_perturbation(real p) {
00313 max_slow_perturbation = p;
00314 max_slow_perturbation_sq = p*p;
00315 }
00316 void set_max_slow_perturbation_sq(real p) {
00317 max_slow_perturbation_sq = p;
00318 max_slow_perturbation = sqrt(p);
00319 }
00320 inline real get_max_slow_perturbation() const {
00321 return max_slow_perturbation;
00322 }
00323 inline real get_max_slow_perturbation_sq() const {
00324 return max_slow_perturbation_sq;
00325 }
00326
00327
00328
00329 inline unsigned int get_config() const {return config;}
00330 inline void set_config(unsigned int c) {config = c;}
00331
00332 inline void set_restart_grape_flag() {restart_grape_flag = true;}
00333 inline bool get_restart_grape_flag() const {return restart_grape_flag;}
00334 inline void clear_restart_grape_flag() {restart_grape_flag = false;}
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 void set_n_threads(int n=0) {n_threads = n;}
00346 int get_n_threads() const {return n_threads;}
00347 void set_thread_cpu(real t=0) {thread_cpu = t;}
00348 real get_thread_cpu() const {return thread_cpu;}
00349
00350
00351
00352
00353
00354 inline bool is_on_integration_list() {return on_integration_list;}
00355 void set_on_integration_list(bool on = true) {on_integration_list = on;}
00356 void clear_on_integration_list() {on_integration_list = false;}
00357
00358
00359
00360 inline real get_perturbation_squared() const
00361 {return perturbation_squared;}
00362 void set_perturbation_squared(real p) {perturbation_squared = p;}
00363
00364 inline bool get_fully_unperturbed() const
00365 {return fully_unperturbed;}
00366 void set_fully_unperturbed(bool f) {fully_unperturbed = f;}
00367
00368 inline real get_unperturbed_timestep() const
00369 {return unperturbed_timestep;}
00370
00371 void set_unperturbed_timestep(real step) {unperturbed_timestep
00372 = step;}
00373
00374
00375
00376 void zero_perturber_list() {n_perturbers
00377 = n_perturbers_low = 0;}
00378 void set_n_perturbers(int n) {
00379 if (is_leaf())
00380 cerr << "warning: setting n_perturbers for leaf "
00381 << format_label() << endl;
00382 n_perturbers = n;
00383 }
00384 void set_n_perturbers_low(int n) {
00385 if (is_leaf())
00386 cerr << "warning: setting n_perturbers_low for leaf "
00387 << format_label() << endl;
00388 n_perturbers_low = n;
00389 }
00390 inline int get_n_perturbers() const {return n_perturbers;};
00391 inline int get_n_perturbers_low() const {return n_perturbers_low;};
00392 inline hdyn ** get_perturber_list() const {return perturber_list;}
00393
00394 void remove_perturber_list() {n_perturbers
00395 = n_perturbers_low = 0;
00396 valid_perturbers
00397 = valid_perturbers_low
00398 = false;
00399 if (perturber_list)
00400 delete [] perturber_list;
00401 perturber_list = NULL;}
00402
00403 void print_perturber_list(ostream & s = cerr, char* pre = "");
00404 void find_print_perturber_list(ostream & s = cerr, char* pre = "");
00405
00406 void new_perturber_list() {
00407 if (perturber_list == NULL) {
00408 perturber_list = new hdyn *[MAX_PERTURBERS];
00409 }
00410 n_perturbers = n_perturbers_low = 0;
00411 valid_perturbers = valid_perturbers_low = false;
00412 }
00413
00414 inline bool get_valid_perturbers() const {return valid_perturbers;}
00415 inline bool get_valid_perturbers_low() const
00416 {return valid_perturbers_low;}
00417 void set_valid_perturbers(const bool vp) {valid_perturbers = vp;}
00418 void set_valid_perturbers_low(const bool vp) {valid_perturbers_low
00419 = vp;}
00420
00421 inline real get_perturbation_radius_factor() const
00422 {return perturbation_radius_factor;}
00423 void set_perturbation_radius_factor(real f)
00424 {perturbation_radius_factor = f;}
00425
00426 inline bool passed_apo() const {return (posvel < 0
00427 && prev_posvel >= 0);}
00428
00429 inline real get_posvel() const {return posvel;}
00430
00431
00432
00433
00434
00435
00436 inline hdyn * get_nn() const {return nn;}
00437 void set_nn(hdyn * new_nn) {nn = new_nn;}
00438 inline real get_d_nn_sq() const {return d_nn_sq;}
00439 void set_d_nn_sq(real d) {d_nn_sq = d;}
00440
00441 inline hdyn * get_coll() const {return coll;}
00442 void set_coll(hdyn * new_coll) {coll = new_coll;}
00443 inline real get_d_coll_sq() const {return d_coll_sq;}
00444 void set_d_coll_sq(real d) {d_coll_sq = d;}
00445
00446
00447
00448 inline int get_grape_index() const {return grape_index;}
00449 void set_grape_index(int hindex) {grape_index = hindex;}
00450 inline real get_grape_rnb_sq() const {return grape_rnb_sq;}
00451 void set_grape_rnb_sq(real rnb_sq) {grape_rnb_sq = rnb_sq;}
00452 inline int get_grape_nb_count() const {return grape_nb_count;}
00453 void set_grape_nb_count(int n) {grape_nb_count = n;}
00454
00455 bool has_grape() const {return (config > 0);}
00456 bool has_grape4() const {return (config > 0
00457 && config%2 != 0);}
00458 bool has_grape6() const {return (config > 0
00459 && config%2 == 0);}
00460
00461
00462
00463 inline real *get_pos_addr() {return &pos[0];}
00464 inline real *get_vel_addr() {return &vel[0];}
00465 inline real *get_acc_addr() {return &acc[0];}
00466 inline real *get_jerk_addr() {return &jerk[0];}
00467 inline real *get_old_acc_addr() {return &old_acc[0];}
00468 inline real *get_old_jerk_addr() {return &old_jerk[0];}
00469 inline real *get_k18_addr() {return &k_over_18[0];}
00470
00471
00472
00473 inline void inc_steps(int i = 1) {steps += i;}
00474 inline void inc_steps(real i) {steps += i;}
00475 inline real get_steps() const {return steps;}
00476 inline void inc_direct_force(int i = 1) {direct_force += i;}
00477 inline void inc_direct_force(real i) {direct_force += i;}
00478 inline real get_direct_force() const {return direct_force;}
00479 inline void inc_indirect_force(int i = 1) {indirect_force += i;}
00480 inline void inc_indirect_force(real i) {indirect_force += i;}
00481 inline real get_indirect_force() const {return indirect_force;}
00482
00483
00484
00485 inline hdyn * get_parent() const
00486 {return (hdyn*) node::get_parent();}
00487 inline hdyn * get_oldest_daughter() const
00488 {return (hdyn*)node::get_oldest_daughter();}
00489 inline hdyn * get_younger_sister() const
00490 {return (hdyn*) node::get_younger_sister();}
00491 inline hdyn * get_elder_sister() const
00492 {return (hdyn*) node::get_elder_sister();}
00493
00494 inline hdyn * get_root() const
00495 {return (hdyn*) node::get_root();}
00496 inline hdyn * get_top_level_node() const
00497 {return (hdyn*) node::get_top_level_node();}
00498 inline hdyn * get_binary_sister()
00499 {return (hdyn*) node::get_binary_sister();}
00500
00501 virtual void null_pointers();
00502 virtual void print_static(ostream &s = cerr);
00503
00504 virtual istream& scan_dyn_story(istream&);
00505
00506 virtual bool check_and_correct_node(bool verbose = true);
00507
00508 virtual ostream& print_dyn_story(ostream &s,
00509 bool print_xreal = true,
00510 int short_output = 0);
00511
00512 inline real get_true_timestep() const {
00513 if (kep)
00514 return unperturbed_timestep;
00515 else
00516 return timestep;
00517 }
00518
00519
00520
00521 inline xreal get_next_time() const {
00522 if (kep)
00523 return get_time() + (xreal)unperturbed_timestep;
00524 else
00525 return get_time() + (xreal)timestep;
00526 }
00527
00528
00529
00530
00531
00532
00533
00534 void initialize_unperturbed();
00535 void initialize_slow();
00536
00537
00538
00539 void update_kepler_from_hdyn();
00540 void reinitialize_kepler_from_hdyn();
00541
00542
00543
00544 hdyn* next_node(hdyn*, bool resolve_unperturbed = true);
00545 hdyn* find_perturber_node();
00546 bool nn_stats(real energy_cutoff, real kT,
00547 vec center, bool verbose,
00548 bool long_binary_output = true,
00549 int which = 0);
00550 real print_pert(bool long_binary_output = true,
00551 int indent = BIN_INDENT);
00552
00553 void setup_binary_node();
00554
00555
00556
00557 void synchronize_node(bool exact = true);
00558
00559 void set_first_timestep(real additional_step_limit = 0);
00560
00561
00562
00563 void update(vec& bt2,
00564 vec& at3);
00565
00566 bool correct_and_update();
00567
00568 int flat_calculate_acc_and_jerk(hdyn* root_node,
00569 bool make_perturber_list);
00570
00571 void perturber_acc_and_jerk_on_leaf(vec & a,
00572 vec & j,
00573 real & p,
00574 real & distance_squared,
00575 hdyn*& nn,
00576 hdyn* pnode,
00577 hdyn* step_node);
00578
00579 void tree_walk_for_partial_acc_and_jerk_on_leaf(hdyn * b,
00580 hdyn * mask,
00581 vec& offset_pos,
00582 vec& offset_vel,
00583 vec& a,
00584 vec& j,
00585 real & p,
00586 real & distance_squared,
00587 hdyn * &p_nn,
00588 bool point_mass_flag,
00589 hdyn * step_node);
00590
00591 void calculate_partial_acc_and_jerk_on_leaf(hdyn * top,
00592 hdyn * common,
00593 hdyn * mask,
00594 vec & a,
00595 vec & j,
00596 real & p,
00597 real & distance_squared,
00598 hdyn * &nn,
00599 bool point_mass_flag,
00600 hdyn * pnode,
00601 hdyn * step_node);
00602
00603 void calculate_partial_acc_and_jerk(hdyn * top,
00604 hdyn * common,
00605 hdyn * mask,
00606 vec & a,
00607 vec & j,
00608 real & p,
00609 real & distance_squared,
00610 hdyn * &p_nn,
00611 bool point_mass_flag,
00612 hdyn* pnode,
00613 hdyn* step_node);
00614
00615 void check_add_perturber(hdyn* p, vec& this_pos);
00616 void create_low_level_perturber_list(hdyn* pnode);
00617 void create_low_level_perturber_lists(bool only_if_null = true);
00618
00619 void calculate_acc_and_jerk_on_low_level_node();
00620 void calculate_acc_and_jerk_on_top_level_node(bool exact);
00621
00622 void top_level_node_prologue_for_force_calculation(bool exact);
00623 int top_level_node_real_force_calculation();
00624 void top_level_node_epilogue_force_calculation();
00625
00626 void calculate_acc_and_jerk(bool exact);
00627
00628 void integrate_node(bool exact = true,
00629 bool integrate_unperturbed = true,
00630 bool force_unperturbed_time = false);
00631
00632
00633
00634 real distance_to_sister_squared();
00635 hdyn* new_sister_node(bool& top_level_combine);
00636 int adjust_tree_structure(int full_dump = 0);
00637
00638 hdyn* check_periapo_node();
00639
00640 hdyn* check_merge_node();
00641 hdyn* merge_nodes(hdyn * bcoll, int full_dump = 0);
00642 void merge_logs_after_collision(hdyn *bi, hdyn* bj);
00643
00644
00645
00646
00647 void print_unperturbed_binary_params();
00648
00649 void update_dyn_from_kepler(bool need_acc_and_jerk = true);
00650 bool is_close_pair();
00651
00652 bool is_unperturbed_and_approaching();
00653 void startup_unperturbed_motion();
00654
00655
00656
00657 real set_unperturbed_timestep(bool check_phase);
00658
00659
00660
00661
00662 real get_max_unperturbed_steps(bool to_apo = true,
00663 bool predict = false);
00664
00665
00666
00667
00668
00669 void recompute_unperturbed_step();
00670 void recompute_unperturbed_steps();
00671
00672 int integrate_unperturbed_motion(bool& reinitialize,
00673 bool force_time = false);
00674
00675
00676
00677 void startup_slow_motion();
00678 void extend_or_end_slow_motion(real P = 0);
00679
00680
00681
00682 bool is_perturbed_cpt();
00683 bool is_perturbed_cm();
00684 void reconstruct_perturbed_list();
00685 void dump_perturbed_list();
00686 int get_index_on_perturbed_list(bool debug = false);
00687 bool on_perturbed_list();
00688 void check_perturbed_list();
00689 void add_to_perturbed_list(int id = 0);
00690 void remove_from_perturbed_list(int id = 0);
00691
00692
00693 };
00694
00695
00696
00697
00698
00699 #include "hdyn_kepler.h"
00700
00701 #include "kira.h"
00702
00703
00704
00705 #define for_all_leaves_or_unperturbed(dyntype, base, node_name) \
00706 for (dyntype* node_name = base; \
00707 node_name != NULL; \
00708 node_name = (dyntype*) node_name->next_node(base, false)) \
00709 if (node_name->get_oldest_daughter() == NULL \
00710 || (node_name->get_oldest_daughter()->get_kepler() \
00711 && node_name->get_oldest_daughter() \
00712 ->get_fully_unperturbed()))
00713
00714
00715
00716
00717 typedef hdyn * hdynptr;
00718
00719
00720
00721
00722
00723
00724 inline node * new_hdyn(hbpfp the_hbpfp,
00725 sbpfp the_sbpfp,
00726 bool use_stories)
00727 {return (node *) new hdyn(the_hbpfp, the_sbpfp);}
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747 inline hdyn * get_hdyn(istream & s = cin,
00748 hbpfp the_hbpfp = new_hydrobase,
00749 sbpfp the_sbpfp = new_starbase)
00750 {
00751
00752
00753 if (dyn::get_ifp() ?
00754 ungetc(getc(dyn::get_ifp()), dyn::get_ifp()) : s.peek() == '(') {
00755
00756 hdyn *root = (hdyn*)get_node(s, new_hdyn, the_hbpfp, the_sbpfp);
00757
00758 root->initialize_unperturbed();
00759 root->initialize_slow();
00760 return root;
00761 }
00762 else return (hdyn*)get_col(s, new_hdyn, the_hbpfp, the_sbpfp, true);
00763 }
00764
00765 #define put_hdyn put_node
00766
00767 inline hdyn * common_ancestor(hdyn * bi, hdyn * bj)
00768 {return (hdyn*) common_ancestor((node*)bi, (node*)bj);}
00769
00770
00771
00772 void pp3_maximal(hdyn *, ostream & s = cerr, int i = 0);
00773 void pp3(hdyn *, ostream & s = cerr, int i = 0);
00774 void pp3_minimal(hdyn *, ostream & s = cerr, int i = 0);
00775 void pp3_tree(hdyn *, ostream & s = cerr, int i = 0);
00776
00777 void pp3_maximal(char *, ostream & s = cerr, int i = 0);
00778 void pp3(char *, ostream & s = cerr, int i = 0);
00779 void pp3_minimal(char *, ostream & s = cerr, int i = 0);
00780 void pp3_tree(char *, ostream & s = cerr, int i = 0);
00781
00782
00783
00784 class QApplication;
00785 int Qt_pp3(hdyn *b,
00786 QApplication *app);
00787 int Qt_pp3(hdyn *b,
00788 const char * disp = NULL);
00789
00790
00791
00792 void print_nn(hdyn* b, int level = 0, ostream& s = cerr);
00793 void print_coll(hdyn* b, int level = 0, ostream& s = cerr);
00794
00795
00796
00797
00798 typedef vec (hdyn::*hdyn_VMF_ptr)(void) const;
00799 typedef void (hdyn::*hdyn_MF_ptr)(const vec &);
00800
00801
00802
00803
00804 void check_consistency_of_node(hdyn * node,
00805 hdyn_VMF_ptr get_something,
00806 char *id);
00807 void check_consistency_of_nodes(hdyn * node);
00808
00809 void create_binary_from_toplevel_nodes(hdyn * bi, hdyn * bj);
00810
00811 void remove_node_and_correct_upto_ancestor(hdyn * ancestor, hdyn * node);
00812
00813 vec something_relative_to_ancestor(hdyn * bj,
00814 hdyn * bi,
00815 hdyn_VMF_ptr get_something);
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825 vec hdyn_something_relative_to_root(hdyn * bi,
00826 hdyn_VMF_ptr get_something);
00827
00828 void correct_leaf_for_change_of_mass(hdyn * node, real dm);
00829
00830 void correct_leaf_for_change_of_vector(hdyn * node,
00831 vec d_something,
00832 hdyn_VMF_ptr get_something,
00833 hdyn_MF_ptr inc_something);
00834
00835 void move_node(hdyn * node_to_move, hdyn * place_to_insert);
00836 void move_node_by_index(int i, int j, hdyn * root);
00837
00838 void calculate_energies(hdyn * root, real eps2,
00839 real & epot, real & ekin, real & etot,
00840 bool cm = false);
00841
00842
00843
00844 void reset_counters(hdyn* bi);
00845
00846
00847
00848 void correct_perturber_lists(hdyn * b,
00849 hdyn ** list,
00850 int n,
00851 hdyn * cm = NULL);
00852
00853 void expand_perturber_lists(hdyn * b,
00854 hdyn * bb,
00855 bool verbose = false);
00856
00857
00858
00859 real kepler_step(hdyn *b, real correction_factor = 1);
00860 real timestep_correction_factor(hdyn *b);
00861
00862 void update_binary_sister(hdyn* bi);
00863
00864 hdyn* node_to_move(hdyn* b, real& tmin);
00865 void get_nodes_to_move(hdyn * b,
00866 hdyn * list[],
00867 int &nlist,
00868 real & tmin);
00869
00870 void initialize_system_phase1(hdyn* b, xreal t);
00871
00872 void correct_acc_and_jerk(hdyn * root,
00873 bool& reset);
00874
00875 void correct_acc_and_jerk(hdyn** next_nodes,
00876 int n_next);
00877
00878
00879
00880 int get_grape4_chip(hdyn *b);
00881 void grape6_set_dma(bool jp_dma = true);
00882
00883 void check_release_grape(unsigned int config,
00884 kira_options *ko, xreal time, bool verbose = true);
00885 void check_release_grape4(kira_options *ko, xreal time, bool verbose = true);
00886 void check_release_grape6(kira_options *ko, xreal time, bool verbose = true);
00887
00888 void grape4_calculate_energies(hdyn *b,
00889 real &epot,
00890 real &ekin,
00891 real &etot,
00892 bool cm = false);
00893 void grape6_calculate_energies(hdyn *b,
00894 real &epot,
00895 real &ekin,
00896 real &etot,
00897 bool cm = false);
00898
00899 int grape4_calculate_acc_and_jerk(hdyn **next_nodes,
00900 int n_next,
00901 xreal time,
00902 bool restart);
00903 int grape6_calculate_acc_and_jerk(hdyn **next_nodes,
00904 int n_next,
00905 xreal time, bool restart);
00906 int grape6_calculate_perturbation(hdyn *parent,
00907 vec& apert1, vec& apert2,
00908 vec& jpert1, vec& jpert2);
00909
00910 bool grape4_calculate_densities(hdyn *root,
00911 real h2_crit = 4);
00912 bool grape6_calculate_densities(hdyn *root,
00913 real h2_crit = 4);
00914
00915
00916
00917 void set_write_unformatted(bool u = true);
00918 bool get_write_unformatted();
00919 void set_complete_system_dump(bool d = true);
00920 void set_hdyn_check_timestep(bool check = true);
00921
00922
00923
00924
00925 void print_sort_counters();
00926
00927 void fast_get_nodes_to_move(hdyn * b,
00928 hdyn * list[],
00929 int & nlist,
00930 xreal & tmin,
00931 bool & reset);
00932
00933 void dump_node_list(int n = 1000000000);
00934 void dump_node_list_for(char *s);
00935
00936
00937
00938 bool has_binary_perturbers(hdyn* b);
00939 void clear_perturbers_slow_perturbed(hdyn *b);
00940 void list_slow_perturbed(hdyn* b);
00941 void check_slow_consistency(hdyn* b);
00942
00943
00944
00945 void synchronize_tree(hdyn * b);
00946
00947 void split_top_level_node(hdyn * bi, int full_dump = 0);
00948 void combine_top_level_nodes(hdyn * bj, hdyn * bi, int full_dump = 0);
00949
00950
00951
00952 void set_allow_unperturbed(hdyn *b, bool value = true);
00953 void set_allow_multiples(hdyn *b, bool value = true);
00954 void toggle_unperturbed(hdyn *b, int level);
00955 void print_unperturbed_options(hdyn *b);
00956 void enable_isolated_multiples(bool value = true);
00957
00958
00959
00960 void set_n_top_level(hdyn *b);
00961 int get_n_top_level();
00962
00963
00964
00965 real pow_approx(real x);
00966
00967
00968
00969 unsigned int kira_config(hdyn *b,
00970 int force_config = -1);
00971
00972 void kira_print_config(unsigned int config);
00973
00974
00975
00976 void initialize_counters_from_log(hdyn* b);
00977 void write_counters_to_log(hdyn* b);
00978 void print_counters(kira_counters* kc,
00979 bool print_all = true,
00980 kira_counters* kc_prev = NULL);
00981
00982
00983
00984 bool kira_calculate_densities(hdyn* b, vec& cod_pos, vec& cod_vel);
00985
00986
00987
00988 void kira_calculate_internal_energies(hdyn* b,
00989 real& epot, real& ekin, real& etot,
00990 bool cm = false,
00991 bool use_grape = true);
00992
00993 void kira_calculate_energies(dyn* b, real eps2,
00994 real &potential, real &kinetic, real &total,
00995 bool cm);
00996
00997 void kira_top_level_energies(dyn *b, real eps2,
00998 real& potential_energy,
00999 real& kinetic_energy);
01000
01001 void print_recalculated_energies(hdyn* b,
01002 bool print_dde = false,
01003 bool save_story = false);
01004
01005 void calculate_energies_with_external(hdyn* b,
01006 real& epot, real& ekin, real& etot,
01007 bool cm = false,
01008 bool use_grape = true);
01009
01010
01011 void check_and_remove_escapers(hdyn* b,
01012 xreal& ttmp, hdyn** next_nodes,
01013 int& n_next, bool& tree_changed);
01014
01015
01016
01017 int kira_calculate_top_level_acc_and_jerk(hdyn **next_nodes,
01018 int n_next,
01019 xreal time,
01020 bool restart_grape);
01021
01022 int top_level_acc_and_jerk_for_list(hdyn **next_nodes,
01023 int n_next,
01024 xreal time);
01025
01026 int calculate_acc_and_jerk_for_list(hdyn ** next_nodes,
01027 int n_next,
01028 xreal time,
01029 bool exact,
01030 bool tree_changed,
01031 bool & reset_force_correction,
01032 bool & restart_grape);
01033
01034 void calculate_acc_and_jerk_on_all_top_level_nodes(hdyn * b);
01035 void calculate_acc_and_jerk_on_top_level_binaries(hdyn * b);
01036
01037 void kira_synchronize_tree(hdyn *b, bool sync_low_level = false);
01038
01039 void initialize_system_phase2(hdyn * b,
01040 int id = 0,
01041 int set_dt = 1);
01042
01043
01044
01045 bool check_kira_flag(hdyn* b, char* kira_flag);
01046 bool check_allowed(bool allow_kira_override,
01047 char * what_is_allowed,
01048 bool verbose, bool& need_skip);
01049
01050
01051
01052 bool kira_initialize(int argc, char** argv,
01053 hdynptr& b,
01054 real& delta_t,
01055 real& dt_log,
01056 int& long_binary_out,
01057 real& dt_snap,
01058 real& dt_sstar,
01059 real& dt_esc,
01060 real& dt_reinit,
01061 real& dt_fulldump,
01062 bool& exact,
01063 real& cpu_time_limit,
01064 bool& verbose,
01065 bool& snap_init,
01066 bool& save_last_snap,
01067 char* snap_save_file,
01068 int& n_stop,
01069 bool& alt_flag);
01070
01071
01072
01073 void kira(hdyn * b,
01074 real delta_t,
01075 real dt_log,
01076 int long_binary_out,
01077 real dt_snap,
01078 real dt_sstar,
01079 real dt_esc,
01080 real dt_reinit,
01081 real dt_fulldump,
01082 bool exact,
01083 real cpu_time_limit,
01084 bool verbose,
01085 bool snap_init,
01086 bool save_snap_at_log,
01087 char* snap_save_file,
01088 int n_stop,
01089 bool alt_flag);
01090
01091 void kira_finalize(hdyn *b);
01092
01093
01094
01095 int integrate_list(hdyn * b,
01096 hdyn ** next_nodes, int n_next,
01097 bool exact, bool & tree_changed,
01098 int& n_list_top_level,
01099 int full_dump,
01100 real r_reflect);
01101
01102
01103
01104 int get_effective_block(real dt);
01105 void print_dstar_params(dyn* b);
01106 bool print_dstar_stats(dyn* b, bool mass_function,
01107 vec center, bool verbose);
01108 void get_energies_with_external(dyn* b, real eps2,
01109 real &kinetic, real &potential, real &total,
01110 bool cm = false);
01111 void print_statistics(hdyn* b, int long_binary_output = 2);
01112 void set_block_check(bool b = true);
01113
01114 void update_cpu_counters(hdyn * b);
01115 void log_output(hdyn * b,
01116 real count, real steps,
01117 real count_top_level, real steps_top_level,
01118 kira_counters* kc_prev,
01119 int long_binary_output = 2);
01120 void force_nodensity();
01121
01122 void snap_output(hdyn * b, real steps, int& snaps,
01123 bool reg_snap, bool last_snap,
01124 char * snap_save_file,
01125 xreal t, xreal ttmp, real t_end,
01126 real& t_snap, real dt_snap, bool verbose);
01127
01128
01129
01130 void clean_up_files();
01131 bool check_file(char* name,
01132 bool del = true);
01133
01134 void check_kira_init(hdyn* b);
01135
01136 bool check_kira_runtime(hdyn* b,
01137 real& t_end, real& new_dt_log, real& new_dt_snap,
01138 int& long_binary_output, char* new_snap_save_file,
01139 bool& tree_changed);
01140
01141
01142
01143 bool evolve_stars(hdyn* b, int full_dump = 0);
01144
01145
01146
01147 real get_sum_of_radii(hdyn* bi, hdyn* bj, bool check_story = false);
01148 real print_encounter_elements(hdyn* bi, hdyn* bj,
01149 char* s = "Collision",
01150 bool verbose = true);
01151
01152 void check_print_close_encounter(hdyn *bi);
01153
01154 void print_close_encounter(hdyn* bi,
01155 hdyn* bj);
01156
01157
01158
01159 void set_smallN_eta(real a);
01160 void set_smallN_gamma(real g);
01161 void set_smallN_niter(int n);
01162 void set_smallN_dtcrit(real dt);
01163 void set_smallN_rcrit(real r);
01164
01165 real get_smallN_eta();
01166 real get_smallN_gamma();
01167 int get_smallN_niter();
01168 real get_smallN_dtcrit();
01169 real get_smallN_rcrit();
01170
01171 real smallN_evolve(hdyn *b,
01172 real t_end = VERY_LARGE_NUMBER,
01173 real break_r2 = VERY_LARGE_NUMBER,
01174 real end_on_unpert = false,
01175 real dt_log = 0,
01176 real dt_energy = 0,
01177 real dt_snap = 0);
01178
01179 real integrate_multiple(hdyn *b);
01180
01181
01182
01183 void clean_up_hdyn_schedule();
01184 void clean_up_hdyn_ev();
01185 void clean_up_hdyn_grape(unsigned int config);
01186 void clean_up_hdyn_grape4();
01187 void clean_up_hdyn_grape6();
01188 void clean_up_kira_ev();
01189
01190 #endif
01191
01192
01193
01194
01195
01196