Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added tools_init_orbit2d() function and changed example

  • Loading branch information...
commit a37516aa57bf4bb67425650d3811db5274ba2072 1 parent 6fc5d19
@hannorein authored
Showing with 33 additions and 9 deletions.
  1. +3 −9 examples/circular_orbit/problem.c
  2. +21 −0 src/tools.c
  3. +9 −0 src/tools.h
View
12 examples/circular_orbit/problem.c
@@ -31,6 +31,7 @@
#include <math.h>
#include <time.h>
#include "main.h"
+#include "tools.h"
#include "output.h"
#include "particle.h"
#include "boundaries.h"
@@ -57,16 +58,9 @@ void problem_init(int argc, char* argv[]){
_N = atoi(argv[1]);
}
- const double shift = 0.0; // Change this number to put particles on eccetric orbits.
+ double eccentricity = 0.4;
for(int n=0; n<_N; n++){
- p.x = cos(2.*M_PI/(double)(_N)*(double)(n)) + shift;
- p.y = sin(2.*M_PI/(double)(_N)*(double)(n));
- p.z = 0;
- p.vx = cos(2.*M_PI/(double)(_N)*(double)(n)+M_PI/2.);
- p.vy = sin(2.*M_PI/(double)(_N)*(double)(n)+M_PI/2.);
- p.vz = 0;
- p.ax = 0; p.ay = 0; p.az = 0;
- p.m = 0;
+ struct particle p = tools_init_orbit2d(1., 0., 1., eccentricity, 0.,2.*M_PI/(double)(_N)*(double)(n));
particles_add(p); // Test particle
}
}
View
21 src/tools.c
@@ -180,6 +180,27 @@ void tools_init_plummer(int _N, double mlow, double rfrac, int quiet, double sca
free(_particles);
}
+struct particle tools_init_orbit2d(double M, double m, double a, double e, double omega, double f){
+ struct particle p;
+ p.m = m;
+ double r = a*(1.-e*e)/(1.+e*cos(f));
+ double n = sqrt(G*(m+M)/(a*a*a));
+ double tx = r*cos(f);
+ double ty = r*sin(f);
+ p.z = 0;
+ double tvx = -n*a/sqrt(1.-e*e)*sin(f);
+ double tvy = n*a/sqrt(1.-e*e)*(e+cos(f));
+ p.vz = 0;
+ p.ax = 0; p.ay = 0; p.az = 0;
+
+ p.x = cos(omega)*tx - sin(omega)*ty;
+ p.y = sin(omega)*tx + cos(omega)*ty;
+
+ p.vx = cos(omega)*tvx - sin(omega)*tvy;
+ p.vy = sin(omega)*tvx + cos(omega)*tvy;
+
+ return p;
+}
#define TINY 1.0e-12
struct orbit tools_p2orbit(struct particle p, double cmass){
View
9 src/tools.h
@@ -79,6 +79,15 @@ double tools_normal(double variance);
void tools_init_plummer(int _N, double mlow, double rfrac, int quiet, double scale, double* shift);
+/**
+ * Initialize a particle on an orbit in the xy plane.
+ * @param M Mass of the central object.
+ * @param m Mass of the particle.
+ * @param a Semi-major axis of the particle.
+ * @param e Eccentricity of the particle.
+ * @param omega Pericenter of the particle.
+ */
+struct particle tools_init_orbit2d(double M, double m, double a, double e, double omega, double f);
/**
* This function calculated orbital elements for a given particle. The center of
Please sign in to comment.
Something went wrong with that request. Please try again.