From 8af308b59e068cd19462982a0688d03f394a3830 Mon Sep 17 00:00:00 2001 From: aZira371 Date: Fri, 13 Jun 2025 18:24:35 +0100 Subject: [PATCH 1/2] ENH: zero inertia check on rocket initialization (issue #826) - ENH adding a small check to avoid singularity of inertia input in rocket class --- rocketpy/rocket/rocket.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index bf938d4be..61e531620 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -294,6 +294,12 @@ def __init__( # pylint: disable=too-many-statements self.I_13_without_motor = inertia[4] self.I_23_without_motor = inertia[5] + # Initial Inertia Tensor determinant singularity check + if abs(inertia) == 0: + raise ValueError( + "The rocket inertia tensor is singular (determinant is zero). " + ) + # Define rocket geometrical parameters in SI units self.center_of_mass_without_motor = center_of_mass_without_motor self.radius = radius From a97c2b2bcaeeff5dfa78f568c0d4f477e54cdeaa Mon Sep 17 00:00:00 2001 From: aZira371 Date: Fri, 20 Jun 2025 23:19:00 +0100 Subject: [PATCH 2/2] MNT: correction to input of inertia tensor into abs(): - MNT: correction to input of inertia tensor into abs(). Created an inertia matrix using Matrix right before the singularity check. --- rocketpy/rocket/rocket.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 61e531620..5b89bc839 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -293,9 +293,12 @@ def __init__( # pylint: disable=too-many-statements self.I_12_without_motor = inertia[3] self.I_13_without_motor = inertia[4] self.I_23_without_motor = inertia[5] - - # Initial Inertia Tensor determinant singularity check - if abs(inertia) == 0: + inertia_matrix = Matrix([ + [self.I_11_without_motor, self.I_12_without_motor, self.I_13_without_motor], + [self.I_12_without_motor, self.I_22_without_motor, self.I_23_without_motor], + [self.I_13_without_motor, self.I_23_without_motor, self.I_33_without_motor], + ]) # Initial Inertia Tensor determinant singularity check + if abs(inertia_matrix) == 0: raise ValueError( "The rocket inertia tensor is singular (determinant is zero). " )