How it works


Python Flight Mechanics Engine

This installs pyfme to be run in this online notebook


In [ ]:
!pip install git+https://github.com/AeroPython/PyFME.git

Aircraft

In order to perform a simulation, the first thing we need is an aircraft:


In [1]:
from pyfme.aircrafts import Cessna172

In [2]:
aircraft = Cessna172()

Aircraft will provide the simulator the forces, moments and inertial properties in order to perform the integration of the dynamic system equations:


In [3]:
print(f"Aircraft mass: {aircraft.mass} kg")
print(f"Aircraft inertia tensor: \n {aircraft.inertia} kg/m²")


Aircraft mass: 1043.2616 kg
Aircraft inertia tensor: 
 [[ 1285.3154166      0.             0.        ]
 [    0.          1824.9309607      0.        ]
 [    0.             0.          2666.89390765]] kg/m²

In [4]:
print(f"forces: {aircraft.total_forces} N")
print(f"moments: {aircraft.total_moments} N·m")


forces: [ 0.  0.  0.] N
moments: [ 0.  0.  0.] N·m

For the aircraft, in order to calculate its forces and moments it is necessary to set the controls values within the limits:


In [5]:
print(aircraft.controls)


{'delta_elevator': 0, 'delta_aileron': 0, 'delta_rudder': 0, 'delta_t': 0}

In [6]:
print(aircraft.control_limits)


{'delta_elevator': (-0.4537856055185257, 0.48869219055841229), 'delta_aileron': (-0.26179938779914941, 0.3490658503988659), 'delta_rudder': (-0.27925268031909273, 0.27925268031909273), 'delta_t': (0, 1)}

but also to provide and environment (ie. atmosphere, winds, gravity) and the aircraft state, which will also determine the aerodynamic contribution.

Environment


In [7]:
from pyfme.environment.atmosphere import ISA1976
from pyfme.environment.wind import NoWind
from pyfme.environment.gravity import VerticalConstant

In [8]:
atmosphere = ISA1976()
gravity = VerticalConstant()
wind = NoWind()

The atmosphere, wind and gravity model make up the environment:


In [9]:
from pyfme.environment import Environment

In [10]:
environment = Environment(atmosphere, gravity, wind)

The environment has an update method which given the state (ie. position, altitude...) updates the environment variables (ie. density, wind magnitude, gravity force...)


In [11]:
help(environment.update)


Help on method update in module pyfme.environment.environment:

update(state) method of pyfme.environment.environment.Environment instance

State

Even if the state can be set manually by giving the position, attitude, velocity, angular velocities... Most of the times, the user will want to trim the aircraft in a stationary condition. The aircraft controls to flight in that condition will be also provided by the trimmer.


In [12]:
from pyfme.utils.trimmer import steady_state_trim

In [13]:
help(steady_state_trim)


Help on function steady_state_trim in module pyfme.utils.trimmer:

steady_state_trim(aircraft, environment, pos, psi, TAS, controls, gamma=0, turn_rate=0, exclude=None, verbose=0)
    Finds a combination of values of the state and control variables
    that correspond to a steady-state flight condition.
    
    Steady-state aircraft flight is defined as a condition in which all
    of the motion variables are constant or zero. That is, the linear and
    angular velocity components are constant (or zero), thus all
     acceleration components are zero.
    
    Parameters
    ----------
    aircraft : Aircraft
        Aircraft to be trimmed.
    environment : Environment
        Environment where the aircraft is trimmed including atmosphere,
        gravity and wind.
    pos : Position
        Initial position of the aircraft.
    psi : float, opt
        Initial yaw angle (rad).
    TAS : float
        True Air Speed (m/s).
    controls : dict
        Initial value guess for each control or fixed value if control is
        included in exclude.
    gamma : float, optional
        Flight path angle (rad).
    turn_rate : float, optional
        Turn rate, d(psi)/dt (rad/s).
    exclude : list, optional
        List with controls not to be trimmed. If not given, every control
        is considered in the trim process.
    verbose : {0, 1, 2}, optional
        Level of least_squares verbosity:
            * 0 (default) : work silently.
            * 1 : display a termination report.
            * 2 : display progress during iterations (not supported by 'lm'
              method).
    
    Returns
    -------
    state : AircraftState
        Trimmed aircraft state.
    trimmed_controls : dict
        Trimmed aircraft controls
    
    Notes
    -----
    See section 3.4 in [1] for the algorithm description.
    See section 2.5 in [1] for the definition of steady-state flight
    condition.
    
    References
    ----------
    .. [1] Stevens, BL and Lewis, FL, "Aircraft Control and Simulation",
        Wiley-lnterscience.


