Replace thrown exceptions with simulation aborts whereever possible
This commit is contained in:
parent
173a3d38e2
commit
a36e7f1049
@ -75,6 +75,16 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
simulationConfig.copyStages(origConfig); // Clone the stage activation configuration
|
simulationConfig.copyStages(origConfig); // Clone the stage activation configuration
|
||||||
|
|
||||||
currentStatus = new SimulationStatus(simulationConfig, simulationConditions);
|
currentStatus = new SimulationStatus(simulationConfig, simulationConditions);
|
||||||
|
// main simulation branch
|
||||||
|
final String branchName = simulationConfig.getRocket().getTopmostStage(currentStatus.getConfiguration()).getName();
|
||||||
|
FlightDataBranch initialBranch = new FlightDataBranch( branchName, FlightDataType.TYPE_TIME);
|
||||||
|
|
||||||
|
// put a point on it so we can plot if we get an early abort event
|
||||||
|
initialBranch.addPoint();
|
||||||
|
initialBranch.setValue(FlightDataType.TYPE_TIME, 0.0);
|
||||||
|
initialBranch.setValue(FlightDataType.TYPE_ALTITUDE, 0.0);
|
||||||
|
currentStatus.setFlightData(initialBranch);
|
||||||
|
|
||||||
|
|
||||||
// Sanity checks on design and configuration
|
// Sanity checks on design and configuration
|
||||||
|
|
||||||
@ -82,7 +92,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
|
|
||||||
// No motors in configuration
|
// No motors in configuration
|
||||||
if (!simulationConfig.hasMotors() ) {
|
if (!simulationConfig.hasMotors() ) {
|
||||||
throw new MotorIgnitionException(trans.get("BasicEventSimulationEngine.error.noMotorsDefined"));
|
currentStatus.abortSimulation(SimulationAbort.NOMOTORSDEFINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Problems that let us simulate, but result is likely bad
|
// Problems that let us simulate, but result is likely bad
|
||||||
@ -93,11 +103,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentStatus.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket()));
|
currentStatus.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket()));
|
||||||
{
|
|
||||||
// main simulation branch
|
|
||||||
final String branchName = simulationConfig.getRocket().getTopmostStage(currentStatus.getConfiguration()).getName();
|
|
||||||
currentStatus.setFlightData(new FlightDataBranch( branchName, FlightDataType.TYPE_TIME));
|
|
||||||
}
|
|
||||||
toSimulate.push(currentStatus);
|
toSimulate.push(currentStatus);
|
||||||
|
|
||||||
SimulationListenerHelper.fireStartSimulation(currentStatus);
|
SimulationListenerHelper.fireStartSimulation(currentStatus);
|
||||||
@ -438,7 +443,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
case BURNOUT: {
|
case BURNOUT: {
|
||||||
// If motor burnout occurs without lift-off, abort
|
// If motor burnout occurs without lift-off, abort
|
||||||
if (!currentStatus.isLiftoff()) {
|
if (!currentStatus.isLiftoff()) {
|
||||||
throw new SimulationLaunchException(trans.get("BasicEventSimulationEngine.error.earlyMotorBurnout"));
|
currentStatus.abortSimulation(SimulationAbort.NOLIFTOFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ejection charge event
|
// Add ejection charge event
|
||||||
@ -632,7 +637,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
// If no motor has ignited, abort
|
// If no motor has ignited, abort
|
||||||
if (!currentStatus.isMotorIgnited()) {
|
if (!currentStatus.isMotorIgnited()) {
|
||||||
// TODO MEDIUM: display this as a warning to the user (e.g. highlight the cell in the simulation panel in red and a hover: 'make sure the motor ignition is correct' or something)
|
// TODO MEDIUM: display this as a warning to the user (e.g. highlight the cell in the simulation panel in red and a hover: 'make sure the motor ignition is correct' or something)
|
||||||
throw new MotorIgnitionException(trans.get("BasicEventSimulationEngine.error.noIgnition"));
|
currentStatus.abortSimulation(SimulationAbort.NOMOTORSFIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -665,22 +670,23 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to check geometry to make sure we can simulation the active
|
// we need to check geometry to make sure we can simulate the active
|
||||||
// stages in a simulation branch when the branch starts executing, and
|
// stages in a simulation branch when the branch starts executing, and
|
||||||
// whenever a stage separation occurs
|
// whenever a stage separation occurs
|
||||||
private void checkGeometry(SimulationStatus currentStatus) throws SimulationException {
|
private void checkGeometry(SimulationStatus currentStatus) throws SimulationException {
|
||||||
|
|
||||||
// Active stages have total length of 0.
|
// Active stages have total length of 0.
|
||||||
if (currentStatus.getConfiguration().getLengthAerodynamic() < MathUtil.EPSILON) {
|
if (currentStatus.getConfiguration().getLengthAerodynamic() < MathUtil.EPSILON) {
|
||||||
throw new SimulationException(trans.get("BasicEventSimulationEngine.error.activeLengthZero"));
|
currentStatus.abortSimulation(SimulationAbort.ACTIVELENGTHZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't calculate stability
|
// Can't calculate stability
|
||||||
if (currentStatus.getSimulationConditions().getAerodynamicCalculator()
|
if (currentStatus.getSimulationConditions().getAerodynamicCalculator()
|
||||||
.getCP(currentStatus.getConfiguration(),
|
.getCP(currentStatus.getConfiguration(),
|
||||||
new FlightConditions(currentStatus.getConfiguration()),
|
new FlightConditions(currentStatus.getConfiguration()),
|
||||||
new WarningSet()).weight < MathUtil.EPSILON)
|
new WarningSet()).weight < MathUtil.EPSILON) {
|
||||||
throw new SimulationException(trans.get("BasicEventSimulationEngine.error.cantCalculateStability"));
|
currentStatus.abortSimulation(SimulationAbort.NOCP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNaN() throws SimulationException {
|
private void checkNaN() throws SimulationException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user