From 18f63b34a5a7176048b01c6bc31257749b8e9e9c Mon Sep 17 00:00:00 2001 From: jic13003 Date: Fri, 4 Dec 2015 18:19:12 -0500 Subject: [PATCH 1/5] test for branching --- .../ThreeBodyExample/ThreeBodyExample.java | 60 +++---------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java index 485a326..683506c 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java @@ -24,9 +24,12 @@ public ThreeBodyExample() { } public static void main(String[] args) { - // TODO Auto-generated method stub + // Class that solves a three body problem and plots it ThreeBodyExample x = new ThreeBodyExample(); - + + // set the final time = one orbit period + double tf = 2.0; + // create a ThreeBody orbit using three masses and gravitational con ThreeBodyAPL sat = new ThreeBodyAPL(10, 0.3, 1.0, 2.0); //initialize VectorN elements @@ -39,58 +42,11 @@ public static void main(String[] args) { System.out.println(format.format(v)); // find out the derivs of the problem - double[] derivs = sat.derivs(2.0, y); - - // set the final time = one orbit period - double tf = 2.0; - + double[] derivs = sat.derivs(tf, y); + // set the initial time to zero double t0 = 0.0; - - // propagate the orbit - FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10); - dp853.addStepHandler(sat.stepHandler); - // double[] y = new double[] { 7000.0, 0, 0, .0, 8, 0 }; // initial - // state - - dp853.integrate(sat, 0.0, y, 8000, y); // now y contains final state at - // tf - - Double[] objArray = sat.time.toArray(new Double[sat.time.size()]); - double[] timeArray = ArrayUtils.toPrimitive(objArray); - double[] xsolArray = ArrayUtils.toPrimitive(sat.xsol.toArray(new Double[sat.time.size()])); - double[] ysolArray = ArrayUtils.toPrimitive(sat.ysol.toArray(new Double[sat.time.size()])); - - double[][] XY = new double[timeArray.length][2]; - - // int a=0; - // System.arraycopy(timeArray,0,XY[a],0,timeArray.length); - // System.arraycopy(ysolArray,0,XY[1],0,ysolArray.length); - - for (int i = 0; i < timeArray.length; i++) { - XY[i][0] = xsolArray[i]; - XY[i][1] = ysolArray[i]; - } - - Plot2DPanel p = new Plot2DPanel(); - - // Plot2DPanel p = new Plot2DPanel(min, max, axesScales, axesLabels); - - ScatterPlot s = new ScatterPlot("orbit", Color.RED, XY); - // LinePlot l = new LinePlot("sin", Color.RED, XY); - // l.closed_curve = false; - // l.draw_dot = true; - p.addPlot(s); - p.setLegendOrientation(PlotPanel.SOUTH); - double plotSize = 10000.; - double[] min = { -plotSize, -plotSize }; - double[] max = { plotSize, plotSize }; - p.setFixedBounds(min, max); - - new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - System.out.println("end"); - + } } From 3a56cffd7490758d0d73cb721db5e5fe215dd8ff Mon Sep 17 00:00:00 2001 From: jic13003 Date: Wed, 2 Dec 2015 17:40:36 -0400 Subject: [PATCH 2/5] partial work on threebody example problem --- .../ThreeBodyExample/ThreeBodyAPL.java | 23 ++++++++++++++++++- .../ThreeBodyExample/ThreeBodyExample.java | 11 +++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java b/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java index 966bccc..28104e0 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java @@ -3,6 +3,7 @@ import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; import jat.coreNOSA.cm.ThreeBody; +import jat.coreNOSA.math.MatrixVector.data.VectorN; public class ThreeBodyAPL extends ThreeBody implements FirstOrderDifferentialEquations{ @@ -21,5 +22,25 @@ public int getDimension() { // returns a dimension of 6 return 6; } - + public double[] randv() { + double[] randv = new double[17]; + randv[1] = 1.0; + randv[2] = 1.0; + randv[3] = 1.0; + randv[4] = 1.0; + randv[5] = 1.0; + randv[6] = 1.0; + randv[7] = 1.0; + randv[8] = 1.0; + randv[9] = 1.0; + randv[10] = 1.0; + randv[11] = 1.0; + randv[12] = 1.0; + randv[13] = 1.0; + randv[14] = 1.0; + randv[15] = 1.0; + randv[16] = 1.0; + randv[17] = 1.0; + return randv; + } } diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java index 59c687e..485a326 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java @@ -5,6 +5,7 @@ import jat.core.plot.plot.Plot2DPanel; import jat.core.plot.plot.PlotPanel; import jat.core.plot.plot.plots.ScatterPlot; +import jat.coreNOSA.math.MatrixVector.data.VectorN; import jat.examples.TwoBodyExample.TwoBodyExample; import java.awt.Color; @@ -29,19 +30,19 @@ public static void main(String[] args) { // create a ThreeBody orbit using three masses and gravitational con ThreeBodyAPL sat = new ThreeBodyAPL(10, 0.3, 1.0, 2.0); //initialize VectorN elements - VectorN randv = new VectorN() - + double[] y = sat.randv(); + ArrayRealVector v = new ArrayRealVector(y); DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00"); RealVectorFormat format = new RealVectorFormat(df2); System.out.println(format.format(v)); - // find out the period of the orbit - double period = sat.period(); + // find out the derivs of the problem + double[] derivs = sat.derivs(2.0, y); // set the final time = one orbit period - double tf = period; + double tf = 2.0; // set the initial time to zero double t0 = 0.0; From 8d7f84adbc0a12d0b4cefb3a2344a39d5d469407 Mon Sep 17 00:00:00 2001 From: jic13003 Date: Fri, 4 Dec 2015 18:32:03 -0500 Subject: [PATCH 3/5] another test of branching --- src/jat/examples/ThreeBodyExample/ThreeBodyExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java index 683506c..55e69d8 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java @@ -46,7 +46,7 @@ public static void main(String[] args) { // set the initial time to zero double t0 = 0.0; - + //test } } From c920ba09ec4f3c1837516ba1d5829b3a804aa40d Mon Sep 17 00:00:00 2001 From: jic13003 Date: Fri, 4 Dec 2015 19:02:52 -0500 Subject: [PATCH 4/5] test for output for derivative function of ThreeBodyExample --- .../ThreeBodyExample/ThreeBodyAPL.java | 37 ++++++++++--------- .../ThreeBodyExample/ThreeBodyExample.java | 14 ++++++- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java b/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java index 28104e0..41a565c 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyAPL.java @@ -23,24 +23,25 @@ public int getDimension() { return 6; } public double[] randv() { - double[] randv = new double[17]; - randv[1] = 1.0; - randv[2] = 1.0; - randv[3] = 1.0; - randv[4] = 1.0; - randv[5] = 1.0; - randv[6] = 1.0; - randv[7] = 1.0; - randv[8] = 1.0; - randv[9] = 1.0; - randv[10] = 1.0; - randv[11] = 1.0; - randv[12] = 1.0; - randv[13] = 1.0; - randv[14] = 1.0; - randv[15] = 1.0; - randv[16] = 1.0; - randv[17] = 1.0; + 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; } } diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java index 55e69d8..890744b 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java @@ -46,7 +46,19 @@ public static void main(String[] args) { // set the initial time to zero double t0 = 0.0; - //test + + // propagate the orbit + //FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10); + //dp853.addStepHandler(sat.stepHandler); + // double[] y = new double[] { 7000.0, 0, 0, .0, 8, 0 }; // initial + // state + //test loop + + for (int i = 0; i< derivs.length; i++) + { + System.out.println(derivs[i]); + } + } } From 9fd3337e1f0e444c9542b36f43537f6606ab6254 Mon Sep 17 00:00:00 2001 From: jic13003 Date: Fri, 4 Dec 2015 19:17:31 -0500 Subject: [PATCH 5/5] outputs of center of mass function and total energy function --- .../examples/ThreeBodyExample/ThreeBodyExample.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java index 890744b..ecdf71b 100644 --- a/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java +++ b/src/jat/examples/ThreeBodyExample/ThreeBodyExample.java @@ -27,6 +27,8 @@ public static void main(String[] args) { // Class that solves a three body problem and plots it ThreeBodyExample x = new ThreeBodyExample(); + //initialize variables + double totalEnergy = 0; // set the final time = one orbit period double tf = 2.0; @@ -46,19 +48,24 @@ public static void main(String[] args) { // set the initial time to zero double t0 = 0.0; + // obtain center of mass + VectorN cm = sat.center_of_mass(y); + + // obtain current energy + totalEnergy = sat.Energy(y); // propagate the orbit //FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10); //dp853.addStepHandler(sat.stepHandler); // double[] y = new double[] { 7000.0, 0, 0, .0, 8, 0 }; // initial // state - //test loop - + //test outputs for (int i = 0; i< derivs.length; i++) { System.out.println(derivs[i]); } - + System.out.println(cm); + System.out.println(totalEnergy); } }