Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

add_power_law.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00040 
00041 //   version 1:  Aug/Sep 2001   Steve McMillan
00042 
00043 #include "dyn.h"
00044 
00045 #ifndef TOOLBOX
00046 
00047 bool get_physical_scales(dyn *b, real& mass, real& length, real& time)
00048 {
00049     mass = length = time = -1;
00050 
00051     if (b)
00052         if (b->get_starbase()) {
00053 
00054 #define Rsun_pc 2.255e-8        // R_sun/1 parsec = 6.960e+10/3.086e+18;
00055 
00056             mass = b->get_starbase()->conv_m_dyn_to_star(1);
00057             length = b->get_starbase()->conv_r_dyn_to_star(1) * Rsun_pc;
00058             time = b->get_starbase()->conv_t_dyn_to_star(1);
00059 
00060             return (mass > 0 && length > 0 && time > 0);
00061         }
00062 
00063     return false;
00064 }
00065 
00066 void add_power_law(dyn *b,
00067                    real coeff, real exponent, real scale,
00068                    vector center,               // default = (0, 0, 0)
00069                    bool n_flag,                 // default = false
00070                    bool verbose,                // default = false
00071                    bool G_flag)                 // default = false
00072 {
00073     // Add power-law parameters for an external field.
00074 
00075     char id[9];
00076     int ind;
00077 
00078     if (exponent == 0) {
00079         strcpy(id, "plummer");
00080         ind = 14;
00081     } else {
00082         strcpy(id, "power_law");
00083         ind = 16;
00084     }
00085 
00086     // Check for physical parameters.
00087 
00088     real mass, length, time;
00089     bool phys = get_physical_scales(b, mass, length, time);
00090 
00091     // If phys, we are using physical units.  Mass and length are
00092     // the physical equivalents of 1 N-body unit, in Msun and pc.
00093     // Time is not used here.
00094 
00095     if (phys && !n_flag) {
00096 
00097         cerr << "add_" << id
00098              << ":  converting input physical parameters to N-body units"
00099              << endl;
00100         PRI(ind);
00101         if (exponent == 0)
00102             cerr << "M";
00103         else
00104             cerr << "A";
00105         cerr << " = " << coeff << " Msun,  a = " << scale
00106              << " pc" << endl;
00107         PRI(ind); cerr << "center = (" << center << ") pc" << endl;
00108         PRI(ind); cerr << "N-body mass scale = " << mass
00109                        << " Msun,  length scale = " << length
00110                        << " pc" << endl;
00111 
00112         // Convert to N-body units.
00113 
00114         coeff *= pow(length, exponent) / mass;
00115         scale /= length;
00116         center /= length;
00117 
00118     } else {
00119 
00120         cerr << "add_" << id
00121              << ":  interpreting input parameters as N-body units"
00122              << endl;
00123 
00124         if (G_flag) {           // won't happen in Plummer case
00125 
00126             // Warn if physical parameters are not set or are being ignored.
00127 
00128             PRI(ind); cerr << "warning:  -G but ";
00129             if (phys)
00130                 cerr << "ignoring";
00131             else
00132                 cerr << "no";
00133             cerr << " physical scaling" << endl;
00134         }
00135     }
00136 
00137     PRI(ind);
00138     if (phys && !n_flag) cerr << "N-body ";
00139 
00140     if (exponent != 0) {
00141 
00142         putrq(b->get_log_story(), "kira_pl_coeff", coeff);
00143         putrq(b->get_log_story(), "kira_pl_exponent", exponent);
00144         putrq(b->get_log_story(), "kira_pl_scale", scale);
00145         putvq(b->get_log_story(), "kira_pl_center", center);
00146 
00147         
00148         cerr << "A = " << coeff << ",  a = " << scale
00149              << ",  x = " << exponent << endl;
00150 
00151     } else {
00152 
00153         putrq(b->get_log_story(), "kira_plummer_mass", coeff);
00154         putrq(b->get_log_story(), "kira_plummer_scale", scale);
00155         putvq(b->get_log_story(), "kira_plummer_center", center);
00156 
00157         cerr << "M = " << coeff << ", a = " << scale << endl;
00158     }
00159 
00160     PRI(ind); cerr << "center = (" << center << ")" << endl;
00161 }
00162 
00163 #else
00164 
00165 main(int argc, char *argv[])
00166 {
00167     bool c_flag = false;
00168     char *comment;              // comment string
00169 
00170     real coeff = 1, scale = 1, exponent = 0;
00171     vector center = 0;
00172 
00173     bool G_flag = false;
00174     bool n_flag = false;
00175 
00176     check_help();
00177 
00178     extern char *poptarg;
00179     extern char *poparr[];
00180     int c;
00181     char* param_string = "A:a:c:C:::e:E:GnR:x:X:";
00182 
00183     dyn *b = get_dyn(cin);
00184     if (b == NULL) err_exit("Can't read input snapshot");
00185 
00186     b->log_history(argc, argv);
00187 
00188     // Parse the argument list:
00189 
00190     while ((c = pgetopt(argc, argv, param_string)) != -1) {
00191         switch (c) {
00192             case 'A':
00193             case 'M':   coeff = atof(poptarg);
00194                         break;
00195 
00196             case 'c':   c_flag = TRUE;
00197                         comment = poptarg;
00198                         break;
00199 
00200             case 'C':   center = vector(atof(poparr[0]),
00201                                         atof(poparr[1]),
00202                                         atof(poparr[2]));
00203                         break;
00204             case 'e':
00205             case 'E':
00206             case 'x':
00207             case 'X':
00208                         exponent = atof(poptarg);
00209                         break;
00210 
00211             case 'a':
00212             case 'R':   scale = atof(poptarg);
00213                         break;
00214 
00215             case 'G':   G_flag = true;
00216                         break;
00217             case 'n':   n_flag = true;
00218                         break;
00219 
00220             default:
00221             case '?':   params_to_usage(cerr, argv[0], param_string);
00222                         get_help();
00223                         return false;
00224         }
00225     }
00226 
00227     if (c_flag)
00228         b->log_comment(comment);
00229 
00230     if (G_flag) {
00231 
00232         // Parameters from Mezger et al. (1999):
00233 
00234         coeff = 4.25e6;
00235         exponent = 1.2;
00236 
00237         scale = 0.1;
00238         center = vector(0,0,0);
00239     }
00240 
00241     add_power_law(b, coeff, exponent, scale, center, n_flag, true, G_flag);
00242     put_node(cout, *b);
00243 }
00244 
00245 #endif

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