Skip to content

Commit c60b5bb

Browse files
Merge pull request #387 from RocketPy-Team/enh/move-liquid-plots-and-prints
ENH: Move Motor Plots and Prints
2 parents 031db97 + c389162 commit c60b5bb

25 files changed

+2249
-225
lines changed

rocketpy/motors/Fluid.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from dataclasses import dataclass
88

9+
from rocketpy.plots.fluid_plots import _FluidPlots
10+
from rocketpy.prints.fluid_prints import _FluidPrints
11+
912

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

51+
# Initialize plots and prints object
52+
self.prints = _FluidPrints(self)
53+
self.plots = _FluidPlots(self)
54+
return None
55+
4856
def __repr__(self):
4957
"""Representation method.
5058

rocketpy/motors/HybridMotor.py

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
except ImportError:
1010
from rocketpy.tools import cached_property
1111

12-
1312
from rocketpy.Function import funcify_method, reset_funcified_methods
13+
from rocketpy.plots.hybrid_motor_plots import _HybridMotorPlots
14+
from rocketpy.prints.hybrid_motor_prints import _HybridMotorPrints
1415

1516
from .LiquidMotor import LiquidMotor
1617
from .Motor import Motor
@@ -318,6 +319,10 @@ def __init__(
318319
interpolationMethod,
319320
coordinateSystemOrientation,
320321
)
322+
# Initialize plots and prints object
323+
self.prints = _HybridMotorPrints(self)
324+
self.plots = _HybridMotorPlots(self)
325+
return None
321326

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

504+
def info(self):
505+
"""Prints out basic data about the Motor."""
506+
self.prints.all()
507+
self.plots.thrust()
508+
return None
509+
499510
def allInfo(self):
500511
"""Prints out all data and graphs available about the Motor.
501512
502513
Return
503514
------
504515
None
505516
"""
506-
# Print nozzle details
507-
print("Nozzle Details")
508-
print("Nozzle Radius: " + str(self.nozzleRadius) + " m")
509-
print("Nozzle Throat Radius: " + str(self.solid.throatRadius) + " m")
510-
511-
# Print grain details
512-
print("\nGrain Details")
513-
print("Number of Grains: " + str(self.solid.grainNumber))
514-
print("Grain Spacing: " + str(self.solid.grainSeparation) + " m")
515-
print("Grain Density: " + str(self.solid.grainDensity) + " kg/m3")
516-
print("Grain Outer Radius: " + str(self.solid.grainOuterRadius) + " m")
517-
print("Grain Inner Radius: " + str(self.solid.grainInitialInnerRadius) + " m")
518-
print("Grain Height: " + str(self.solid.grainInitialHeight) + " m")
519-
print("Grain Volume: " + "{:.3f}".format(self.solid.grainInitialVolume) + " m3")
520-
print("Grain Mass: " + "{:.3f}".format(self.solid.grainInitialMass) + " kg")
521-
522-
# Print motor details
523-
print("\nMotor Details")
524-
print("Total Burning Time: " + str(self.burnDuration) + " s")
525-
print(
526-
"Total Propellant Mass: "
527-
+ "{:.3f}".format(self.propellantInitialMass)
528-
+ " kg"
529-
)
530-
print(
531-
"Average Propellant Exhaust Velocity: "
532-
+ "{:.3f}".format(self.exhaustVelocity.average(*self.burn_time))
533-
+ " m/s"
534-
)
535-
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
536-
print(
537-
"Maximum Thrust: "
538-
+ str(self.maxThrust)
539-
+ " N at "
540-
+ str(self.maxThrustTime)
541-
+ " s after ignition."
542-
)
543-
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")
544-
545-
# Show plots
546-
print("\nPlots")
547-
self.thrust.plot(*self.burn_time)
548-
self.totalMass.plot(*self.burn_time)
549-
self.massFlowRate.plot(*self.burn_time)
550-
self.solid.grainInnerRadius.plot(*self.burn_time)
551-
self.solid.grainHeight.plot(*self.burn_time)
552-
self.solid.burnRate.plot(self.burn_time[0], self.solid.grainBurnOut)
553-
self.solid.burnArea.plot(*self.burn_time)
554-
self.solid.Kn.plot(*self.burn_time)
555-
self.centerOfMass.plot(*self.burn_time)
556-
self.I_11.plot(*self.burn_time)
557-
self.I_22.plot(*self.burn_time)
558-
self.I_33.plot(*self.burn_time)
559-
self.I_12.plot(*self.burn_time)
560-
self.I_13.plot(*self.burn_time)
561-
self.I_23.plot(*self.burn_time)
562-
517+
self.prints.all()
518+
self.plots.all()
519+
return None
563520
return None

rocketpy/motors/LiquidMotor.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from rocketpy.tools import cached_property
1111

1212
from rocketpy.Function import Function, funcify_method, reset_funcified_methods
13+
from rocketpy.plots.liquid_motor_plots import _LiquidMotorPlots
14+
from rocketpy.prints.liquid_motor_prints import _LiquidMotorPrints
1315

1416
from .Motor import Motor
1517

@@ -243,6 +245,11 @@ def __init__(
243245

244246
self.positioned_tanks = []
245247

248+
# Initialize plots and prints object
249+
self.prints = _LiquidMotorPrints(self)
250+
self.plots = _LiquidMotorPlots(self)
251+
return None
252+
246253
@funcify_method("Time (s)", "Exhaust Velocity (m/s)")
247254
def exhaustVelocity(self):
248255
"""Computes the exhaust velocity of the motor from its mass flow
@@ -432,50 +439,19 @@ def addTank(self, tank, position):
432439
self.positioned_tanks.append({"tank": tank, "position": position})
433440
reset_funcified_methods(self)
434441

