From cda428147525f68e543b06a6ab5aeeedfe33f1d6 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Thu, 25 Oct 2012 12:10:28 -0500 Subject: [PATCH] Changed the management of the SimulationStatus WarningSet so it is not copied by the copy constructor. Management of the warning set is controlled by the BasicEventSimulationEngine. Cleaned up some warnings: removed unused includes, changed annotations, removed unused local variables. --- .../BasicEventSimulationEngine.java | 19 +++-- .../sf/openrocket/simulation/EventQueue.java | 1 + .../sf/openrocket/simulation/FlightData.java | 2 +- .../openrocket/simulation/FlightDataType.java | 1 - .../simulation/RK4SimulationStatus.java | 6 +- .../simulation/RK4SimulationStepper.java | 2 + .../simulation/SimulationOptions.java | 5 -- .../simulation/SimulationStatus.java | 69 ++++++++++--------- 8 files changed, 52 insertions(+), 53 deletions(-) diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index 4a1ff4fe1..4916fd647 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -1,10 +1,7 @@ package net.sf.openrocket.simulation; -import java.util.HashSet; import java.util.Iterator; -import java.util.Set; -import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.logging.LogHelper; @@ -14,7 +11,6 @@ import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.motor.MotorInstanceConfiguration; import net.sf.openrocket.rocketcomponent.Configuration; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration; -import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.MotorConfiguration; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RecoveryDevice; @@ -30,7 +26,6 @@ import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.Pair; -import net.sf.openrocket.util.Quaternion; import net.sf.openrocket.util.SimpleStack; @@ -66,7 +61,13 @@ public class BasicEventSimulationEngine implements SimulationEngine { throw new MotorIgnitionException("No motors defined in the simulation."); } - status = new SimulationStatus(configuration, motorConfiguration, simulationConditions, flightData.getWarningSet()); + status = new SimulationStatus(configuration, motorConfiguration, simulationConditions); + status.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket())); + { + // main sustainer stage + RocketComponent sustainer = configuration.getRocket().getChild(0); + status.setFlightData( new FlightDataBranch( sustainer.getName(), FlightDataType.TYPE_TIME)); + } stages.add(status); SimulationListenerHelper.fireStartSimulation(status); @@ -82,6 +83,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { status = stageStatus; FlightDataBranch dataBranch = simulateLoop(); flightData.addBranch(dataBranch); + flightData.getWarningSet().addAll( status.getWarnings() ); } SimulationListenerHelper.fireEndSimulation(status, null); @@ -352,8 +354,6 @@ public class BasicEventSimulationEngine implements SimulationEngine { case IGNITION: { // Ignite the motor - MotorMount mount = (MotorMount) event.getSource(); - RocketComponent component = (RocketComponent) mount; MotorId motorId = (MotorId) event.getData(); MotorInstanceConfiguration config = status.getMotorConfiguration(); config.setMotorIgnitionTime(motorId, event.getTime()); @@ -408,8 +408,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { // Prepare the booster status for simulation. SimulationStatus boosterStatus = new SimulationStatus(status); - FlightDataBranch boosterFlightData = new FlightDataBranch( "Stage-" + n, FlightDataType.TYPE_TIME); - boosterStatus.setFlightData(boosterFlightData); + boosterStatus.setFlightData(new FlightDataBranch( stage.getName(), FlightDataType.TYPE_TIME)); stages.add(boosterStatus); diff --git a/core/src/net/sf/openrocket/simulation/EventQueue.java b/core/src/net/sf/openrocket/simulation/EventQueue.java index 1ac9fb821..41c27d81d 100644 --- a/core/src/net/sf/openrocket/simulation/EventQueue.java +++ b/core/src/net/sf/openrocket/simulation/EventQueue.java @@ -52,6 +52,7 @@ public class EventQueue extends PriorityQueue implements Monitorabl return super.remove(o); } + @Override public int getModID() { return modID; } diff --git a/core/src/net/sf/openrocket/simulation/FlightData.java b/core/src/net/sf/openrocket/simulation/FlightData.java index c0fb90e80..8eb7d576a 100644 --- a/core/src/net/sf/openrocket/simulation/FlightData.java +++ b/core/src/net/sf/openrocket/simulation/FlightData.java @@ -226,7 +226,7 @@ public class FlightData { // Launch rod velocity - eventloop: for (FlightEvent event : branch.getEvents()) { + for (FlightEvent event : branch.getEvents()) { if (event.getType() == FlightEvent.Type.LAUNCHROD) { double t = event.getTime(); List velocity = branch.get(FlightDataType.TYPE_VELOCITY_TOTAL); diff --git a/core/src/net/sf/openrocket/simulation/FlightDataType.java b/core/src/net/sf/openrocket/simulation/FlightDataType.java index 3c73fc781..fabb25f10 100644 --- a/core/src/net/sf/openrocket/simulation/FlightDataType.java +++ b/core/src/net/sf/openrocket/simulation/FlightDataType.java @@ -257,7 +257,6 @@ public class FlightDataType implements Comparable { * @param u the unit group the new type should belong to if a new group is created. * @return a data type. */ - @SuppressWarnings("null") public static synchronized FlightDataType getType(String s, String symbol, UnitGroup u) { // if symbol is null : try finding by name diff --git a/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java b/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java index 0f554e813..db366fbdc 100644 --- a/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java +++ b/core/src/net/sf/openrocket/simulation/RK4SimulationStatus.java @@ -1,6 +1,5 @@ package net.sf.openrocket.simulation; -import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.models.atmosphere.AtmosphericConditions; import net.sf.openrocket.motor.MotorInstanceConfiguration; import net.sf.openrocket.rocketcomponent.Configuration; @@ -18,8 +17,8 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable { public RK4SimulationStatus(Configuration configuration, MotorInstanceConfiguration motorConfiguration, - SimulationConditions simulationConditions, WarningSet warnings) { - super(configuration, motorConfiguration, simulationConditions, warnings); + SimulationConditions simulationConditions ) { + super(configuration, motorConfiguration, simulationConditions); } public RK4SimulationStatus( SimulationStatus other ) { @@ -83,6 +82,7 @@ public class RK4SimulationStatus extends SimulationStatus implements Cloneable { this.startWarningTime = startWarningTime; } + @Override public RK4SimulationStatus clone() { return (RK4SimulationStatus) super.clone(); } diff --git a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java index 178018d65..2f6fde315 100644 --- a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java @@ -67,6 +67,8 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { public RK4SimulationStatus initialize(SimulationStatus original) { RK4SimulationStatus status = new RK4SimulationStatus(original); + // Copy the existing warnings + status.setWarnings( original.getWarnings() ); SimulationConditions sim = original.getSimulationConditions(); diff --git a/core/src/net/sf/openrocket/simulation/SimulationOptions.java b/core/src/net/sf/openrocket/simulation/SimulationOptions.java index 4ea6ee146..62f2121f7 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationOptions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationOptions.java @@ -5,10 +5,8 @@ import java.util.EventListener; import java.util.EventObject; import java.util.List; import java.util.Random; -import java.util.Set; import net.sf.openrocket.aerodynamics.BarrowmanCalculator; -import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.masscalc.BasicMassCalculator; import net.sf.openrocket.models.atmosphere.AtmosphericModel; import net.sf.openrocket.models.atmosphere.ExtendedISAModel; @@ -16,7 +14,6 @@ import net.sf.openrocket.models.gravity.GravityModel; import net.sf.openrocket.models.gravity.WGSGravityModel; import net.sf.openrocket.models.wind.PinkNoiseWindModel; import net.sf.openrocket.rocketcomponent.Rocket; -import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.GeodeticComputationStrategy; @@ -34,8 +31,6 @@ import net.sf.openrocket.util.WorldCoordinate; */ public class SimulationOptions implements ChangeSource, Cloneable { - private static final LogHelper log = Application.getLogger(); - public static final double MAX_LAUNCH_ROD_ANGLE = Math.PI / 3; /** diff --git a/core/src/net/sf/openrocket/simulation/SimulationStatus.java b/core/src/net/sf/openrocket/simulation/SimulationStatus.java index 0dd4bb2f4..444ed4330 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationStatus.java +++ b/core/src/net/sf/openrocket/simulation/SimulationStatus.java @@ -86,40 +86,39 @@ public class SimulationStatus implements Monitorable { public SimulationStatus( Configuration configuration, MotorInstanceConfiguration motorConfiguration, - SimulationConditions simulationConditions, WarningSet warnings ) { + SimulationConditions simulationConditions ) { - this.setSimulationConditions(simulationConditions); - this.setConfiguration(configuration); - this.setMotorConfiguration(motorConfiguration); + this.simulationConditions = simulationConditions; + this.configuration = configuration; + this.motorConfiguration = motorConfiguration; - this.setSimulationTime(0); - this.setPreviousTimeStep(simulationConditions.getTimeStep()); - this.setRocketPosition(Coordinate.NUL); - this.setRocketVelocity(Coordinate.NUL); - this.setRocketWorldPosition(simulationConditions.getLaunchSite()); + this.time = 0; + this.previousTimeStep = this.simulationConditions.getTimeStep(); + this.position = Coordinate.NUL; + this.velocity = Coordinate.NUL; + this.worldPosition = this.simulationConditions.getLaunchSite(); // Initialize to roll angle with least stability w.r.t. the wind Quaternion o; - FlightConditions cond = new FlightConditions(configuration); - simulationConditions.getAerodynamicCalculator().getWorstCP(configuration, cond, null); - double angle = -cond.getTheta() - simulationConditions.getLaunchRodDirection(); + FlightConditions cond = new FlightConditions(this.configuration); + this.simulationConditions.getAerodynamicCalculator().getWorstCP(this.configuration, cond, null); + double angle = -cond.getTheta() - this.simulationConditions.getLaunchRodDirection(); o = Quaternion.rotation(new Coordinate(0, 0, angle)); // Launch rod angle and direction - o = o.multiplyLeft(Quaternion.rotation(new Coordinate(0, simulationConditions.getLaunchRodAngle(), 0))); - o = o.multiplyLeft(Quaternion.rotation(new Coordinate(0, 0, simulationConditions.getLaunchRodDirection()))); - - this.setRocketOrientationQuaternion(o); - this.setRocketRotationVelocity(Coordinate.NUL); + o = o.multiplyLeft(Quaternion.rotation(new Coordinate(0, this.simulationConditions.getLaunchRodAngle(), 0))); + o = o.multiplyLeft(Quaternion.rotation(new Coordinate(0, 0, this.simulationConditions.getLaunchRodDirection()))); + this.orientation = o; + this.rotationVelocity = Coordinate.NUL; /* * Calculate the effective launch rod length taking into account launch lugs. * If no lugs are found, assume a tower launcher of full length. */ - double length = simulationConditions.getLaunchRodLength(); + double length = this.simulationConditions.getLaunchRodLength(); double lugPosition = Double.NaN; - for (RocketComponent c : configuration) { + for (RocketComponent c : this.configuration) { if (c instanceof LaunchLug) { double pos = c.toAbsolute(new Coordinate(c.getLength()))[0].x; if (Double.isNaN(lugPosition) || pos > lugPosition) { @@ -129,7 +128,7 @@ public class SimulationStatus implements Monitorable { } if (!Double.isNaN(lugPosition)) { double maxX = 0; - for (Coordinate c : configuration.getBounds()) { + for (Coordinate c : this.configuration.getBounds()) { if (c.x > maxX) maxX = c.x; } @@ -137,25 +136,27 @@ public class SimulationStatus implements Monitorable { length = Math.max(0, length - (maxX - lugPosition)); } } - this.setEffectiveLaunchRodLength(length); + this.effectiveLaunchRodLength = length; - this.setSimulationStartWallTime(System.nanoTime()); + this.simulationStartWallTime = System.nanoTime(); - this.setMotorIgnited(false); - this.setLiftoff(false); - this.setLaunchRodCleared(false); - this.setApogeeReached(false); + this.motorIgnited = false; + this.liftoff = false; + this.launchRodCleared = false; + this.apogeeReached = false; - this.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket())); - - this.setFlightData(new FlightDataBranch("MAIN", FlightDataType.TYPE_TIME)); - this.setWarnings(warnings); + this.warnings = new WarningSet(); } /** - * Copies the data from the provided object to this object. Most included object are - * deep-cloned, except for the flight data object. + * Performs a deep copy of the on SimulationStatus object. + * Most included object are deep-cloned, except for the flight data object (which is shallow copied) + * and the WarningSet (which is initialized to a new WarningSet). + * The intention of this constructor is to be used for conversion from one type + * of SimulationStatus to another, or when simulating multiple stages. + * When used for simulating multiple stages, a new FlightDataBranch object + * needs to be associated with the new object. * * @param orig the object from which to copy */ @@ -163,6 +164,7 @@ public class SimulationStatus implements Monitorable { this.simulationConditions = orig.simulationConditions.clone(); this.configuration = orig.configuration.clone(); this.motorConfiguration = orig.motorConfiguration.clone(); + // FlightData is not cloned. this.flightData = orig.flightData; this.time = orig.time; this.previousTimeStep = orig.previousTimeStep; @@ -185,7 +187,8 @@ public class SimulationStatus implements Monitorable { this.eventQueue.clear(); this.eventQueue.addAll(orig.eventQueue); - this.warnings = orig.warnings; + // WarningSet is not cloned. + this.warnings = new WarningSet(); this.extraData.clear(); this.extraData.putAll(orig.extraData);