Skip to content

Commit e8c0bfe

Browse files
Merge pull request #436 from RocketPy-Team/enh/draw-motors
ENH: draw motors
2 parents 84b126e + a64c0ef commit e8c0bfe

File tree

11 files changed

+626
-20
lines changed

11 files changed

+626
-20
lines changed

rocketpy/motors/hybrid_motor.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ class HybridMotor(Motor):
4141
Solid motor object that composes the hybrid motor.
4242
HybridMotor.liquid : LiquidMotor
4343
Liquid motor object that composes the hybrid motor.
44+
HybridMotor.positioned_tanks : list
45+
List containing the motor's added tanks and their respective
46+
positions.
47+
HybridMotor.grains_center_of_mass_position : float
48+
Position of the center of mass of the grains in meters, specified in
49+
the motor's coordinate system.
50+
See :doc:`Positions and Coordinate Systems </user/positions>`
51+
for more information.
52+
HybridMotor.grain_number : int
53+
Number of solid grains.
54+
HybridMotor.grain_density : float
55+
Density of each grain in kg/meters cubed.
56+
HybridMotor.grain_outer_radius : float
57+
Outer radius of each grain in meters.
58+
HybridMotor.grain_initial_inner_radius : float
59+
Initial inner radius of each grain in meters.
60+
HybridMotor.grain_initial_height : float
61+
Initial height of each grain in meters.
62+
HybridMotor.grain_separation : float
63+
Distance between two grains in meters.
4464
HybridMotor.dry_mass : float
4565
Same as in Motor class. See the :class:`Motor <rocketpy.Motor>` docs.
4666
HybridMotor.propellant_initial_mass : float
@@ -326,6 +346,17 @@ def __init__(
326346
interpolation_method,
327347
coordinate_system_orientation,
328348
)
349+
350+
self.positioned_tanks = self.liquid.positioned_tanks
351+
self.grain_number = grain_number
352+
self.grain_density = grain_density
353+
self.grain_outer_radius = grain_outer_radius
354+
self.grain_initial_inner_radius = grain_initial_inner_radius
355+
self.grain_initial_height = grain_initial_height
356+
self.grain_separation = grain_separation
357+
self.grains_center_of_mass_position = grains_center_of_mass_position
358+
self.throat_radius = throat_radius
359+
329360
# Initialize plots and prints object
330361
self.prints = _HybridMotorPrints(self)
331362
self.plots = _HybridMotorPlots(self)
@@ -569,6 +600,10 @@ def add_tank(self, tank, position):
569600
)
570601
reset_funcified_methods(self)
571602

603+
def draw(self):
604+
"""Draws a representation of the HybridMotor."""
605+
self.plots.draw()
606+
572607
def info(self):
573608
"""Prints out basic data about the Motor."""
574609
self.prints.all()

rocketpy/motors/liquid_motor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ def add_tank(self, tank, position):
451451
self.positioned_tanks.append({"tank": tank, "position": position})
452452
reset_funcified_methods(self)
453453

454+
def draw(self):
455+
"""Draw a representation of the LiquidMotor."""
456+
self.plots.draw()
457+
454458
def info(self):
455459
"""Prints out basic data about the Motor."""
456460
self.prints.all()

rocketpy/motors/solid_motor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ def propellant_I_13(self):
700700
def propellant_I_23(self):
701701
return 0
702702

703+
def draw(self):
704+
"""Draw a representation of the SolidMotor."""
705+
self.plots.draw()
706+
703707
def info(self):
704708
"""Prints out basic data about the SolidMotor."""
705709
self.prints.all()

rocketpy/motors/tank.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ def inertia(self):
410410
"""
411411
return self.liquid_inertia + self.gas_inertia
412412

413+
def draw(self):
414+
"""Draws the tank geometry."""
415+
self.plots.draw()
416+
413417

414418
class MassFlowRateBasedTank(Tank):
415419
"""Class to define a tank based on mass flow rates inputs. This class

