Skip to content

Commit da2b94b

Browse files
DOC: improve flight class documentation page
1 parent 6811e6c commit da2b94b

File tree

2 files changed

+172
-3
lines changed

2 files changed

+172
-3
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"filt",
120120
"firstsimulation",
121121
"flightcsys",
122+
"flightusage",
122123
"Fluxogram",
123124
"fmax",
124125
"fmin",
@@ -181,6 +182,7 @@
181182
"Kaleb",
182183
"Karman",
183184
"Krasser",
185+
"Kutta",
184186
"labelrotation",
185187
"linalg",
186188
"Lince",
@@ -273,6 +275,7 @@
273275
"rtol",
274276
"rtype",
275277
"rucsoundings",
278+
"Runge",
276279
"runslow",
277280
"rwork",
278281
"savetxt",

docs/user/flight.rst

Lines changed: 169 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ The Flight class automatically calculates appropriate initial conditions based o
125125
You can also specify custom initial conditions by passing an ``initial_solution``
126126
array or another Flight object to continue from a previous state.
127127

128+
**Custom Initial Solution Vector**
129+
130+
The ``initial_solution`` parameter accepts a 14-element array defining the complete
131+
initial state of the rocket:
132+
133+
.. code-block:: python
134+
135+
initial_solution = [
136+
t_initial, # Initial time (s)
137+
x_init, # Initial X position - East coordinate (m)
138+
y_init, # Initial Y position - North coordinate (m)
139+
z_init, # Initial Z position - altitude above launch site (m)
140+
vx_init, # Initial velocity in X direction - East (m/s)
141+
vy_init, # Initial velocity in Y direction - North (m/s)
142+
vz_init, # Initial velocity in Z direction - upward (m/s)
143+
e0_init, # Initial Euler parameter 0 (quaternion scalar part)
144+
e1_init, # Initial Euler parameter 1 (quaternion i component)
145+
e2_init, # Initial Euler parameter 2 (quaternion j component)
146+
e3_init, # Initial Euler parameter 3 (quaternion k component)
147+
w1_init, # Initial angular velocity about rocket's x-axis (rad/s)
148+
w2_init, # Initial angular velocity about rocket's y-axis (rad/s)
149+
w3_init # Initial angular velocity about rocket's z-axis (rad/s)
150+
]
151+
152+
**Using a Previous Flight as Initial Condition**
153+
154+
You can also continue a simulation from where another flight ended:
155+
156+
.. code-block:: python
157+
158+
# Continue from the final state of a previous flight
159+
continued_flight = Flight(
160+
rocket=rocket,
161+
environment=env,
162+
rail_length=0, # Set to 0 when continuing from free flight
163+
initial_solution=flight # Use previous Flight object
164+
)
165+
166+
This is particularly useful for multi-stage simulations or when analyzing
167+
different scenarios from a specific flight condition.
168+
128169
Simulation Control Parameters
129170
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130171

@@ -134,6 +175,13 @@ Simulation Control Parameters
134175
- ``max_time_step``: Maximum integration step size (default: infinity)
135176
- ``min_time_step``: Minimum integration step size (default: 0)
136177

178+
.. note::
179+
180+
These time control parameters can significantly help with integration stability \
181+
in challenging simulation cases. This is particularly useful for liquid and \
182+
hybrid motors, which often have more complex thrust curves and transient \
183+
behaviors that can cause numerical integration difficulties.
184+
137185
**Accuracy Control:**
138186

139187
- ``rtol``: Relative tolerance for numerical integration (default: 1e-6)
@@ -252,6 +300,94 @@ Key performance indicators:
252300
static_margin = flight.static_margin
253301
stability_margin = flight.stability_margin
254302

