Skip to content

Commit e381237

Browse files
ENH: Add static margin validation to prevent unstable rocket simulations in Flight class
1 parent 63b7fa4 commit e381237

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"Glauert",
137137
"gmaps",
138138
"Gnss",
139+
"Golay",
139140
"Gomes",
140141
"Gonçalvez",
141142
"grav",
@@ -204,6 +205,7 @@
204205
"Meteomatics",
205206
"Metrum",
206207
"modindex",
208+
"motorless",
207209
"mult",
208210
"Mumma",
209211
"NASADEM",
@@ -266,6 +268,7 @@
266268
"rwork",
267269
"savetxt",
268270
"savgol",
271+
"Savitzky",
269272
"SBMT",
270273
"scilimits",
271274
"searchsorted",

rocketpy/simulation/flight.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import simplekml
1010
from scipy.integrate import BDF, DOP853, LSODA, RK23, RK45, OdeSolver, Radau
1111

12+
from ..exceptions import UnstableRocketError
1213
from ..mathutils.function import Function, funcify_method
1314
from ..mathutils.vector_matrix import Matrix, Vector
1415
from ..plots.flight_plots import _FlightPlots
@@ -639,6 +640,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-statements
639640
self.__init_solution_monitors()
640641
self.__init_equations_of_motion()
641642
self.__init_solver_monitors()
643+
self.__validate_rocket_static_margin()
642644

643645
# Create known flight phases
644646
self.flight_phases = self.FlightPhases()
@@ -664,6 +666,15 @@ def __repr__(self):
664666
f"name= {self.name})>"
665667
)
666668

669+
def __validate_rocket_static_margin(self):
670+
"""
671+
Avoids running a flight simulation if the rocket stability margin is
672+
negative. This is a common mistake that can lead to unstable flights,
673+
which usually runs indefinitely.
674+
"""
675+
if (s := self.rocket.static_margin(0)) < 0:
676+
raise UnstableRocketError(s)
677+
667678
# pylint: disable=too-many-nested-blocks, too-many-branches, too-many-locals,too-many-statements
668679
def __simulate(self, verbose):
669680
"""Simulate the flight trajectory."""

0 commit comments

Comments
 (0)