Skip to content

Commit 6656659

Browse files
ENH: more abstract acceleration properties
1 parent 47b220c commit 6656659

File tree

1 file changed

+88
-58
lines changed

1 file changed

+88
-58
lines changed

rocketpy/Flight.py

Lines changed: 88 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ class Flight:
145145
Current integration state vector u.
146146
Flight.postProcessed : bool
147147
Defines if solution data has been post processed.
148-
Flight.retrievedAcceleration: bool
149-
Defines if acceleration data has been retrieved from the integration scheme.
150148
Flight.retrievedTemporaryValues: bool
151149
Defines if temporary values have been retrieved from the integration scheme.
152150
Flight.calculatedRailButtonForces: bool
@@ -639,7 +637,6 @@ def __init__(
639637
self.impactState = np.array([0])
640638
self.parachuteEvents = []
641639
self.postProcessed = False
642-
self.retrievedAcceleration = False
643640
self.retrievedTemporaryValues = False
644641
self.calculatedRailButtonForces = False
645642
self.calculatedGeodesicCoordinates = False
@@ -1128,18 +1125,18 @@ def __init_post_process_variables(self):
11281125
"""Initialize post-process variables."""
11291126
# Initialize all variables created during Flight.postProcess()
11301127
# Important to do so that MATLAB® can access them
1131-
self.windVelocityX = Function(0)
1132-
self.windVelocityY = Function(0)
1133-
self.density = Function(0)
1134-
self.pressure = Function(0)
1135-
self.dynamicViscosity = Function(0)
1136-
self.speedOfSound = Function(0)
1137-
self.ax = Function(0)
1138-
self.ay = Function(0)
1139-
self.az = Function(0)
1140-
self.alpha1 = Function(0)
1141-
self.alpha2 = Function(0)
1142-
self.alpha3 = Function(0)
1128+
self._windVelocityX = Function(0)
1129+
self._windVelocityY = Function(0)
1130+
self._density = Function(0)
1131+
self._pressure = Function(0)
1132+
self._dynamicViscosity = Function(0)
1133+
self._speedOfSound = Function(0)
1134+
self._ax = Function(0)
1135+
self._ay = Function(0)
1136+
self._az = Function(0)
1137+
self._alpha1 = Function(0)
1138+
self._alpha2 = Function(0)
1139+
self._alpha3 = Function(0)
11431140
self._speed = Function(0)
11441141
self._maxSpeed = 0
11451142
self._maxSpeedTime = 0
@@ -1156,12 +1153,12 @@ def __init_post_process_variables(self):
11561153
self._phi = Function(0)
11571154
self._theta = Function(0)
11581155
self._psi = Function(0)
1159-
self.R1 = Function(0)
1160-
self.R2 = Function(0)
1161-
self.R3 = Function(0)
1162-
self.M1 = Function(0)
1163-
self.M2 = Function(0)
1164-
self.M3 = Function(0)
1156+
self._R1 = Function(0)
1157+
self._R2 = Function(0)
1158+
self._R3 = Function(0)
1159+
self._M1 = Function(0)
1160+
self._M2 = Function(0)
1161+
self._M3 = Function(0)
11651162
self._aerodynamicLift = Function(0)
11661163
self._aerodynamicDrag = Function(0)
11671164
self._aerodynamicBendingMoment = Function(0)
@@ -1744,6 +1741,49 @@ def w3(self):
17441741
extrapolation="natural",
17451742
)
17461743

1744+
# Process second type of outputs - accelerations components
1745+
@cached_property
1746+
def ax(self):
1747+
ax, ay, az, alpha1, alpha2, alpha3 = self.__retrieved_acceleration_arrays()
1748+
# Convert accelerations to functions
1749+
ax = Function(ax, "Time (s)", "Ax (m/s2)")
1750+
return ax
1751+
1752+
@cached_property
1753+
def ay(self):
1754+
ax, ay, az, alpha1, alpha2, alpha3 = self.__retrieved_acceleration_arrays()
1755+
# Convert accelerations to functions
1756+
ay = Function(ay, "Time (s)", "Ay (m/s2)")
1757+
return ay
1758+
1759+
@cached_property
1760+
def az(self):
1761+
ax, ay, az, alpha1, alpha2, alpha3 = self.__retrieved_acceleration_arrays()
1762+
# Convert accelerations to functions
1763+
az = Function(az, "Time (s)", "Az (m/s2)")
1764+
return az
1765+
1766+
@cached_property
1767+
def alpha1(self):
1768+
ax, ay, az, alpha1, alpha2, alpha3 = self.__retrieved_acceleration_arrays()
1769+
# Convert accelerations to functions
1770+
alpha1 = Function(alpha1, "Time (s)", "α1 (rad/s2)")
1771+
return alpha1
1772+
1773+
@cached_property
1774+
def alpha2(self):
1775+
ax, ay, az, alpha1, alpha2, alpha3 = self.__retrieved_acceleration_arrays()
1776+
# Convert accelerations to functions
1777+
alpha2 = Function(alpha2, "Time (s)", "α2 (rad/s2)")
1778+
return alpha2
1779+
1780+
@cached_property
1781+
def alpha3(self):
1782+
ax, ay, az, alpha1, alpha2, alpha3 = self.__retrieved_acceleration_arrays()
1783+
# Convert accelerations to functions
1784+
alpha3 = Function(alpha3, "Time (s)", "α3 (rad/s2)")
1785+
return alpha3
1786+
17471787
# Process fourth type of output - values calculated from previous outputs
17481788

