diff --git a/simulator/.idea/vcs.xml b/simulator/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/simulator/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/simulator/.idea/workspace.xml b/simulator/.idea/workspace.xml
index 2af5ccd..9c54a96 100644
--- a/simulator/.idea/workspace.xml
+++ b/simulator/.idea/workspace.xml
@@ -6,9 +6,21 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -29,57 +41,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
@@ -197,8 +167,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -219,6 +225,10 @@
+
+
+
+
@@ -255,6 +265,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -467,12 +497,14 @@
-
+
+
-
+
+
@@ -490,6 +522,14 @@
1467700295902
+
+ 1473923710842
+
+
+
+ 1473923710842
+
+
@@ -498,22 +538,22 @@
-
+
-
+
-
+
-
+
@@ -534,6 +574,10 @@
+
+
+
+
@@ -545,70 +589,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -623,7 +603,9 @@
-
+
+
+
@@ -672,7 +654,7 @@
-
+
@@ -681,7 +663,9 @@
-
+
+
+
@@ -699,7 +683,9 @@
-
+
+
+
@@ -733,7 +719,7 @@
-
+
@@ -742,7 +728,9 @@
-
+
+
+
@@ -776,7 +764,7 @@
-
+
@@ -785,7 +773,9 @@
-
+
+
+
@@ -819,7 +809,7 @@
-
+
@@ -828,7 +818,9 @@
-
+
+
+
@@ -862,7 +854,7 @@
-
+
@@ -871,7 +863,9 @@
-
+
+
+
@@ -895,7 +889,9 @@
-
+
+
+
@@ -915,43 +911,88 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -965,14 +1006,22 @@
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class b/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class
index 26319cc..e20a5ce 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class b/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class
index d8f74f8..b695225 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class b/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class
index 5cf14b6..ae34570 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class b/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class
index 90a9cc5..6530133 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/dataWriter/DataWriter.class b/simulator/out/production/simulator/com/verictas/pos/simulator/dataWriter/DataWriter.class
new file mode 100644
index 0000000..5a68c96
Binary files /dev/null and b/simulator/out/production/simulator/com/verictas/pos/simulator/dataWriter/DataWriter.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/dataWriter/WritingException.class b/simulator/out/production/simulator/com/verictas/pos/simulator/dataWriter/WritingException.class
new file mode 100644
index 0000000..63438e4
Binary files /dev/null and b/simulator/out/production/simulator/com/verictas/pos/simulator/dataWriter/WritingException.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/AU.class b/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/AU.class
new file mode 100644
index 0000000..fdd910d
Binary files /dev/null and b/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/AU.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/nBabel.class b/simulator/out/production/simulator/com/verictas/pos/simulator/nBabel.class
deleted file mode 100644
index 1a8f96e..0000000
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/nBabel.class and /dev/null differ
diff --git a/simulator/src/com/verictas/pos/simulator/Main.java b/simulator/src/com/verictas/pos/simulator/Main.java
index 11ff5b1..ed906c7 100644
--- a/simulator/src/com/verictas/pos/simulator/Main.java
+++ b/simulator/src/com/verictas/pos/simulator/Main.java
@@ -1,5 +1,7 @@
package com.verictas.pos.simulator;
+import com.verictas.pos.simulator.mathUtils.AU;
+
import javax.vecmath.*;
public class Main {
@@ -19,16 +21,19 @@ public class Main {
public static void main(String[] args) {
/**
- * Object definitions
+ * Object definitions (in 1990)
*/
- Object object1 = new Object(1/6.67384E-11, new Vector3d(1,0,0), new Vector3d(0,0,0));
- Object object2 = new Object(1, new Vector3d(0,0,0), new Vector3d(0,0,0));
+ Object sun = new Object("Sun", 1.988544E30, AU.convertToMeter(new Vector3d(3.621484938699030E-03,3.203347049968909E-03,-1.609087138389905E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.730306264794065E-06,6.909301960615850E-06,3.332250766613383E-08)));
+ Object venus = new Object("Venus", 48.685E23, AU.convertToMeter(new Vector3d(-3.786926829662159E-01,-6.122709221027441E-01,1.346180701578967E-02)), AU.convertToMetersPerSecond(new Vector3d(1.703979708314098E-02,-1.075790617185284E-02,-1.130972411646143E-03)));
+ Object earth = new Object("Earth", 5.97219E24, AU.convertToMeter(new Vector3d(1.000272608326749E+00,-1.305632418724720E-01,-1.614384880329670E-04)), AU.convertToMetersPerSecond(new Vector3d(2.003180730888720E-03,1.698793770993201E-02,5.869001824818362E-08)));
+ Object mars = new Object("Mars", 6.4185E23, AU.convertToMeter(new Vector3d(8.638055532014732E-01,-1.094520306989018E+00,-4.427515002554464E-02)), AU.convertToMetersPerSecond(new Vector3d(1.154235320339802E-02,9.839355267552327E-03,-7.723750026136471E-05)));
+ Object jupiter = new Object("Jupiter", 1898.13E24, AU.convertToMeter(new Vector3d(-5.440309619306835E+00,-2.383659935837559E-01,1.226571001615609E-01)), AU.convertToMetersPerSecond(new Vector3d(2.422143907277735E-04,-7.182284468246539E-03,2.440789748210396E-05)));
/**
* Object listing
*/
- Object[] objects = {object1, object2};
+ Object[] objects = {sun, venus, earth, mars, jupiter};
/**
* Run the simulator for the specified objects
diff --git a/simulator/src/com/verictas/pos/simulator/Object.java b/simulator/src/com/verictas/pos/simulator/Object.java
index 31d1a5a..a495488 100644
--- a/simulator/src/com/verictas/pos/simulator/Object.java
+++ b/simulator/src/com/verictas/pos/simulator/Object.java
@@ -10,6 +10,8 @@ public class Object {
public Vector3d acceleration;
public Vector3d oldAcceleration;
+ public String name;
+
private double gravitationalConstant = 6.67384E-11;
/**
@@ -18,10 +20,16 @@ public class Object {
* @param position The position vector of the object
* @param speed The speed vector of the object
*/
- public Object(double mass, Vector3d position, Vector3d speed) {
+ public Object(String name, double mass, Vector3d position, Vector3d speed) {
+ this.name = name;
this.mass = mass;
this.position = position;
this.speed = speed;
+
+ System.out.println(speed);
+
+ this.oldAcceleration = new Vector3d(0,0,0);
+ this.acceleration = new Vector3d(0,0,0);
}
/**
diff --git a/simulator/src/com/verictas/pos/simulator/Simulator.java b/simulator/src/com/verictas/pos/simulator/Simulator.java
index ef836f3..e964af5 100644
--- a/simulator/src/com/verictas/pos/simulator/Simulator.java
+++ b/simulator/src/com/verictas/pos/simulator/Simulator.java
@@ -1,5 +1,9 @@
package com.verictas.pos.simulator;
import javax.vecmath.*;
+
+import com.verictas.pos.simulator.dataWriter.DataWriter;
+import com.verictas.pos.simulator.dataWriter.WritingException;
+import com.verictas.pos.simulator.mathUtils.AU;
import com.verictas.pos.simulator.mathUtils.Vector3dMatrix;
public class Simulator {
@@ -16,49 +20,73 @@ public class Simulator {
*/
System.out.println("========== Simulation Started ==========\n");
+ // Create a timer
+ long startTime = System.currentTimeMillis();
+
/**
- * Define the forces matrix for this round
+ * Define the forces matrix and the DataWriter
*/
Vector3dMatrix matrix = new Vector3dMatrix(objects.length,objects.length);
- accelerate(objects, matrix);
+ try {
+ DataWriter writer = new DataWriter();
- /**
- * Start the rounds loop
- */
- for(int t = 0; t != rounds; t++) {
/**
- * The round has started
+ * Write begin values
*/
- System.out.println("\nRound " + (t + 1) + " started!");
- /**
- * Define the initial values
- */
- double time = SimulatorConfig.time;
for(int i = 0; i < objects.length; i++) {
- System.out.println("Object " + (i+1) + " was at " + objects[i].position);
- objects[i].updatePosition(time);
- objects[i].updateAcceleration();
- System.out.println("Object " + (i+1) + " is at " + objects[i].position);
+ writer.write(objects[i].name, objects[i].position, objects[i].speed, objects[i].oldAcceleration, objects[i].acceleration, objects[i].mass);
}
+ /**
+ * Start the leap frog integration!
+ */
+
accelerate(objects, matrix);
/**
- * Print the matrix for this round
+ * Start the rounds loop
*/
+ for(int t = 0; t != rounds; t++) {
+ /**
+ * The round has started
+ */
+ System.out.println("\nRound " + (t + 1) + " started!");
+ /**
+ * Define the initial values
+ */
+ double time = SimulatorConfig.time;
+
+ for(int i = 0; i < objects.length; i++) {
+ objects[i].updatePosition(time);
+ objects[i].updateAcceleration();
+ }
+
+ accelerate(objects, matrix);
+
+ /**
+ * Print the matrix for this round
+ */
+
+ for(int i = 0; i < objects.length; i++) {
+ writer.write(objects[i].name, objects[i].position, objects[i].speed, objects[i].oldAcceleration, objects[i].acceleration, objects[i].mass);
+ }
- for(int i = 0; i < objects.length; i++) {
- objects[i].updateSpeed(time);
}
+ /**
+ * Log that the simulation has finished and save info to file
+ */
+ writer.save();
+ System.out.println("========== Simulation Finished ==========");
+
+ // Display time info
+ long stopTime = System.currentTimeMillis();
+ System.out.println("Simulation took: " + (stopTime - startTime) + "ms");
+ } catch(WritingException e) {
+ e.printStackTrace();
}
-
- /**
- * Log that the simulation has finished
- */
- System.out.println("========== Simulation Finished ==========");
}
public static void accelerate(Object[] objects, Vector3dMatrix matrix) {
diff --git a/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java b/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java
index f10afe6..8790757 100644
--- a/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java
+++ b/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java
@@ -1,6 +1,6 @@
package com.verictas.pos.simulator;
public class SimulatorConfig {
- public static int rounds = 2;
- public static double time = 1;
+ public static int rounds = 60 * 60 * 24 * 10;
+ public static double time = 0.1; // in seconds
}
diff --git a/simulator/src/com/verictas/pos/simulator/dataWriter/DataWriter.java b/simulator/src/com/verictas/pos/simulator/dataWriter/DataWriter.java
new file mode 100644
index 0000000..07b352d
--- /dev/null
+++ b/simulator/src/com/verictas/pos/simulator/dataWriter/DataWriter.java
@@ -0,0 +1,82 @@
+package com.verictas.pos.simulator.dataWriter;
+
+import com.verictas.pos.simulator.mathUtils.AU;
+
+import javax.vecmath.Vector3d;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DataWriter {
+ private FileWriter writer = null;
+
+ // Delimiter used in text file (for import in Excel)
+ private static final String DELIMITER = "\t";
+ private static final String NEW_LINE = "\n";
+
+ public DataWriter() throws WritingException {
+ try {
+ // Define the save path
+ String directory = System.getProperty("user.home") + File.separator + "simulatorExports";
+ File directoryPath = new File(directory);
+
+ String path = directory + File.separator + getCurrentTimeStamp() + ".txt";
+ System.out.println("WRITING DATA TO: " + path);
+
+ if (!directoryPath.exists()) {
+ directoryPath.mkdirs();
+ }
+
+ this.writer = new FileWriter(path);
+ this.writer.write("Object" + DELIMITER + "Position (m)" + DELIMITER + "Position (AU)" + DELIMITER + "Speed (m)" + DELIMITER + "Speed (AU)" + DELIMITER + "Old Acceleration" + DELIMITER + "Acceleration" + DELIMITER + "Mass" + NEW_LINE);
+ } catch(IOException e) {
+ throw new WritingException("Whoop! Creation error!");
+ } catch(Exception e) {
+ throw new WritingException("Whoop! Unknown creation error!");
+ }
+ }
+
+ public void write(String string) throws WritingException {
+ if (this.writer == null) {
+ throw new WritingException("The writer isn't defined yet");
+ } else {
+ try {
+ this.writer.append(string);
+ } catch (Exception e) {
+ throw new WritingException("Whoop! Write error!");
+ }
+ }
+ }
+
+ public void write(String id, Vector3d position, Vector3d speed, Vector3d oldAcceleration, Vector3d acceleration, double mass) throws WritingException {
+ if (this.writer == null) {
+ throw new WritingException("The writer isn't defined yet");
+ } else {
+ try {
+ this.writer.append(id + DELIMITER + position.toString() + DELIMITER + AU.convertFromMeter(position).toString() + DELIMITER + speed.toString() + DELIMITER + AU.convertFromMetersPerSecond(speed).toString() + DELIMITER + oldAcceleration.toString() + DELIMITER + acceleration.toString() + DELIMITER + String.valueOf(mass) + NEW_LINE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new WritingException("Whoop! Write error!");
+ }
+ }
+ }
+
+ public void save() throws WritingException {
+ if (this.writer == null) {
+ throw new WritingException("The writer isn't defined yet");
+ } else {
+ try {
+ this.writer.flush();
+ this.writer.close();
+ } catch (IOException e) {
+ throw new WritingException("Whoop! Save error!");
+ }
+ }
+ }
+
+ public String getCurrentTimeStamp() {
+ return new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
+ }
+}
diff --git a/simulator/src/com/verictas/pos/simulator/dataWriter/WritingException.java b/simulator/src/com/verictas/pos/simulator/dataWriter/WritingException.java
new file mode 100644
index 0000000..70e7b66
--- /dev/null
+++ b/simulator/src/com/verictas/pos/simulator/dataWriter/WritingException.java
@@ -0,0 +1,8 @@
+package com.verictas.pos.simulator.dataWriter;
+
+public class WritingException extends Exception {
+ public WritingException() { super(); }
+ public WritingException(String message) { super(message); }
+ public WritingException(String message, Throwable cause) { super(message, cause); }
+ public WritingException(Throwable cause) { super(cause); }
+}
diff --git a/simulator/src/com/verictas/pos/simulator/mathUtils/AU.java b/simulator/src/com/verictas/pos/simulator/mathUtils/AU.java
new file mode 100644
index 0000000..5c8463e
--- /dev/null
+++ b/simulator/src/com/verictas/pos/simulator/mathUtils/AU.java
@@ -0,0 +1,45 @@
+package com.verictas.pos.simulator.mathUtils;
+
+import javax.vecmath.Vector3d;
+
+public class AU {
+ /**
+ * Helper class for working with astronomical units
+ */
+ public static Vector3d convertToMeter(Vector3d input) {
+ Vector3d output = new Vector3d(input);
+
+ // Convert AU to m by NASA
+ output.scale(149597870.700); // Number to large when multiplied with 1000
+ output.scale(1000);
+
+ return output;
+ }
+
+ public static Vector3d convertToMetersPerSecond(Vector3d input) {
+ Vector3d output = new Vector3d(input);
+
+ // 1 AU/day to M/s
+ output.scale(1731456.84);
+
+ return output;
+ }
+
+ public static Vector3d convertFromMeter(Vector3d input) {
+ Vector3d output = new Vector3d(input);
+
+ // Convert m to AU by NASA
+ output.scale(6.6845871E-12);
+
+ return output;
+ }
+
+ public static Vector3d convertFromMetersPerSecond(Vector3d input) {
+ Vector3d output = new Vector3d(input);
+
+ // Convert seconds to days by NASA
+ output.scale(5.77548327E-7);
+
+ return output;
+ }
+}
diff --git a/simulator/src/com/verictas/pos/simulator/nBabel.java b/simulator/src/com/verictas/pos/simulator/nBabel.java
deleted file mode 100644
index da03435..0000000
--- a/simulator/src/com/verictas/pos/simulator/nBabel.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.verictas.pos.simulator;
-
-public class nBabel {
-}