Move calculation of summary data to a "finally" block so we display what we can, even if there was an exception during the simulation. In particular, if the exception happened in a branch other than the sustainer branch we still get all our summary data.
Added a commented-out bit of code forcing an exception for testing purposes. Since many former exceptions are now sim aborts, there isn't a reliable way to create a broken rocket design to test exception behavior -- which is a good thing!
This commit is contained in:
parent
64832fe8d6
commit
9a06464afe
@ -67,87 +67,91 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
// Set up flight data
|
// Set up flight data
|
||||||
flightData = new FlightData();
|
flightData = new FlightData();
|
||||||
|
|
||||||
// Set up rocket configuration
|
try {
|
||||||
this.fcid = simulationConditions.getFlightConfigurationID();
|
// Set up rocket configuration
|
||||||
FlightConfiguration origConfig = simulationConditions.getRocket().getFlightConfiguration(this.fcid);
|
this.fcid = simulationConditions.getFlightConfigurationID();
|
||||||
FlightConfiguration simulationConfig = origConfig.clone(simulationConditions.getRocket().copyWithOriginalID());
|
FlightConfiguration origConfig = simulationConditions.getRocket().getFlightConfiguration(this.fcid);
|
||||||
simulationConfig.copyStages(origConfig); // Clone the stage activation configuration
|
FlightConfiguration simulationConfig = origConfig.clone(simulationConditions.getRocket().copyWithOriginalID());
|
||||||
|
simulationConfig.copyStages(origConfig); // Clone the stage activation configuration
|
||||||
|
|
||||||
currentStatus = new SimulationStatus(simulationConfig, simulationConditions);
|
currentStatus = new SimulationStatus(simulationConfig, simulationConditions);
|
||||||
// main simulation branch. Need to watch for pathological case with no stages defined
|
// main simulation branch. Need to watch for pathological case with no stages defined
|
||||||
final AxialStage topStage = simulationConfig.getRocket().getTopmostStage(currentStatus.getConfiguration());
|
final AxialStage topStage = simulationConfig.getRocket().getTopmostStage(currentStatus.getConfiguration());
|
||||||
final String branchName;
|
final String branchName;
|
||||||
if (topStage != null) {
|
if (topStage != null) {
|
||||||
branchName = topStage.getName();
|
branchName = topStage.getName();
|
||||||
} else {
|
} else {
|
||||||
branchName = trans.get("BasicEventSimulationEngine.nullBranchName");
|
branchName = trans.get("BasicEventSimulationEngine.nullBranchName");
|
||||||
}
|
}
|
||||||
FlightDataBranch initialBranch = new FlightDataBranch( branchName, FlightDataType.TYPE_TIME);
|
FlightDataBranch initialBranch = new FlightDataBranch( branchName, FlightDataType.TYPE_TIME);
|
||||||
|
|
||||||
// put a point on it so we can plot if we get an early abort event
|
// put a point on it so we can plot if we get an early abort event
|
||||||
initialBranch.addPoint();
|
initialBranch.addPoint();
|
||||||
initialBranch.setValue(FlightDataType.TYPE_TIME, 0.0);
|
initialBranch.setValue(FlightDataType.TYPE_TIME, 0.0);
|
||||||
initialBranch.setValue(FlightDataType.TYPE_ALTITUDE, 0.0);
|
initialBranch.setValue(FlightDataType.TYPE_ALTITUDE, 0.0);
|
||||||
|
|
||||||
currentStatus.setFlightDataBranch(initialBranch);
|
currentStatus.setFlightDataBranch(initialBranch);
|
||||||
|
|
||||||
// Sanity checks on design and configuration
|
// Sanity checks on design and configuration
|
||||||
|
|
||||||
// Problems that keep us from simulating at all
|
// Problems that keep us from simulating at all
|
||||||
|
|
||||||
// No active stages
|
// No active stages
|
||||||
if (topStage == null) {
|
if (topStage == null) {
|
||||||
currentStatus.abortSimulation(SimulationAbort.Cause.NO_ACTIVE_STAGES);
|
currentStatus.abortSimulation(SimulationAbort.Cause.NO_ACTIVE_STAGES);
|
||||||
}
|
|
||||||
|
|
||||||
// No motors in configuration
|
|
||||||
if (!simulationConfig.hasMotors() ) {
|
|
||||||
currentStatus.abortSimulation(SimulationAbort.Cause.NO_MOTORS_DEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Problems that let us simulate, but result is likely bad
|
|
||||||
|
|
||||||
// No recovery device
|
|
||||||
if (!simulationConfig.hasRecoveryDevice()) {
|
|
||||||
currentStatus.getWarnings().add(Warning.NO_RECOVERY_DEVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentStatus.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket()));
|
|
||||||
toSimulate.push(currentStatus);
|
|
||||||
|
|
||||||
SimulationListenerHelper.fireStartSimulation(currentStatus);
|
|
||||||
do {
|
|
||||||
if (toSimulate.peek() == null) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
currentStatus = toSimulate.pop();
|
|
||||||
FlightDataBranch dataBranch = currentStatus.getFlightDataBranch();
|
|
||||||
flightData.addBranch(dataBranch);
|
|
||||||
log.info(">>Starting simulation of branch: " + currentStatus.getFlightDataBranch().getName());
|
|
||||||
|
|
||||||
simulateLoop();
|
// No motors in configuration
|
||||||
dataBranch.immute();
|
if (!simulationConfig.hasMotors() ) {
|
||||||
flightData.getWarningSet().addAll(currentStatus.getWarnings());
|
currentStatus.abortSimulation(SimulationAbort.Cause.NO_MOTORS_DEFINED);
|
||||||
|
|
||||||
log.info(String.format("<<Finished simulating branch: %s curTime:%s finTime:%s",
|
|
||||||
dataBranch.getName(),
|
|
||||||
currentStatus.getSimulationTime(),
|
|
||||||
dataBranch.getLast(FlightDataType.TYPE_TIME)));
|
|
||||||
|
|
||||||
|
|
||||||
// Did the branch generate any data?
|
|
||||||
if (dataBranch.getLength() == 0) {
|
|
||||||
flightData.getWarningSet().add(Warning.EMPTY_BRANCH, dataBranch.getName());
|
|
||||||
}
|
}
|
||||||
} while (!toSimulate.isEmpty());
|
|
||||||
|
|
||||||
SimulationListenerHelper.fireEndSimulation(currentStatus, null);
|
// Problems that let us simulate, but result is likely bad
|
||||||
|
|
||||||
if (!flightData.getWarningSet().isEmpty()) {
|
// No recovery device
|
||||||
log.info("Warnings at the end of simulation: " + flightData.getWarningSet());
|
if (!simulationConfig.hasRecoveryDevice()) {
|
||||||
|
currentStatus.getWarnings().add(Warning.NO_RECOVERY_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentStatus.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket()));
|
||||||
|
toSimulate.push(currentStatus);
|
||||||
|
|
||||||
|
SimulationListenerHelper.fireStartSimulation(currentStatus);
|
||||||
|
do {
|
||||||
|
if (toSimulate.peek() == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
currentStatus = toSimulate.pop();
|
||||||
|
FlightDataBranch dataBranch = currentStatus.getFlightDataBranch();
|
||||||
|
flightData.addBranch(dataBranch);
|
||||||
|
log.info(">>Starting simulation of branch: " + currentStatus.getFlightDataBranch().getName());
|
||||||
|
|
||||||
|
simulateLoop();
|
||||||
|
dataBranch.immute();
|
||||||
|
flightData.getWarningSet().addAll(currentStatus.getWarnings());
|
||||||
|
|
||||||
|
log.info(String.format("<<Finished simulating branch: %s curTime:%s finTime:%s",
|
||||||
|
dataBranch.getName(),
|
||||||
|
currentStatus.getSimulationTime(),
|
||||||
|
dataBranch.getLast(FlightDataType.TYPE_TIME)));
|
||||||
|
|
||||||
|
|
||||||
|
// Did the branch generate any data?
|
||||||
|
if (dataBranch.getLength() == 0) {
|
||||||
|
flightData.getWarningSet().add(Warning.EMPTY_BRANCH, dataBranch.getName());
|
||||||
|
}
|
||||||
|
} while (!toSimulate.isEmpty());
|
||||||
|
|
||||||
|
SimulationListenerHelper.fireEndSimulation(currentStatus, null);
|
||||||
|
|
||||||
|
if (!flightData.getWarningSet().isEmpty()) {
|
||||||
|
log.info("Warnings at the end of simulation: " + flightData.getWarningSet());
|
||||||
|
}
|
||||||
|
} catch (SimulationException e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
flightData.calculateInterestingValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
flightData.calculateInterestingValues();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void simulateLoop() throws SimulationException {
|
private void simulateLoop() throws SimulationException {
|
||||||
@ -291,9 +295,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
|
|
||||||
flightData.getWarningSet().addAll(currentStatus.getWarnings());
|
flightData.getWarningSet().addAll(currentStatus.getWarnings());
|
||||||
|
|
||||||
//e.setFlightData(flightData);
|
|
||||||
//e.setFlightDataBranch(currentStatus.getFlightDataBranch());
|
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -698,6 +699,11 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
currentStatus.abortSimulation(SimulationAbort.Cause.ACTIVE_LENGTH_ZERO);
|
currentStatus.abortSimulation(SimulationAbort.Cause.ACTIVE_LENGTH_ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test -- force an exception if we aren't the sustainer
|
||||||
|
if (currentStatus.getConfiguration().isStageActive(0)) {
|
||||||
|
throw new SimulationCalculationException("test", currentStatus.getFlightDataBranch());
|
||||||
|
}
|
||||||
|
|
||||||
// Can't calculate stability. If it's the sustainer we'll abort; if a booster
|
// Can't calculate stability. If it's the sustainer we'll abort; if a booster
|
||||||
// we'll just transition to tumbling (if it's a booster and under thrust code elsewhere
|
// we'll just transition to tumbling (if it's a booster and under thrust code elsewhere
|
||||||
// will abort).
|
// will abort).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user