17491789
# Kinematics functions and values
@@ -1766,8 +1806,6 @@ def maxSpeed(self):
17661806
# Accelerations
17671807
@cached_property
17681808
def acceleration(self):
1769-
if self.retrievedAcceleration is not True:
1770-
self.__retrieve_acceleration_array
17711809
acceleration = (self.ax**2 + self.ay**2 + self.az**2) ** 0.5
17721810
acceleration.setOutputs("Acceleration Magnitude (m/s²)")
17731811
return acceleration
@@ -2230,27 +2268,33 @@ def attitudeFrequencyResponse(self):
22302268
def staticMargin(self):
22312269
return self.rocket.staticMargin
22322270

2233-
# Define initialization functions for post process variables
2271+
# Define initialization functions for post process variables
22342272

2235-
def __retrieve_acceleration_array(
2236-
self, interpolation="spline", extrapolation="natural"
2237-
):
2238-
"""Retrieve acceleration array from the integration scheme
2273+
@cached_property
2274+
def __retrieved_acceleration_arrays(self):
2275+
"""Retrieve acceleration arrays from the integration scheme
22392276
22402277
Parameters
22412278
----------
2242-
interpolation : str, optional
2243-
Selected model for interpolation, by default "spline"
2244-
extrapolation : str, optional
2245-
Selected model for extrapolation, by default "natural"
22462279
22472280
Returns
22482281
-------
2249-
None
2282+
ax: list
2283+
acceleration in x direction
2284+
ay: list
2285+
acceleration in y direction
2286+
az: list
2287+
acceleration in z direction
2288+
alpha1: list
2289+
angular acceleration in x direction
2290+
alpha2: list
2291+
angular acceleration in y direction
2292+
alpha3: list
2293+
angular acceleration in z direction
22502294
"""
22512295
# Initialize acceleration arrays
2252-
self.ax, self.ay, self.az = [], [], []
2253-
self.alpha1, self.alpha2, self.alpha3 = [], [], []
2296+
ax, ay, az = [], [], []
2297+
alpha1, alpha2, alpha3 = [], [], []
22542298
# Go through each time step and calculate accelerations
22552299
# Get flight phases
22562300
for phase_index, phase in self.timeIterator(self.flightPhases):
@@ -2266,27 +2310,17 @@ def __retrieve_acceleration_array(
22662310
# Get derivatives
22672311
uDot = currentDerivative(step[0], step[1:])
22682312
# Get accelerations
2269-
ax, ay, az = uDot[3:6]
2270-
alpha1, alpha2, alpha3 = uDot[10:]
2313+
ax_value, ay_value, az_value = uDot[3:6]
2314+
alpha1_value, alpha2_value, alpha3_value = uDot[10:]
22712315
# Save accelerations
2272-
self.ax.append([step[0], ax])
2273-
self.ay.append([step[0], ay])
2274-
self.az.append([step[0], az])
2275-
self.alpha1.append([step[0], alpha1])
2276-
self.alpha2.append([step[0], alpha2])
2277-
self.alpha3.append([step[0], alpha3])
2278-
2279-
# Convert accelerations to functions
2280-
self.ax = Function(self.ax, "Time (s)", "Ax (m/s2)", interpolation)
2281-
self.ay = Function(self.ay, "Time (s)", "Ay (m/s2)", interpolation)
2282-
self.az = Function(self.az, "Time (s)", "Az (m/s2)", interpolation)
2283-
self.alpha1 = Function(self.alpha1, "Time (s)", "α1 (rad/s2)", interpolation)
2284-
self.alpha2 = Function(self.alpha2, "Time (s)", "α2 (rad/s2)", interpolation)
2285-
self.alpha3 = Function(self.alpha3, "Time (s)", "α3 (rad/s2)", interpolation)
2316+
ax.append([step[0], ax_value])
2317+
ay.append([step[0], ay_value])
2318+
az.append([step[0], az_value])
2319+
alpha1.append([step[0], alpha1_value])
2320+
alpha2.append([step[0], alpha2_value])
2321+
alpha3.append([step[0], alpha3_value])
22862322

2287-
self.retrievedAcceleration = True
2288-
2289-
return None
2323+
return ax, ay, az, alpha1, alpha2, alpha3
22902324

22912325
def __retrieve_temporary_values_arrays(
22922326
self, interpolation="spline", extrapolation="natural"
@@ -2607,10 +2641,6 @@ def postProcess(self, interpolation="spline", extrapolation="natural"):
26072641
None
26082642
"""
26092643

2610-
# Process second type of outputs - accelerations
2611-
if self.retrievedAcceleration is not True:
2612-
self.__retrieve_acceleration_array()
2613-
26142644
# Process third type of outputs - temporary values calculated during integration
26152645
if self.retrievedTemporaryValues is not True:
26162646
self.__retrieve_temporary_values_arrays()

0 commit comments

Comments
 (0)