303+
Accessing Raw Simulation Data
304+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305+
306+
For users who need direct access to the raw numerical simulation results,
307+
the Flight object provides the complete solution array through the ``solution``
308+
and ``solution_array`` attributes.
309+
310+
**Flight.solution**
311+
312+
The ``Flight.solution`` attribute contains the raw simulation data as a list of
313+
state vectors, where each row represents the rocket's complete state at a specific time:
314+
315+
.. jupyter-execute::
316+
317+
# Access the raw solution list
318+
raw_solution = flight.solution
319+
320+
# Each element is a 14-element state vector:
321+
# [time, x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
322+
initial_state = flight.solution[0] # First time step
323+
final_state = flight.solution[-1] # Last time step
324+
325+
print(f"Initial state: {initial_state}")
326+
print(f"Final state: {final_state}")
327+
328+
**Flight.solution_array**
329+
330+
For easier numerical analysis, use ``solution_array`` which provides the same data
331+
as a NumPy array:
332+
333+
.. jupyter-execute::
334+
335+
import numpy as np
336+
337+
# Get solution as NumPy array for easier manipulation
338+
solution_array = flight.solution_array # Shape: (n_time_steps, 14)
339+
340+
# Extract specific columns (state variables)
341+
time_array = solution_array[:, 0] # Time values
342+
position_data = solution_array[:, 1:4] # X, Y, Z positions
343+
velocity_data = solution_array[:, 4:7] # Vx, Vy, Vz velocities
344+
quaternions = solution_array[:, 7:11] # e0, e1, e2, e3
345+
angular_velocities = solution_array[:, 11:14] # w1, w2, w3
346+
347+
# Example: Calculate velocity magnitude manually
348+
velocity_magnitude = np.sqrt(np.sum(velocity_data**2, axis=1))
349+
350+
**State Vector Format**
351+
352+
Each row in the solution array follows this 14-element format:
353+
354+
.. code-block:: python
355+
356+
[time, x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
357+
358+
Where:
359+
- ``time``: Simulation time in seconds
360+
- ``x, y, z``: Position coordinates in meters (East, North, Up)
361+
- ``vx, vy, vz``: Velocity components in m/s (East, North, Up)
362+
- ``e0, e1, e2, e3``: Euler parameters (quaternions) for attitude
363+
- ``w1, w2, w3``: Angular velocities in rad/s (body frame: roll, pitch, yaw rates)
364+
365+
**Getting State at Specific Time**
366+
367+
You can extract the rocket's state at any specific time during the flight:
368+
369+
.. jupyter-execute::
370+
371+
# Get complete state vector at t=10 seconds
372+
state_at_10s = flight.get_solution_at_time(10.0)
373+
374+
print(f"State at t=10s: {state_at_10s}")
375+
376+
# Extract specific values from the state vector
377+
time_10s = state_at_10s[0]
378+
altitude_10s = state_at_10s[3] # Z coordinate
379+
speed_10s = np.sqrt(state_at_10s[4]**2 + state_at_10s[5]**2 + state_at_10s[6]**2)
380+
381+
print(f"At t={time_10s}s: altitude={altitude_10s:.1f}m, speed={speed_10s:.1f}m/s")
382+
383+
This raw data access is particularly useful for:
384+
385+
- Custom post-processing and analysis
386+
- Exporting data to external tools
387+
- Implementing custom flight metrics
388+
- Monte Carlo analysis and statistical studies
389+
- Integration with other simulation frameworks
390+
255391

256392
Plotting Flight Data
257393
--------------------
@@ -392,12 +528,22 @@ RocketPy supports different sets of equations of motion:
392528
Integration Method Selection
393529
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394530

395-
You can choose different numerical integration methods:
531+
You can choose different numerical integration methods using the ``ode_solver`` parameter.
532+
RocketPy supports the following integration methods from ``scipy.integrate.solve_ivp``:
533+
534+
**Available ODE Solvers:**
535+
536+
- **'LSODA'** (default): Recommended for most flights. Automatically switches between stiff and non-stiff methods
537+
- **'RK45'**: Explicit Runge-Kutta method of order 5(4). Good for non-stiff problems
538+
- **'RK23'**: Explicit Runge-Kutta method of order 3(2). Faster but less accurate than RK45
539+
- **'DOP853'**: Explicit Runge-Kutta method of order 8. High accuracy for smooth problems
540+
- **'Radau'**: Implicit Runge-Kutta method of order 5. Good for stiff problems
541+
- **'BDF'**: Implicit multi-step variable-order method. Efficient for stiff problems
396542

397543
.. code-block:: python
398544
399-
# High-accuracy integration (default)
400-
flight_accurate = Flight(
545+
# High-accuracy integration (default, recommended for most cases)
546+
flight_default = Flight(
401547
rocket=rocket,
402548
environment=env,
403549
rail_length=5.2,
@@ -412,6 +558,26 @@ You can choose different numerical integration methods:
412558
ode_solver="RK45"
413559
)
414560
561+
# Very high accuracy for smooth problems
562+
flight_high_accuracy = Flight(
563+
rocket=rocket,
564+
environment=env,
565+
rail_length=5.2,
566+
ode_solver="DOP853"
567+
)
568+
569+
# For stiff problems (e.g., complex motor thrust curves)
570+
flight_stiff = Flight(
571+
rocket=rocket,
572+
environment=env,
573+
rail_length=5.2,
574+
ode_solver="BDF"
575+
)
576+
577+
You can also pass a custom ``scipy.integrate.OdeSolver`` object for advanced use cases.
578+
For more information on integration methods, see the `scipy documentation
579+
<https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html>`_.
580+
415581
Exporting Flight Data
416582
---------------------
417583

0 commit comments

Comments
 (0)