27 input = fopen (filename,
"r");
29 fprintf (stderr,
"Error : can't find '%s'.\n", filename);
32 while (fgets(s, 510, input) != NULL) {
43 real *mass, *x, *y, *z, *vx, *vy, *vz, *acc, *ax, *ay, *az;
44 boolean *feeldisk, *feelothers;
49 fprintf (stderr,
"Not enough memory.\n");
52 x = (
real *)malloc (
sizeof(
real)*(nb+1));
53 y = (
real *)malloc (
sizeof(
real)*(nb+1));
54 z = (
real *)malloc (
sizeof(
real)*(nb+1));
55 vx = (
real *)malloc (
sizeof(
real)*(nb+1));
56 vy = (
real *)malloc (
sizeof(
real)*(nb+1));
57 vz = (
real *)malloc (
sizeof(
real)*(nb+1));
58 mass = (
real *)malloc (
sizeof(
real)*(nb+1));
59 acc = (
real *)malloc (
sizeof(
real)*(nb+1));
60 if ((x == NULL) || (y == NULL) || (z == NULL) || (vx == NULL) || (vy == NULL) || (vz == NULL) || (acc == NULL) || (mass == NULL)) {
61 fprintf (stderr,
"Not enough memory.\n");
64 ax = (
real *)malloc (
sizeof(
real)*(nb+1));
65 ay = (
real *)malloc (
sizeof(
real)*(nb+1));
66 az = (
real *)malloc (
sizeof(
real)*(nb+1));
67 if ((ax == NULL) || (ay == NULL) || (az == NULL)) {
68 fprintf (stderr,
"Not enough memory.\n");
71 feeldisk = (
boolean *)malloc (
sizeof(
real)*(nb+1));
72 feelothers = (
boolean *)malloc (
sizeof(
real)*(nb+1));
73 if ((feeldisk == NULL) || (feelothers == NULL)) {
74 fprintf (stderr,
"Not enough memory.\n");
90 for (i = 0; i < nb; i++) {
91 x[i] = y[i] = z[i] = vx[i] = vy[i] = vz[i] = mass[i] = acc[i] = 0.0;
92 ax[i] = ay[i] = az[i] = 0.0;
93 feeldisk[i] = feelothers[i] =
YES;
112 free (sys->FeelOthers);
113 free (sys->FeelDisk);
121 char s[512], nm[512], test1[512], test2[512], *s1;
124 float mass, dist, accret;
125 boolean feeldis, feelothers;
128 printf (
"%d planet(s) found.\n", nb);
130 input = fopen (filename,
"r");
132 while (fgets(s, 510, input) != NULL) {
133 sscanf(s,
"%s ", nm);
136 sscanf(s1 + strspn(s1,
"\t :=>_"),
"%f %f %f %s %s", &dist, &mass, &accret, test1, test2);
138 feeldis = feelothers =
YES;
139 if (tolower(*test1) ==
'n') feeldis =
NO;
140 if (tolower(*test2) ==
'n') feelothers =
NO;
143 sys->
vy[i] = (
real)sqrt((1.0+mass)/dist)*\
145 sys->
vx[i] = -0.0000000001*sys->
vy[i];
146 sys->
acc[i] = accret;
162 for (i = 0; i < nb; i++) {
163 printf (
"Planet number %d\n", i);
164 printf (
"---------------\n");
165 printf (
"x = %.10f\ty = %.10f\tz = %.10f\n", sys->x[i],sys->y[i],sys->z[i]);
166 printf (
"vx = %.10f\tvy = %.10f\tvz = %.10f\n", sys->vx[i],sys->vy[i],sys->vz[i]);
167 if (sys->acc[i] == 0.0)
168 printf (
"Non-accreting.\n");
170 printf (
"accretion time = %.10f\n", 1.0/(sys->acc[i]));
171 if (sys->FeelDisk[i] ==
YES) {
172 printf (
"Feels the disk potential\n");
174 printf (
"Doesn't feel the disk potential\n");
176 if (sys->FeelOthers[i] ==
YES) {
177 printf (
"Feels the other planets potential\n");
179 printf (
"Doesn't feel the other planets potential\n");
194 real x,y,z, vx, vy, vz, m, a3;
195 real hx,hy,hz,d,Ax,Ay,PerihelionPA;
197 struct reb_orbit orbit;
198 struct reb_particle p={0};
199 static struct reb_particle primary={0};
201 if (primary.m != 1.0) {
204 p.
x = xc = x = sys->x[0];
205 p.y = yc = y = sys->y[0];
207 p.vx = vx = sys->vx[0];
208 p.vy = vy = sys->vy[0];
209 p.vz = vz = sys->vz[0];
212 orbit = reb_tools_particle_to_orbit (
G, p, primary);
214 if (orbit.e > 1e-8 && orbit.inc > 1e-8) {
219 d = sqrt(x*x+y*y+z*z);
220 Ax = vy*hz-vz*hy -
G*m*x/d;
221 Ay = vz*hx-vx*hz -
G*m*y/d;
222 if (Ax*Ax+Ay*Ay > 0.0) {
223 PerihelionPA = atan2(Ay,Ax);
225 PerihelionPA = atan2(y,x);
227 xc = orbit.a*cos(orbit.M+PerihelionPA)*cos(orbit.inc);
228 yc = orbit.a*sin(orbit.M+PerihelionPA)*cos(orbit.inc);
245 return asin(cross/(d1*d2));
249 a3 = (orbit.a)*(orbit.a)*(orbit.a);
252 return (x*vy-y*vx)/(x*x+y*y);
263 struct reb_simulation *rsim;
266 struct reb_particle*
const particles = rsim->particles;
268 real x,y,z, vx, vy, vz, m, a3;
269 real hx,hy,hz,d,Ax,Ay,PerihelionPA;
271 struct reb_orbit orbit;
273 xc = x = particles[1].x;
274 yc = y = particles[1].y;
276 vx = particles[1].vx;
277 vy = particles[1].vy;
278 vz = particles[1].vz;
279 m = particles[1].m + particles[0].m;
280 orbit = reb_tools_particle_to_orbit (
G, particles[1], particles[0]);
282 if (orbit.e > 1e-8 && orbit.inc > 1e-8) {
287 d = sqrt(x*x+y*y+z*z);
288 Ax = vy*hz-vz*hy -
G*m*x/d;
289 Ay = vz*hx-vx*hz -
G*m*y/d;
290 if (Ax*Ax+Ay*Ay > 0.0) {
291 PerihelionPA = atan2(Ay,Ax);
293 PerihelionPA = atan2(y,x);
295 xc = orbit.a*cos(orbit.M+PerihelionPA)*cos(orbit.inc);
296 yc = orbit.a*sin(orbit.M+PerihelionPA)*cos(orbit.inc);
313 return asin(cross/(d1*d2));
317 a3 = (orbit.a)*(orbit.a)*(orbit.a);
320 return (x*vy-y*vx)/(x*x+y*y);
331 struct reb_simulation *rsim;
335 real sint, cost, xt, yt;
336 struct reb_particle*
const particles = rsim->particles;
339 for (i=1; i<rsim->N; i++) {
342 particles[i].x = xt*cost+yt*sint;
343 particles[i].y = -xt*sint+yt*cost;
344 xt = particles[i].vx;
345 yt = particles[i].vy;
346 particles[i].vx = xt*cost+yt*sint;
347 particles[i].vy = -xt*sint+yt*cost;
double real
Definition of the type 'real' used throughout the code.
boolean * FeelOthers
For each planet tells if it feels the other planet's gravity.
boolean * FeelDisk
For each planet tells if it feels the disk (ie migrates)
real * z
z-coordinate of the planets
real * vz
z-coordinate of the planets'velocities
real * x
x-coordinate of the planets
real * y
y-coordinate of the planets
real * vx
x-coordinate of the planets'velocities
real * mass
Masses of the planets.
Contains all the information about a planetary system at a given instant in time. ...
PlanetarySystem * InitPlanetarySystem(char *filename)
int FindNumberOfPlanets(char *filename)
real * acc
The planets' accretion times^-1.
real * ay
ay-coordinate of the planets' acceleration from the disk
real * vy
y-coordinate of the planets'velocities
real GetPsysInfoFromRsim(struct reb_simulation *rsim, boolean action)
An analogue of the GetPsysInfo() function; here a rebound simulation structure is used as a call argu...
void FreePlanetary(PlanetarySystem *sys)
Contains all the include directives requested by the code.
real * ax
ax-coordinate of the planets' acceleration from the disk
real * az
az-coordinate of the planets' acceleration from the disk
real GetPsysInfo(PlanetarySystem *sys, boolean action)
The original function was modified to handle 3D inclined orbits.
void RotatePsys(struct reb_simulation *rsim, real angle)
Synchronises the planetary system with the frame.
PlanetarySystem * AllocPlanetSystem(int nb)
void ListPlanets(PlanetarySystem *sys)