Skip to content

Commit

Permalink
Merge pull request #436 from RocketPy-Team/enh/draw-motors
Browse files Browse the repository at this point in the history
ENH: draw motors
  • Loading branch information
Gui-FernandesBR authored Nov 18, 2023
2 parents 84b126e + a64c0ef commit e8c0bfe
Show file tree
Hide file tree
Showing 11 changed files with 626 additions and 20 deletions.
35 changes: 35 additions & 0 deletions rocketpy/motors/hybrid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ class HybridMotor(Motor):
Solid motor object that composes the hybrid motor.
HybridMotor.liquid : LiquidMotor
Liquid motor object that composes the hybrid motor.
HybridMotor.positioned_tanks : list
List containing the motor's added tanks and their respective
positions.
HybridMotor.grains_center_of_mass_position : float
Position of the center of mass of the grains in meters, specified in
the motor's coordinate system.
See :doc:`Positions and Coordinate Systems </user/positions>`
for more information.
HybridMotor.grain_number : int
Number of solid grains.
HybridMotor.grain_density : float
Density of each grain in kg/meters cubed.
HybridMotor.grain_outer_radius : float
Outer radius of each grain in meters.
HybridMotor.grain_initial_inner_radius : float
Initial inner radius of each grain in meters.
HybridMotor.grain_initial_height : float
Initial height of each grain in meters.
HybridMotor.grain_separation : float
Distance between two grains in meters.
HybridMotor.dry_mass : float
Same as in Motor class. See the :class:`Motor <rocketpy.Motor>` docs.
HybridMotor.propellant_initial_mass : float
Expand Down Expand Up @@ -326,6 +346,17 @@ def __init__(
interpolation_method,
coordinate_system_orientation,
)

self.positioned_tanks = self.liquid.positioned_tanks
self.grain_number = grain_number
self.grain_density = grain_density
self.grain_outer_radius = grain_outer_radius
self.grain_initial_inner_radius = grain_initial_inner_radius
self.grain_initial_height = grain_initial_height
self.grain_separation = grain_separation
self.grains_center_of_mass_position = grains_center_of_mass_position
self.throat_radius = throat_radius

# Initialize plots and prints object
self.prints = _HybridMotorPrints(self)
self.plots = _HybridMotorPlots(self)
Expand Down Expand Up @@ -569,6 +600,10 @@ def add_tank(self, tank, position):
)
reset_funcified_methods(self)

def draw(self):
"""Draws a representation of the HybridMotor."""
self.plots.draw()

def info(self):
"""Prints out basic data about the Motor."""
self.prints.all()
Expand Down
4 changes: 4 additions & 0 deletions rocketpy/motors/liquid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ def add_tank(self, tank, position):
self.positioned_tanks.append({"tank": tank, "position": position})
reset_funcified_methods(self)

def draw(self):
"""Draw a representation of the LiquidMotor."""
self.plots.draw()

def info(self):
"""Prints out basic data about the Motor."""
self.prints.all()
Expand Down
4 changes: 4 additions & 0 deletions rocketpy/motors/solid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ def propellant_I_13(self):
def propellant_I_23(self):
return 0

def draw(self):
"""Draw a representation of the SolidMotor."""
self.plots.draw()

def info(self):
"""Prints out basic data about the SolidMotor."""
self.prints.all()
Expand Down
4 changes: 4 additions & 0 deletions rocketpy/motors/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ def inertia(self):
"""
return self.liquid_inertia + self.gas_inertia

def draw(self):
"""Draws the tank geometry."""
self.plots.draw()


class MassFlowRateBasedTank(Tank):
"""Class to define a tank based on mass flow rates inputs. This class
Expand Down
42 changes: 41 additions & 1 deletion rocketpy/plots/hybrid_motor_plots.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from matplotlib import pyplot as plt

from .motor_plots import _MotorPlots


Expand Down Expand Up @@ -120,6 +122,44 @@ def Kn(self, lower_limit=None, upper_limit=None):

self.motor.solid.Kn.plot(lower=lower_limit, upper=upper_limit)

def draw(self):
"""Draw a representation of the HybridMotor.
Returns
-------
None
"""
_, ax = plt.subplots(figsize=(8, 6), facecolor="#EEEEEE")

tanks_and_centers = self._generate_positioned_tanks(csys=self.motor._csys)
nozzle = self._generate_nozzle(
translate=(self.motor.nozzle_position, 0), csys=self.motor._csys
)
chamber = self._generate_combustion_chamber(
translate=(self.motor.grains_center_of_mass_position, 0)
)
grains = self._generate_grains(
translate=(self.motor.grains_center_of_mass_position, 0)
)
outline = self._generate_motor_region(
list_of_patches=[nozzle, chamber, *grains]
+ [tank for tank, _ in tanks_and_centers]
)

ax.add_patch(outline)
ax.add_patch(chamber)
for grain in grains:
ax.add_patch(grain)
for patch, center in tanks_and_centers:
ax.add_patch(patch)
ax.plot(center[0], center[1], marker="o", color="red", markersize=2)
ax.add_patch(nozzle)

ax.set_title("Hybrid Motor Representation")
self._draw_center_of_mass(ax)
self._set_plot_properties(ax)
plt.show()

def all(self):
"""Prints out all graphs available about the HybridMotor. It simply calls
all the other plotter methods in this class.
Expand All @@ -128,7 +168,7 @@ def all(self):
-------
None
"""

self.draw()
self.thrust(*self.motor.burn_time)
self.total_mass(*self.motor.burn_time)
self.center_of_mass(*self.motor.burn_time)
Expand Down
33 changes: 33 additions & 0 deletions rocketpy/plots/liquid_motor_plots.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import matplotlib.pyplot as plt

from .motor_plots import _MotorPlots


Expand Down Expand Up @@ -25,6 +27,36 @@ def __init__(self, liquid_motor):
"""
super().__init__(liquid_motor)

def draw(self):
"""Draw a representation of the LiquidMotor.
Returns
-------
None
"""
_, ax = plt.subplots(figsize=(8, 6), facecolor="#EEEEEE")

tanks_and_centers = self._generate_positioned_tanks(csys=self.motor._csys)
nozzle = self._generate_nozzle(
translate=(self.motor.nozzle_position, 0), csys=self.motor._csys
)
outline = self._generate_motor_region(
list_of_patches=[nozzle] + [tank for tank, _ in tanks_and_centers]
)

ax.add_patch(outline)
for patch, center in tanks_and_centers:
ax.add_patch(patch)
ax.plot(center[0], center[1], marker="o", color="red", markersize=2)

# add the nozzle
ax.add_patch(nozzle)

ax.set_title("Liquid Motor Representation")
self._draw_center_of_mass(ax)
self._set_plot_properties(ax)
plt.show()

def all(self):
"""Prints out all graphs available about the LiquidMotor. It simply calls
all the other plotter methods in this class.
Expand All @@ -33,6 +65,7 @@ def all(self):
-------
None
"""
self.draw()
self.thrust(*self.motor.burn_time)
self.mass_flow_rate(*self.motor.burn_time)
self.exhaust_velocity(*self.motor.burn_time)
Expand Down
Loading

0 comments on commit e8c0bfe

Please sign in to comment.