Skip to content

ENH: Move Motor Plots and Prints #387

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

Merged
merged 8 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions rocketpy/motors/Fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from dataclasses import dataclass

from rocketpy.plots.fluid_plots import _FluidPlots
from rocketpy.prints.fluid_prints import _FluidPrints


@dataclass
class Fluid:
Expand Down Expand Up @@ -45,6 +48,11 @@ def __post_init__(self):
if self.quality < 0 or self.quality > 1:
raise ValueError("The quality must be a number between 0 and 1.")

# Initialize plots and prints object
self.prints = _FluidPrints(self)
self.plots = _FluidPlots(self)
return None

def __repr__(self):
"""Representation method.

Expand Down
73 changes: 15 additions & 58 deletions rocketpy/motors/HybridMotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
except ImportError:
from rocketpy.tools import cached_property


from rocketpy.Function import funcify_method, reset_funcified_methods
from rocketpy.plots.hybrid_motor_plots import _HybridMotorPlots
from rocketpy.prints.hybrid_motor_prints import _HybridMotorPrints

from .LiquidMotor import LiquidMotor
from .Motor import Motor
Expand Down Expand Up @@ -318,6 +319,10 @@ def __init__(
interpolationMethod,
coordinateSystemOrientation,
)
# Initialize plots and prints object
self.prints = _HybridMotorPrints(self)
self.plots = _HybridMotorPlots(self)
return None

@funcify_method("Time (s)", "Exhaust velocity (m/s)")
def exhaustVelocity(self):
Expand Down Expand Up @@ -496,68 +501,20 @@ def addTank(self, tank, position):
self.solid.massFlowRate = self.totalMassFlowRate - self.liquid.massFlowRate
reset_funcified_methods(self)

def info(self):
"""Prints out basic data about the Motor."""
self.prints.all()
self.plots.thrust()
return None

def allInfo(self):
"""Prints out all data and graphs available about the Motor.

Return
------
None
"""
# Print nozzle details
print("Nozzle Details")
print("Nozzle Radius: " + str(self.nozzleRadius) + " m")
print("Nozzle Throat Radius: " + str(self.solid.throatRadius) + " m")

# Print grain details
print("\nGrain Details")
print("Number of Grains: " + str(self.solid.grainNumber))
print("Grain Spacing: " + str(self.solid.grainSeparation) + " m")
print("Grain Density: " + str(self.solid.grainDensity) + " kg/m3")
print("Grain Outer Radius: " + str(self.solid.grainOuterRadius) + " m")
print("Grain Inner Radius: " + str(self.solid.grainInitialInnerRadius) + " m")
print("Grain Height: " + str(self.solid.grainInitialHeight) + " m")
print("Grain Volume: " + "{:.3f}".format(self.solid.grainInitialVolume) + " m3")
print("Grain Mass: " + "{:.3f}".format(self.solid.grainInitialMass) + " kg")

# Print motor details
print("\nMotor Details")
print("Total Burning Time: " + str(self.burnDuration) + " s")
print(
"Total Propellant Mass: "
+ "{:.3f}".format(self.propellantInitialMass)
+ " kg"
)
print(
"Average Propellant Exhaust Velocity: "
+ "{:.3f}".format(self.exhaustVelocity.average(*self.burn_time))
+ " m/s"
)
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
print(
"Maximum Thrust: "
+ str(self.maxThrust)
+ " N at "
+ str(self.maxThrustTime)
+ " s after ignition."
)
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")

# Show plots
print("\nPlots")
self.thrust.plot(*self.burn_time)
self.totalMass.plot(*self.burn_time)
self.massFlowRate.plot(*self.burn_time)
self.solid.grainInnerRadius.plot(*self.burn_time)
self.solid.grainHeight.plot(*self.burn_time)
self.solid.burnRate.plot(self.burn_time[0], self.solid.grainBurnOut)
self.solid.burnArea.plot(*self.burn_time)
self.solid.Kn.plot(*self.burn_time)
self.centerOfMass.plot(*self.burn_time)
self.I_11.plot(*self.burn_time)
self.I_22.plot(*self.burn_time)
self.I_33.plot(*self.burn_time)
self.I_12.plot(*self.burn_time)
self.I_13.plot(*self.burn_time)
self.I_23.plot(*self.burn_time)

self.prints.all()
self.plots.all()
return None
return None
56 changes: 16 additions & 40 deletions rocketpy/motors/LiquidMotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from rocketpy.tools import cached_property

from rocketpy.Function import Function, funcify_method, reset_funcified_methods
from rocketpy.plots.liquid_motor_plots import _LiquidMotorPlots
from rocketpy.prints.liquid_motor_prints import _LiquidMotorPrints

from .Motor import Motor

Expand Down Expand Up @@ -243,6 +245,11 @@ def __init__(

self.positioned_tanks = []

# Initialize plots and prints object
self.prints = _LiquidMotorPrints(self)
self.plots = _LiquidMotorPlots(self)
return None

@funcify_method("Time (s)", "Exhaust Velocity (m/s)")
def exhaustVelocity(self):
"""Computes the exhaust velocity of the motor from its mass flow
Expand Down Expand Up @@ -432,50 +439,19 @@ def addTank(self, tank, position):
self.positioned_tanks.append({"tank": tank, "position": position})
reset_funcified_methods(self)

