Automatic Control Knowledge Repository

You currently have javascript disabled. Some features will be unavailable. Please consider enabling javascript.

Details for: "B767 aircraft at a flutter condition"

Name: B767 aircraft at a flutter condition (Key: COM18)
Path: ackrep_data/system_models/compleib_models/AC18 View on GitHub
Type: system_model
Short Description: AC18 B767 aircraft at a flutter condition Davison see AC10! reduced order system generated by /export/home/leibfr/bsp37/bsp37bal.m
Created: 2022-10-10 15:53:24
Compatible Environment: default_conda_environment (Key: CDAMA)
Source Code [ / ] simulation.py
# This file was autogenerated from the template: simulation.py.template (2022-10-10 15:53:24).

import numpy as np
import system_model
from scipy.integrate import solve_ivp, odeint

from ackrep_core import ResultContainer
from ackrep_core.system_model_management import save_plot_in_dir
import matplotlib.pyplot as plt
import os
from ipydex import Container

# link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html


def simulate():
    """
    simulate the system model with scipy.integrate.solve_ivp

    :return: result of solve_ivp, might contains input function
    """

    model = system_model.Model()

    rhs_xx_pp_symb = model.get_rhs_symbolic()
    rhs = model.get_rhs_func()

    # initial state values
    xx0 = np.ones(model.sys_dim)

    t_end = 10
    tt = np.linspace(0, t_end, 1000)

    simulation_data = solve_ivp(rhs, (0, t_end), xx0, t_eval=tt)

    # using odeint for models with large state vectors
    # res = odeint(rhs, y0=xx0, t=tt, tfirst=True)
    # simulation_data = Container()
    # simulation_data.y = res.transpose()
    # simulation_data.t = tt

    # postprocessing: calc output
    ny = 2
    C = model.get_parameter_value("C")
    D21 = model.get_parameter_value("D21")
    output = np.zeros((ny, len(tt)))
    for i in range(len(tt)):
        output[:,i] = np.matmul(C, simulation_data.y[:,i]) # + np.matmul(D21, w)
    simulation_data.output = output

    save_plot(simulation_data)

    return simulation_data


def save_plot(simulation_data):
    """
    plot your data and save the plot
    access to data via: simulation_data.t   array of time values
                        simulation_data.y   array of data components
                        simulation_data.uu  array of input values

    :param simulation_data: simulation_data of system_model
    :return: None
    """

    for i in range(simulation_data.output.shape[0]):
        plt.plot(simulation_data.t, simulation_data.output[i], label=f"$y_{i}$")

    plt.legend()
    plt.tight_layout()

    save_plot_in_dir()


def evaluate_simulation(simulation_data):
    """
    assert that the simulation results are as expected

    :param simulation_data: simulation_data of system_model
    :return:
    """
    expected_final_state = np.array([ 2.73485791e-06,  9.19818719e-07, -3.15388824e-06, -2.00360408e-05,
       -1.32973217e-05,  8.30823206e-06, -7.13694925e-06,  5.37979739e-06,
        2.41468043e+00, -3.10756760e+00])

    rc = ResultContainer(score=1.0)
    simulated_final_state = simulation_data.y[:, -1]
    rc.final_state_errors = [
        simulated_final_state[i] - expected_final_state[i] for i in np.arange(0, len(simulated_final_state))
    ]
    rc.success = np.allclose(expected_final_state, simulated_final_state, rtol=0, atol=1e-2)

    return rc
system_model.py
# This file was autogenerated from the template: system_model.py.template (2022-10-10 15:53:24).

import sympy as sp
import numpy as np
import symbtools as st
import importlib
import sys, os
#from ipydex import IPS, activate_ips_on_exception  

from ackrep_core.system_model_management import GenericModel, import_parameters

# Import parameter_file
params = import_parameters()


#link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html


