00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00025
00026
00027
00028 #include "dyn.h"
00029
00030 #ifndef TOOLBOX
00031
00032 void dyn::set_com(vector pos, vector vel)
00033 {
00034 vector com_pos;
00035 vector com_vel;
00036
00037 compute_com(this, com_pos, com_vel);
00038
00039 vector dpos = pos - com_pos;
00040 vector dvel = vel - com_vel;
00041
00042
00043
00044 for_all_daughters(dyn, this, bb) {
00045 bb->inc_pos(dpos);
00046 bb->inc_vel(dvel);
00047 }
00048
00049
00050
00051 putvq(get_dyn_story(), "com_pos", pos);
00052 putvq(get_dyn_story(), "com_vel", vel);
00053
00054
00055
00056 }
00057
00058 #else
00059
00060 main(int argc, char ** argv)
00061 {
00062 bool c_flag = FALSE;
00063 char *comment;
00064 vector r = 0;
00065 vector v = 0;
00066
00067 bool n_flag = false;
00068
00069 check_help();
00070
00071 extern char *poptarg;
00072 extern char *poparr[];
00073 int c;
00074 char* param_string = "c:nr:::v:::";
00075
00076 while ((c = pgetopt(argc, argv, param_string)) != -1)
00077 switch(c) {
00078 case 'c': c_flag = TRUE;
00079 comment = poptarg;
00080 break;
00081 case 'n': n_flag = true;
00082 break;
00083
00084 case 'r': r = vector(atof(poparr[0]),
00085 atof(poparr[1]),
00086 atof(poparr[2]));
00087 break;
00088 case 'v': v = vector(atof(poparr[0]),
00089 atof(poparr[1]),
00090 atof(poparr[2]));
00091 break;
00092
00093 case '?': params_to_usage(cerr, argv[0], param_string);
00094 get_help();
00095 exit(1);
00096 }
00097
00098 dyn *b;
00099
00100 while (b = get_dyn(cin)) {
00101
00102 if (c_flag == TRUE)
00103 b->log_comment(comment);
00104 b->log_history(argc, argv);
00105
00106
00107
00108
00109 real mass, length, time;
00110 bool phys = get_physical_scales(b, mass, length, time);
00111
00112
00113
00114
00115 check_set_external(b, false);
00116 bool ext = (b->get_external_field() != 0);
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 if (phys && !n_flag) {
00131
00132 cerr << "set_com: converting input physical parameters"
00133 << " to N-body units" << endl;
00134 cerr << " r = (" << r << ") pc, v = ("
00135 << v << ") v_circ" << endl;
00136 cerr << " N-body length scale = " << length << " pc"
00137 << endl;
00138
00139
00140
00141 r /= length;
00142 if (!ext) {
00143
00144
00145
00146
00147 real vunit = 0.978*length/time;
00148 v /= vunit;
00149 }
00150
00151 } else
00152
00153 cerr << "set_com: interpreting input parameters"
00154 << " as N-body units" << endl;
00155
00156 if (ext) {
00157
00158
00159
00160 real vc = vcirc(b, r);
00161
00162 if (vc > 0) {
00163 v *= vc;
00164 cerr << " circular orbit speed = " << vc;
00165 if (phys && !n_flag) cerr << " (N-body)";
00166 cerr << ", period = " << 2*M_PI*abs(r)/vc
00167 << endl;
00168 }
00169 }
00170
00171
00172
00173 b->set_com(r, v);
00174 cerr << " r = (" << r << "), v = (" << v << ")"
00175 << endl;
00176
00177 put_dyn(cout, *b);
00178 rmtree(b);
00179 }
00180 }
00181
00182 #endif