Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stephandler methods added to ThreeBodyAPL, began trying to figure out
how to integrate the derivatives. there's a few comments that I
unchecked to show the outputs of energy, center of mass, and the
derivatives. Also, this does return a graph, but no changes are observed
in the plot, so it results in one dot.
  • Loading branch information
John Costa III authored and John Costa III committed Dec 6, 2015
1 parent f276491 commit 47dd6e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java
Expand Up @@ -2,10 +2,13 @@ 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;

Expand All @@ -14,14 +17,15 @@ 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>();

public ThreeBodyAPL(double G, double m1, double m2, double m3) {
super(G, m1, m2, m3);
}

@Override
public void computeDerivatives(double arg0, double[] arg1, double[] arg2) {
// TODO Auto-generated method stub

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

@Override
Expand All @@ -30,6 +34,13 @@ public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEqu
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;
Expand All @@ -51,19 +62,20 @@ public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEqu
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]);
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]);
}
};
}

}
6 changes: 3 additions & 3 deletions src/jat/examples/ThreeBodyExample/ThreeBodyExample.java
Expand Up @@ -31,10 +31,10 @@ public class ThreeBodyExample {
//initialize variables
double totalEnergy = 0;
// set the final time = one orbit period
double tf = 7.0;
double tf = 1.0;

// create a ThreeBody orbit using three masses and gravitational con
ThreeBodyAPL sat = new ThreeBodyAPL(10, 0.3, 1.0, 2.0);
ThreeBodyAPL sat = new ThreeBodyAPL(9.87, 0.3, 1.0, 2.0);
//initialize VectorN elements
double[] y = sat.randv();

Expand Down Expand Up @@ -71,7 +71,7 @@ public class ThreeBodyExample {

double[][] XY = new double[timeArray.length][2];

// int a=0;
int a=0;
// System.arraycopy(timeArray,0,XY[a],0,timeArray.length);
// System.arraycopy(ysolArray,0,XY[1],0,ysolArray.length);

Expand Down

0 comments on commit 47dd6e6

Please sign in to comment.