00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026 #include "node.h"
00027 #include "star_state.h"
00028 #include "main_sequence.h"
00029
00030 #ifdef TOOLBOX
00031
00032 node* get_complete_star(const real mass, const real time) {
00033
00034 int number = 1;
00035 node *n = mknode(number);
00036
00037 stellar_type type = Main_Sequence;
00038 int id = 0;
00039 real start_time = 0;
00040 real relative_mass, total_mass;
00041 relative_mass = total_mass = mass;
00042 real core_mass=0.01;
00043 real co_core=0;
00044 real p_rot=0, b_fld=0;
00045
00046 node* bi = n->get_oldest_daughter();
00047 single_star* element =
00048 new_single_star(type, id, time, start_time, relative_mass,
00049 total_mass, core_mass, co_core,
00050 p_rot, b_fld, bi);
00051
00052 bi->get_starbase()->evolve_element(time);
00053 return bi;
00054 }
00055
00056 real get_stellar_radius(const real mass, const real time, stellar_type& type) {
00057
00058 int number = 1;
00059 node *n = mknode(number);
00060
00061 type = Main_Sequence;
00062 int id = 0;
00063 real start_time = 0;
00064 real relative_mass, total_mass;
00065 relative_mass = total_mass = mass;
00066 real core_mass=0.01;
00067 real co_core = 0;
00068 real p_rot=0, b_fld=0;
00069
00070 node* bi = n->get_oldest_daughter();
00071 single_star* element =
00072 new_single_star(type, id, time, start_time, relative_mass,
00073 total_mass, core_mass, co_core,
00074 p_rot, b_fld, bi);
00075
00076 bi->get_starbase()->evolve_element(time);
00077 type = bi->get_starbase()->get_element_type();
00078 return bi->get_starbase()->get_effective_radius();
00079 }
00080
00081 real obtain_maximum_radius(const real mass,
00082 real& time, stellar_type& type) {
00083
00084 type = Main_Sequence;
00085 time = 0;
00086
00087 int number = 1;
00088 node *n = mknode(number);
00089
00090 int id = 0;
00091 real relative_mass, total_mass;
00092 relative_mass = total_mass = mass;
00093 real core_mass=min(0.01, total_mass);
00094 real co_core = 0;
00095 real p_rot=0, b_fld=0;
00096
00097 node* bi = n->get_oldest_daughter();
00098 single_star* element =
00099 new_single_star(type, id, time, time, relative_mass,
00100 total_mass, core_mass, co_core
00101 p_rot, b_fld, bi);
00102
00103 real radius=0;
00104 real r_max = 0;
00105 real dt = 0;
00106 real time_max=0;
00107 stellar_type current_type;
00108 do {
00109 dt = max(cnsts.safety(minimum_timestep),
00110 bi->get_starbase()->get_evolve_timestep());
00111 time += dt;
00112 bi->get_starbase()->evolve_element(time);
00113 radius = bi->get_starbase()->get_effective_radius();
00114 current_type = bi->get_starbase()->get_element_type();
00115
00116 if (radius>=r_max) {
00117 r_max = radius;
00118 time_max = time;
00119 type = current_type;
00120 }
00121 }
00122 while (current_type!=Black_Hole &&
00123 current_type!=Neutron_Star &&
00124 current_type!=White_Dwarf &&
00125 current_type!=Brown_Dwarf &&
00126 current_type!=Disintegrated);
00127
00128 time = time_max;
00129 return r_max;
00130 }
00131
00132 bool close_enough(const real a, const real b) {
00133
00134 if (abs((a-b)/b)<=0.0001)
00135 return false;
00136 return true;
00137 }
00138
00139 real obtain_time_at_radius(const real mass,
00140 real& radius, stellar_type& type) {
00141
00142 type = Main_Sequence;
00143 real time = 0;
00144
00145 stellar_type zams_type = Main_Sequence;
00146 real zero = 0;
00147 real r_zams = get_stellar_radius(mass, zero, zams_type);
00148 if (radius<=r_zams)
00149 return zero;
00150
00151 real time_max;
00152 stellar_type type_max;
00153 real r_max = obtain_maximum_radius(mass, time_max, type_max);
00154 if (radius>=r_max) {
00155 type = type_max;
00156 return time_max;
00157 }
00158
00159 real time_min = time;
00160 real dt;
00161 real previous_radius, current_radius=0;
00162 do {
00163 dt = 0.5*(time_max-time_min);
00164 time += dt;
00165 previous_radius = current_radius;
00166 current_radius = get_stellar_radius(mass, time, type);
00167 if (current_radius>radius) {
00168 time_max = time;
00169 time -= dt;
00170 }
00171 else
00172 time_min = time;
00173 }
00174 while (close_enough(radius, current_radius) &&
00175 close_enough(previous_radius, current_radius));
00176 radius = current_radius;
00177
00178 return time;
00179 }
00180
00181
00182
00183
00184
00185 main(int argc, char ** argv) {
00186
00187 int c;
00188 real mass = 10;
00189 real time = 10;
00190 real radius = 250;
00191
00192 char *comment;
00193 extern char *poptarg;
00194 int pgetopt(int, char **, char *);
00195
00196 check_help();
00197
00198 char* param_string = "m:r:t:";
00199
00200 while ((c = pgetopt(argc, argv, param_string)) != -1)
00201 switch(c) {
00202 case 'm': mass = atof(poptarg);
00203 break;
00204 case 'r': radius = atof(poptarg);
00205 break;
00206 case 't': time = atof(poptarg);
00207 break;
00208 case '?': params_to_usage(cerr, argv[0], param_string);
00209 get_help();
00210 exit(1);
00211 }
00212
00213 node* str = get_complete_star(mass, time);
00214 stellar_type type = NAS;
00215 real rad = get_stellar_radius(mass, time, type);
00216
00217 cout << rad
00218 <<" = get_stellar_radius(mass=" <<mass<<", time="
00219 <<time<<", type="<<type<<")"<<endl;
00220
00221 rad = obtain_maximum_radius(mass, time, type);
00222 cout << rad << " = obtain_maximum_radius(mass=" <<mass<<", time="
00223 <<time<<", type="<<type<<")"<<endl;
00224
00225 time = obtain_time_at_radius(mass, radius, type);
00226 cout << time << " = obtain_time_at_radius(mass=" <<mass<<", radius="
00227 <<radius<<", type="<<type<<")"<<endl;
00228 }
00229
00230 #endif