class Model(GenericModel): 

    def initialize(self):
        """
        this function is called by the constructor of GenericModel

        :return: None
        """

        # Define number of inputs -- MODEL DEPENDENT
        self.u_dim = 2

        # Set "sys_dim" to constant value, if system dimension is constant 
        self.sys_dim = 10

        # check existence of params file
        self.has_params = True
        self.params = params
        

    # ----------- SET DEFAULT INPUT FUNCTION ---------- # 
    def uu_default_func(self):
        """
        define input function
    
        :return:(function with 2 args - t, xx_nv) default input function 
        """ 
        
        def uu_rhs(t, xx_nv):
            """
            sequence of numerical input values

            :param t:(scalar or vector) time
            :param xx_nv:(vector or array of vectors) numeric state vector
            :return:(list) numeric inputs 
            """ 
            u = np.zeros(self.u_dim)
            return u

        return uu_rhs


    # ----------- SYMBOLIC RHS FUNCTION ---------- # 

    def get_rhs_symbolic(self):
        """
        define symbolic rhs function

        :return: matrix of symbolic rhs-functions
        """
        if self.dxx_dt_symb is not None:
            return self.dxx_dt_symb

        x = self.xx_symb  
        A, B, B1, C1, C, D11, D12, D21 = self.pp_symb   # parameters
        w = np.zeros(3) # noise
        u = self.uu_symb   # inputs

        # define symbolic rhs functions
        self.dxx_dt_symb = np.matmul(A,x) + np.matmul(B1,w) + np.matmul(B,u)
        



        return self.dxx_dt_symb
    
parameters.py
# This file was autogenerated from the template: parameters.py.template (2022-10-10 15:53:24).

import sys
import os
import numpy as np
import sympy as sp

import tabulate as tab


#link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html


# set model name
model_name = 'B767 aircraft at a flutter condition'


# ---------- create symbolic parameters
A = sp.MatrixSymbol('A', 10, 10)
B = sp.MatrixSymbol('B', 10, 2)
B1 = sp.MatrixSymbol('B1', 10, 3)
C1 = sp.MatrixSymbol('C1', 5, 10)
C = sp.MatrixSymbol('C', 2, 10)
D11 = sp.MatrixSymbol('D11', 5, 3)
D12 = sp.MatrixSymbol('D12', 5, 2)
D21 = sp.MatrixSymbol('D21', 2, 3)

pp_symb = [A, B, B1, C1, C, D11, D12, D21]


# ---------- create auxiliary symbolic parameters 

# set numerical values of auxiliary parameters
# trailing "_nv" stands for "numerical value"
A_nv = sp.Matrix(np.array([[-1.96218173e+00,  2.93478561e+01,  7.09938479e+00,
        -4.27052563e+00, -2.19720836e+00,  7.02022433e+00,
         2.35656948e+00, -1.40306963e+00,  0.00000000e+00,
         0.00000000e+00],
       [-2.89729781e+01, -3.83047005e-01, -2.45254213e+00,
         6.87681195e+00,  6.38239536e-01, -2.31607847e+00,
        -1.21423520e+00,  7.87197471e-01,  0.00000000e+00,
         0.00000000e+00],
       [-6.44710154e+00,  1.83216052e+00, -8.04826868e-01,
         4.36597956e+01,  2.01284810e+00, -2.92931277e+00,
        -2.17952258e+00,  1.45964753e+00,  0.00000000e+00,
         0.00000000e+00],
       [-5.53605690e-01, -6.43547046e+00, -4.33013521e+01,
        -3.91559217e+00, -4.22367888e+00,  1.77005820e+01,
         3.36727549e+00, -2.29564242e+00,  0.00000000e+00,
         0.00000000e+00],
       [ 1.52819246e+00,  1.87500302e-01, -1.61371325e+00,
         2.75649933e+00, -7.99488823e-01,  3.65849001e+01,
         3.48459826e+00, -1.77183757e+00,  0.00000000e+00,
         0.00000000e+00],
       [-4.79608198e+00, -1.72327607e-01, -1.95196537e+00,
        -1.71293232e+01, -3.42626087e+01, -9.67071839e+00,
        -2.06893198e+01,  1.07436612e+01,  0.00000000e+00,
         0.00000000e+00],
       [-1.18111938e-01,  6.90456628e-01,  1.60965467e+00,
         1.74630944e+00, -2.04901942e+00,  2.00082173e+01,
        -3.12200502e+00,  2.76301358e+01,  0.00000000e+00,
         0.00000000e+00],
       [-6.49363841e-01, -4.28785767e-01, -1.22836446e+00,
        -9.82039173e-01,  4.32613018e-01, -9.07399499e+00,
        -2.53592198e+01, -1.46376176e+00,  0.00000000e+00,
         0.00000000e+00],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  1.16397307e+01,
         1.69018602e+02],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00, -3.10015383e+00,
        -1.14367307e+01]]))
