Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

evolve_star.C

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 //++ Notes:
00011 //++  Assymetry in supernova is taken care of by integrator (see starev).
00012 //++
00013 //++ Example of usage:      
00014 //++  evolve_star -c -d 2 -m 10 -t 30
00015 //++
00016 //++ See also: addstar
00017 //++           mkmass
00018 //++           mknode
00019 //++           nstarev
00020 //++           starev
00021 
00022 
00024 
00025 //   version 1:        1997   Steven McMillan
00026 //   version 1.1: July 1998   Simon F. Portegies Zwart
00027 //                            spz@grape.c.u-tokyo.ac.jp
00028 
00029 // evolve_star: Handy little program using Simon's stellar evolution
00030 //              package to track the evolution of one or more stars.
00031 //
00032 //              NOTE: There is no particular reason to keep this
00033 //                    program in the hdyn section of starlab...
00034 //
00035 //                    Dyn is necessary here because of flatten_node and
00036 //                    system_time, and also because stellar_evolution()
00037 //                    expects a dyn pointer.
00038 
00039 #include "dyn.h"
00040 #include <star/sstar_to_dyn.h>
00041 #include <star/dstar_to_dyn.h>
00042 
00043 main(int argc, char **argv)
00044 {
00045     // Defaults:
00046 
00047     int n = 1;                                  // 1 star
00048     real m = 1.0;                               // 1 solar mass
00049     real t = 0.0, dt = 10.0, t_end = 1000.0;    // 1 Gyr, 10 Myr steps
00050 
00051     bool create_system = false;                 // expect system on stdin
00052 
00053     extern char *poptarg;
00054     int c;
00055     char* param_string = "cd:m:M:n:ct:";
00056 
00057     while ((c = pgetopt(argc, argv, param_string)) != -1) {
00058         switch (c) {
00059             case 'c':   create_system = true;
00060                         break;
00061             case 'd':   dt = atof(poptarg);
00062                         break;
00063 
00064             case 'm':
00065             case 'M':   m = atof(poptarg);      // Note: M, m, and n are used
00066                         break;                  // only if we are creating
00067             case 'n':   n = atoi(poptarg);      // our own system ("-c").
00068                         break;
00069 
00070             case 't':   t_end = atof(poptarg);
00071                         break;
00072             default:
00073             case '?': params_to_usage(cerr, argv[0], param_string);
00074                       get_help();
00075                       exit(1);
00076         }
00077     }
00078 
00079     dyn *b;                                     // root node
00080 
00081     if (create_system) {
00082 
00083         if (n < 1 || m <= 0.0) err_exit("Need N and M > 0");
00084         b = (dyn*) mknode_mass(n, m);
00085 
00086     } else {
00087 
00088         b = get_dyn(cin);
00089         if (b == NULL) err_exit("Can't read input snapshot");
00090 
00091         n = 0;
00092         m = 0;
00093         b->flatten_node();
00094         for_all_daughters(dyn, b, bb) {
00095             n++;
00096             m += bb->get_mass();
00097         }
00098 
00099     }
00100 
00101     // Now total number of star nodes is n, total mass is m (solar),
00102     // in *all* cases.
00103 
00104     // Set stellar evolution mass unit to 1 solar mass, length unit
00105     // to 1 pc, time unit to 1 Myr:
00106 
00107     b->get_starbase()->set_stellar_evolution_scaling(1.0, 1.0, 1.0);
00108 
00109     // Start star(s) on the Main Sequence:
00110 
00111     addstar(b, 0.0, Main_Sequence);
00112 
00113     // End of initialization.  Now loop over evolution.
00114 
00115     while (t < t_end - 0.0001*dt) {
00116 
00117         int old_id_sum = 0;
00118         {for_all_daughters(dyn, b, bb) {
00119             star* s = (star*) bb->get_starbase();
00120             old_id_sum += s->get_element_type();
00121         }}
00122 
00123         // Evolve the system through one timestep.
00124 
00125         // NOTE that the stellar evolution routines expect
00126         // system_time and node->mass to be properly set.
00127 
00128         b->set_system_time(t += dt);
00129         stellar_evolution(b);
00130 
00131         int new_id_sum = 0;
00132         {for_all_daughters(dyn, b, bb) {
00133 
00134             star* s = (star*) bb->get_starbase();
00135             new_id_sum += s->get_element_type();
00136 
00137             // Routinely update the mass.
00138 
00139             bb->set_mass(s->get_total_mass());  // (Note: get_total_mass()
00140                                                 //        is in dyn units)
00141         }}
00142 
00143         // Change in identity of any star signals output from single_star_io.
00144         // Extra line feed here just cleans up output...
00145 
00146         if (new_id_sum != old_id_sum) cerr << endl;
00147 
00148         // Current verbose output on every star at every step:
00149 
00150         int count = 0;
00151         {for_all_daughters(dyn, b, bb) {
00152 
00153             if (count++ == 0)
00154                 fprintf(stderr, "time = %9.2f  ", t);
00155             else
00156                 fprintf(stderr, "                  ");
00157 
00158             star* s = (star*) bb->get_starbase();
00159             single_star* ss = (single_star*) s;
00160 
00161             ss->dump(cerr, false);
00162             
00163             cerr << bb->format_label() << "  "
00164                  << type_string(s->get_element_type())
00165                  << "  M = " << s->get_total_mass()
00166                  << "  Mcore = " << s->get_core_mass()
00167                  << "  L = " << ss->get_luminosity()
00168                  << "  V = " << ss->magnitude()
00169                  << "  T = " << ss->temperature()
00170                  << "  R = " << ss->get_radius()
00171                  << endl;
00172         }}
00173 
00174     }
00175 }

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