Add check for zero-length active stages

Add geometry checks to stage separation

Add branch name to simulation exception dialog
This commit is contained in:
JoePfeiffer 2023-02-27 10:01:08 -07:00
parent 022a986130
commit 4c136441ff
4 changed files with 50 additions and 12 deletions

View File

@ -571,9 +571,11 @@ SimuRunDlg.lbl.Altitude = Altitude:
SimuRunDlg.lbl.Velocity = Velocity:
SimuRunDlg.msg.Unabletosim = Unable to simulate:
SimuRunDlg.msg.errorOccurred = An error occurred during the simulation:
SimuRunDlg.msg.branchErrorOccurred = An error occurred during simulation branch
BasicEventSimulationEngine.error.noMotorsDefined = No motors defined in the simulation.
BasicEventSimulationEngine.error.cantCalculateStability = Can't calculate rocket stability.
BasicEventSimulationEngine.error.activeLengthZero = Active airframe has length 0
BasicEventSimulationEngine.error.cantCalculateStability = Can't calculate stability
BasicEventSimulationEngine.error.earlyMotorBurnout = Motor burnout without liftoff.
BasicEventSimulationEngine.error.noConfiguredIgnition = No motors configured to ignite at liftoff
BasicEventSimulationEngine.error.noIgnition = No motors ignited.

View File

@ -86,13 +86,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
throw new MotorIgnitionException(trans.get("BasicEventSimulationEngine.error.noMotorsDefined"));
}
// Can't calculate stability
if (currentStatus.getSimulationConditions().getAerodynamicCalculator()
.getCP(currentStatus.getConfiguration(),
new FlightConditions(currentStatus.getConfiguration()),
new WarningSet()).weight < MathUtil.EPSILON)
throw new SimulationException(trans.get("BasicEventSimulationEngine.error.cantCalculateStability"));
// Problems that let us simulate, but result is likely bad
// No recovery device
@ -158,6 +151,8 @@ public class BasicEventSimulationEngine implements SimulationEngine {
try {
checkGeometry(currentStatus);
// Start the simulation
while (handleEvents()) {
// Take the step
@ -284,6 +279,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
flightData.getWarningSet().addAll(currentStatus.getWarnings());
e.setFlightData(flightData);
e.setFlightDataBranch(currentStatus.getFlightData());
throw e;
}
@ -504,6 +500,10 @@ public class BasicEventSimulationEngine implements SimulationEngine {
boosterStatus.getConfiguration().clearStagesAbove(stageNumber);
toSimulate.push(boosterStatus);
// Make sure upper stages can still be simulated
checkGeometry(currentStatus);
log.info(String.format("==>> @ %g; from Branch: %s ---- Branching: %s ---- \n",
currentStatus.getSimulationTime(),
currentStatus.getFlightData().getBranchName(), boosterStatus.getFlightData().getBranchName()));
@ -666,7 +666,23 @@ public class BasicEventSimulationEngine implements SimulationEngine {
}
}
// we need to check geometry to make sure we can simulation the active
// stages in a simulation branch when the branch starts executing, and
// whenever a stage separation occurs
private void checkGeometry(SimulationStatus currentStatus) throws SimulationException {
// Active stages have total length of 0.
if (currentStatus.getConfiguration().getLengthAerodynamic() < MathUtil.EPSILON) {
throw new SimulationException(trans.get("BasicEventSimulationEngine.error.activeLengthZero"));
}
// Can't calculate stability
if (currentStatus.getSimulationConditions().getAerodynamicCalculator()
.getCP(currentStatus.getConfiguration(),
new FlightConditions(currentStatus.getConfiguration()),
new WarningSet()).weight < MathUtil.EPSILON)
throw new SimulationException(trans.get("BasicEventSimulationEngine.error.cantCalculateStability"));
}
private void checkNaN() throws SimulationException {
double d = 0;

View File

@ -1,10 +1,12 @@
package net.sf.openrocket.simulation.exception;
import net.sf.openrocket.simulation.FlightData;
import net.sf.openrocket.simulation.FlightDataBranch;
public class SimulationException extends Exception {
private FlightData flightData = null;
private FlightDataBranch flightDataBranch = null;
public SimulationException() {
@ -29,4 +31,13 @@ public class SimulationException extends Exception {
public FlightData getFlightData() {
return flightData;
}
public void setFlightDataBranch(FlightDataBranch f) {
flightDataBranch = f;
}
public FlightDataBranch getFlightDataBranch() {
return flightDataBranch;
}
}

View File

@ -38,6 +38,7 @@ import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.IgnitionEvent;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.simulation.FlightDataBranch;
import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.simulation.SimulationStatus;
import net.sf.openrocket.simulation.customexpression.CustomExpression;
@ -433,11 +434,19 @@ public class SimulationRunDialog extends JDialog {
null, simulation.getName(), JOptionPane.ERROR_MESSAGE);
} else if (t instanceof SimulationException) {
String title = simulation.getName();
FlightDataBranch dataBranch = ((SimulationException) t).getFlightDataBranch();
String message;
if (dataBranch != null) {
message = trans.get("SimuRunDlg.msg.branchErrorOccurred") + "\"" + dataBranch.getBranchName() + "\"";
} else {
message = trans.get("SimuRunDlg.msg.errorOccurred");
}
DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
new Object[] {
//// A error occurred during the simulation:
trans.get("SimuRunDlg.msg.errorOccurred"), t.getMessage() },
message, t.getMessage() },
null, simulation.getName(), JOptionPane.ERROR_MESSAGE);
} else {