Skip to content
Permalink
16bedf55ff
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
94 lines (82 sloc) 2.78 KB
package jat.examples.ThreeBodyExample;
import java.util.ArrayList;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math3.ode.sampling.StepHandler;
import org.apache.commons.math3.ode.sampling.StepInterpolator;
import jat.coreNOSA.algorithm.integrators.Printable;
import jat.coreNOSA.cm.Constants;
import jat.coreNOSA.cm.ThreeBody;
import jat.coreNOSA.math.MatrixVector.data.VectorN;
public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEquations{
public ArrayList<Double> time = new ArrayList<Double>();
public ArrayList<Double> xsol = new ArrayList<Double>();
public ArrayList<Double> ysol = new ArrayList<Double>();
public ArrayList<Double> zsol = new ArrayList<Double>();
/*
* 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) {
super(G, m1, m2, m3);
}
@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
return 18;
}
public double[] randv() {
// returns the position and velocity of the three objects
// vector r1 is x[0], x[1], x[2]
// vector v1 is x[3], x[4], x[5]
// vector r2 is x[6], x[7], x[8]
// vector v2 is x[9], x[10], x[11]
// vector r3 is x[12], x[13], x[14]
// vector v3 is x[15], x[16], x[17]
double[] randv = new double[18];
randv[0] = 2.0;
randv[1] = 6.0;
randv[2] = 7.0;
randv[3] = 4.0;
randv[4] = 8.0;
randv[5] = 7.0;
randv[6] = 5.0;
randv[7] = 8.0;
randv[8] = 3.0;
randv[9] = 6.0;
randv[10] = 8.0;
randv[11] = 9.0;
randv[12] = 0.0;
randv[13] = 7.0;
randv[14] = 4.0;
randv[15] = 5.0;
randv[16] = 7.0;
randv[17] = 8.0;
return randv;
}
public StepHandler stepHandler = new StepHandler() {
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]);
time.add(t);
xsol.add(y[0]);
ysol.add(y[1]);
zsol.add(y[2]);
}
};
}