From 8af308b59e068cd19462982a0688d03f394a3830 Mon Sep 17 00:00:00 2001 From: aZira371 Date: Fri, 13 Jun 2025 18:24:35 +0100 Subject: [PATCH 1/3] 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/3] 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). " ) From fb94874c1590602fa86d44f0be06319a9e3e168d Mon Sep 17 00:00:00 2001 From: MateusStano Date: Fri, 4 Jul 2025 20:04:19 +0200 Subject: [PATCH 3/3] DEV: format and changelog --- CHANGELOG.md | 1 + rocketpy/rocket/rocket.py | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f78b34edb..bc100f3a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ Attention: The newest changes should be on top --> - ENH: _MotorPrints inheritance - issue #460 [#828](https://github.com/RocketPy-Team/RocketPy/pull/828) - MNT: fix deprecations and warnings [#829](https://github.com/RocketPy-Team/RocketPy/pull/829) +- Enh/zero inertia tensor check [#833](https://github.com/RocketPy-Team/RocketPy/pull/833) ### Fixed diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 0e7c61e70..67ae4568e 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -292,11 +292,25 @@ 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] - 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 + 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). "