Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

starev.C

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 //++ the single stars are part of the dynamical tree.
00019 //++ Since the assymetry in supernovae are taken care of by the 
00020 //++   dynamical model no kicks are applied.
00021 
00022 //   version 1.0:  Februari 1993   Simon F. Portegies Zwart
00023 //                                 spz@grape.c.u-tokyo.ac.jp 
00024 
00025 //#include "dyn.h"
00026 #include "node.h"
00027 #include "single_star.h"
00028 #include "main_sequence.h"
00029 //#include "sstar_to_dyn.h"
00030 #define EPSILON 1.e-10
00031 
00032 #ifdef TOOLBOX
00033 
00034 local void evolve_star_until_next_time(node* bi, const real out_time) {
00035 
00036           real current_time = ((star*)bi->get_starbase())->get_current_time();
00037           real time_step    =  bi->get_starbase()->get_evolve_timestep();
00038 
00039           while (out_time>current_time+time_step) {
00040              bi->get_starbase()->evolve_element(current_time+time_step);
00041              bi->get_starbase()->evolve_element(
00042                  min(current_time+time_step+EPSILON, out_time));
00043              current_time = ((star*)bi->get_starbase())->get_current_time();
00044              time_step    =  bi->get_starbase()->get_evolve_timestep();
00045 
00046              star_state ss(dynamic_cast(star*, bi->get_starbase()));
00047              put_state(ss, cerr);
00048 
00049              // print_star(bi->get_starbase(), cerr);
00050 
00051              int p = cerr.precision(HIGH_PRECISION);
00052              bi->get_starbase()->dump(cerr, false);
00053              cerr.precision(p);
00054           }
00055          bi->get_starbase()->evolve_element(out_time);
00056 
00057          print_star(bi->get_starbase(), cerr);
00058 
00059 /*
00060 cerr<< "ov: " << bi->get_starbase()->get_element_type() 
00061         << " " <<bi->get_starbase()->get_total_mass() << " t= "
00062         << ((star*)bi->get_starbase())->get_current_time() << " "
00063         << ((star*)bi->get_starbase())->get_current_time()
00064            +bi->get_starbase()->get_evolve_timestep() << " -> "
00065         << out_time << endl;
00066 */
00067 }
00068 
00069 /*-----------------------------------------------------------------------------
00070  *  main  --
00071  *      usage:
00072  *              addstar -t # [options]  ,
00073  *
00074  *              where # is the initial age of the cluster.
00075  *      options:
00076  *              The following options are allowed:
00077  *      cluster age:
00078  *              -t #    Where # stands for the initial age of the
00079  *                      in Myear.
00080  *
00081  *              At present the running time of the integrator correspnds
00082  *              to the stellar age an a one by 10e6year basis.
00083  *              This however should be scaled to the cluster parameters.
00084  *-----------------------------------------------------------------------------
00085  */
00086 void main(int argc, char ** argv)
00087     {
00088     stellar_type type = Main_Sequence;
00089     char * star_type_string;
00090     int  c;
00091 
00092     bool  t_flag = FALSE;
00093     bool  S_flag = FALSE;
00094     bool  c_flag = FALSE;
00095     bool  M_flag = FALSE;
00096     bool  n_flag = FALSE;
00097     bool  T_flag = FALSE;
00098     bool  R_flag = FALSE;
00099     real  m_tot = 10;
00100     real  r_hm = 100;
00101     real  t_hc = 1;
00102     real  t_start = 0;           // default value;
00103     real  t_end = 100;
00104     int n_steps = 1;
00105     char  *comment;
00106     int input_seed=0, actual_seed;
00107     extern char *poptarg;
00108     int  pgetopt(int, char **, char *);
00109     char *param_string = "n:M:R:T:t:S:s:c:";
00110 
00111     check_help();
00112     
00113     if (argc <= 1)
00114         {
00115         cerr <<"usage: starev -M # -R # -T # -t # -S # -s # [-c \"..\"]\n";
00116         exit(1);
00117         }
00118  
00119     while ((c = pgetopt(argc, argv, param_string)) != -1)
00120         switch(c)
00121             {
00122             case 'n': n_steps = atoi(poptarg);
00123                       break;
00124             case 'M': M_flag = TRUE;
00125                       m_tot = atof(poptarg);
00126                       break;
00127             case 'R': r_hm = atof(poptarg);
00128                       break;
00129             case 'T': t_hc = atof(poptarg);
00130                       break;
00131             case 't': t_end = atof(poptarg);
00132                       break;
00133             case 'S': S_flag = TRUE;
00134                       input_seed = atoi(poptarg);
00135                       break;
00136             case 's': strcpy(star_type_string, poptarg);
00137                       type = extract_stellar_type_string(star_type_string);
00138                       break;
00139             case 'c': c_flag = TRUE;
00140                       comment = poptarg;
00141                       break;
00142             case '?': params_to_usage(cerr, argv[0], param_string);
00143                       get_help();
00144                       exit(1);
00145             }
00146 
00147     cerr.precision(HIGH_PRECISION);
00148 
00149     if(!S_flag) actual_seed = 0;
00150     actual_seed = srandinter(input_seed);
00151 
00152     // make flat tree 
00153     node *root  = mknode(1);
00154     root->log_history(argc, argv);
00155     root->get_starbase()->set_stellar_evolution_scaling(m_tot, r_hm, t_hc);
00156 
00157     node *the_star = root->get_oldest_daughter();
00158 
00159     addstar(root, t_start, type);
00160 
00161     cerr.precision(STD_PRECISION);
00162 
00163     //    put_node(cout, *root);
00164 
00165     real dt, time = 0;
00166     real delta_t = t_end/((real)n_steps);
00167     real out_time, current_time; 
00168     real time1, time2;
00169     real previous_time;
00170     int  nstps=0;
00171     for_all_daughters(node, root, bi) {
00172        out_time = 0;
00173        do {
00174           out_time = min(out_time+delta_t, t_end);
00175           evolve_star_until_next_time(bi, out_time);
00176           bi->get_starbase()->dump(cerr, false);
00177        }
00178        while(out_time < t_end);
00179     }
00180 
00181     for_all_daughters(node, root, bi) {
00182        cerr << "Time = " << bi->get_starbase()->get_current_time()
00183             << " [Myear],  mass = " << bi->get_starbase()->get_total_mass() 
00184             << " [Msun],  radius = " << bi->get_starbase()
00185                                           ->get_effective_radius() 
00186             << "   " << type_string(bi->get_starbase()->get_element_type())
00187             << endl;
00188     }
00189 //    put_node(cout, *root);
00190     delete root;
00191 }
00192 
00193 #endif

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