// // nbody2.C Copyright Jun Makino 1998 // // phase space coordinates are expressed in a single big vector // // #include "cpgplot.h" #include #include #include #ifndef N_BODY const int NBODY = 2; #else const int NBODY = N_BODY; #endif const int NDIM = 3; const int VLEN = NBODY*NDIM*2; #include "vector.h" typedef void (*vintegfunc)(vector &, vfunc_ptr, double, int&); const double EPS = 1e-10; #include "integrators.C" typedef void (*vintegfunc)(vector &, vfunc_ptr, double, int&); typedef struct plot_control{ int xvarid; int yvarid; int mode; double xmax; }PLOT_CONTROL; struct plot_control pctr; void initgraph(const double xmax) { cerr << "Enter var to plot (x, y):"; cin >> pctr.xvarid >> pctr.yvarid ; cerr << "Enter mode (0: snapplot, 1: trakplot):"; cin >> pctr.mode ; char pgdevname[255]; cerr << "Enter devname"; cin >> pgdevname ; if(cpgopen(pgdevname) != 1) exit(EXIT_FAILURE); cpgask(0); cpgenv(-xmax, xmax, -xmax, xmax, 1, 0); pctr.xmax = xmax; const char * name[6]={"x","vx","y","vy","z","vz"}; char label[255]; cpglab(name[pctr.xvarid],name[pctr.yvarid], label); if(pctr.mode == 0){ cpgslw(10); } } inline real & pos(vector &x, int i, int k) {return x[6*i+2*k];} inline real & vel(vector &x, int i, int k) {return x[6*i+2*k+1];} inline real & acc(vector &x, int i, int k) {return x[6*i+2*k+1];} double eps2; calc_force(vector & x, vector & d, int i, int j) { int k; double dx[NDIM]; double r2 = eps2; // PRC(i);PRL(j); for(k=0;k> x; } void dump(vector & x) { cerr << "N = " << NBODY << " eps2 = " << eps2 << "\n"; cerr << x << "\n"; } #ifndef TESTMAIN #define STANDARD_MAIN #endif #ifdef STANDARD_MAIN main() { vector x; double t, toutstep, tend, h ; cerr << "Enter tend,toustep, h, eps2:"; cin >> tend >> toutstep >> h >> eps2; PRC(tend); PRC(h); PRL(eps2); cerr << "Enter xmax:"; double xmax; cin >> xmax; initgraph(xmax); getbody(x); plot(x); double e0; e0 = energy(x); cout << "Energy " << e0 <<"\n"; dump(x); plot(x); int first_call = 1; for(t=0; t> dum; cpgend(); } #endif #ifdef TESTMAIN // // test main routine for error plot // main() { vector x; double t, toutstep, tend, h ; cerr << "Enter tend,toustep, h, eps2:"; cin >> tend >> toutstep >> h >> eps2; PRC(tend); PRC(h); PRL(eps2); cerr << "Enter xmax:"; double xmax; cin >> xmax; initgraph(xmax); getbody(x); plot(x); double e0; e0 = energy(x); cout << "Energy " << e0 <<"\n"; dump(x); plot(x); int first_call = 1; for(t=0; t> dum; cpgend(); } #endif