diff --git a/simulator/.idea/workspace.xml b/simulator/.idea/workspace.xml index 577f451..36fd428 100644 --- a/simulator/.idea/workspace.xml +++ b/simulator/.idea/workspace.xml @@ -7,10 +7,13 @@ - + + + + @@ -22,6 +25,7 @@ + @@ -34,8 +38,8 @@ - - + + @@ -46,21 +50,19 @@ - - + + - - + + - - - - - + + + @@ -68,8 +70,8 @@ - - + + @@ -114,7 +116,6 @@ - @@ -152,7 +155,16 @@ - + + + + + + + + + + @@ -168,9 +180,17 @@ + + + + + + + + + + + + + + + + + + - - - + @@ -250,6 +290,10 @@ + + + + @@ -293,7 +337,7 @@ - + @@ -400,6 +426,27 @@ + + + + + + + + @@ -474,6 +521,34 @@ + + + + + @@ -484,7 +559,7 @@ - + - - + + - - - - - + + + - - - - - + + + + + - - + + - + + - + + - + @@ -589,7 +673,7 @@ - @@ -598,20 +682,10 @@ - - - - - - - - - - - + @@ -633,21 +707,21 @@ - + - + - + @@ -657,7 +731,7 @@ - + @@ -679,21 +753,21 @@ - + - + - + @@ -703,7 +777,7 @@ - + @@ -725,21 +799,21 @@ - + - + - + @@ -749,7 +823,7 @@ - + @@ -771,21 +845,21 @@ - + - + - + @@ -808,7 +882,7 @@ - + @@ -823,7 +897,7 @@ - + @@ -834,25 +908,23 @@ - + - - - + - + @@ -863,14 +935,14 @@ - + - + @@ -878,24 +950,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - + - - + + + + + + + + + + + - - + + @@ -916,52 +1031,32 @@ - - + + - - - - - - - - - - - - + + - - - - - - - - - - - - + + - - + + diff --git a/simulator/src/com/verictas/pos/simulator/Main.java b/simulator/src/com/verictas/pos/simulator/Main.java index 528f8af..5bc0406 100644 --- a/simulator/src/com/verictas/pos/simulator/Main.java +++ b/simulator/src/com/verictas/pos/simulator/Main.java @@ -25,16 +25,8 @@ public class Main { */ /** - * Definitions for the ecliptic plane + * Definitions for the ecliptic plane (by 1st of january 2016) */ - //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 moon = new Object("The Moon", 734.9E20, AU.convertToMeter(new Vector3d(1.002390058141768E+00,-1.318677081380600E-01,-1.051759034600983E-04)), AU.convertToMetersPerSecond(new Vector3d(2.294349896503608E-03,1.752303034437222E-02,-5.522655228080146E-05))); - - // 1 januari startdag Object sun = new Object("Sun", 1.988544E30, AU.convertToMeter(new Vector3d(3.737881713150281E-03,1.402397586692506E-03,-1.612700291840256E-04)), AU.convertToMetersPerSecond(new Vector3d(8.619338996535534E-07,6.895607793642275E-06,-2.794074909231784E-08))); Object earth = new Object("Earth", 5.97219E24, AU.convertToMeter(new Vector3d(-1.630229002588497E-01,9.704723344534316E-01,-1.955367328932975E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.723383356491747E-02,-2.969134550063944E-03,-4.433758674928828E-07))); Object moon = new Object("The Moon", 734.9E20, AU.convertToMeter(new Vector3d(-1.657103868749121E-01,9.706382026425473E-01,-1.879812512691582E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.728100931961937E-02,-3.525371122447976E-03,4.909148618073602E-05))); @@ -59,7 +51,7 @@ public class Main { * Object listing */ - Object[] objects = {sun, earth, moon, jupiter}; + Object[] objects = {sun, earth, moon, jupiter, mars, venus}; /** diff --git a/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java b/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java index 363173d..888a177 100644 --- a/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java +++ b/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java @@ -1,17 +1,40 @@ package com.verictas.pos.simulator; public class SimulatorConfig { + + /** + * (Example) Settings for the EARTH + * Rounds: 1051896 * (amount of years to run) + * Time: 30 + * Mod arg: 1051896 (1 Earth year) + */ + + /** + * (Example) Settings for SEDNA + * Rounds: 184000000 (approx. 1 million years) + * Time: 172800 (2 days) + * Modulo argument: 2101968 (1 Sedna year) + */ + + /** + * (Example) Settings for 2012 VP113 + * Rounds: 184000000 (approx. 1 million years) + * Time: 172800 (2 days) + * Modulo argument: 788923 (1 2012VP113 year) + */ + /** * Time settings */ - public static int rounds = 530000*2; // Amount of rounds to run the simulator for // 3000000 = 250.000 jaar - public static double time = 60 * 60; // Time steps in seconds // 259200 = 1 month + public static int rounds = 525948*2*500; // Amount of rounds to run the simulator for + public static double time = 30; // Time steps in seconds /** * Object settings */ + public static String sunName = "Sun"; // The name of the sun to calculate values TO public static String[] objectNames = { "Earth" }; // The name of the object(s) your want to calculate the values OF /** @@ -26,11 +49,12 @@ public class SimulatorConfig { /** * Console settings */ - public static boolean logConsole = false; + public static boolean logConsole = true; public static int skipConsole = 100000; /** * Processor settings */ - public static int moduloArgument = 12*100; + public static boolean autoModulo = true; + public static int moduloArgument = 14400; } diff --git a/simulator/src/com/verictas/pos/simulator/Test.java b/simulator/src/com/verictas/pos/simulator/Test.java deleted file mode 100644 index 1802c7d..0000000 --- a/simulator/src/com/verictas/pos/simulator/Test.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.verictas.pos.simulator; - -import com.verictas.pos.simulator.mathUtils.AOP; - -import javax.vecmath.Vector3d; - -public class Test { - public static void main(String[] args) { - Vector3d fakePos = new Vector3d(1E20,2E20,3E20); - Vector3d fakeSpeed = new Vector3d(4E20,5E20,6E20); - - double aop = AOP.calculate(fakePos, fakeSpeed); - System.out.println("END:" + fakePos); - System.out.println("END:" + fakeSpeed); - System.out.println("END:" + aop); - } -} diff --git a/simulator/src/com/verictas/pos/simulator/mathUtils/AOP.java b/simulator/src/com/verictas/pos/simulator/mathUtils/AOP.java index 5f3e39d..e0d0dd8 100644 --- a/simulator/src/com/verictas/pos/simulator/mathUtils/AOP.java +++ b/simulator/src/com/verictas/pos/simulator/mathUtils/AOP.java @@ -16,8 +16,7 @@ public class AOP { //System.out.println("n = " + ascendingNode); // ECCENTRICITY VECTOR - // double mu = 1.32712440018E20; - double mu = 3.9860044189E14; + double mu = 1.32712440018E20; Vector3d upCross = new Vector3d(0,0,0); upCross.cross(speed, orbitalMomentum); diff --git a/simulator/src/com/verictas/pos/simulator/processor/ObjectProcessor.java b/simulator/src/com/verictas/pos/simulator/processor/ObjectProcessor.java new file mode 100644 index 0000000..0d10527 --- /dev/null +++ b/simulator/src/com/verictas/pos/simulator/processor/ObjectProcessor.java @@ -0,0 +1,128 @@ +package com.verictas.pos.simulator.processor; + +import com.verictas.pos.simulator.Node; +import com.verictas.pos.simulator.Object; +import com.verictas.pos.simulator.Simulator; +import com.verictas.pos.simulator.SimulatorConfig; + +import javax.vecmath.Vector3d; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class ObjectProcessor { + public Node aphelion; + public Node perihelion; + public double aphelionDistance = -1; + public double perihelionDistance = -1; + + private Object thisObject; + private Object referenceObject; + + private Vector3d startingPosition; + private double lastStartDistance = -1; + private double beforeLastStartDistance = -1; + + public void setStartingPosition(Vector3d position) { + this.startingPosition = position; + } + + public void setObjectData(Object object) { + this.thisObject = object; + } + + public void setReferenceObjectData(Object object) { + this.referenceObject = object; + } + + /** + * Processes the aphelion & perihelion + */ + public void processAphelionAndPerihelion() { + double sunDistance = this.thisObject.getDistance(this.referenceObject).length(); + + /** + * Set the defaults + */ + + if (this.aphelionDistance == -1) { + this.aphelionDistance = sunDistance; + } + + if (this.perihelionDistance == -1) { + this.perihelionDistance = sunDistance; + } + + /** + * Check if the aphelion or perihelion should be changed + */ + + if (sunDistance > aphelionDistance) { + this.aphelion = new Node(this.thisObject.position); + this.aphelion.setRound(Simulator.round); + this.aphelionDistance = sunDistance; + } + + if (sunDistance < perihelionDistance) { + this.perihelion = new Node(this.thisObject.position); + this.perihelion.setRound(Simulator.round); + this.perihelionDistance = sunDistance; + } + } + + /** + * Processes the round check + */ + public boolean processRoundCheck() { + double startDistance = this.thisObject.getDistance(this.startingPosition).length(); + boolean fullRotation = false; + + /** + * Check if all are set and shuffle! + */ + + if (beforeLastStartDistance != -1 && lastStartDistance != -1) { + // Ready to go! + if (beforeLastStartDistance > lastStartDistance && startDistance > lastStartDistance) { + // Last point was the closest to the starting position overall! + fullRotation = true; + if (SimulatorConfig.logConsole) { + System.out.println("INFO:: Object " + this.thisObject.name + " has made a full rotation last round."); + } + } + + beforeLastStartDistance = lastStartDistance; + lastStartDistance = startDistance; + } + + /** + * Check if 1st distance is set and 2nd isn't set + */ + + if (beforeLastStartDistance != -1 && lastStartDistance == -1) { + lastStartDistance = startDistance; + } + + /** + * Check if the 1st distance isn't set + */ + if (beforeLastStartDistance == -1) { + beforeLastStartDistance = startDistance; + } + + if(fullRotation) { + return true; + } else { + return false; + } + } + + public void reset() { + aphelionDistance = -1; + perihelionDistance = -1; + lastStartDistance = -1; + beforeLastStartDistance = -1; + aphelion = new Node(); + perihelion = new Node(); + } +} diff --git a/simulator/src/com/verictas/pos/simulator/processor/Processor.java b/simulator/src/com/verictas/pos/simulator/processor/Processor.java index b0de05b..013bbf1 100644 --- a/simulator/src/com/verictas/pos/simulator/processor/Processor.java +++ b/simulator/src/com/verictas/pos/simulator/processor/Processor.java @@ -7,8 +7,10 @@ import com.verictas.pos.simulator.dataWriter.AOPDataWriter; import com.verictas.pos.simulator.dataWriter.PosDataWriter; import com.verictas.pos.simulator.dataWriter.WritingException; import com.verictas.pos.simulator.mathUtils.AOP; +import com.verictas.pos.simulator.mathUtils.AU; import javax.vecmath.Vector3d; +import java.util.ArrayList; import java.util.HashMap; import java.util.TreeMap; @@ -16,6 +18,7 @@ public class Processor { private PosDataWriter writer; private AOPDataWriter aopWriter; public HashMap initialObjectValues = new HashMap<>(); + public HashMap objects = new HashMap<>(); public HashMap> arguments = new HashMap<>(); public Processor(Object[] objects) throws ProcessingException, WritingException { @@ -32,6 +35,14 @@ public class Processor { // Write initial values to file this.writePos(initialObjectValues); + + /** + * Create the object processing array + */ + for (Object object : initialObjectValues.values()) { + this.objects.put(object.name, new ObjectProcessor()); + this.objects.get(object.name).setStartingPosition(object.position); + } } public void process(Object[] objectArray) throws ProcessingException, WritingException { @@ -43,8 +54,37 @@ public class Processor { * Calculate AOP for specified objects */ for(String objectName : SimulatorConfig.objectNames) { - // Check if we need to calculate the AOP - if (Simulator.round % SimulatorConfig.moduloArgument == 0) { + // Process the aphelion & perihelion for reference + ObjectProcessor object = this.objects.get(objectName); + + object.setObjectData(objects.get(objectName)); + object.setReferenceObjectData(objects.get(SimulatorConfig.sunName)); + + // Check if the object has gone round last round + + boolean round = object.processRoundCheck(); + if (round) { + System.out.println("\n\n============== ROTATION DATA: " + objectName.toUpperCase() + ", ROUND " + (Simulator.round - 1) + " ============="); + System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during apastron in km: " + object.aphelionDistance / 1000); + System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during apastron in AU: " + AU.convertFromMeter(object.aphelionDistance)); + System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during periastron in km: " + object.perihelionDistance / 1000); + System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during periastron in AU: " + AU.convertFromMeter(object.perihelionDistance)); + System.out.println("===========================================================================\n\n"); + + object.reset(); + + // Reset starting position + this.objects.get(objectName).setStartingPosition(objects.get(objectName).position); + } + + object.processAphelionAndPerihelion(); + this.objects.put(objectName, object); + + + /** + * Calculate AOP + */ + if (SimulatorConfig.autoModulo && round) { if (arguments.get(objectName) == null) { // If not defined TreeMap agmnts = new TreeMap<>(); @@ -52,10 +92,28 @@ public class Processor { } // Calculate AOP and put it in the array - Object object = objects.get(objectName); - Vector3d pos = new Vector3d(object.position); - Vector3d speed = new Vector3d(object.speed); + Object AOPobject = objects.get(objectName); + Vector3d pos = new Vector3d(AOPobject.position); + Vector3d speed = new Vector3d(AOPobject.speed); arguments.get(objectName).put(Simulator.round, AOP.calculate(pos, speed)); + + if (SimulatorConfig.logConsole) { + System.out.println("Last rounds AOP: " + AOP.calculate(pos, speed)); + } + } else if (!SimulatorConfig.autoModulo) { + if (Simulator.round % SimulatorConfig.moduloArgument == 0) { + if (arguments.get(objectName) == null) { + // If not defined + TreeMap agmnts = new TreeMap<>(); + arguments.put(objectName, agmnts); + } + + // Calculate AOP and put it in the array + Object AOPobject = objects.get(objectName); + Vector3d pos = new Vector3d(AOPobject.position); + Vector3d speed = new Vector3d(AOPobject.speed); + arguments.get(objectName).put(Simulator.round, AOP.calculate(pos, speed)); + } } } }