Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

star_state.C

Go to the documentation of this file.
00001 //
00002 // star_support: Helper functions to aid in setting up and manipulating
00003 //
00004 
00005 #include "star.h"
00006 #include "star_state.h"
00007 
00008 #include "main_sequence.h"
00009 
00010 inline  single_star * new_single_star(stellar_type type,  // All defaults are
00011                                       int  id,            // now specified in
00012                                       real t_cur,         // star_state.h
00013                                       real t_rel,         // star_state.h
00014                                       real m_rel,
00015                                       real m_tot,
00016                                       real m_core,
00017                                       real co_core,
00018                                       real p_rot,
00019                                       real b_fld,
00020                                       node* n)
00021 {
00022 
00023      single_star* element = 0;
00024       switch(type) {
00025          case Planet:
00026          case Brown_Dwarf: element = new brown_dwarf(n);
00027                              break;
00028          case Main_Sequence: element = new main_sequence(n);
00029                             break;
00030          case Hyper_Giant: element = new hyper_giant(n);
00031                              break;
00032          case Hertzsprung_Gap: element = new hertzsprung_gap(n);
00033                              break;
00034          case Sub_Giant: element = new sub_giant(n);
00035                              break;
00036          case Horizontal_Branch: element = new horizontal_branch(n);
00037                              break;
00038          case Super_Giant: element = new super_giant(n);
00039                              break;
00040          case Carbon_Star:
00041          case Helium_Star:
00042          case Helium_Giant: element = new helium_star(n);
00043                              break;
00044          case Helium_Dwarf:
00045          case Carbon_Dwarf:
00046          case Oxygen_Dwarf: element = new white_dwarf(n);
00047                              break;
00048          case Thorn_Zytkow: element = new thorne_zytkow(n);
00049                             break;
00050          case Xray_Pulsar:
00051          case Radio_Pulsar:
00052          case Neutron_Star: element = new neutron_star(n);
00053                             element->set_rotation_period(p_rot);
00054                             element->set_magnetic_field(b_fld);
00055                             break;
00056          case Black_Hole: element = new black_hole(n);
00057                              break;
00058          case Disintegrated: element = new disintegrated(n);
00059                             break;
00060          default: element = new main_sequence(n);
00061       }
00062 
00063       element->initialize(id, t_cur, t_rel, m_rel, m_tot, m_core, co_core);
00064       
00065       return element;
00066    }
00067 
00068 //
00069 // star_hist: helper history function.
00070 //
00071 
00072 void star_hist::put_star_hist() {
00073 
00074      printf("\n %d %f %f %f %f",
00075              star_type, relative_age, relative_mass,
00076              core_mass, radius);
00077 
00078 }
00079 
00080 //
00081 // star_state: state op star.
00082 //
00083 
00084 star_state::star_state() {
00085  
00086   identity = 0;
00087   type = NAS;
00088   class_tpe = O5; //O0_O9;
00089   for (int i=Emission; i<no_of_spec_type; i++) 
00090     class_spec[i] = NAC;
00091   mass = radius = velocity = mdot = 0;
00092   lclass=no_luminosity_class;
00093 }
00094 
00095 star_state::star_state(star* str) {
00096 
00097   identity = 0;
00098   type = NAS;
00099   class_tpe = O5; //O0_O9;
00100   for (int i=Emission; i<no_of_spec_type; i++) 
00101     class_spec[i] = NAC;
00102   mass = radius = velocity = mdot = 0;
00103   lclass=no_luminosity_class;
00104 
00105   make_star_state(str);
00106 
00107 }
00108 
00109 bool remnant(stellar_type type) {
00110 
00111   if ( //type==Brown_Dwarf || type==Planet ||
00112       type==Carbon_Star || type==Helium_Star || type==Helium_Giant ||
00113       type==Helium_Dwarf || type==Carbon_Dwarf || type==Oxygen_Dwarf ||
00114       type==Xray_Pulsar || type==Radio_Pulsar || type==Neutron_Star ||
00115       type==Black_Hole ||  type==Disintegrated)
00116 
00117     return true;
00118 
00119   else
00120     return false;
00121 }
00122 
00123 
00124 void star_state::put_star_state(ostream & s) {
00125 
00126      if(type!=Disintegrated)
00127        s << type_string(class_tpe);
00128      
00129      if (!remnant(type) && type!=Double) {
00130        if (lclass!=no_luminosity_class)
00131          s << type_string(lclass);
00132        s << type_short_string(type);
00133      }
00134      for (int i=Emission; i<no_of_spec_type; i++)
00135          if (class_spec[i])
00136             s << "-" << type_short_string((star_type_spec)i);
00137 }
00138 
00139 void star_state::init_star_state(star* str) {
00140     
00141      identity = str->get_identity();
00142 
00143      mass = str->get_total_mass();
00144      velocity = str->get_velocity();
00145      mdot = 0;
00146 
00147      type = str->get_element_type();
00148 
00149      if (!str->remnant()) {
00150         class_tpe = get_spectral_class(str->temperature()); 
00151                   //get_spectral_class(mass);
00152      }
00153      else if(type==Carbon_Star || Helium_Star || Helium_Giant)
00154         class_tpe = he;
00155      else if(type==Helium_Dwarf || type==Carbon_Dwarf ||type==Oxygen_Dwarf)
00156         class_tpe = wd;
00157      else if(type==Xray_Pulsar || type==Radio_Pulsar || type==Neutron_Star)
00158         class_tpe = ns;
00159      else if(type==Black_Hole)
00160         class_tpe = bh;
00161      else if(type==Brown_Dwarf || type==Planet)
00162         class_tpe = bd;
00163      else if(type==Disintegrated)
00164         class_tpe = di;
00165      else if(type==Double)
00166         class_tpe = bin;
00167      else
00168         class_tpe = no_spectral_class;
00169 
00170      for (int i=Emission; i<no_of_spec_type; i++)
00171          class_spec[i] = str->get_spec_type(
00172                          dynamic_cast(star_type_spec, i));
00173 
00174      if(str->is_binary_component() &&
00175         str->get_effective_radius() >= str->get_binary()->roche_radius(str)) {
00176        class_spec[Rl_filling] = 1;
00177      }
00178 }
00179 
00180 void star_state::make_star_state(star* str) {
00181   //  cerr<<"star_state::make_star_state"<<endl;
00182   //  str->dump(cerr);
00183   
00184      type = str->get_element_type();
00185      lclass = get_luminosity_class(str->temperature(),
00186                                    str->get_luminosity());
00187      if (identity) // is star initialized?
00188         mdot = str->get_total_mass() - mass;
00189      velocity = str->get_velocity();
00190      mass = str->get_total_mass();
00191      // Changed the effective radius to real radius so that
00192      // the double star can see that it is indeed filling its Roche-lobe.
00193      // (SPZ:2/1998)
00194      //     radius = str->get_effective_radius();
00195 
00196      if (!str->remnant()){
00197         class_tpe = get_spectral_class(str->temperature());
00198                     //get_spectral_class(str->get_total_mass());
00199      }
00200      else if(type==Carbon_Star || type==Helium_Star || type==Helium_Giant)
00201         class_tpe = he;
00202      else if(type==Helium_Dwarf || type==Carbon_Dwarf || type==Oxygen_Dwarf)
00203         class_tpe = wd;
00204      else if(type==Xray_Pulsar || type==Radio_Pulsar || type==Neutron_Star)
00205         class_tpe = ns;
00206      else if(type==Black_Hole)
00207         class_tpe = bh;
00208      else if(type==Brown_Dwarf || type==Planet)
00209         class_tpe = bd;
00210      else if(type==Disintegrated)
00211         class_tpe = di;
00212      else if(type==Double)
00213         class_tpe = bin;
00214      else
00215         class_tpe = no_spectral_class;
00216 
00217      for (int i=NAC; i<no_of_spec_type; i++)
00218          class_spec[i] = str->get_spec_type(
00219                          dynamic_cast(star_type_spec, i));
00220 
00221      if(str->is_binary_component() &&
00222         str->get_effective_radius() >= str->get_binary()->roche_radius(str)) {
00223          class_spec[Rl_filling] = 1;
00224        }
00225    }
00226 
00227 bool star_state::special() {
00228 
00229   bool special_star = false;
00230 
00231   if (!class_spec[Dsntgr] &&
00232       (class_spec[Emission] ||
00233        class_spec[Merger] ||
00234        class_spec[Blue_Straggler] ||
00235        class_spec[Barium] ||
00236        (remnant(type) && class_spec[Accreting])))
00237     special_star = true;
00238 
00239   return special_star;
00240 }
00241 
00242 void put_state(star_state st, ostream & s) {
00243   //  cerr<<"put_state: "<<endl;
00244   //cerr << st.type<<" "<<st.lclass<<" "
00245   //   <<st.mass<<" "<<st.radius<<" "<<st.velocity<<endl;
00246 
00247      if (st.type!=Disintegrated)
00248        s << type_string(st.class_tpe);
00249      
00250      if (!remnant(st.type) && st.type!=Double) {
00251        if (st.lclass!=no_luminosity_class)
00252          s << type_string(st.lclass);
00253        s << type_short_string(st.type);
00254      }
00255      for (int i=Emission; i<no_of_spec_type; i++)
00256          if (st.class_spec[i])
00257             s << "-" << type_short_string((star_type_spec)i);
00258 }
00259 
00260 void put_short_state(star_state st, ostream & s) {
00261   
00262      s << type_string(st.class_tpe);
00263      if (!remnant(st.type) && st.type!=Double) {
00264        if (st.lclass!=no_luminosity_class)
00265          s << type_string(st.lclass);
00266        s << type_short_string(st.type);
00267      }
00268 }
00269 
00270 char* type_dominant_state(star_state sts) {
00271 
00272   if (sts.class_spec[Blue_Straggler])
00273     return type_string(Blue_Straggler);
00274   
00275   else if (sts.class_spec[Barium])
00276     return type_string(Barium);
00277   
00278   else if (sts.class_spec[Emission])
00279     return type_string(Emission);
00280   
00281   else if (sts.class_spec[Accreting])
00282     return type_string(Accreting);
00283   
00284   else if (sts.class_spec[Merger])
00285     return type_string(Merger);
00286   
00287   return "?";
00288   
00289 }
00290 
00291 void print_star(starbase* b, ostream & s) {
00292   
00293   //  if (has_dstar(dynamic_cast(hdyn*, b->get_node));
00294   if (b->get_element_type()==Double) {
00295 
00296     // SPZ+SMcM: Temporarily Removed at July 21, 1998
00297     cerr << "SPZ+SMcM: Temporarily Removed at July 21, 1998"<<endl;
00298     cerr << "in print_star" << endl;
00299     //    put_state(make_state(dynamic_cast(double_star*, b)), s);
00300     
00301   //  else if (has_sstar(dynamic_cast(hdyn*, b->get_node));
00302   }  else if (b->get_element_type()) {
00303     star_state ss(dynamic_cast(star*, b));
00304     put_state(ss, s);
00305   }
00306   else {
00307     s << "No star attached to starbase of: ";
00308     b->get_node()->pretty_print_tree(s);
00309   }
00310 }
00311 
00312 void pretty_print_star(starbase* b, int depth_level, ostream & s) {
00313     int  k = depth_level;
00314     while (k--)
00315         s << "  ";
00316     print_star(b, s);
00317     s << endl;
00318     if (b->get_node()->is_parent())
00319         for_all_daughters(node, b->get_node(), n)
00320             pretty_print_star(n->get_starbase(), depth_level + 1, s);
00321     }
00322 
00323 void pretty_print_star(starbase* b, ostream & s) {
00324 
00325       pretty_print_star(b, 0, s);
00326     }
00327 
00328 
00329 

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