442+
def info(self):
443+
"""Prints out basic data about the Motor."""
444+
self.prints.all()
445+
self.plots.thrust()
446+
return None
447+
435448
def allInfo(self):
436449
"""Prints out all data and graphs available about the Motor.
437450
438451
Return
439452
------
440453
None
441454
"""
442-
# Print nozzle details
443-
print("Nozzle Details")
444-
print("Nozzle Radius: " + str(self.nozzleRadius) + " m")
445-
446-
# Print motor details
447-
print("\nMotor Details")
448-
print("Total Burning Time: " + str(self.burnDuration) + " s")
449-
print(
450-
"Total Propellant Mass: "
451-
+ "{:.3f}".format(self.propellantInitialMass)
452-
+ " kg"
453-
)
454-
print(
455-
"Average Propellant Exhaust Velocity: "
456-
+ "{:.3f}".format(self.exhaustVelocity.average(*self.burn_time))
457-
+ " m/s"
458-
)
459-
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
460-
print(
461-
"Maximum Thrust: "
462-
+ str(self.maxThrust)
463-
+ " N at "
464-
+ str(self.maxThrustTime)
465-
+ " s after ignition."
466-
)
467-
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")
468-
469-
# Show plots
470-
print("\nPlots")
471-
self.thrust.plot(*self.burn_time)
472-
self.totalMass.plot(*self.burn_time)
473-
self.massFlowRate.plot(*self.burn_time)
474-
self.exhaustVelocity.plot(*self.burn_time)
475-
self.centerOfMass.plot(*self.burn_time)
476-
self.I_11.plot(*self.burn_time)
477-
self.I_22.plot(*self.burn_time)
478-
self.I_33.plot(*self.burn_time)
479-
self.I_12.plot(*self.burn_time)
480-
self.I_13.plot(*self.burn_time)
481-
self.I_23.plot(*self.burn_time)
455+
self.prints.all()
456+
self.plots.all()
457+
return None

rocketpy/motors/Motor.py

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import warnings
99
from abc import ABC, abstractmethod
1010

11+
from rocketpy.plots.motor_plots import _MotorPlots
12+
from rocketpy.prints.motor_prints import _MotorPrints
1113
from rocketpy.tools import tuple_handler
1214

