From 481551231e624fc165d94f8b2485824cbce4b79e Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 8 Mar 2024 11:27:48 -0500 Subject: [PATCH] MNT: apply parallel_axis_theorem function to hybrid and liquid motors --- rocketpy/motors/hybrid_motor.py | 31 +++++++++++++++---------------- rocketpy/motors/liquid_motor.py | 8 +++----- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/rocketpy/motors/hybrid_motor.py b/rocketpy/motors/hybrid_motor.py index 4b28a96d2..0320c9f3c 100644 --- a/rocketpy/motors/hybrid_motor.py +++ b/rocketpy/motors/hybrid_motor.py @@ -1,3 +1,5 @@ +from rocketpy.tools import parallel_axis_theorem + from ..mathutils.function import Function, funcify_method, reset_funcified_methods from ..plots.hybrid_motor_plots import _HybridMotorPlots from ..prints.hybrid_motor_prints import _HybridMotorPrints @@ -455,23 +457,20 @@ def propellant_I_11(self): ---------- .. [1] https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor """ - solid_correction = ( - self.solid.propellant_mass - * (self.solid.center_of_propellant_mass - self.center_of_propellant_mass) - ** 2 - ) - liquid_correction = ( - self.liquid.propellant_mass - * (self.liquid.center_of_propellant_mass - self.center_of_propellant_mass) - ** 2 - ) - I_11 = ( - self.solid.propellant_I_11 - + solid_correction - + self.liquid.propellant_I_11 - + liquid_correction - ) + solid_mass = self.solid.propellant_mass + liquid_mass = self.liquid.propellant_mass + + cm = self.center_of_propellant_mass + solid_cm_to_cm = self.solid.center_of_propellant_mass - cm + liquid_cm_to_cm = self.liquid.center_of_propellant_mass - cm + + solid_prop_inertia = self.solid.propellant_I_11 + liquid_prop_inertia = self.liquid.propellant_I_11 + + I_11 = parallel_axis_theorem( + solid_prop_inertia, solid_mass, solid_cm_to_cm + ) + parallel_axis_theorem(liquid_prop_inertia, liquid_mass, liquid_cm_to_cm) return I_11 diff --git a/rocketpy/motors/liquid_motor.py b/rocketpy/motors/liquid_motor.py index ac525b379..62caa44e7 100644 --- a/rocketpy/motors/liquid_motor.py +++ b/rocketpy/motors/liquid_motor.py @@ -7,6 +7,7 @@ funcify_method, reset_funcified_methods, ) +from rocketpy.tools import parallel_axis_theorem from ..plots.liquid_motor_plots import _LiquidMotorPlots from ..prints.liquid_motor_prints import _LiquidMotorPrints @@ -388,11 +389,8 @@ def propellant_I_11(self): for positioned_tank in self.positioned_tanks: tank = positioned_tank.get("tank") tank_position = positioned_tank.get("position") - I_11 += ( - tank.inertia - + tank.fluid_mass - * (tank_position + tank.center_of_mass - center_of_mass) ** 2 - ) + distance = tank_position + tank.center_of_mass - center_of_mass + I_11 += parallel_axis_theorem(tank.inertia, tank.fluid_mass, distance) return I_11