Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/Maegans_Branch' into John's-Branch
  • Loading branch information
rog13002 committed Dec 8, 2015
2 parents b695237 + 9d8b1db commit 16bedf5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/jat/coreNOSA/cm/ThreeBody.java
Expand Up @@ -34,9 +34,9 @@ import jat.coreNOSA.math.MatrixVector.data.VectorN;

public class ThreeBody implements Derivatives //, Printable
{
protected double steps = 500.;
protected double G; // Gravitational constant
protected double m1, m2, m3; // masses

private double G; // Gravitational constant
private double m1, m2, m3; // masses

/**
* Method ThreeBody.
Expand Down
24 changes: 17 additions & 7 deletions src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java
Expand Up @@ -17,20 +17,30 @@ public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEqu
public ArrayList<Double> xsol = new ArrayList<Double>();
public ArrayList<Double> ysol = new ArrayList<Double>();
public ArrayList<Double> zsol = new ArrayList<Double>();
protected double[] randv[];

/*
* Why we created the ThreeBodyAPL:
* The APL is responsible for computing the derivatives used in the ThreeBodyExample and interpolating data
* APL stands for Applied Physics Laboratory
*/

/*
* What we used from existing code
* The information that this class uses from the ThreeBody class are calculations for:
* Masses, center of mass and energy.
* This is usefull for us because all of this is necessary for our modification
*/

public ThreeBodyAPL(double G, double m1, double m2, double m3) {
//constructor
super(G, m1, m2, m3);
this.randv();
}

@Override
public void computeDerivatives(double t, double[] y, double[] yDot) {
// returns the derivatives of the ThreeBody problem
yDot = this.derivs(t, y);
}

@Override
public int getDimension() {
// returns a dimension of 6
Expand Down Expand Up @@ -67,18 +77,18 @@ public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEqu
}

public StepHandler stepHandler = new StepHandler() {
//step handler for dp853 integrator
public void init(double t0, double[] y0, double t) {
}

public void handleStep(StepInterpolator interpolator, boolean isLast) {
double t = interpolator.getCurrentTime();
double[] y = interpolator.getInterpolatedState();
System.out.println(t + " " + y[0] + " " + y[1]+ " " + y[2]); //prints time and xyz positions
System.out.println(t + " " + y[0] + " " + y[1]+ " " + y[2]);
time.add(t);
xsol.add(y[0]);
ysol.add(y[1]);
zsol.add(y[2]);
}
};

}
24 changes: 22 additions & 2 deletions src/jat/examples/ThreeBodyExample/ThreeBodyExample.java
Expand Up @@ -19,6 +19,13 @@ import org.apache.commons.math3.linear.RealVectorFormat;
import org.apache.commons.math3.ode.FirstOrderIntegrator;
import org.apache.commons.math3.ode.nonstiff.DormandPrince853Integrator;

/*
* We modified the ThreeBodyProblem by emulating the two body problem, and expanding it to ThreeBody
* Elements of two body, such as the orbit calculations, were not as heavily focused on
* We acknowledge that some of our calculations may be a bit inaccurate because some of the math got a bit over our heads
*
* @author Maegan and John
*/
public class ThreeBodyExample {

public ThreeBodyExample() {
Expand Down Expand Up @@ -53,8 +60,21 @@ public class ThreeBodyExample {
VectorN cm = sat.center_of_mass(y);

// obtain current energy

totalEnergy = sat.Energy(y);

/*
* Notes about the calculations:
* Dormand Prince is a type of Runge-Kutta diff eq. (another method of checking diff eq)
* Errors are calculated looking at 4th and 5th level differential equations
* These were most likely chosen by the original creator of the project because they take the error into account fairly accurately
* In relation to physics, this calculates the relative orbits for the bodies
* The step handler is another type of analyzing the algorithms for each body
* These provide fairly accurate results
*
* In general, these equations went over our heads, but refer to the NASA site as well as
* look into other resources to get more information on 3-Body calculations
*
*/
// propagate the orbit
FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10);
dp853.addStepHandler(sat.stepHandler);
Expand Down Expand Up @@ -112,4 +132,4 @@ public class ThreeBodyExample {

System.out.println("end");
}
}
}

0 comments on commit 16bedf5

Please sign in to comment.