def info(self):
"""Prints out basic data about the Motor."""
self.prints.all()
self.plots.thrust()
return None

def allInfo(self):
"""Prints out all data and graphs available about the Motor.

Return
------
None
"""
# Print nozzle details
print("Nozzle Details")
print("Nozzle Radius: " + str(self.nozzleRadius) + " m")

# Print motor details
print("\nMotor Details")
print("Total Burning Time: " + str(self.burnDuration) + " s")
print(
"Total Propellant Mass: "
+ "{:.3f}".format(self.propellantInitialMass)
+ " kg"
)
print(
"Average Propellant Exhaust Velocity: "
+ "{:.3f}".format(self.exhaustVelocity.average(*self.burn_time))
+ " m/s"
)
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
print(
"Maximum Thrust: "
+ str(self.maxThrust)
+ " N at "
+ str(self.maxThrustTime)
+ " s after ignition."
)
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")

# Show plots
print("\nPlots")
self.thrust.plot(*self.burn_time)
self.totalMass.plot(*self.burn_time)
self.massFlowRate.plot(*self.burn_time)
self.exhaustVelocity.plot(*self.burn_time)
self.centerOfMass.plot(*self.burn_time)
self.I_11.plot(*self.burn_time)
self.I_22.plot(*self.burn_time)
self.I_33.plot(*self.burn_time)
self.I_12.plot(*self.burn_time)
self.I_13.plot(*self.burn_time)
self.I_23.plot(*self.burn_time)
self.prints.all()
self.plots.all()
return None
77 changes: 18 additions & 59 deletions rocketpy/motors/Motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import warnings
from abc import ABC, abstractmethod

from rocketpy.plots.motor_plots import _MotorPlots
from rocketpy.prints.motor_prints import _MotorPrints
from rocketpy.tools import tuple_handler

try:
Expand Down Expand Up @@ -309,6 +311,10 @@ def __init__(
maxThrustIndex = np.argmax(self.thrust.yArray)
self.maxThrustTime = self.thrust.source[maxThrustIndex, 0]
self.averageThrust = self.totalImpulse / self.burnDuration

# Initialize plots and prints object
self.prints = _MotorPrints(self)
self.plots = _MotorPlots(self)
return None

@property
Expand Down Expand Up @@ -1029,38 +1035,18 @@ def info(self):
Motor.
"""
# Print motor details
print("\nMotor Details")
print("Total Burning Time: " + str(self.burnDuration) + " s")
print(
"Total Propellant Mass: "
+ "{:.3f}".format(self.propellantInitialMass)
+ " kg"
)
print(
"Propellant Exhaust Velocity: "
+ "{:.3f}".format(self.exhaustVelocity.average(*self.burn_time))
+ " m/s"
)
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
print(
"Maximum Thrust: "
+ str(self.maxThrust)
+ " N at "
+ str(self.maxThrustTime)
+ " s after ignition."
)
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")

# Show plots
print("\nPlots")
self.thrust()
self.prints.all()
self.plots.thrust()
return None

return None

@abstractmethod
def allInfo(self):
"""Prints out all data and graphs available about the Motor."""
pass
self.prints.all()
self.plots.all()
return None


class GenericMotor(Motor):
Expand Down Expand Up @@ -1109,6 +1095,9 @@ def __init__(
self.center_of_dry_mass = (
center_of_dry_mass if center_of_dry_mass else chamberPosition
)
# Initialize plots and prints object
self.prints = _MotorPrints(self)
self.plots = _MotorPlots(self)
return None

@cached_property
Expand Down Expand Up @@ -1232,39 +1221,9 @@ def propellant_I_23(self):
def allInfo(self):
"""Prints out all data and graphs available about the Motor."""
# Print motor details
print("\nMotor Details")
print("Total Burning Time: " + str(self.burnOutTime) + " s")
print(
"Total Propellant Mass: "
+ "{:.3f}".format(self.propellantInitialMass)
+ " kg"
)
print(
"Propellant Exhaust Velocity: "
+ "{:.3f}".format(self.exhaustVelocity)
+ " m/s"
)
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
print(
"Maximum Thrust: "
+ str(self.maxThrust)
+ " N at "
+ str(self.maxThrustTime)
+ " s after ignition."
)
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")

# Show plots
print("\nPlots")
self.thrust()
self.totalMass()
self.centerOfMass()
self.I_11()
self.I_22()
self.I_33()
self.I_12()
self.I_13()
self.I_23()
self.prints.all()
self.plots.all()
return None


class EmptyMotor:
Expand Down
Loading