Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

conv_star_to_dyn.C

Go to the documentation of this file.
00001  
00016 //  SPZ @MIT, August 2001
00017 
00018 #include "dyn.h"
00019 #include "constants.h"
00020 
00021 #ifdef TOOLBOX
00022 
00023 #define  FALSE  0
00024 #define  TRUE   1
00025 
00026 main(int argc, char ** argv) {
00027 
00028     bool virial_units = false;
00029     real eps = 0;
00030 
00031     dyn *root;
00032 
00033     check_help();
00034 
00035     extern char *poptarg;
00036     int c;
00037     char* param_string = "e:v";
00038 
00039     while ((c = pgetopt(argc, argv, param_string)) != -1)
00040         switch(c) {
00041             case 'e': eps = atof(poptarg);
00042                       break;
00043             case 'v': virial_units = true;
00044                       break;
00045             case '?': params_to_usage(cerr, argv[0], param_string);
00046                       get_help();
00047                       exit(1);
00048         }
00049 
00050     // real input snapshot
00051     root = get_dyn(cin);
00052     root->log_history(argc, argv);
00053     
00054     real mtot = root->get_mass();
00055     PRL(mtot);
00056 
00057     // Calculate unit for G (called Newton_G)
00058     // Note here that the assumed units are:
00059     // mass in [Msun]
00060     // position in [pc]
00061     // velocity in [km/s]
00062     // time in [Myr]
00063     // Yes, these are strange units.
00064     real Uk = cnsts.parameters(Msun)*square(cnsts.physics(km_per_s));
00065     real Up = cnsts.physics(G)*square(cnsts.parameters(Msun))
00066             / cnsts.parameters(PC);
00067     real Newton_G = Up/Uk;
00068 
00069     real P, K, E;
00070     get_top_level_energies(root, eps*eps, P, K);
00071     P *= Newton_G;
00072     E = K + P;
00073     real Q = -K/P;
00074 
00075     cerr << "basis scaling units" << endl;
00076     cerr << "Unit for kinetic energy:   " << K << endl;
00077     cerr << "Unit for potential energy: " << P << endl;
00078     cerr << "Unit for total energy:     " << E << endl;
00079     cerr << "Unit for virial ratio:     " << Q << endl;
00080     cerr << "Unit for G:              1/" << 1/Newton_G << endl;
00081 
00082     cerr << "Virial units" << endl;
00083     real r_vir = -0.5 * Newton_G * pow(mtot, 2) / P;
00084     PRL(r_vir);
00085     real t_vir= 21.0 * sqrt(Q*pow(r_vir, 3) / mtot);
00086     PRL(t_vir);
00087 
00088     real Um = mtot;
00089     real Ul = Newton_G * pow(Um, 2)/(-4*E);
00090     real Ut = Newton_G * pow(Um, 5./2.) / pow(-4*E, 3./2.);
00091         
00092     if(virial_units || Ul<0) {
00093       cerr << "Use virial radius instead of distance unit" << endl;
00094       Ul = r_vir;
00095       cerr << "Use virial radius crossing time as time unit" << endl;
00096       Ut = t_vir;
00097     }
00098 
00099     real Uv = Ul/Ut;
00100 
00101     cerr << "Unit for M:                " << Um << endl;
00102     cerr << "Unit for R:                " << Ul << endl;
00103     cerr << "Unit for T:                " << Ut << endl;
00104     cerr << "Unit for v:                " << Uv << endl;
00105 
00106     // Now transform the snapshot
00107     for_all_leaves(dyn, root, bi) {
00108       bi->set_mass(bi->get_mass() / Um);
00109       bi->set_pos(bi->get_pos() / Ul);
00110       bi->set_vel(bi->get_vel() / Uv);
00111     }
00112 
00113     // Now initialize the units for stellar evolution
00114     // These units are curious too:
00115     // mass unit is 1/mtot
00116     real mf = Um;
00117     // distance unit is Rsun/pc
00118     real rf = Ul;
00119       // cnsts.parameters(Rsun)/(cnsts.parameters(PC)*Ul);
00120     // time unit is 1/Myear
00121     real tf = Ut; //cnsts.physics(Myear);
00122     PRC(mf);PRC(rf);PRL(tf);
00123 
00124     root->get_starbase()->set_stellar_evolution_scaling(mf, rf, tf);
00125     root->get_starbase()->print_stellar_evolution_scaling(cerr);
00126 
00127     root->set_mass(1);
00128     put_node(cout, *root);
00129 }
00130 
00131 #endif
00132 
00133 // end of: conv_star_to_dyn.C
00134  
00135 

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