In [14]:
from pyfme.models.state.position import EarthPosition

In [15]:
pos = EarthPosition(x=0, y=0, height=1000)
psi = 0.5  # rad
TAS = 45  # m/s
controls0 = {'delta_elevator': 0, 'delta_aileron': 0, 'delta_rudder': 0, 'delta_t': 0.5}

In [16]:
trimmed_state, trimmed_controls = steady_state_trim(
    aircraft,
    environment,
    pos,
    psi,
    TAS,
    controls0
)

In [17]:
trimmed_state


Out[17]:
Aircraft State 
x_e: 0.00 m, y_e: 0.00 m, z_e: -1000.00 m 
theta: 0.076 rad, phi: 0.000 rad, psi: 0.500 rad 
u: 44.87 m/s, v: 0.00 m/s, w: 3.40 m/s 
P: 0.00 rad/s, Q: 0.00 rad/s, R: 0.00 rad/s 
u_dot: 0.00 m/s², v_dot: -0.00 m/s², w_dot: 0.00 m/s² 
P_dot: 0.00 rad/s², Q_dot: -0.00 rad/s², R_dot: 0.00 rad/s² 

In [18]:
trimmed_controls


Out[18]:
{'delta_aileron': 2.4925251333542672e-18,
 'delta_elevator': -0.048951124635247797,
 'delta_rudder': -1.0367511099559949e-17,
 'delta_t': 0.57799667845248515}

Now, all the necessary elements in order to calculate forces and moments are available


In [19]:
# Environment conditions for the current state:
environment.update(trimmed_state)

# Forces and moments calculation:
forces, moments = aircraft.calculate_forces_and_moments(trimmed_state, environment, controls0)

In [20]:
forces, moments


Out[20]:
(array([  1.68256520e-11,  -1.49629613e-18,   2.36468622e-11]),
 array([  3.03652088e-14,  -1.54951943e-11,   3.06443592e-14]))

The aircraft is trimmed indeed: the total forces and moments (aerodynamics + gravity + thrust) are zero

Simulation

In order to simulate the dynamics of the aircraft under certain inputs in an environment, the user can set up a simulation using a dynamic system:


In [21]:
from pyfme.models import EulerFlatEarth

In [22]:
system = EulerFlatEarth(t0=0, full_state=trimmed_state)

Constant Controls

Let's set the controls for the aircraft during the simulation. As a first step we will set them constant and equal to the trimmed values.


In [23]:
from pyfme.utils.input_generator import Constant

In [24]:
controls = controls = {
    'delta_elevator': Constant(trimmed_controls['delta_elevator']),
    'delta_aileron': Constant(trimmed_controls['delta_aileron']),
    'delta_rudder': Constant(trimmed_controls['delta_rudder']),
    'delta_t': Constant(trimmed_controls['delta_t'])
}

In [25]:
from pyfme.simulator import Simulation

In [26]:
sim = Simulation(aircraft, system, environment, controls)

Once the simulation is set, the propagation can be performed:


In [27]:
results = sim.propagate(10)


time: 100%|█████████▉| 9.999999999999831/10 [00:05<00:00,  1.91it/s]  

The results are returned in a DataFrame:


In [28]:
results


