Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

kira_encounter.C

Go to the documentation of this file.
00001 
00002 #include "hdyn.h"
00003 #include <star/dstar_to_kira.h>
00004 #include <star/single_star.h>
00005 
00006 real get_sum_of_radii(hdyn* bi, hdyn* bj) {
00007 
00008     // by default
00009     real sum_of_radii = bi->get_radius()+bj->get_radius();
00010 
00011     // For black hole use tidal horizon instead of radius
00012     if(bi->get_starbase()->get_element_type() == Black_Hole ||
00013        (find_qmatch(bi->get_log_story(), "black_hole") &&
00014         getiq(bi->get_log_story(), "black_hole")==1)) {
00015 
00016         if(!(bi->get_starbase()->get_element_type() == Black_Hole ||
00017              find_qmatch(bj->get_log_story(), "black_hole"))) {
00018 
00019             sum_of_radii = 2 * bj->get_radius()
00020                 * (pow(bi->get_mass()/bj->get_mass(), ONE_THIRD));
00021           }
00022       }
00023     else if(bj->get_starbase()->get_element_type() == Black_Hole ||
00024             (find_qmatch(bj->get_log_story(), "black_hole") &&
00025              getiq(bj->get_log_story(), "black_hole")==1)) {
00026 
00027         sum_of_radii = 2 * bi->get_radius()
00028             * (pow(bj->get_mass()/bi->get_mass(), ONE_THIRD));
00029       }
00030 
00031     return sum_of_radii;
00032   }
00033 
00034 real print_encounter_elements(hdyn* bi, hdyn* bj,
00035                               char* s,              // default = "Collision"
00036                               bool verbose /* = true */)
00037 {
00038     kepler k;
00039     initialize_kepler_from_dyn_pair(k, bi, bj, true);   // minimal kepler
00040                                                         // -- no phase info
00041 
00042     cerr << endl;
00043     cerr << s << " at time = " << bi->get_time();
00044 
00045     if (bi->get_use_sstar() && verbose) {
00046 
00047         cerr << " ("
00048              << bi->get_starbase()->conv_t_dyn_to_star(bi->get_time())
00049              << " [Myr])";
00050         cerr << " between \n"
00051              << "     " << bi->format_label() << " (";
00052         put_state(make_star_state(bi), cerr);
00053         cerr << "; M = " << bi->get_starbase()->get_total_mass()
00054              << " [Msun], "
00055              << " R = " << bi->get_starbase()->get_effective_radius()
00056              << " [Rsun]) and\n"
00057              << "     " << bj->format_label()
00058              << " (";
00059         put_state(make_star_state(bj), cerr);
00060         cerr << "; M = " << bj->get_starbase()->get_total_mass()
00061              << " [Msun], "
00062              << " R = " << bj->get_starbase()->get_effective_radius()
00063              << " [Rsun]) "
00064              <<"\n     at distance "
00065              << k.get_periastron()
00066              << " ("
00067              << bi->get_starbase()->conv_r_dyn_to_star(k.get_periastron())
00068              << " [Rsun]).";
00069 
00070     } else {
00071 
00072       cerr << " between " << bi->format_label();
00073       if(bi->get_starbase()->get_element_type() == Black_Hole ||
00074          (find_qmatch(bi->get_log_story(), "black_hole") &&
00075           getiq(bi->get_log_story(), "black_hole")==1))
00076         cerr << " [bh] ";
00077       
00078       cerr << " and " << bj->format_label();
00079       if(bj->get_starbase()->get_element_type() == Black_Hole ||
00080          (find_qmatch(bj->get_log_story(), "black_hole") &&
00081           getiq(bj->get_log_story(), "black_hole")==1))
00082         cerr << " [bh] ";
00083       
00084     }
00085 
00086     cerr << endl;
00087 
00088     if (k.get_energy() < 0) {
00089         cerr << "     Orbital parameters: ";
00090 
00091         print_binary_params(&k, bi->get_mass(), 0.0,
00092                             abs(bi->get_pos()), verbose, 10, 10);
00093         cerr << endl;
00094     }
00095     else
00096         cerr << "     E = " << k.get_energy() << endl;
00097       
00098 
00099     return k.get_energy();
00100 }
00101 
00102 
00103 void check_print_close_encounter(hdyn *bi)
00104 {
00105     if (bi && bi->is_valid()) {
00106 
00107         hdyn *nn = bi->get_nn();
00108 
00109         // Use nearest neighbor for encounter diagnostics.
00110         // Only consider encounters between nodes at the top level
00111         // or the next level down (added by Steve 4/99 to prevent
00112         // multiple output in bound hierarchical systems).
00113 
00114         if (nn && bi->is_leaf()
00115             && (bi->is_top_level_node()
00116                 || bi->get_parent()->is_top_level_node())
00117             && bi->get_kepler() == NULL
00118             && bi->get_nn() != NULL
00119             && nn->is_valid()
00120             && nn->is_leaf()
00121             && (nn->is_top_level_node()
00122                 || nn->get_parent()->is_top_level_node())
00123             && nn->get_kepler() == NULL
00124             && bi->get_d_nn_sq()
00125                         <= bi->get_stellar_encounter_criterion_sq())
00126 
00127                 print_close_encounter(bi, nn);
00128     }
00129 }
00130 
00131 // Flag close encounter distances between stars.  Output occurs on any
00132 // unbound encounter, and on the first encounter in a bound system.
00133 // Self-contained function, using the log story to propogate data.
00134 
00135 void print_close_encounter(hdyn* bi,
00136                            hdyn* bj)
00137 {
00138     if (bi->get_mass() < bj->get_mass())  // Note: this "<" means that equal-
00139         return;                           // mass stars get printed twice!
00140 
00141     real d2cc_2 = -1;
00142     real d2cc_1 = -1;
00143     real d2cc   = -1;
00144 
00145     // Variables:       bi is primary, bj is current coll
00146     //                  cc_name is label of previous coll
00147     //                  cc_time is time of previous coll
00148     //                  d2cc is squared distance to coll
00149     //                  d2cc_1 is previous d2cc
00150     //                  d2cc_2 is previous d2cc_1
00151     //                  pcc_name is label of coll at last pericenter
00152     //                  pcc_time is time of last pericenter
00153     //                  pcc_cntr counts bound pericenters
00154     //
00155     // All but bi and bj are stored in the bi log story.
00156 
00157     char *cc_name = getsq(bi->get_log_story(), "cc_name");
00158 
00159 #if 0
00160     cerr << "\nIn print_close_encounter with bi =  " << bi->format_label()
00161          << "  at time " << bi->get_system_time() << endl;
00162     cerr << "     "; print_coll(bi,2);
00163     cerr << "     "; print_nn(bi,2); 
00164     cerr << "     (bj = " << bj->format_label();
00165     cerr << ":  coll = "; print_coll(bj);
00166     cerr << ",  nn = "; print_nn(bj); cerr << ")" << endl;
00167 
00168     cerr << "     cc_name = " << getsq(bi->get_log_story(), "cc_name")
00169          << endl;
00170 #endif
00171   
00172     if (cc_name && streq(cc_name, bj->format_label())) {
00173 
00174         // Retrieve coll information from the log story.
00175 
00176         d2cc_2 = getrq(bi->get_log_story(), "d2cc_1");
00177         d2cc_1 = getrq(bi->get_log_story(), "d2cc");
00178         d2cc   = square(bi->get_pos() - bj->get_pos());
00179 
00180         if (d2cc_2 > d2cc_1 && d2cc >= d2cc_1) {    // just passed pericenter
00181 
00182             int pcc_cntr = 0;
00183             real E = get_total_energy(bi, bj);
00184 
00185             if (E > 0) {
00186 
00187                 // Always print unbound encounter elements.
00188 
00189                 if (bi->get_kira_diag()->report_close_encounters >= 1)
00190                     print_encounter_elements(bi, bj, "Close encounter");
00191 
00192             }
00193             else {
00194 
00195                 // Only print first bound encounter.
00196 
00197                 char *pcc_name = getsq(bi->get_log_story(), "pcc_name");
00198         
00199                 if (pcc_name && streq(pcc_name, bj->format_label())) {
00200                     pcc_cntr = getiq(bi->get_log_story(), "pcc_cntr");
00201                     if (pcc_cntr == -1) 
00202                         pcc_cntr=0;
00203                 }
00204 
00205                 pcc_cntr++;
00206 
00207                 if (pcc_cntr == 1
00208                     && bi->get_kira_diag()->report_close_encounters >= 2)
00209                     print_encounter_elements(bi, bj, "First bound encounter");
00210             }
00211 
00212             // Save data on last pericenter (bound or unbound).
00213             // Note that an unbound pericenter resets pcc_cntr to zero.
00214 
00215             putiq(bi->get_log_story(), "pcc_cntr", pcc_cntr);
00216             putsq(bi->get_log_story(), "pcc_name", bj->format_label());
00217             putrq(bi->get_log_story(), "pcc_time", bi->get_time());  
00218 
00219         }
00220 
00221     }
00222     else if (getsq(bi->get_log_story(), "pcc_name"))
00223 
00224         if ((cc_name == NULL
00225             || strcmp(cc_name, getsq(bi->get_log_story(), "pcc_name")))
00226             && bi->get_kira_diag()->report_close_encounters > 0) {
00227 
00228             // Unlikely multiple encounter(?).  Has been known to occur
00229             // when one incoming star overtakes another.
00230 
00231             cerr << endl << "print_close_encounter:  "
00232                  << "bi = " << bi->format_label()
00233                  << " at time " << bi->get_system_time() << endl;
00234             cerr << "     current coll = " << bj->format_label();
00235             cerr << "  previous coll = ";
00236             if (cc_name)
00237                 cerr << cc_name;
00238             else
00239                 cerr << "(null)";
00240             cerr << endl;
00241             cerr << "     coll at last pericenter = "
00242                  << getsq(bi->get_log_story(), "pcc_name");
00243             cerr << "  (periastron counter = "
00244                  << getiq(bi->get_log_story(), "pcc_cntr") << ")\n";
00245         }
00246 
00247     putsq(bi->get_log_story(), "cc_name", bj->format_label());
00248     putrq(bi->get_log_story(), "d2cc_1", d2cc_1);  
00249     putrq(bi->get_log_story(), "d2cc", d2cc);  
00250     putrq(bi->get_log_story(), "cc_time", bi->get_time());  
00251 
00252 #if 0
00253     cerr << "\nAt end of print_close_encounter at time "
00254          << bi->get_system_time() << endl;
00255     cerr << "bi = " << bi->format_label();
00256     cerr << ", cc_name = " << getsq(bi->get_log_story(), "cc_name") << endl;
00257 #endif
00258 
00259 }
00260 

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