1315
try:
@@ -309,6 +311,10 @@ def __init__(
309311
maxThrustIndex = np.argmax(self.thrust.yArray)
310312
self.maxThrustTime = self.thrust.source[maxThrustIndex, 0]
311313
self.averageThrust = self.totalImpulse / self.burnDuration
314+
315+
# Initialize plots and prints object
316+
self.prints = _MotorPrints(self)
317+
self.plots = _MotorPlots(self)
312318
return None
313319

314320
@property
@@ -1029,38 +1035,18 @@ def info(self):
10291035
Motor.
10301036
"""
10311037
# Print motor details
1032-
print("\nMotor Details")
1033-
print("Total Burning Time: " + str(self.burnDuration) + " s")
1034-
print(
1035-
"Total Propellant Mass: "
1036-
+ "{:.3f}".format(self.propellantInitialMass)
1037-
+ " kg"
1038-
)
1039-
print(
1040-
"Propellant Exhaust Velocity: "
1041-
+ "{:.3f}".format(self.exhaustVelocity.average(*self.burn_time))
1042-
+ " m/s"
1043-
)
1044-
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
1045-
print(
1046-
"Maximum Thrust: "
1047-
+ str(self.maxThrust)
1048-
+ " N at "
1049-
+ str(self.maxThrustTime)
1050-
+ " s after ignition."
1051-
)
1052-
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")
1053-
1054-
# Show plots
1055-
print("\nPlots")
1056-
self.thrust()
1038+
self.prints.all()
1039+
self.plots.thrust()
1040+
return None
10571041

10581042
return None
10591043

10601044
@abstractmethod
10611045
def allInfo(self):
10621046
"""Prints out all data and graphs available about the Motor."""
1063-
pass
1047+
self.prints.all()
1048+
self.plots.all()
1049+
return None
10641050

10651051

10661052
class GenericMotor(Motor):
@@ -1109,6 +1095,9 @@ def __init__(
11091095
self.center_of_dry_mass = (
11101096
center_of_dry_mass if center_of_dry_mass else chamberPosition
11111097
)
1098+
# Initialize plots and prints object
1099+
self.prints = _MotorPrints(self)
1100+
self.plots = _MotorPlots(self)
11121101
return None
11131102

11141103
@cached_property
@@ -1232,39 +1221,9 @@ def propellant_I_23(self):
12321221
def allInfo(self):
12331222
"""Prints out all data and graphs available about the Motor."""
12341223
# Print motor details
1235-
print("\nMotor Details")
1236-
print("Total Burning Time: " + str(self.burnOutTime) + " s")
1237-
print(
1238-
"Total Propellant Mass: "
1239-
+ "{:.3f}".format(self.propellantInitialMass)
1240-
+ " kg"
1241-
)
1242-
print(
1243-
"Propellant Exhaust Velocity: "
1244-
+ "{:.3f}".format(self.exhaustVelocity)
1245-
+ " m/s"
1246-
)
1247-
print("Average Thrust: " + "{:.3f}".format(self.averageThrust) + " N")
1248-
print(
1249-
"Maximum Thrust: "
1250-
+ str(self.maxThrust)
1251-
+ " N at "
1252-
+ str(self.maxThrustTime)
1253-
+ " s after ignition."
1254-
)
1255-
print("Total Impulse: " + "{:.3f}".format(self.totalImpulse) + " Ns")
1256-
1257-
# Show plots
1258-
print("\nPlots")
1259-
self.thrust()
1260-
self.totalMass()
1261-
self.centerOfMass()
1262-
self.I_11()
1263-
self.I_22()
1264-
self.I_33()
1265-
self.I_12()
1266-
self.I_13()
1267-
self.I_23()
1224+
self.prints.all()
1225+
self.plots.all()
1226+
return None
12681227

12691228

12701229
class EmptyMotor:

0 commit comments

Comments
 (0)