Skip to content

Commit 54b706a

Browse files
ENH: new Flight.get_solution_at_time() method
1 parent 3f9271e commit 54b706a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

rocketpy/simulation/flight.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,32 @@ def time(self):
19341934
"""Returns time array from solution."""
19351935
return self.solution_array[:, 0]
19361936

1937+
def get_solution_at_time(self, t):
1938+
"""Returns the solution state vector at a given time. If the time is
1939+
not found in the solution, the closest time is used and a warning is
1940+
raised.
1941+
1942+
Parameters
1943+
----------
1944+
t : float
1945+
Time in seconds.
1946+
1947+
Returns
1948+
-------
1949+
solution : np.array
1950+
Solution state at time t. The array follows the format of the
1951+
solution array, with the first column being time like this:
1952+
[t, x, y, z, vx, vy, vz, e0, e1, e2, e3, omega1, omega2, omega3].
1953+
1954+
"""
1955+
time_index = find_closest(self.time, t)
1956+
if abs(self.time[time_index] - t) > 1e-5:
1957+
warnings.warn(
1958+
f"Time {t} not found in solution. Closest time is "
1959+
f"{self.time[time_index]}. Using closest time.", UserWarning
1960+
)
1961+
return self.solution_array[time_index, :]
1962+
19371963
# Process first type of outputs - state vector
19381964
# Transform solution array into Functions
19391965
@funcify_method("Time (s)", "X (m)", "spline", "constant")

0 commit comments

Comments
 (0)