Out[28]:
Fx Fy Fz Mach Mx My Mz TAS a aileron ... thrust u v v_down v_east v_north w x_earth y_earth z_earth
time
0.01 1.682565e-11 3.988299e-17 2.364686e-11 0.133756 2.931208e-14 -1.502423e-11 3.036133e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.373417e-16 4.440892e-16 21.574149 39.491215 3.396464 0 0 -1000
0.02 1.682565e-11 1.113008e-16 2.364686e-11 0.133756 2.830690e-14 -1.456759e-11 3.008343e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.372773e-16 4.440892e-16 21.574149 39.491215 3.396464 0 0 -1000
0.03 1.682565e-11 2.118543e-16 2.364686e-11 0.133756 2.734757e-14 -1.412482e-11 2.981037e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.371706e-16 4.440892e-16 21.574149 39.491215 3.396464 1 0 -1000
0.04 1.682565e-11 3.406791e-16 2.364686e-11 0.133756 2.643204e-14 -1.369551e-11 2.954186e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.370221e-16 4.440892e-16 21.574149 39.491215 3.396464 1 0 -1000
0.05 1.682565e-11 4.969478e-16 2.364686e-11 0.133756 2.555839e-14 -1.327925e-11 2.927764e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.368322e-16 4.440892e-16 21.574149 39.491215 3.396464 1 1 -1000
0.06 1.671197e-11 6.798681e-16 2.546585e-11 0.133756 2.472474e-14 -1.287564e-11 2.901745e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.366015e-16 4.440892e-16 21.574149 39.491215 3.396464 2 1 -1000
0.07 1.671197e-11 8.886811e-16 2.546585e-11 0.133756 2.392932e-14 -1.248430e-11 2.876107e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.363303e-16 4.440892e-16 21.574149 39.491215 3.396464 2 1 -1000
0.08 1.671197e-11 1.122661e-15 2.546585e-11 0.133756 2.317044e-14 -1.210485e-11 2.850826e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.360192e-16 4.440892e-16 21.574149 39.491215 3.396464 3 1 -1000
0.09 1.671197e-11 1.381110e-15 2.546585e-11 0.133756 2.244646e-14 -1.173694e-11 2.825879e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.356686e-16 4.440892e-16 21.574149 39.491215 3.396464 3 1 -1000
0.10 1.682565e-11 1.663364e-15 2.546585e-11 0.133756 2.175583e-14 -1.138021e-11 2.801248e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.352790e-16 8.881784e-16 21.574149 39.491215 3.396464 3 2 -1000
0.11 1.705303e-11 1.968783e-15 2.546585e-11 0.133756 2.109706e-14 -1.103432e-11 2.776911e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.348508e-16 1.776357e-15 21.574149 39.491215 3.396464 4 2 -1000
0.12 1.716671e-11 2.296755e-15 2.546585e-11 0.133756 2.046872e-14 -1.069894e-11 2.752851e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.343846e-16 2.220446e-15 21.574149 39.491215 3.396464 4 2 -1000
0.13 1.728040e-11 2.646694e-15 2.546585e-11 0.133756 1.986945e-14 -1.037376e-11 2.729050e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.338806e-16 2.664535e-15 21.574149 39.491215 3.396464 5 2 -1000
0.14 1.739409e-11 3.018038e-15 2.546585e-11 0.133756 1.929794e-14 -1.005846e-11 2.705491e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.333395e-16 3.552714e-15 21.574149 39.491215 3.396464 5 3 -1000
0.15 1.750777e-11 3.410248e-15 2.546585e-11 0.133756 1.875295e-14 -9.752741e-12 2.682158e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.327615e-16 3.996803e-15 21.574149 39.491215 3.396464 5 3 -1000
0.16 1.762146e-11 3.816426e-15 2.728484e-11 0.133756 1.819868e-14 -9.079912e-12 -7.014492e-16 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.321473e-16 4.440892e-15 21.574149 39.491215 3.396464 6 3 -1000
0.17 1.773515e-11 4.196172e-15 2.728484e-11 0.133756 1.744420e-14 -8.803938e-12 -8.500321e-16 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.315258e-16 4.440892e-15 21.574149 39.491215 3.396464 6 3 -1000
0.18 1.750777e-11 4.585643e-15 2.910383e-11 0.133756 1.670343e-14 -8.156199e-12 8.450127e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.309147e-16 4.440892e-15 21.574149 39.491215 3.396464 7 3 -1000
0.19 1.762146e-11 5.007389e-15 2.910383e-11 0.133756 1.609528e-14 -7.147997e-12 1.098344e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.303082e-16 4.884981e-15 21.574149 39.491215 3.396464 7 4 -1000
0.20 1.784883e-11 5.449073e-15 2.910383e-11 0.133756 1.554361e-14 -6.930741e-12 1.081493e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.296945e-16 4.884981e-15 21.574149 39.491215 3.396464 7 4 -1000
0.21 1.784883e-11 5.904860e-15 2.910383e-11 0.133756 1.501568e-14 -6.720088e-12 1.064987e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.290711e-16 5.329071e-15 21.574149 39.491215 3.396464 8 4 -1000
0.22 1.750777e-11 6.378532e-15 3.456080e-11 0.133756 1.453281e-14 -6.143234e-12 1.553733e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.284374e-16 5.329071e-15 21.574149 39.491215 3.396464 8 4 -1000
0.23 1.750777e-11 6.868901e-15 3.456080e-11 0.133756 1.408436e-14 -5.576365e-12 2.210854e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.277876e-16 5.329071e-15 21.574149 39.491215 3.396464 9 4 -1000
0.24 1.750777e-11 7.388058e-15 3.637979e-11 0.133756 1.373220e-14 -5.406877e-12 2.191748e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.271166e-16 5.773160e-15 21.574149 39.491215 3.396464 9 5 -1000
0.25 1.762146e-11 7.912658e-15 3.819878e-11 0.133756 1.334583e-14 -4.869937e-12 1.028275e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.264191e-16 5.773160e-15 21.574149 39.491215 3.396464 9 5 -1000
0.26 1.762146e-11 8.435388e-15 4.001777e-11 0.133756 1.290080e-14 -4.341769e-12 1.957141e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.257109e-16 6.217249e-15 21.574149 39.491215 3.396464 10 5 -1000
0.27 1.773515e-11 8.990677e-15 4.001777e-11 0.133756 1.258186e-14 -4.209805e-12 1.939235e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.249888e-16 6.217249e-15 21.574149 39.491215 3.396464 10 5 -1000
0.28 1.750777e-11 9.568884e-15 4.183676e-11 0.133756 1.232674e-14 -3.709249e-12 3.032277e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.242409e-16 6.217249e-15 21.574149 39.491215 3.396464 11 6 -1000
0.29 1.762146e-11 1.017752e-14 4.365575e-11 0.133756 1.216324e-14 -3.216358e-12 1.797171e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.234528e-16 6.661338e-15 21.574149 39.491215 3.396464 11 6 -1000
0.30 1.762146e-11 1.077698e-14 4.365575e-11 0.133756 1.188180e-14 -2.738449e-12 1.206311e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.226298e-16 6.661338e-15 21.574149 39.491215 3.396464 11 6 -1000
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
9.71 1.496119e-10 9.333875e-13 6.366463e-11 0.133756 2.985816e-16 3.356707e-26 7.112137e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.049488e-15 5.906386e-13 21.574149 39.491215 3.396464 383 209 -1000
9.72 1.497256e-10 9.345363e-13 6.366463e-11 0.133756 3.020084e-16 3.222438e-26 7.119961e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.050029e-15 5.910827e-13 21.574149 39.491215 3.396464 383 209 -1000
9.73 1.498393e-10 9.356856e-13 6.366463e-11 0.133756 3.054401e-16 3.088170e-26 7.127691e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.050570e-15 5.919709e-13 21.574149 39.491215 3.396464 384 209 -1000
9.74 1.500666e-10 9.368356e-13 6.366463e-11 0.133756 3.088762e-16 3.088170e-26 7.135326e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.051109e-15 5.924150e-13 21.574149 39.491215 3.396464 384 210 -1000
9.75 1.501803e-10 9.379861e-13 6.366463e-11 0.133756 3.123162e-16 2.953902e-26 7.142868e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.051648e-15 5.933032e-13 21.574149 39.491215 3.396464 385 210 -1000
9.76 1.502940e-10 9.391371e-13 6.366463e-11 0.133756 3.157596e-16 2.819634e-26 7.150315e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.052185e-15 5.937473e-13 21.574149 39.491215 3.396464 385 210 -1000
9.77 1.504077e-10 9.402888e-13 6.548362e-11 0.133756 3.192060e-16 2.551097e-26 7.157668e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.052722e-15 5.946355e-13 21.574149 39.491215 3.396464 385 210 -1000
9.78 1.505214e-10 9.414411e-13 6.548362e-11 0.133756 3.226548e-16 2.551097e-26 7.164927e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.053258e-15 5.955236e-13 21.574149 39.491215 3.396464 386 210 -1000
9.79 1.505214e-10 9.425939e-13 6.548362e-11 0.133756 3.261057e-16 2.416829e-26 7.172090e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.053792e-15 5.955236e-13 21.574149 39.491215 3.396464 386 211 -1000
9.80 1.507487e-10 9.437473e-13 6.548362e-11 0.133756 3.295581e-16 2.282561e-26 7.179160e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.054326e-15 5.959677e-13 21.574149 39.491215 3.396464 387 211 -1000
9.81 1.508624e-10 9.449014e-13 6.548362e-11 0.133756 3.330116e-16 2.148292e-26 7.186134e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.054859e-15 5.968559e-13 21.574149 39.491215 3.396464 387 211 -1000
9.82 1.509761e-10 9.460560e-13 6.548362e-11 0.133756 3.364657e-16 2.014024e-26 7.193015e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.055391e-15 5.973000e-13 21.574149 39.491215 3.396464 387 211 -1000
9.83 1.510898e-10 9.472112e-13 6.548362e-11 0.133756 3.399199e-16 2.014024e-26 7.199800e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.055922e-15 5.977441e-13 21.574149 39.491215 3.396464 388 212 -1000
9.84 1.513172e-10 9.483671e-13 6.548362e-11 0.133756 3.433738e-16 1.879756e-26 7.206491e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.056453e-15 5.986323e-13 21.574149 39.491215 3.396464 388 212 -1000
9.85 1.514309e-10 9.495235e-13 6.548362e-11 0.133756 3.468269e-16 1.745487e-26 7.213087e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.056982e-15 5.990763e-13 21.574149 39.491215 3.396464 388 212 -1000
9.86 1.515446e-10 9.506806e-13 6.548362e-11 0.133756 3.502788e-16 1.745487e-26 7.219589e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.057510e-15 5.999645e-13 21.574149 39.491215 3.396464 389 212 -1000
9.87 1.516582e-10 9.518383e-13 6.548362e-11 0.133756 3.537290e-16 1.745487e-26 7.225996e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.058037e-15 6.004086e-13 21.574149 39.491215 3.396464 389 212 -1000
9.88 1.517719e-10 9.529966e-13 6.548362e-11 0.133756 3.571770e-16 1.745487e-26 7.232309e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.058563e-15 6.008527e-13 21.574149 39.491215 3.396464 390 213 -1000
9.89 1.521130e-10 9.541555e-13 6.548362e-11 0.133756 3.606225e-16 1.745487e-26 7.238527e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.059089e-15 6.017409e-13 21.574149 39.491215 3.396464 390 213 -1000
9.90 1.522267e-10 9.553150e-13 6.548362e-11 0.133756 3.640649e-16 1.745487e-26 7.244651e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.059613e-15 6.021850e-13 21.574149 39.491215 3.396464 390 213 -1000
9.91 1.523404e-10 9.564752e-13 6.548362e-11 0.133756 3.675038e-16 1.745487e-26 7.250681e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.060137e-15 6.030731e-13 21.574149 39.491215 3.396464 391 213 -1000
9.92 1.524540e-10 9.576360e-13 6.548362e-11 0.133756 3.709388e-16 1.745487e-26 7.256617e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.060659e-15 6.035172e-13 21.574149 39.491215 3.396464 391 214 -1000
9.93 1.526814e-10 9.587975e-13 6.548362e-11 0.133756 3.743695e-16 1.745487e-26 7.262459e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.061180e-15 6.039613e-13 21.574149 39.491215 3.396464 392 214 -1000
9.94 1.527951e-10 9.599596e-13 6.548362e-11 0.133756 3.777954e-16 1.745487e-26 7.268207e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.061701e-15 6.048495e-13 21.574149 39.491215 3.396464 392 214 -1000
9.95 1.529088e-10 9.611223e-13 6.548362e-11 0.133756 3.812161e-16 1.745487e-26 7.273862e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.062220e-15 6.052936e-13 21.574149 39.491215 3.396464 392 214 -1000
9.96 1.530225e-10 9.622857e-13 6.548362e-11 0.133756 3.846312e-16 1.745487e-26 7.279423e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.062739e-15 6.061818e-13 21.574149 39.491215 3.396464 393 214 -1000
9.97 1.531362e-10 9.634497e-13 6.548362e-11 0.133756 3.880402e-16 1.745487e-26 7.284891e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.063256e-15 6.066259e-13 21.574149 39.491215 3.396464 393 215 -1000
9.98 1.533635e-10 9.646144e-13 6.548362e-11 0.133756 3.914427e-16 1.745487e-26 7.290265e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.063773e-15 6.070699e-13 21.574149 39.491215 3.396464 394 215 -1000
9.99 1.534772e-10 9.657797e-13 6.548362e-11 0.133756 3.948383e-16 1.745487e-26 7.295547e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.064288e-15 6.079581e-13 21.574149 39.491215 3.396464 394 215 -1000
10.00 1.535909e-10 9.669457e-13 6.548362e-11 0.133756 3.982266e-16 1.745487e-26 7.300736e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 1.064803e-15 6.084022e-13 21.574149 39.491215 3.396464 394 215 -1000

