Skip to content

Commit

Permalink
MNT: improve parallel_axis_theorem_from_com documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-FernandesBR committed Mar 21, 2024
1 parent 4815512 commit 4a7ba18
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
8 changes: 5 additions & 3 deletions rocketpy/motors/hybrid_motor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rocketpy.tools import parallel_axis_theorem
from rocketpy.tools import parallel_axis_theorem_from_com

from ..mathutils.function import Function, funcify_method, reset_funcified_methods
from ..plots.hybrid_motor_plots import _HybridMotorPlots
Expand Down Expand Up @@ -468,9 +468,11 @@ def propellant_I_11(self):
solid_prop_inertia = self.solid.propellant_I_11
liquid_prop_inertia = self.liquid.propellant_I_11

I_11 = parallel_axis_theorem(
I_11 = parallel_axis_theorem_from_com(
solid_prop_inertia, solid_mass, solid_cm_to_cm
) + parallel_axis_theorem(liquid_prop_inertia, liquid_mass, liquid_cm_to_cm)
) + parallel_axis_theorem_from_com(
liquid_prop_inertia, liquid_mass, liquid_cm_to_cm
)

return I_11

Expand Down
6 changes: 4 additions & 2 deletions rocketpy/motors/liquid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
funcify_method,
reset_funcified_methods,
)
from rocketpy.tools import parallel_axis_theorem
from rocketpy.tools import parallel_axis_theorem_from_com

from ..plots.liquid_motor_plots import _LiquidMotorPlots
from ..prints.liquid_motor_prints import _LiquidMotorPrints
Expand Down Expand Up @@ -390,7 +390,9 @@ def propellant_I_11(self):
tank = positioned_tank.get("tank")
tank_position = positioned_tank.get("position")
distance = tank_position + tank.center_of_mass - center_of_mass
I_11 += parallel_axis_theorem(tank.inertia, tank.fluid_mass, distance)
I_11 += parallel_axis_theorem_from_com(
tank.inertia, tank.fluid_mass, distance
)

return I_11

Expand Down
8 changes: 5 additions & 3 deletions rocketpy/motors/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..mathutils.function import Function, funcify_method
from ..plots.motor_plots import _MotorPlots
from ..prints.motor_prints import _MotorPrints
from ..tools import parallel_axis_theorem, tuple_handler
from ..tools import parallel_axis_theorem_from_com, tuple_handler

try:
from functools import cached_property
Expand Down Expand Up @@ -520,8 +520,10 @@ def I_11(self):
prop_to_cm = self.center_of_propellant_mass - self.center_of_mass
dry_to_cm = self.center_of_dry_mass_position - self.center_of_mass

prop_I_11 = parallel_axis_theorem(prop_I_11, self.propellant_mass, prop_to_cm)
dry_I_11 = parallel_axis_theorem(dry_I_11, self.dry_mass, dry_to_cm)
prop_I_11 = parallel_axis_theorem_from_com(
prop_I_11, self.propellant_mass, prop_to_cm
)
dry_I_11 = parallel_axis_theorem_from_com(dry_I_11, self.dry_mass, dry_to_cm)

return prop_I_11 + dry_I_11

Expand Down
22 changes: 13 additions & 9 deletions rocketpy/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from rocketpy.rocket.components import Components
from rocketpy.rocket.parachute import Parachute
from rocketpy.tools import parallel_axis_theorem
from rocketpy.tools import parallel_axis_theorem_from_com


class Rocket:
Expand Down Expand Up @@ -634,13 +634,17 @@ def evaluate_dry_inertias(self):
)

# Compute dry inertias
self.dry_I_11 = parallel_axis_theorem(
self.dry_I_11 = parallel_axis_theorem_from_com(
self.I_11_without_motor, mass, noMCM_to_CDM
) + parallel_axis_theorem(self.motor.dry_I_11, motor_dry_mass, motorCDM_to_CDM)
) + parallel_axis_theorem_from_com(
self.motor.dry_I_11, motor_dry_mass, motorCDM_to_CDM
)

self.dry_I_22 = parallel_axis_theorem(
self.dry_I_22 = parallel_axis_theorem_from_com(
self.I_22_without_motor, mass, noMCM_to_CDM
) + parallel_axis_theorem(self.motor.dry_I_22, motor_dry_mass, motorCDM_to_CDM)
) + parallel_axis_theorem_from_com(
self.motor.dry_I_22, motor_dry_mass, motorCDM_to_CDM
)

self.dry_I_33 = self.I_33_without_motor + self.motor.dry_I_33
self.dry_I_12 = self.I_12_without_motor + self.motor.dry_I_12
Expand Down Expand Up @@ -698,13 +702,13 @@ def evaluate_inertias(self):
CM_to_CPM = self.center_of_mass - self.center_of_propellant_position

# Compute inertias
self.I_11 = parallel_axis_theorem(
self.I_11 = parallel_axis_theorem_from_com(
self.dry_I_11, dry_mass, CM_to_CDM
) + parallel_axis_theorem(self.motor.I_11, prop_mass, CM_to_CPM)
) + parallel_axis_theorem_from_com(self.motor.I_11, prop_mass, CM_to_CPM)

self.I_22 = parallel_axis_theorem(
self.I_22 = parallel_axis_theorem_from_com(
self.dry_I_22, dry_mass, CM_to_CDM
) + parallel_axis_theorem(self.motor.I_22, prop_mass, CM_to_CPM)
) + parallel_axis_theorem_from_com(self.motor.I_22, prop_mass, CM_to_CPM)

self.I_33 = self.dry_I_33 + self.motor.I_33
self.I_12 = self.dry_I_12 + self.motor.I_12
Expand Down
22 changes: 14 additions & 8 deletions rocketpy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,25 +382,31 @@ def check_requirement_version(module_name, version):
return True


def parallel_axis_theorem(initial_inertia_moment, mass, distance):
"""Converts the moment of inertia from one axis to another using the
parallel axis theorem. The axes must be parallel to each other.
def parallel_axis_theorem_from_com(com_inertia_moment, mass, distance):
"""Calculates the moment of inertia of a object relative to a new axis using
the parallel axis theorem. The new axis is parallel to and at a distance
'distance' from the original axis, which *must* passes through the object's
center of mass.
Parameters
----------
initial_inertia_moment : float
Initial moment of inertia.
com_inertia_moment : float
Moment of inertia relative to the center of mass of the object.
mass : float
Mass of the object.
distance : float
Distance between the two points.
Perpendicular distance between the original and new axis.
Returns
-------
float
New moment of inertia.
Moment of inertia relative to the new axis.
Reference
---------
https://en.wikipedia.org/wiki/Parallel_axis_theorem
"""
return initial_inertia_moment + mass * distance**2
return com_inertia_moment + mass * distance**2


# Flight
Expand Down

0 comments on commit 4a7ba18

Please sign in to comment.