Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: draw motors #436

Merged
merged 22 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
033e8d3
ENH: _generate_nozzle draw method
Gui-FernandesBR Oct 11, 2023
e514b8f
ENH: draw the solid motor
Gui-FernandesBR Oct 11, 2023
93b85d2
ENH: add solid motor to rocket draw
Gui-FernandesBR Oct 11, 2023
33c3116
ENH: liquid motors draw
Gui-FernandesBR Oct 11, 2023
838daf3
Merge pull request #434 from RocketPy-Team/enh/liquid-motors-draw
Gui-FernandesBR Oct 11, 2023
74cb5ac
Merge remote-tracking branch 'RocketPy-Team/enh/draw-motors' into enh…
Gui-FernandesBR Oct 11, 2023
ec37e76
MNT: fix some plot settings
Gui-FernandesBR Oct 11, 2023
abedd45
Merge pull request #435 from RocketPy-Team/enh/solid-motors-draw
Gui-FernandesBR Oct 11, 2023
d1e4a37
Fix code style issues with Black
lint-action Oct 11, 2023
cdc3d48
Merge branch 'develop' into enh/draw-motors
Gui-FernandesBR Nov 13, 2023
eb6a95d
ENH: add basic grain and tanks atributes to hybrid
MateusStano Nov 16, 2023
3e61371
ENH: add motor draw related methods to MotorPlots
MateusStano Nov 16, 2023
501c581
ENH: motor drawings
MateusStano Nov 16, 2023
1155b31
ENH: clean plots __init__
MateusStano Nov 16, 2023
deafe5b
DOC: draw function docs
MateusStano Nov 16, 2023
16436a3
ENH: add motors to rocket drawing
MateusStano Nov 16, 2023
6c40f32
Fix code style issues with Black
lint-action Nov 16, 2023
fe529d7
Update rocketpy/plots/motor_plots.py
MateusStano Nov 18, 2023
0b3cbea
Merge branch 'develop' into enh/draw-motors
Gui-FernandesBR Nov 18, 2023
dc943d0
MNT: small adjustments before merging...
Gui-FernandesBR Nov 18, 2023
0854200
TST: Update atol value in test_max_values
Gui-FernandesBR Nov 18, 2023
a64c0ef
ENH: Add draw methods to all_info()
Gui-FernandesBR Nov 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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