Skip to content

Commit 553df48

Browse files
authored
Merge pull request #289 from RocketPy-Team/enh/flight_prints
ENH: Moved Flight prints to flight_prints.py
2 parents 7925d60 + d0da62b commit 553df48

2 files changed

Lines changed: 436 additions & 264 deletions

File tree

rocketpy/Flight.py

Lines changed: 6 additions & 262 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from scipy import integrate
1717

1818
from .Function import Function
19+
from .prints.flight_prints import _FlightPrints
1920

2021
try:
2122
from functools import cached_property
@@ -636,6 +637,10 @@ def __init__(
636637
self._bearing = Function(0)
637638
self._latitude = Function(0)
638639
self._longitude = Function(0)
640+
641+
# Initialize prints and plots objects
642+
self.prints = _FlightPrints(self)
643+
639644
# Initialize solver monitors
640645
self.functionEvaluations = []
641646
self.functionEvaluationsPerTimeStep = []
@@ -3288,256 +3293,7 @@ def info(self):
32883293
------
32893294
None
32903295
"""
3291-
3292-
# Get index of out of rail time
3293-
outOfRailTimeIndexes = np.nonzero(self.x[:, 0] == self.outOfRailTime)
3294-
outOfRailTimeIndex = (
3295-
-1 if len(outOfRailTimeIndexes) == 0 else outOfRailTimeIndexes[0][0]
3296-
)
3297-
3298-
# Get index of time before parachute event
3299-
if len(self.parachuteEvents) > 0:
3300-
eventTime = self.parachuteEvents[0][0] + self.parachuteEvents[0][1].lag
3301-
eventTimeIndex = np.nonzero(self.x[:, 0] == eventTime)[0][0]
3302-
else:
3303-
eventTime = self.tFinal
3304-
eventTimeIndex = -1
3305-
3306-
# Print surface wind conditions
3307-
print("Surface Wind Conditions\n")
3308-
print("Frontal Surface Wind Speed: {:.2f} m/s".format(self.frontalSurfaceWind))
3309-
print("Lateral Surface Wind Speed: {:.2f} m/s".format(self.lateralSurfaceWind))
3310-
3311-
# Print out of rail conditions
3312-
print("\n\n Rail Departure State\n")
3313-
print("Rail Departure Time: {:.3f} s".format(self.outOfRailTime))
3314-
print("Rail Departure Velocity: {:.3f} m/s".format(self.outOfRailVelocity))
3315-
print(
3316-
"Rail Departure Static Margin: {:.3f} c".format(
3317-
self.staticMargin(self.outOfRailTime)
3318-
)
3319-
)
3320-
print(
3321-
"Rail Departure Angle of Attack: {:.3f}°".format(
3322-
self.angleOfAttack(self.outOfRailTime)
3323-
)
3324-
)
3325-
print(
3326-
"Rail Departure Thrust-Weight Ratio: {:.3f}".format(
3327-
self.rocket.thrustToWeight(self.outOfRailTime)
3328-
)
3329-
)
3330-
print(
3331-
"Rail Departure Reynolds Number: {:.3e}".format(
3332-
self.ReynoldsNumber(self.outOfRailTime)
3333-
)
3334-
)
3335-
3336-
# Print burnOut conditions
3337-
print("\n\nBurnOut State\n")
3338-
print("BurnOut time: {:.3f} s".format(self.rocket.motor.burnOutTime))
3339-
print(
3340-
"Altitude at burnOut: {:.3f} m (AGL)".format(
3341-
self.z(self.rocket.motor.burnOutTime) - self.env.elevation
3342-
)
3343-
)
3344-
print(
3345-
"Rocket velocity at burnOut: {:.3f} m/s".format(
3346-
self.speed(self.rocket.motor.burnOutTime)
3347-
)
3348-
)
3349-
print(
3350-
"Freestream velocity at burnOut: {:.3f} m/s".format(
3351-
(
3352-
self.streamVelocityX(self.rocket.motor.burnOutTime) ** 2
3353-
+ self.streamVelocityY(self.rocket.motor.burnOutTime) ** 2
3354-
+ self.streamVelocityZ(self.rocket.motor.burnOutTime) ** 2
3355-
)
3356-
** 0.5
3357-
)
3358-
)
3359-
print(
3360-
"Mach Number at burnOut: {:.3f}".format(
3361-
self.MachNumber(self.rocket.motor.burnOutTime)
3362-
)
3363-
)
3364-
print(
3365-
"Kinetic energy at burnOut: {:.3e} J".format(
3366-
self.kineticEnergy(self.rocket.motor.burnOutTime)
3367-
)
3368-
)
3369-
3370-
# Print apogee conditions
3371-
print("\n\nApogee\n")
3372-
print(
3373-
"Apogee Altitude: {:.3f} m (ASL) | {:.3f} m (AGL)".format(
3374-
self.apogee, self.apogee - self.env.elevation
3375-
)
3376-
)
3377-
print("Apogee Time: {:.3f} s".format(self.apogeeTime))
3378-
print("Apogee Freestream Speed: {:.3f} m/s".format(self.apogeeFreestreamSpeed))
3379-
3380-
# Print events registered
3381-
print("\n\nEvents\n")
3382-
if len(self.parachuteEvents) == 0:
3383-
print("No Parachute Events Were Triggered.")
3384-
for event in self.parachuteEvents:
3385-
triggerTime = event[0]
3386-
parachute = event[1]
3387-
openTime = triggerTime + parachute.lag
3388-
velocity = self.freestreamSpeed(openTime)
3389-
altitude = self.z(openTime)
3390-
name = parachute.name.title()
3391-
print(name + " Ejection Triggered at: {:.3f} s".format(triggerTime))
3392-
print(name + " Parachute Inflated at: {:.3f} s".format(openTime))
3393-
print(
3394-
name
3395-
+ " Parachute Inflated with Freestream Speed of: {:.3f} m/s".format(
3396-
velocity
3397-
)
3398-
)
3399-
print(
3400-
name
3401-
+ " Parachute Inflated at Height of: {:.3f} m (AGL)".format(
3402-
altitude - self.env.elevation
3403-
)
3404-
)
3405-
3406-
# Print impact conditions
3407-
if len(self.impactState) != 0:
3408-
print("\n\nImpact\n")
3409-
print("X Impact: {:.3f} m".format(self.xImpact))
3410-
print("Y Impact: {:.3f} m".format(self.yImpact))
3411-
print("Time of Impact: {:.3f} s".format(self.tFinal))
3412-
print("Velocity at Impact: {:.3f} m/s".format(self.impactVelocity))
3413-
elif self.terminateOnApogee is False:
3414-
print("\n\nEnd of Simulation\n")
3415-
print("Time: {:.3f} s".format(self.solution[-1][0]))
3416-
print("Altitude: {:.3f} m".format(self.solution[-1][3]))
3417-
3418-
# Print maximum values
3419-
print("\n\nMaximum Values\n")
3420-
print(
3421-
"Maximum Speed: {:.3f} m/s at {:.2f} s".format(
3422-
self.maxSpeed, self.maxSpeedTime
3423-
)
3424-
)
3425-
print(
3426-
"Maximum Mach Number: {:.3f} Mach at {:.2f} s".format(
3427-
self.maxMachNumber, self.maxMachNumberTime
3428-
)
3429-
)
3430-
print(
3431-
"Maximum Reynolds Number: {:.3e} at {:.2f} s".format(
3432-
self.maxReynoldsNumber, self.maxReynoldsNumberTime
3433-
)
3434-
)
3435-
print(
3436-
"Maximum Dynamic Pressure: {:.3e} Pa at {:.2f} s".format(
3437-
self.maxDynamicPressure, self.maxDynamicPressureTime
3438-
)
3439-
)
3440-
print(
3441-
"Maximum Acceleration: {:.3f} m/s² at {:.2f} s".format(
3442-
self.maxAcceleration, self.maxAccelerationTime
3443-
)
3444-
)
3445-
print(
3446-
"Maximum Gs: {:.3f} g at {:.2f} s".format(
3447-
self.maxAcceleration / self.env.g, self.maxAccelerationTime
3448-
)
3449-
)
3450-
print(
3451-
"Maximum Upper Rail Button Normal Force: {:.3f} N".format(
3452-
self.maxRailButton1NormalForce
3453-
)
3454-
)
3455-
print(
3456-
"Maximum Upper Rail Button Shear Force: {:.3f} N".format(
3457-
self.maxRailButton1ShearForce
3458-
)
3459-
)
3460-
print(
3461-
"Maximum Lower Rail Button Normal Force: {:.3f} N".format(
3462-
self.maxRailButton2NormalForce
3463-
)
3464-
)
3465-
print(
3466-
"Maximum Lower Rail Button Shear Force: {:.3f} N".format(
3467-
self.maxRailButton2ShearForce
3468-
)
3469-
)
3470-
3471-
return None
3472-
3473-
def printInitialConditionsData(self):
3474-
"""Prints all initial conditions data available about the flight
3475-
3476-
Parameters
3477-
----------
3478-
None
3479-
3480-
Return
3481-
------
3482-
None
3483-
"""
3484-
3485-
print(
3486-
"Position - x: {:.2f} m | y: {:.2f} m | z: {:.2f} m".format(
3487-
self.x(0), self.y(0), self.z(0)
3488-
)
3489-
)
3490-
print(
3491-
"Velocity - Vx: {:.2f} m/s | Vy: {:.2f} m/s | Vz: {:.2f} m/s".format(
3492-
self.vx(0), self.vy(0), self.vz(0)
3493-
)
3494-
)
3495-
print(
3496-
"Attitude - e0: {:.3f} | e1: {:.3f} | e2: {:.3f} | e3: {:.3f}".format(
3497-
self.e0(0), self.e1(0), self.e2(0), self.e3(0)
3498-
)
3499-
)
3500-
print(
3501-
"Euler Angles - Spin φ : {:.2f}° | Nutation θ: {:.2f}° | Precession ψ: {:.2f}°".format(
3502-
self.phi(0), self.theta(0), self.psi(0)
3503-
)
3504-
)
3505-
print(
3506-
"Angular Velocity - ω1: {:.2f} rad/s | ω2: {:.2f} rad/s| ω3: {:.2f} rad/s".format(
3507-
self.w1(0), self.w2(0), self.w3(0)
3508-
)
3509-
)
3510-
return None
3511-
3512-
def printNumericalIntegrationSettings(self):
3513-
"""Prints out the Numerical Integration settings
3514-
3515-
Parameters
3516-
----------
3517-
None
3518-
3519-
Return
3520-
------
3521-
None
3522-
"""
3523-
print("Maximum Allowed Flight Time: {:f} s".format(self.maxTime))
3524-
print("Maximum Allowed Time Step: {:f} s".format(self.maxTimeStep))
3525-
print("Minimum Allowed Time Step: {:e} s".format(self.minTimeStep))
3526-
print("Relative Error Tolerance: ", self.rtol)
3527-
print("Absolute Error Tolerance: ", self.atol)
3528-
print("Allow Event Overshoot: ", self.timeOvershoot)
3529-
print("Terminate Simulation on Apogee: ", self.terminateOnApogee)
3530-
print("Number of Time Steps Used: ", len(self.timeSteps))
3531-
print(
3532-
"Number of Derivative Functions Evaluation: ",
3533-
sum(self.functionEvaluationsPerTimeStep),
3534-
)
3535-
print(
3536-
"Average Function Evaluations per Time Step: {:3f}".format(
3537-
sum(self.functionEvaluationsPerTimeStep) / len(self.timeSteps)
3538-
)
3539-
)
3540-
3296+
self.prints.all()
35413297
return None
35423298

35433299
def calculateStallWindVelocity(self, stallAngle):
@@ -4706,21 +4462,9 @@ def allInfo(self):
47064462
None
47074463
"""
47084464

4709-
# Print initial conditions
4710-
print("Initial Conditions\n")
4711-
self.printInitialConditionsData()
4712-
4713-
# Print launch rail orientation
4714-
print("\n\nLaunch Rail Orientation\n")
4715-
print("Launch Rail Inclination: {:.2f}°".format(self.inclination))
4716-
print("Launch Rail Heading: {:.2f}°\n\n".format(self.heading))
4717-
47184465
# Print a summary of data about the flight
47194466
self.info()
47204467

4721-
print("\n\nNumerical Integration Information\n")
4722-
self.printNumericalIntegrationSettings()
4723-
47244468
print("\n\nTrajectory 3d Plot\n")
47254469
self.plot3dTrajectory()
47264470

0 commit comments

Comments
 (0)