B_nv = sp.Matrix(np.array([[ 1.96050016e+02, -2.48625964e+02],
       [ 1.35519420e+02, -1.08092698e+02],
       [ 8.22820478e+01,  3.45059108e+01],
       [ 3.88173470e+02, -8.16977915e+01],
       [-8.64042347e+01,  8.09998941e+01],
       [ 4.11451840e+02,  1.08055257e+02],
       [-2.11799057e+02, -1.12447245e+02],
       [ 1.62719831e+01, -8.03096928e+01],
       [-6.75043395e+00, -5.13305891e+00],
       [-3.80529228e-01, -1.98627271e-01]]))
B1_nv = sp.Matrix(np.array([[ 1.96050016e+02, -2.48625964e+02],
       [ 1.35519420e+02, -1.08092698e+02],
       [ 8.22820478e+01,  3.45059108e+01],
       [ 3.88173470e+02, -8.16977915e+01],
       [-8.64042347e+01,  8.09998941e+01],
       [ 4.11451840e+02,  1.08055257e+02],
       [-2.11799057e+02, -1.12447245e+02],
       [ 1.62719831e+01, -8.03096928e+01],
       [-6.75043395e+00, -5.13305891e+00],
       [-3.80529228e-01, -1.98627271e-01]]))
C1_nv = sp.Matrix(np.array([[-5.17831065e-02,  4.97408918e-03,  3.05824415e-02,
        -4.74937127e-03, -3.40836085e-02,  2.08896197e-03,
         8.48048683e-02,  2.93624869e-02, -4.29143581e-01,
         1.38941769e+00],
       [-2.51959506e-02,  8.46171194e-02, -1.27201614e-02,
        -1.88764130e-02, -2.73381391e-02, -2.53508129e-02,
         1.27010131e-01,  1.06588519e-02, -2.94542997e+00,
         8.51492319e-01],
       [-3.49186404e-02, -1.37979567e-02, -4.81092443e-03,
         1.39399957e-02, -9.43321237e-04, -1.37398529e-02,
         7.81378714e-02, -8.93968773e-02, -1.42117826e+00,
        -7.72993515e+00],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00],
       [ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
         0.00000000e+00]]))
C_nv = sp.Matrix(np.array([[ 2.53925381e-03, -1.16707666e-03,  1.27739519e-04,
        -4.18514541e-03,  6.34051980e-05,  2.14779377e-03,
        -3.03778405e-03, -3.95940559e-03,  9.61325407e-03,
        -3.63057818e-02],
       [ 4.15967367e+02, -1.79554835e+02, -2.32410488e+02,
         4.94159169e+02,  1.68026991e+02, -5.58302763e+02,
        -2.47012577e+02,  1.62864214e+02,  8.83344413e+03,
         4.68785017e+04]]))
D11_nv = sp.Matrix(np.array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]]))
D12_nv = sp.Matrix(np.array([[0.        , 0.        ],
       [0.        , 0.        ],
       [0.        , 0.        ],
       [0.13503703, 0.        ],
       [0.        , 0.02700926]]))
D21_nv = sp.Matrix(np.array([[0., 0., 0.],
       [0., 0., 0.]]))


# ---------- create symbolic parameter functions
# parameter values can be constant/fixed values OR set in relation to other parameters (for example: a = 2*b)  


# list of symbolic parameter functions
# tailing "_sf" stands for "symbolic parameter function"
pp_sf = [A_nv, B_nv, B1_nv, C1_nv, C_nv, D11_nv, D12_nv, D21_nv]


#  ---------- list for substitution
# -- entries are tuples like: (independent symbolic parameter, numerical value)
pp_subs_list = []


# OPTONAL: Dictionary which defines how certain variables shall be written
# in the table - key: Symbolic Variable, Value: LaTeX Representation/Code
# useful for example for complex variables: {Z: r"\underline{Z}"}
latex_names = {}


# ---------- Define LaTeX table

# Define table header 
# DON'T CHANGE FOLLOWING ENTRIES: "Symbol", "Value"
tabular_header = ["Symbol", "Value"]

# Define column text alignments
col_alignment = ["center", "left"]


# Define Entries of all columns before the Symbol-Column
# --- Entries need to be latex code
col_1 = [] 

# contains all lists of the columns before the "Symbol" Column
# --- Empty list, if there are no columns before the "Symbol" Column
start_columns_list = []


# Define Entries of the columns after the Value-Column
# --- Entries need to be latex code
col_4 = []

# contains all lists of columns after the FIX ENTRIES
# --- Empty list, if there are no columns after the "Value" column
end_columns_list = []

Related Problems:
Extensive Material:
Download pdf
Result: Success.
Last Build: Checkout CI Build
Runtime: 3.7 (estimated: 10s)