Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

sstar_to_dyn.C

Go to the documentation of this file.
00001 //
00002 // sstar_to_dyn.C 
00003 //
00004 /*      Communication between the dynamics and the single stelaar
00005  *      evolution.
00006  *
00007  */
00008 
00009 #include "sstar_to_dyn.h"
00010 #include "star.h"
00011 #include "dyn.h"
00012 //#define MASS_UPDATE_LIMIT 0.01
00013 
00014 #define DEBUG false
00015 
00016 
00017 bool has_sstar(dyn * bi) {
00018 
00019   if(bi->is_leaf() && bi->get_starbase()->get_element_type()!=NAS) {
00020     return true;
00021   }else{
00022     return false;
00023   }
00024 }
00025 
00026 vector conv_v_star_to_dyn(vector& v, real rf, real tf) {
00027 
00028 //              Internal velocity is km/s
00029 //              Internal size is solar raii
00030 //              Internal time is Myr.
00031 //              km/s to Rsun/Myr
00032       real to_Rsun_Myr = cnsts.physics(km_per_s) * cnsts.physics(Myear)
00033                        / cnsts.parameters(solar_radius);
00034       real to_dyn      = rf/tf;
00035       //cerr<<"scaling: "<<to_dyn<<endl;
00036       //cerr <<"kick: " << v << " dyn_V: " << to_Rsun_Myr * to_dyn * v << endl;
00037       return to_Rsun_Myr * to_dyn * v;
00038    }
00039 
00040 vector anomalous_velocity(dyn* b) {
00041     //cerr << "in anomalous_velocity..." << endl;
00042     //PRL(b->get_starbase()->get_anomal_velocity());
00043 
00044      vector anomal_velocity = b->get_starbase()->get_anomal_velocity();
00045      vector zero_vector=0;
00046      b->get_starbase()->set_anomal_velocity(zero_vector);
00047 
00048      vector new_velocity = conv_v_star_to_dyn(anomal_velocity,
00049                        b->get_starbase()->conv_r_star_to_dyn(1),
00050                        b->get_starbase()->conv_t_star_to_dyn(1));
00051 
00052     //PRL(b->get_starbase()->get_anomal_velocity());
00053 
00054      return new_velocity;
00055    }
00056 
00057 real get_effective_radius(dyn *b) {
00058      return b->get_starbase()->conv_r_star_to_dyn( 
00059             b->get_starbase()->get_effective_radius());
00060    }
00061 
00062 real get_total_mass(dyn *b) {
00063       return b->get_starbase()->conv_m_star_to_dyn(
00064              b->get_starbase()->get_total_mass());
00065    }
00066 
00067 stellar_type get_element_type(dyn *b) {
00068       return (stellar_type)b->get_starbase()->get_element_type();
00069    }
00070 
00071 #define EPSILON 1.e-10
00072 local void evolve_the_stars(node* bi, const real end_time) {
00073 
00074   if(DEBUG) 
00075       cerr << "evolve_the_stars: " <<bi->format_label() <<" "<<end_time;
00076   
00077     real current_time = ((star*)bi->get_starbase())->get_current_time();
00078     real time_step    =  bi->get_starbase()->get_evolve_timestep();
00079 
00080     while (end_time>current_time+time_step) {
00081        bi->get_starbase()->evolve_element(current_time+time_step);
00082        bi->get_starbase()->evolve_element(
00083              min(current_time+time_step+EPSILON, end_time));
00084        current_time = ((star*)bi->get_starbase())->get_current_time();
00085        time_step    =  bi->get_starbase()->get_evolve_timestep();
00086 
00087       if(DEBUG) 
00088          cerr <<" -dt="<<current_time<<" "<<time_step<<endl;
00089    }
00090 
00091     bi->get_starbase()->evolve_element(end_time);
00092 
00093     //bi->get_starbase()->get_seba_counters()->step_sstar++;
00094 
00095     if(DEBUG) 
00096       cerr<<" and leave"<<endl;
00097 }
00098 #undef EPSILON
00099 
00100 
00101 bool stellar_evolution(dyn *b)
00102 {
00103     bool update_all_masses = false;
00104     
00105     real stellar_evolution_time = b->get_starbase()->
00106                 conv_t_dyn_to_star(b->get_system_time());
00107 
00108     for_all_leaves(dyn, b, bi) {
00109         if (! bi->is_low_level_node()
00110             || !((star*)(bi->get_starbase()))->is_binary_component()) {
00111 
00112           if(DEBUG) 
00113                 ((star*)bi->get_starbase())->dump(cerr);
00114 
00115 //        cerr << "Time = " << bi->get_system_time() << " "
00116 //             << bi->format_label() << endl;
00117 //        PRC(get_total_mass(bi) - bi->get_mass());
00118 
00119    
00120             real old_dyn_mass = bi->get_mass();
00121             evolve_the_stars(bi, stellar_evolution_time);
00122 //          bi->get_starbase()->evolve_element(stellar_evolution_time);
00123             real new_dyn_mass_from_star = get_total_mass(bi);
00124             real new_radius =  b->get_starbase()->
00125                 conv_r_star_to_dyn(bi->get_starbase()->get_effective_radius());
00126             if (old_dyn_mass <= 0 || new_dyn_mass_from_star <= 0){
00127                 PRC(old_dyn_mass);PRC(new_dyn_mass_from_star);PRL(new_radius);
00128                 ((star*)(bi->get_starbase()))->dump(cerr);
00129             }
00130 
00131             bi->set_radius(new_radius);
00132 
00133 //        cerr << bi->get_system_time() << " "
00134 //             << bi->format_label() << endl;
00135 //        PRC(get_total_mass(bi) - bi->get_mass());
00136 
00137             if(DEBUG) 
00138               ((star*)bi->get_starbase())->dump(cerr);
00139  
00140             if (abs(new_dyn_mass_from_star-old_dyn_mass)/old_dyn_mass
00141                 >=cnsts.star_to_dyn(stellar_mass_update_limit)) {
00142                 update_all_masses = true;
00143             }
00144 
00145 //          if (abs(new_dyn_mass_from_star-old_dyn_mass)/old_dyn_mass
00146 //              >=MASS_UPDATE_LIMIT){
00147 //              update_all_masses = true;
00148         }
00149     }
00150     return update_all_masses;
00151 }
00152 
00153 real sudden_mass_loss(dyn* stellar_node) {
00154 
00155    real dm_sun =  stellar_node->get_starbase()->sudden_mass_loss();
00156    real dm_dyn = stellar_node->get_starbase()->conv_m_star_to_dyn(dm_sun);
00157 
00158    if (dm_sun!=0 && dm_dyn!=0)
00159      cerr << "sudden mass loss form single star "
00160           << stellar_node->format_label()
00161           << " dm = " << dm_dyn << " (" << dm_sun << " [Msun]" << endl;
00162 
00163    return dm_dyn;
00164                                                   
00165    }
00166 
00167 
00168 // Normally the primary (in mass) coalesces with the secondary.
00169 // However, this can be rather dangerous if the primary is a giant
00170 // and the total mass of the merger product is likely to exceed that
00171 // for a Wolf-Rayet star.
00172 // Here we check wehter or not this exception occurs.
00173 // Normally completley unimportand. But for 30-Doradus it can very wel
00174 // happen. (SPZ:02/1998).
00175 bool merge_with_primary(star* primary, star *secondary) {
00176 
00177   bool merge_with_primary = true;
00178   
00179   real m_conserved = primary->get_total_mass() 
00180     + secondary->get_total_mass();
00181 
00182   if (primary->get_total_mass() < secondary->get_total_mass()) {
00183 
00184     merge_with_primary = false;
00185 
00186     if (m_conserved >= cnsts.parameters(massive_star_mass_limit) &&
00187         !(secondary->get_element_type()==Main_Sequence ||
00188           secondary->remnant())) {
00189 
00190       merge_with_primary = true;   // Merge with primary anyway
00191 
00192       if (!(primary->get_element_type()!=Main_Sequence ||
00193             primary->remnant()))
00194       
00195         cerr << "Merge secondary with primary, although secondary is a "
00196              << type_string(secondary->get_element_type())
00197              << " and the total mass exceeds that for a Wolf-Rayet."
00198              << endl;
00199     }
00200 
00201   }
00202   else {
00203 
00204     if (m_conserved >= cnsts.parameters(massive_star_mass_limit) &&
00205         !(primary->get_element_type()==Main_Sequence ||
00206           primary->remnant())) {
00207       
00208       if (secondary->get_element_type()==Main_Sequence ||
00209           secondary->remnant())
00210         
00211           merge_with_primary = false;   // Merge with secondary.
00212       
00213       else
00214           cerr << "Merge primary with secondary, although primary is a "
00215                << type_string(primary->get_element_type())
00216                << " and the total mass exceeds that for a Wolf-Rayet."
00217                << endl;
00218     }
00219   }
00220 
00221   return merge_with_primary;
00222 }
00223 

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