rocketpy/plots/hybrid_motor_plots.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from matplotlib import pyplot as plt
2+
13
from .motor_plots import _MotorPlots
24

35

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

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

125+
def draw(self):
126+
"""Draw a representation of the HybridMotor.
127+
128+
Returns
129+
-------
130+
None
131+
"""
132+
_, ax = plt.subplots(figsize=(8, 6), facecolor="#EEEEEE")
133+
134+
tanks_and_centers = self._generate_positioned_tanks(csys=self.motor._csys)
135+
nozzle = self._generate_nozzle(
136+
translate=(self.motor.nozzle_position, 0), csys=self.motor._csys
137+
)
138+
chamber = self._generate_combustion_chamber(
139+
translate=(self.motor.grains_center_of_mass_position, 0)
140+
)
141+
grains = self._generate_grains(
142+
translate=(self.motor.grains_center_of_mass_position, 0)
143+
)
144+
outline = self._generate_motor_region(
145+
list_of_patches=[nozzle, chamber, *grains]
146+
+ [tank for tank, _ in tanks_and_centers]
147+
)
148+
149+
ax.add_patch(outline)
150+
ax.add_patch(chamber)
151+
for grain in grains:
152+
ax.add_patch(grain)
153+
for patch, center in tanks_and_centers:
154+
ax.add_patch(patch)
155+
ax.plot(center[0], center[1], marker="o", color="red", markersize=2)
156+
ax.add_patch(nozzle)
157+
158+
ax.set_title("Hybrid Motor Representation")
159+
self._draw_center_of_mass(ax)
160+
self._set_plot_properties(ax)
161+
plt.show()
162+
123163
def all(self):
124164
"""Prints out all graphs available about the HybridMotor. It simply calls
125165
all the other plotter methods in this class.
@@ -128,7 +168,7 @@ def all(self):
128168
-------
129169
None
130170
"""
131-
171+
self.draw()
132172
self.thrust(*self.motor.burn_time)
133173
self.total_mass(*self.motor.burn_time)
134174
self.center_of_mass(*self.motor.burn_time)

rocketpy/plots/liquid_motor_plots.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import matplotlib.pyplot as plt
2+
13
from .motor_plots import _MotorPlots
24

35

@@ -25,6 +27,36 @@ def __init__(self, liquid_motor):
2527
"""
2628
super().__init__(liquid_motor)
2729

30+
def draw(self):
31+
"""Draw a representation of the LiquidMotor.
32+
33+
Returns
34+
-------
35+
None
36+
"""
37+
_, ax = plt.subplots(figsize=(8, 6), facecolor="#EEEEEE")
38+
39+
tanks_and_centers = self._generate_positioned_tanks(csys=self.motor._csys)
40+
nozzle = self._generate_nozzle(
41+
translate=(self.motor.nozzle_position, 0), csys=self.motor._csys
42+
)
43+
outline = self._generate_motor_region(
44+
list_of_patches=[nozzle] + [tank for tank, _ in tanks_and_centers]
45+
)
46+
47+
ax.add_patch(outline)
48+
for patch, center in tanks_and_centers:
49+
ax.add_patch(patch)
50+
ax.plot(center[0], center[1], marker="o", color="red", markersize=2)
51+
52+
# add the nozzle
53+
ax.add_patch(nozzle)
54+
55+
ax.set_title("Liquid Motor Representation")
56+
self._draw_center_of_mass(ax)
57+
self._set_plot_properties(ax)
58+
plt.show()
59+
2860
def all(self):
2961
"""Prints out all graphs available about the LiquidMotor. It simply calls
3062
all the other plotter methods in this class.
@@ -33,6 +65,7 @@ def all(self):
3365
-------
3466
None
3567
"""
68+
self.draw()
3669
self.thrust(*self.motor.burn_time)
3770
self.mass_flow_rate(*self.motor.burn_time)
3871
self.exhaust_velocity(*self.motor.burn_time)

0 commit comments

Comments
 (0)