Skip to content

Commit c0f17a5

Browse files
committed
ENH: add custom warning for Rocket with no components
This enhancement adds a warning when a Rocket object has no motors, parachutes, or AeroSurface components. It notifies the user so that they can add missing components before running simulations. See #285
1 parent 37dbbf8 commit c0f17a5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

rocketpy/rocket/rocket.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,35 @@ def __init__( # pylint: disable=too-many-statements
384384
self.prints = _RocketPrints(self)
385385
self.plots = _RocketPlots(self)
386386

387+
def _check_missing_components(self):
388+
"""Check if the rocket is missing any essential components and issue a warning.
389+
390+
This method verifies whether the rocket has the following key components:
391+
- motor
392+
- parachute(s)
393+
- aerodynamic surface(s)
394+
395+
If any of these components are missing, a single warning message is issued
396+
listing all missing components. This helps users quickly identify potential
397+
issues before running simulations or analyses.
398+
399+
Notes:
400+
- The warning uses Python's built-in `warnings.warn` function.
401+
"""
402+
missing_components = []
403+
if isinstance(self.motor, EmptyMotor):
404+
missing_components.append("motor")
405+
if not self.parachutes:
406+
missing_components.append("parachutes")
407+
if not self.aerodynamic_surfaces or len(self.aerodynamic_surfaces) == 0:
408+
missing_components.append("aerodynamic surfaces")
409+
410+
if missing_components:
411+
component_list = ", ".join(missing_components)
412+
warnings.warn(
413+
f"[WARNING] Rocket has no {component_list} defined.", UserWarning
414+
)
415+
387416
@property
388417
def nosecones(self):
389418
"""A list containing all the nose cones currently added to the rocket."""

0 commit comments

Comments
 (0)