1000 rows × 35 columns


In [29]:
%matplotlib inline

In [30]:
kwargs = {'marker': '.',
          'subplots': True,
          'sharex': True,
          'figsize': (12, 6)}

In [31]:
results.plot(y=['x_earth', 'y_earth', 'height'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [32]:
results.plot(y=['psi', 'theta', 'phi'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [33]:
results.plot(y=['v_north', 'v_east', 'v_down'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [34]:
results.plot(y=['p', 'q', 'r'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [35]:
results.plot(y=['alpha', 'beta', 'TAS'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [36]:
results.plot(y=['Fx', 'Fy', 'Fz'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [37]:
results.plot(y=['Mx', 'My', 'Mz'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [38]:
results.plot(y=['elevator', 'aileron', 'rudder', 'thrust'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

Doublet

Let's set the controls for the aircraft during the simulation. As a first step we will set them constant and equal to the trimmed values.


In [39]:
from pyfme.utils.input_generator import Doublet

In [40]:
de0 = trimmed_controls['delta_elevator']

In [41]:
controls = controls = {
    'delta_elevator': Doublet(t_init=2, T=1, A=0.1, offset=de0),
    'delta_aileron': Constant(trimmed_controls['delta_aileron']),
    'delta_rudder': Constant(trimmed_controls['delta_rudder']),
    'delta_t': Constant(trimmed_controls['delta_t'])
}

In [42]:
sim = Simulation(aircraft, system, environment, controls)

Once the simulation is set, the propagation can be performed:


In [43]:
results = sim.propagate(90)


time: 90.00000000000914it [00:48,  1.88it/s]                          

In [44]:
results.plot(y=['x_earth', 'y_earth', 'height'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [45]:
results.plot(y=['psi', 'theta', 'phi'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [46]:
results.plot(y=['v_north', 'v_east', 'v_down'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [47]:
results.plot(y=['p', 'q', 'r'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [48]:
results.plot(y=['alpha', 'beta', 'TAS'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [49]:
results.plot(y=['Fx', 'Fy', 'Fz'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [50]:
results.plot(y=['Mx', 'My', 'Mz'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

In [51]:
results.plot(y=['elevator', 'aileron', 'rudder', 'thrust'], **kwargs);


/home/asaez/miniconda3/envs/pyfme/lib/python3.6/site-packages/pandas/plotting/_core.py:1714: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label

Propagating only one time step


In [52]:
dt = 0.05  # seconds
sim = Simulation(aircraft, system, environment, controls, dt)

In [53]:
results = sim.propagate(0.5)
results


time: 100%|█████████▉| 0.49999999999999994/0.5 [00:00<00:00,  4.02it/s]
Out[53]:
Fx Fy Fz Mach Mx My Mz TAS a aileron ... thrust u v v_down v_east v_north w x_earth y_earth z_earth
time
0.05 1.716671e-11 2.641222e-16 2.182787e-11 0.133756 2.459194e-14 -1.360312e-11 8.035347e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.371463e-16 1.332268e-15 21.574149 39.491215 3.396464 1 1 -1000
0.10 1.739409e-11 1.000965e-15 2.364686e-11 0.133756 1.976768e-14 -1.164692e-11 7.251039e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.369266e-16 2.664535e-15 21.574149 39.491215 3.396464 3 2 -1000
0.15 1.739409e-11 2.337016e-15 2.728484e-11 0.133756 1.678983e-14 -9.240578e-12 6.009923e-16 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.365954e-16 3.552714e-15 21.574149 39.491215 3.396464 5 3 -1000
0.20 1.762146e-11 3.932746e-15 2.910383e-11 0.133756 1.365093e-14 -6.789590e-12 1.213662e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.357530e-16 4.884981e-15 21.574149 39.491215 3.396464 7 4 -1000
0.25 1.762146e-11 5.945782e-15 3.637979e-11 0.133756 1.163916e-14 -5.474300e-12 1.650906e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.346854e-16 6.661338e-15 21.574149 39.491215 3.396464 9 5 -1000
0.30 1.807621e-11 8.315261e-15 4.001777e-11 0.133756 1.020804e-14 -3.640737e-12 2.051842e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.330276e-16 7.993606e-15 21.574149 39.491215 3.396464 11 6 -1000
0.35 1.841727e-11 1.098849e-14 4.365575e-11 0.133756 9.148544e-15 -2.045869e-12 1.306538e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.307814e-16 9.769963e-15 21.574149 39.491215 3.396464 13 7 -1000
0.40 1.875833e-11 1.383942e-14 4.729372e-11 0.133756 7.977795e-15 -1.049373e-12 7.766174e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.281022e-16 1.199041e-14 21.574149 39.491215 3.396464 15 8 -1000
0.45 1.887202e-11 1.687040e-14 5.275069e-11 0.133756 7.010262e-15 1.565743e-13 1.094014e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.252482e-16 1.421085e-14 21.574149 39.491215 3.396464 17 9 -1000
0.50 1.944045e-11 2.009447e-14 5.456968e-11 0.133756 6.310511e-15 8.749163e-13 1.579341e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.221523e-16 1.643130e-14 21.574149 39.491215 3.396464 19 10 -1000

10 rows × 35 columns

We can propagate for one time step even once the simulation has been propagated before:


In [54]:
results = sim.propagate(sim.time+dt)
results


time: 100%|██████████| 0.55/0.55 [00:00<00:00, 73.33it/s]
Out[54]:
Fx Fy Fz Mach Mx My Mz TAS a aileron ... thrust u v v_down v_east v_north w x_earth y_earth z_earth
time
0.05 1.716671e-11 2.641222e-16 2.182787e-11 0.133756 2.459194e-14 -1.360312e-11 8.035347e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.371463e-16 1.332268e-15 21.574149 39.491215 3.396464 1 1 -1000
0.10 1.739409e-11 1.000965e-15 2.364686e-11 0.133756 1.976768e-14 -1.164692e-11 7.251039e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.369266e-16 2.664535e-15 21.574149 39.491215 3.396464 3 2 -1000
0.15 1.739409e-11 2.337016e-15 2.728484e-11 0.133756 1.678983e-14 -9.240578e-12 6.009923e-16 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.365954e-16 3.552714e-15 21.574149 39.491215 3.396464 5 3 -1000
0.20 1.762146e-11 3.932746e-15 2.910383e-11 0.133756 1.365093e-14 -6.789590e-12 1.213662e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.357530e-16 4.884981e-15 21.574149 39.491215 3.396464 7 4 -1000
0.25 1.762146e-11 5.945782e-15 3.637979e-11 0.133756 1.163916e-14 -5.474300e-12 1.650906e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.346854e-16 6.661338e-15 21.574149 39.491215 3.396464 9 5 -1000
0.30 1.807621e-11 8.315261e-15 4.001777e-11 0.133756 1.020804e-14 -3.640737e-12 2.051842e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.330276e-16 7.993606e-15 21.574149 39.491215 3.396464 11 6 -1000
0.35 1.841727e-11 1.098849e-14 4.365575e-11 0.133756 9.148544e-15 -2.045869e-12 1.306538e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.307814e-16 9.769963e-15 21.574149 39.491215 3.396464 13 7 -1000
0.40 1.875833e-11 1.383942e-14 4.729372e-11 0.133756 7.977795e-15 -1.049373e-12 7.766174e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.281022e-16 1.199041e-14 21.574149 39.491215 3.396464 15 8 -1000
0.45 1.887202e-11 1.687040e-14 5.275069e-11 0.133756 7.010262e-15 1.565743e-13 1.094014e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.252482e-16 1.421085e-14 21.574149 39.491215 3.396464 17 9 -1000
0.50 1.944045e-11 2.009447e-14 5.456968e-11 0.133756 6.310511e-15 8.749163e-13 1.579341e-14 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.221523e-16 1.643130e-14 21.574149 39.491215 3.396464 19 10 -1000
0.55 1.978151e-11 2.349783e-14 5.820766e-11 0.133756 5.781185e-15 1.472049e-12 4.463381e-15 45.0 336.434581 2.492525e-18 ... 0.577997 44.87164 8.187520e-16 1.909584e-14 21.574149 39.491215 3.396464 21 11 -1000

11 rows × 35 columns

Notice that results will include the previous timesteps as well as the last one. To get just the last one one can use pandas loc or iloc:


In [55]:
results.iloc[-1]  # last time step


Out[55]:
Fx             1.978151e-11
Fy             2.349783e-14
Fz             5.820766e-11
Mach           1.337556e-01
Mx             5.781185e-15
My             1.472049e-12
Mz             4.463381e-15
TAS            4.500000e+01
a              3.364346e+02
aileron        2.492525e-18
alpha          7.554882e-02
beta           1.819449e-17
elevator      -4.895112e-02
height         1.000000e+03
p              5.629520e-18
phi            2.023926e-18
pressure       8.987627e+04
psi            5.000000e-01
q             -1.670347e-15
q_inf          1.125555e+03
r              2.473422e-18
rho            1.111660e+00
rudder        -1.036751e-17
temperature    2.816510e+02
theta          7.554882e-02
thrust         5.779967e-01
u              4.487164e+01
v              8.187520e-16
v_down         1.909584e-14
v_east         2.157415e+01
v_north        3.949122e+01
w              3.396464e+00
x_earth        2.100000e+01
y_earth        1.100000e+01
z_earth       -1.000000e+03
Name: 0.55, dtype: float64

In [56]:
results.loc[sim.time]  # results for current simulation time


Out[56]:
Fx             1.978151e-11
Fy             2.349783e-14
Fz             5.820766e-11
Mach           1.337556e-01
Mx             5.781185e-15
My             1.472049e-12
Mz             4.463381e-15
TAS            4.500000e+01
a              3.364346e+02
aileron        2.492525e-18
alpha          7.554882e-02
beta           1.819449e-17
elevator      -4.895112e-02
height         1.000000e+03
p              5.629520e-18
phi            2.023926e-18
pressure       8.987627e+04
psi            5.000000e-01
q             -1.670347e-15
q_inf          1.125555e+03
r              2.473422e-18
rho            1.111660e+00
rudder        -1.036751e-17
temperature    2.816510e+02
theta          7.554882e-02
thrust         5.779967e-01
u              4.487164e+01
v              8.187520e-16
v_down         1.909584e-14
v_east         2.157415e+01
v_north        3.949122e+01
w              3.396464e+00
x_earth        2.100000e+01
y_earth        1.100000e+01
z_earth       -1.000000e+03
Name: 0.55, dtype: float64