def polaire_equi(P):
    q = 0
    mss = [0.2, 1]
    alphas = np.arange(ut.rad_of_deg(-10), ut.rad_of_deg(20), ut.rad_of_deg(1))
    km = 0.1
    for ms in mss:
        P.set_mass_and_static_margin(km, ms)
        dphrs = []
        dphrs = np.array([(P.ms * P.CLa * (alpha - P.a0) - P.Cm0) / P.Cmd
                          for alpha in alphas])
        CLe = []
        CLe = [
            dyn.get_aero_coefs(dyn.va_of_mach(0.7, 7000), alpha, q, dphr, P)[0]
            for alpha, dphr in zip(alphas, dphrs)
        ]
        Cxe = [
            dyn.get_aero_coefs(dyn.va_of_mach(0.7, 7000), alpha, q, dphr, P)[1]
            for alpha, dphr in zip(alphas, dphrs)
        ]
        finesse = [CL / Cx for Cx, CL in zip(Cxe, CLe)]
        fmax = np.max(finesse)
        idmax = np.argmax(finesse)
        print(fmax)
        plt.plot([0, Cxe[idmax]], [0, CLe[idmax]])
        plt.plot(Cxe, CLe)
    label1 = patches.Patch(color='blue', label='fmax (ms = 0.2)')
    label2 = patches.Patch(color='green', label='Polaire (ms = 0.2)')
    label3 = patches.Patch(color='red', label='fmax (ms = 1)')
    label4 = patches.Patch(color='cyan', label='Polaire (ms = 1)')
    plt.legend(loc='upper left', handles=[label1, label2, label3, label4])
    ut.decorate(plt.gca(), "Evolution de la polaire équilibrée",
                'Coefficient de trainée équilibrée',
                'Coefficient de portance équilibrée')
    plt.show
Esempio n. 2
0
 def q2():
     lm = np.linspace(Ma[0], Ma[1])
     n = len(lm)
     for i, ms_i in enumerate(ms):
         for j, km_i in enumerate(km):
             PLANE.set_mass_and_static_margin(km_i, ms_i)
             F0 = np.zeros(n)
             F1 = np.zeros(n)
             for k, m_i in enumerate(lm):
                 va0 = dynamic.va_of_mach(m_i, h[0])
                 va1 = dynamic.va_of_mach(m_i, h[1])
                 X0, U0 = dynamic.trim(PLANE, {'va': va0, 'h': h[0]})
                 X1, U1 = dynamic.trim(PLANE, {'va': va1, 'h': h[1]})
                 F0[k] = dynamic.propulsion_model(X0, U0, PLANE)
                 F1[k] = dynamic.propulsion_model(X1, U1, PLANE)
             plt.subplot(2, 2, i + 2 * j + 1)
             plt.plot(lm, F0, label="$h={}$".format(h[0]))
             plt.plot(lm, F1, label="$h={}$".format(h[1]))
             plt.legend()
             plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
             plt.xlabel("$M_a$")
             plt.ylabel("$F$")
     plt.tight_layout(.5)
     plt.savefig(file + "q2" + format)
     plt.show()
def get_linearized_model(aicraft, h, Ma, sm, km):    
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, h)
    Xe, Ue = dyn.trim(aircraft, {'va':va, 'h':h, 'gamma':0})
    A, B = ut.num_jacobian(Xe, Ue, aicraft, dyn.dyn)
    poles, vect_p = np.linalg.eig(A[dyn.s_va:, dyn.s_va:])
    return A, B, poles, vect_p
Esempio n. 4
0
 def val_propre(n):
     vp = np.zeros((n, n, n, n, 4), dtype=complex)
     lh = np.linspace(h[0], h[1], n)
     lMa = np.linspace(Ma[0], Ma[1], n)
     lms = np.linspace(ms[0], ms[1], n)
     lkm = np.linspace(km[0], km[1], n)
     for i, h_i in enumerate(lh):
         for j, Ma_j in enumerate(lMa):
             for k, ms_k in enumerate(lms):
                 for l, km_l in enumerate(lkm):
                     PLANE.set_mass_and_static_margin(km_l, ms_k)
                     params = {
                         'va': dynamic.va_of_mach(Ma_j, h_i),
                         'h': h_i,
                         'gamma': 0
                     }
                     X, U = dynamic.trim(PLANE, params)
                     A, B = dynamic.ut.num_jacobian(X, U, PLANE,
                                                    dynamic.dyn)
                     A_4 = A[2:, 2:]
                     liste_vp = np.linalg.eigvals(A_4)
                     for m, ev in enumerate(liste_vp):
                         vp[i][j][k][l][m] = ev
     #print(A_4)
     #print(np.linalg.eigvals(A_4))
     return vp
Esempio n. 5
0
def etat_lin4(h_tuple, mac_tuple, km_tuple, ms_tuple):
    '''
    calcule les repr d'état linéarisées A et B
    :param h_tuple: tuple contenant le altitudes
    :param mac_tuple:
    :param km_tuple:
    :param ms_tuple:
    :return:
    '''
    dico_etat = {}  # dico pour stocker les 16 états associés au 16 pts de trim
    dico_etat_lin = {}
    dico_etat_lin4 = {}

    for i, km in enumerate(km_tuple):
        for j, ms in enumerate(ms_tuple):
            P.set_mass_and_static_margin(km, ms)
            for idx, mac in enumerate(mac_tuple):
                dico = {}  # dico = args dans la fonction trim
                for h in h_tuple:
                    dico['h'] = h
                    dico['va'] = dy.va_of_mach(mac, h)  # conv mach en m/s
                    # calcul des points de trim associés aux 4 valeurs h, mac, km et ms
                    # et ajout dans le tuple etat
                    etat = (X, U) = dy.trim(P, dico)
                    etat_lin = (A, B) = ut.num_jacobian(X, U, P, dy.dyn)
                    A4 = np.copy(A[2:, 2:])
                    B4 = np.copy(B[2:])
                    etat_lin4 = (A4, B4)
                    # construction du tuple (h,mac,km,ms) qui jouera le role de clé du dico states
                    pt_trim = (h, mac, km, ms)
                    dico_etat[pt_trim] = etat
                    dico_etat_lin[pt_trim] = etat_lin
                    dico_etat_lin4[pt_trim] = etat_lin4
    return dico_etat_lin4
Esempio n. 6
0
def function_transfere(aircraft, point_trim):

    alt, Ma, sm, km = point_trim
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, alt)
    xtrim, utrim = dyn.trim(aircraft, {'va': va, 'gamm': 0, 'h': alt})
    A, B = utils.num_jacobian(xtrim, utrim, aircraft, dyn.dyn)
    A_4, B_4 = A[2:,2:], B[2:,:2][:,0].reshape((4,1))
    C_4 = np.zeros((1,4))
    C_4[0][2] = 1
    Acc_4 = np.zeros((4, 4))
    Bcc_4 = np.zeros((4, 1))
    Bcc_4[3,0] = 1
    valeursp, M = np.linalg.eig(A_4)
    coeff = np.poly(valeursp)
    for i in range(3):
        Acc_4[i,i+1] = 1
        Acc_4[3,3-i] = -coeff[i+1]
    Acc_4[3,0] = -coeff[4]
    Qccc = np.zeros((4, 4))
    Q = np.zeros((4, 4))
    for i in range(4):
        Qccc[:,i:i+1] = np.dot(np.linalg.matrix_power(Acc_4, i), Bcc_4)
        Q[:,i:i+1] = np.dot(np.linalg.matrix_power(A_4, i), B_4)
    Mcc = np.dot(Q, np.linalg.inv(Qccc))
    Ccc_4 = np.dot(C_4, Mcc)
    num = list(Ccc_4)
    num.reverse()
    den = list(-Acc_4[3, :])
    den.append(1.)
    den.reverse()
    return num, den, valeursp
def get_trim(aircraft, h, Ma, sm, km):
    '''
    Calcul du trim pour un point de vol
    '''
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, h)
    Xe, Ue = dyn.trim(aircraft, {'va':va, 'h':h, 'gamma':0})
    return Xe, Ue
Esempio n. 8
0
def trace(km, ms):
    P.set_mass_and_static_margin(km, ms)  # km masse avion, ms : marge statique
    for idx, mac in enumerate(mac_tuple):
        dico = {}  # dico = args dans la fonction trim
        alphas = [
        ]  # liste avec alpha1 obtenu avec h1=3000m et alpha2 associé à h2
        dphrs = []
        dths = []

        for h in h_tuple:
            dico['h'] = h
            dico['va'] = dy.va_of_mach(mac, h)  # conv mach en m/s
            X, U = dy.trim(P, dico)
            # alphas += [ut.deg_of_rad(X[3])]  # alpha en degrés
            # dphrs += [ut.deg_of_rad(U[0])] # delta PHR en degrés
            alphas += [X[3]]  # alpha en radians
            dphrs += [U[0]]  # delta PHR en radians
            dths += [U[1]]  # thrust de 0 à 1
        plt.title("ms = " + str(ms_tuple[0]) + "  km = " + str(km_tuple[0]) +
                  " - " + P.name)
        # plt.title(r"$\alpha$")

        # grille 1x3 1 ligne 3 colonnes figure 1 : numérotation par ligne de gauche à droite
        plt.subplot(1, 3, 1)
        plt.plot(h_kilometre,
                 alphas,
                 marker=markeur[idx],
                 label="Mac = " + str(mac))
        plt.plot(h_kilometre,
                 alphas,
                 marker=markeur[idx],
                 label="Mac = " + str(mac))
        # plt.axis([abs_min, abs_max, 0., 20])
        plt.title(r"$\alpha$")

        # grille 1x3  figure 2
        plt.subplot(1, 3, 2)
        plt.subplots_adjust(wspace=0.4)
        plt.title(r"$\delta$phr")
        plt.plot(h_kilometre,
                 dphrs,
                 marker=markeur[idx],
                 label="Mac = " + str(mac))
        # plt.axis([abs_min, abs_max, 0., 10])
        # plt.legend(loc=3,prop={'size':7})
        # plt.yticks(color='red')
        plt.xlabel('Altitude en km - ms = ' + str(ms) +
                   " - coef. de masse km = " + str(km))  # , color='red')

        # grille 1x3  figure 3
        plt.subplot(1, 3, 3)
        plt.title(r"$\delta$th")
        plt.plot(h_kilometre,
                 dths,
                 marker=markeur[idx],
                 label="Mac = " + str(mac))
        plt.legend(loc=1, prop={'size': 7})
        plt.axis([abs_min, abs_max, 0., ord_max])
Esempio n. 9
0
 def simu():
     time = np.arange(0, 100, 0.1)
     PLANE.set_mass_and_static_margin(km[1], Ma[1])
     va = dynamic.va_of_mach(Ma[1], h[1])
     Xtrim, Utrim = dynamic.trim(PLANE, {'va': va, 'h': h[1]})
     x = integrate.odeint(dynamic.dyn, Xtrim, time, args=(Utrim, PLANE))
     dynamic.plot(time, x)
     plt.savefig(file + "simu" + format)
     plt.show()
Esempio n. 10
0
def nonLinearModel(aircraft, point_trim, wh, time):

    alt, Ma, sm, km = point_trim
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, alt)
    xtrim, uTrim = dyn.trim(aircraft, {'va':va, 'h':alt})
    xtrim[dyn.s_a] = xtrim[dyn.s_a] + np.arctan(wh/xtrim[dyn.s_va])
    X = scipy.integrate.odeint(dyn.dyn, xtrim, time, args=(uTrim, aircraft))
    return X
def get_linearized_model(aicraft, h, Ma, sm, km):
    '''
    Calcul numérique du modèle tangeant linéarisé pour un point de trim
    '''
    aircraft.set_mass_and_static_margin(km, sm)
    Xe, Ue = dyn.trim(aircraft, {'va':dyn.va_of_mach(Ma, h), 'h':h, 'gamma':0})
    A, B = ut.num_jacobian(Xe, Ue, aicraft, dyn.dyn)
    poles, vect_p = np.linalg.eig(A[dyn.s_va:, dyn.s_va:])
    return A, B, poles, vect_p
def plot_traj_trim(aircraft, h, Ma, sm, km):
    '''
    Affichage d'une trajectoire avec un point de trim comme condition initiale
    '''
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, h)
    Xe, Ue = dyn.trim(aircraft, {'va':va, 'h':h, 'gamma':0})
    time = np.arange(0., 100, 0.5)
    X = scipy.integrate.odeint(dyn.dyn, Xe, time, args=(Ue, aircraft))
    dyn.plot(time, X)
def trajectoire(M, h, ms, km, P):
    t = np.arange(0, 100, 0.5)
    P.set_mass_and_static_margin(km, ms)
    va = dyn.va_of_mach(M, h, k=1.4, Rs=287.05)
    param = {'va': va, 'h': h, 'gamma': 0}
    Xe, Ue = dyn.trim(P, param)
    X = scipy.integrate.odeint(dyn.dyn, Xe, t, args=(Ue, P))
    trace = dyn.plot(t, X)
    plt.suptitle("Trajectoire de l'avion", fontsize=22)
    plt.show()
def obtain_matrices(km, ms, M, h, P):
    P.set_mass_and_static_margin(km, ms)
    va = dyn.va_of_mach(M, h)
    param = {'va': va, 'gamma': 0, 'h': h}
    X, U = dyn.trim(P, param)
    A, B = ut.num_jacobian(X, U, P, dyn.dyn)
    print('\n \n A et B pour M={}, h={}, ms={} et km={}'.format(M, h, ms, km))
    A2 = reduire(A)
    print(np.linalg.eig(A2))
    liste = np.linalg.eig(A2)[0]
    trace_vpropres(liste, km, ms, M, h)
def evol_Cm(P):
    ms = [-0.1, 0, 0.2, 1]
    dphr = 0
    alphas = np.arange(ut.rad_of_deg(-10), ut.rad_of_deg(20), ut.rad_of_deg(1))
    Cm_tab1 = []
    Cm_tab2 = []
    Cm_tab3 = []
    Cm_tab4 = []
    q = 0
    for alpha in alphas:
        Cm1 = P.Cm0 - ms[0] * P.CLa * (alpha -
                                       P.a0) + P.Cmq * P.lt / dyn.va_of_mach(
                                           0.7, 7000) * q + P.Cmd * dphr
        Cm_tab1.append(Cm1)
        Cm2 = P.Cm0 - ms[1] * P.CLa * (alpha -
                                       P.a0) + P.Cmq * P.lt / dyn.va_of_mach(
                                           0.7, 7000) * q + P.Cmd * dphr
        Cm_tab2.append(Cm2)
        Cm3 = P.Cm0 - ms[2] * P.CLa * (alpha -
                                       P.a0) + P.Cmq * P.lt / dyn.va_of_mach(
                                           0.7, 7000) * q + P.Cmd * dphr
        Cm_tab3.append(Cm3)
        Cm4 = P.Cm0 - ms[3] * P.CLa * (alpha -
                                       P.a0) + P.Cmq * P.lt / dyn.va_of_mach(
                                           0.7, 7000) * q + P.Cmd * dphr
        Cm_tab4.append(Cm4)
    plt.plot(ut.deg_of_rad(alphas), Cm_tab1)
    plt.plot(ut.deg_of_rad(alphas), Cm_tab2)
    plt.plot(ut.deg_of_rad(alphas), Cm_tab3)
    plt.plot(ut.deg_of_rad(alphas), Cm_tab4)
    label1 = patches.Patch(color='blue', label='ms = -0.1')
    label2 = patches.Patch(color='green', label='ms = 0')
    label3 = patches.Patch(color='red', label='ms = 0.2')
    label4 = patches.Patch(color='cyan', label='ms = 1')
    plt.legend(loc='upper right', handles=[label1, label2, label3, label4])
    ut.decorate(plt.gca(),
                title="Evolution du Cm en fonction de l'incidence",
                xlab='Incidence',
                ylab='Cm')
    plt.show()
Esempio n. 16
0
def stability(aircraf, point_trim):

    alt, Ma, sm, km = point_trim
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, alt)
    xtrim, utrim = dyn.trim(aircraft, {'va': va, 'gamm': 0, 'h': alt})
    A, B = utils.num_jacobian(xtrim, utrim, aircraft, dyn.dyn)
    A_4 = A[2:,2:]
    valeursp, M = np.linalg.eig(A_4)
    V_reals = []
    for V in valeursp:
        V_reals.append(V.real)
    return V_reals
def plot_thrust(P, filename=None):
    figure = ut.prepare_fig(None, u'Poussée {}'.format(P.name))
    hs = np.linspace(3000, 11000, 5)
    for h in hs:
        Machs = np.linspace(0.5, 0.8, 30)
        thrusts = np.zeros(len(Machs))
        for i in range(0, len(Machs)):
            thrusts[i] = dyn.propulsion_model([0, h, dyn.va_of_mach(Machs[i], h), 0, 0, 0], [0, 1., 0, 0], P)
        plt.plot(Machs, thrusts)
    ut.decorate(plt.gca(), u'Poussée maximum {}'.format(P.name), r'Mach', '$N$', 
                ['{} m'.format(h) for h in hs])
    if filename<> None: plt.savefig(filename, dpi=160)
    return figure
Esempio n. 18
0
def controllability(aircraf, point_trim):

    alt, Ma, sm, km = point_trim
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, alt)
    xtrim, utrim = dyn.trim(aircraft, {'va': va, 'gamm': 0, 'h': alt})
    xtrim_4 = xtrim[2:]
    A, B = utils.num_jacobian(xtrim, utrim, aircraft, dyn.dyn)
    A_4, B_4 = A[2:, 2:], B[2:, :2]
    Q = np.zeros((4, 4*2))
    for i in range(3):
        Q[:,2*i:2*(i+1)] = np.dot(np.linalg.matrix_power(A_4, i),B_4)
    return Q
def LinearTraj(aircraft, h, Ma, sm, km, Wh, time):
    '''
    Calcul d'une trajectoire avec un point de trim comme condition initiale
    '''
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, h)
    Xe, Ue = dyn.trim(aircraft, {'va':va, 'h':h, 'gamma':0})
    A, B = ut.num_jacobian(Xe, Ue, aircraft, dyn.dyn)
    dX0 = np.zeros(dyn.s_size)
    dU = np.zeros(dyn.i_size)
    dX0[dyn.s_a] = math.atan(Wh/Xe[dyn.s_va]) #perturbation
    dX = scipy.integrate.odeint(LinearDyn, dX0, time, args=(dU, A, B))
    Xlin = np.array([dXi+Xe for dXi in dX])
    return Xlin
Esempio n. 20
0
def modal_form(aircraft, point_trim):

    alt, Ma, sm, km = point_trim
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, alt)
    xtrim, utrim = dyn.trim(aircraft, {'va': va, 'gamm': 0, 'h': alt})
    xtrim_4 = xtrim[2:]
    A, B = utils.num_jacobian(xtrim, utrim, aircraft, dyn.dyn)
    A_4, B_4 = A[2:,2:], B[2:,:2]
    valeursp, M = np.linalg.eig(A_4)
    M_inv = np.linalg.inv(M)
    Am_4 = np.diag(valeursp)
    Bm_4 = np.dot(M_inv, B_4)
    return '{} = {}\n\n{} = {}'.format('Am', Am_4,'Bm', Bm_4)
def evol_coeff_portance(P):
    alphas = np.arange(ut.rad_of_deg(-10), ut.rad_of_deg(20), ut.rad_of_deg(1))
    dphrs = [ut.rad_of_deg(-30), ut.rad_of_deg(20)]
    q = 0
    Cz_tab1 = []
    Cz_tab2 = []
    for alpha in alphas:
        coeff_portance1 = dyn.get_aero_coefs(dyn.va_of_mach(0.7, 7000), alpha,
                                             q, dphrs[0], P)
        Cz_tab1.append(coeff_portance1[0])
        coeff_portance2 = dyn.get_aero_coefs(dyn.va_of_mach(0.7, 7000), alpha,
                                             q, dphrs[1], P)
        Cz_tab2.append(coeff_portance2[0])
    plt.plot(ut.deg_of_rad(alphas), Cz_tab1, 'r')
    plt.plot(ut.deg_of_rad(alphas), Cz_tab2, 'b')
    label1 = patches.Patch(color='red', label='dPHR1 = -30°')
    label2 = patches.Patch(color='blue', label='dPHR2 = 20°')
    plt.legend(loc='upper left', handles=[label1, label2])
    ut.decorate(plt.gca(),
                title="Evolution du Cz en fonction de l'incidence",
                xlab='Incidence',
                ylab='Cz')
    plt.show()
def get_all_trims(aircraft, hs, Mas, sms, kms):
    '''
    Calcul de trims pour une serie de points de vol
    '''
    trims = []
    for h in hs:
        for Ma in Mas:
            va = dyn.va_of_mach(Ma,h)
            arg = {'va':va, 'h':h, 'gamma':0}
            trim = dyn.trim(dyn.Param_737_300(), arg)
            trims.append(trim)
            print trim

    return trims
Esempio n. 23
0
def LinearModel(aircraft, point_trim, wh, time):

    alt, Ma, sm, km = point_trim
    aircraft.set_mass_and_static_margin(km, sm)
    va = dyn.va_of_mach(Ma, alt)
    xtrim, utrim = dyn.trim(aircraft, {'va':va,'gamm':0, 'h':alt})
    xtrim[dyn.s_a] = xtrim[dyn.s_a] + np.arctan(wh / xtrim[dyn.s_va])
    wing = [0] * 6
    A, B = utils.num_jacobian(xtrim, utrim, aircraft, dyn.dyn)
    du = np.zeros((4,))
    wing[dyn.s_a] += np.arctan(wh / xtrim[dyn.s_va])
    dX = scipy.integrate.odeint(dynlin, wing, time, args=(A, B, du))
    X = dX+xtrim
    for i in range(len(X)):
        X[i][dyn.s_y] = X[i][dyn.s_va]*time[i]
    return X
def evol_poussee(P):
    U = [0, 1, 0, 0]
    hs = np.linspace(3000, 11000, 5)
    machs = np.linspace(0.5, 0.8, 30)
    for h in hs:
        Poussee = [
            dyn.propulsion_model([0, h, dyn.va_of_mach(mach, h), 0, 0, 0], U,
                                 P) for mach in machs
        ]
        plt.plot(machs, Poussee)
    ut.decorate(plt.gca(),
                title='Poussée maximale en fonction du Mach',
                xlab='Mach',
                ylab='Poussee (N)',
                legend=['{} m'.format(h) for h in hs])
    plt.show()
Esempio n. 25
0
def state(PLANE, pt_trim):
    """
    Computes model of a trim condition
    :param PLANE:
    :param pt_trim: list of [h, Ma, ms, km]
    :return:
    """
    PLANE.set_mass_and_static_margin(pt_trim[3], pt_trim[2])
    params = {
        'va': dynamic.va_of_mach(pt_trim[1], pt_trim[0]),
        'h': pt_trim[0],
        'gamma': 0
    }
    X, U = dynamic.trim(PLANE, params)
    A, B = dynamic.ut.num_jacobian(X, U, PLANE, dynamic.dyn)
    return X, U, A, B
Esempio n. 26
0
def v_propre(h_tuple, mac_tuple, km_tuple, ms_tuple):
    '''

    :param h_tuple: tuple contenant le altitudes
    :param mac_tuple:
    :param km_tuple:
    :param ms_tuple:
    :return:
    '''
    dico_etat = {}  # dico pour stocker les 16 états associés au 16 pts de trim
    dico_etat_lin = {}
    dico_etat_lin4 = {}
    dico_vp = {}
    dico_vecteur_propre = {}

    for i, km in enumerate(km_tuple):
        for j, ms in enumerate(ms_tuple):
            P.set_mass_and_static_margin(km, ms)
            for idx, mac in enumerate(mac_tuple):
                dico = {}  # dico = args dans la fonction trim
                for h in h_tuple:
                    dico['h'] = h
                    dico['va'] = dy.va_of_mach(mac, h)  # conv mach en m/s
                    # calcul des points de trim associés aux 4 valeurs h, mac, km et ms
                    # et ajout dans le tuple etat
                    etat = (X, U) = dy.trim(P, dico)
                    etat_lin = (A, B) = ut.num_jacobian(X, U, P, dy.dyn)
                    A4 = A[2:, 2:].copy()
                    B4 = B[2:].copy()
                    etat_lin4 = (A4, B4)
                    # calcul vp val propre
                    vp = np.linalg.eig(A4)
                    # construction du tuple (h,mac,km,ms) qui jouera le role de clé du dico states
                    pt_trim = (h, mac, km, ms)
                    dico_etat[pt_trim] = etat
                    dico_etat_lin[pt_trim] = etat_lin
                    dico_etat_lin4[pt_trim] = etat_lin4
                    dico_vp[pt_trim] = vp[0]
                    dico_vecteur_propre[pt_trim] = vp[1:][
                        0]  # car vp est un tuple ; indice 1 => array des vect propre indice 0 val propres

    return dico_vp, dico_vecteur_propre, dico_etat_lin4, dico_etat, dico_etat_lin
Esempio n. 27
0
def v_propre(h_tuple, mac_tuple, km_tuple, ms_tuple):
    '''

    :param h_tuple: tuple contenant le altitudes
    :param mac_tuple:
    :param km_tuple:
    :param ms_tuple:
    :return:
    '''
    dico_etat = {}  # dico pour stocker les 16 états associés au 16 pts de trim
    dico_etat_lin = {}
    dico_etat_lin4 = {}
    dico_vp = {}
    dico_vecteur_propre = {}

    for i, km in enumerate(km_tuple):
        for j, ms in enumerate(ms_tuple):
            P.set_mass_and_static_margin(km, ms)
            for idx, mac in enumerate(mac_tuple):
                dico = {}  # dico = args dans la fonction trim
                for h in h_tuple:
                    dico['h'] = h
                    dico['va'] = dy.va_of_mach(mac, h)  # conv mach en m/s
                    # calcul des points de trim associés aux 4 valeurs h, mac, km et ms
                    # et ajout dans le tuple etat
                    etat = (X, U) = dy.trim(P, dico)
                    etat_lin = (A, B) = ut.num_jacobian(X, U, P, dy.dyn)
                    A4 = A[2:, 2:].copy()
                    B4 = B[2:].copy()
                    etat_lin4 = (A4, B4)
                    # calcul vp val propre
                    vp = np.linalg.eig(A4)
                    # construction du tuple (h,mac,km,ms) qui jouera le role de clé du dico states
                    pt_trim = (h, mac, km, ms)
                    dico_etat[pt_trim] = etat
                    dico_etat_lin[pt_trim] = etat_lin
                    dico_etat_lin4[pt_trim] = etat_lin4
                    dico_vp[pt_trim] = vp[0]
                    dico_vecteur_propre[pt_trim] = vp[1:][
                        0]  # car vp est un tuple ; indice 1 => array des vect propre indice 0 val propres

    return dico_vp, dico_vecteur_propre, dico_etat_lin4, dico_etat, dico_etat_lin
def evol_CLe(P):
    q = 0
    mss = [0.2, 1]
    alphas = np.arange(ut.rad_of_deg(-10), ut.rad_of_deg(20), ut.rad_of_deg(1))
    km = 0.1
    for ms in mss:
        P.set_mass_and_static_margin(km, ms)
        dphrs = []
        dphrs = np.array([(P.ms * P.CLa * (alpha - P.a0) - P.Cm0) / P.Cmd
                          for alpha in alphas])
        CLe = []
        CLe = [
            dyn.get_aero_coefs(dyn.va_of_mach(0.7, 7000), alpha, q, dphr, P)[0]
            for alpha, dphr in zip(alphas, dphrs)
        ]
        plt.plot(ut.deg_of_rad(alphas), CLe)
    label1 = patches.Patch(color='blue', label='ms = 0.2')
    label2 = patches.Patch(color='green', label='ms = 1')
    plt.legend(loc='upper left', handles=[label1, label2])
    ut.decorate(plt.gca(), "Evolution de CLe en fonction de l'incidence",
                'Incidence', 'Coefficient de portance équilibrée')
    plt.show
Esempio n. 29
0
def Trim_dyn(P):
    hs = [3000, 11000]
    x = np.linspace(3000, 11000, 2)
    Ms = [0.5, 0.8]
    couples = [[0.2, 0.1], [0.2, 0.9], [1., 0.1], [1., 0.9]]
    alphatab1, alphatab2, dphrtab1, dphrtab2, dthtab1, dthtab2 = [], [], [], [], [], []
    for couple in couples:
        P.set_mass_and_static_margin(couple[1], couple[0])
        alpha1, alpha2, dphr1, dphr2, dth1, dth2 = [], [], [], [], [], []
        for h in hs:
            param1 = {'va': dyn.va_of_mach(Ms[0], h), 'gamma': 0, 'h': h}
            alpha1.append(dyn.trim(P, param1)[0][3])
            param2 = {'va': dyn.va_of_mach(Ms[1], h), 'gamma': 0, 'h': h}
            alpha2.append(dyn.trim(P, param2)[0][3])
        alphatab1.append(alpha1)
        alphatab2.append(alpha2)
        for h in hs:
            param1 = {'va': dyn.va_of_mach(Ms[0], h), 'gamma': 0, 'h': h}
            dphr1.append(dyn.trim(P, param1)[1][0])
            param2 = {'va': dyn.va_of_mach(Ms[1], h), 'gamma': 0, 'h': h}
            dphr2.append(dyn.trim(P, param2)[1][0])
        dphrtab1.append(dphr1)
        dphrtab2.append(dphr2)
        for h in hs:
            param1 = {'va': dyn.va_of_mach(Ms[0], h), 'gamma': 0, 'h': h}
            dth1.append(dyn.trim(P, param1)[1][1])
            param2 = {'va': dyn.va_of_mach(Ms[1], h), 'gamma': 0, 'h': h}
            dth2.append(dyn.trim(P, param2)[1][1])
        dthtab1.append(dth1)
        dthtab2.append(dth2)
    print('alpha1 :', alphatab1)
    print('alpha2 :', alphatab2)
    print('dphr1 :', dphrtab1)
    print('dphr2 :', dphrtab2)
    print('dth1 :', dthtab1)
    print('dth2 :', dthtab2)
    al1 = np.array(alphatab1)
    al2 = np.array(alphatab2)
    f, axarr = plt.subplots(4, 3)
    axarr[0, 0].plot(x, al1[0])
    axarr[0, 0].set_title('Alpha')
    axarr[1, 0].plot(x, al1[1])
    axarr[2, 0].plot(x, al1[2])
    axarr[3, 0].plot(x, al1[3])
    axarr[0, 0].plot(x, al2[0])
    axarr[1, 0].plot(x, al2[1])
    axarr[2, 0].plot(x, al2[2])
    axarr[3, 0].plot(x, al2[3])
    dp1 = np.array(dphrtab1)
    dp2 = np.array(dphrtab2)
    axarr[0, 1].plot(x, dp1[0])
    axarr[0, 1].set_title('Dphr')
    axarr[1, 1].plot(x, dp1[1])
    axarr[2, 1].plot(x, dp1[2])
    axarr[3, 1].plot(x, dp1[3])
    axarr[0, 1].plot(x, dp2[0])
    axarr[1, 1].plot(x, dp2[1])
    axarr[2, 1].plot(x, dp2[2])
    axarr[3, 1].plot(x, dp2[3])
    dt1 = np.array(dthtab1)
    dt2 = np.array(dthtab2)
    axarr[0, 2].plot(x, dt1[0])
    axarr[0, 2].set_title('Dth')
    axarr[1, 2].plot(x, dt1[1])
    axarr[2, 2].plot(x, dt1[2])
    axarr[3, 2].plot(x, dt1[3])
    axarr[0, 2].plot(x, dt2[0])
    axarr[1, 2].plot(x, dt2[1])
    axarr[2, 2].plot(x, dt2[2])
    axarr[3, 2].plot(x, dt2[3])
    f.suptitle(
        "Valeur de Alpha, Dphr et Dth pour un vol en palier en fonction de l'Altitude pour les couples \n [ms, km] suivants : [0.2, 0.1], [0.2, 0.9], [1., 0.1], [1., 0.9]"
    )
    plt.show()
def get_CL_Fmax_trim(aircraft, h, Ma):
    p, rho, T = ut.isa(h)
    va = dyn.va_of_mach(Ma, h)
    pdyn = 0.5*rho*va**2
    return P.m*P.g/(pdyn*P.S), propulsion_model([0, h, va, 0, 0, 0], [0, 1, 0, 0], aircraft)
Esempio n. 31
0
abs_min = 3
abs_max = 11
nb_ligne = len(km_tuple) * len(ms_tuple)


# on choisit le point de trim numéro 16 pour lequel on a :
h = 3000.
mac = 0.8
km = 0.9
ms = 1.

# intialisation de l'avion
P.set_mass_and_static_margin(km, ms)  # km masse avion, ms : marge statique

# calcul de va en m/s
va = dy.va_of_mach(mac, h)

# calcul de rho
rho = ut.isa(h)[1]

args = {}
args['h'] = h
args['va'] = dy.va_of_mach(mac, h)  # conv mach en m/s
X, U = dy.trim(P, args)
(A, B) = ut.num_jacobian(X, U, P, dy.dyn)


val_propre = np.linalg.eig(A)
print(np.real(val_propre[0]))
exit()
Esempio n. 32
0
 def get_Cl():
     Va = dynamic.va_of_mach(Ma[1], h[1])
     PLANE.set_mass_and_static_margin(km[1], ms[1])
     rho = utils.isa(h[1])[1]
     Cl = (PLANE.m * PLANE.g) / (0.5 * rho * PLANE.S * Va**2)
     return Cl
Esempio n. 33
0
def main():

    PLANE = dynamic.Param_737_800()
    Vt = PLANE.lt*PLANE.St/PLANE.cbar/PLANE.S
    va = dynamic.va_of_mach(0.9, 0)
    km = 1

    ###q1

    def pousse_max(h, mach):
        M = np.linspace(mach[0], mach[1], 100)
        rho0 = utils.isa(0)[1]
        F0 = PLANE.F0
        plt.figure(0)
        for h_i in h :
            F = F0*(utils.isa(h_i)[1]/rho0)**(0.6)*(0.568+0.25*(1.2-M)**3)
            plt.plot(M, F, label='$h={:.0f}$'.format(h_i))
        plt.xlabel("$M_a$")
        plt.ylabel("$F$")
        plt.title("Evolution de la poussée maximale avec l'altitude et le nombre de Mach")
        plt.legend()
        plt.savefig(file+"q1"+format)
        plt.show()

    ###q2

    def coeff_Cl(a, delta_PHR):
        """

        :param a: a list of two angles (min an max) in degree !
        :param delta_PHR: degree !
        :return:
        """
        alpha = np.linspace(a[0], a[1], 100)
        plt.figure(1)
        for d in delta_PHR:
            Cl = dynamic.get_aero_coefs(va, alpha*pi/180, 0, d*pi/180, PLANE)[0]
            plt.plot(alpha, Cl, label="$\delta_{{PHR}}={:.0f}$".format(d))
        plt.xlabel("$\\alpha$")
        plt.ylabel("$C_L$")
        plt.title("$\\alpha\\mapsto C_l$")
        plt.legend()
        plt.savefig(file + "q2" + format)
        plt.show()

    ###q3

    def coeff_Cm(a, m_s):
        dphr = 0
        alpha = np.linspace(a[0], a[1], 100)
        m_s_original = PLANE.ms
        plt.figure(2)
        for m in m_s:
            PLANE.set_mass_and_static_margin(km, m)
            Cm = dynamic.get_aero_coefs(va, alpha*pi/180, 0, dphr, PLANE)[2]
            plt.plot(alpha, Cm, label="$m_s={}$".format(m))
        plt.xlabel("$\\alpha$")
        plt.ylabel("$C_m$")
        plt.title("$\\alpha \\mapsto C_m$")
        plt.legend()
        plt.savefig(file + "q3" + format)
        plt.show()
        PLANE.set_mass_and_static_margin(km, m_s_original)

    ###q4



    def dphre(a, m_s, vt):
        """

        :param a:couple of alpha angle (min and max) in degrees!
        :param m_s:
        :param vt:
        :return:
        """
        ms_original = PLANE.ms
        alpha = np.linspace(a[0], a[1], 100)
        alpha0 = PLANE.a0*180/pi
        plt.figure(3)
        for m in m_s:
            PLANE.set_mass_and_static_margin(km, m)
            dphre = (PLANE.Cm0 - PLANE.ms * PLANE.CLa * ((alpha - alpha0)*pi/180)) / (Vt * PLANE.CLat)
            plt.plot(alpha, dphre*180/pi, label='$m_s = {}$'.format(m))
        plt.xlabel('$\\alpha_e$')
        plt.ylabel('$\\delta_{{PHRe}}$')
        plt.title("$\\alpha \\mapsto \\delta_{{PHRe}}$")
        plt.legend()
        plt.savefig(file + "q4_ms" + format)
        plt.show()

        PLANE.set_mass_and_static_margin(km, ms_original)
        plt.figure(4)
        for v in vt:
            dphre = (PLANE.Cm0 - PLANE.ms * PLANE.CLa * ((alpha - alpha0) * pi / 180)) / (v * PLANE.CLat)
            plt.plot(alpha, dphre*180/pi, label='$V_t = {:.3f}$'.format(v))
        plt.title("$\\alpha_e \\mapsto \\delta_{{PHRe}}$")
        plt.xlabel('$\\alpha_e$')
        plt.ylabel('$\\delta_{{PHRe}}$')
        plt.legend()
        plt.savefig(file + "q4_Vt" + format)
        plt.show()

    ### q5

    def coeff_CLe(a, m_s):
        alpha = np.linspace(a[0], a[1], 100)
        alpha0 = PLANE.a0 * 180 / pi
        plt.figure(5)
        for m in m_s:
            PLANE.set_mass_and_static_margin(km, m)
            dphre = (PLANE.Cm0 - PLANE.ms * PLANE.CLa * ((alpha - alpha0)*pi/180)) / (Vt * PLANE.CLat)
            CL = dynamic.get_aero_coefs(va, alpha*pi/180, 0, dphre, PLANE)[0]
            plt.plot(alpha, CL, label='$m_s={}$'.format(m))
        plt.xlabel("$\\alpha_{eq}$")
        plt.ylabel("$C_{L_e}$")
        plt.title('$\\alpha_e\\mapsto C_L$')
        plt.legend()
        plt.savefig(file + "q5" + format)
        plt.show()


    ###q6

    def polaire(a, m_s):
        alpha = np.linspace(a[0], a[1], 100)
        plt.figure(6)
        fmax = np.zeros(len(m_s))
        for i, m in enumerate(m_s):
            PLANE.set_mass_and_static_margin(km, m)
            dphre = (PLANE.Cm0 - PLANE.ms * PLANE.CLa * (alpha*pi/180)) / (Vt * PLANE.CLat)
            CL, CD = dynamic.get_aero_coefs(va, alpha*pi/180, 0,dphre, PLANE)[0:2]
            plt.plot(CD, CL, label='$m_s={}$'.format(m))
            fmax[i] = max(CL / CD)
        plt.title('Polaire équilibrée')
        plt.xlabel('$C_D$')
        plt.ylabel('$C_L$')
        plt.legend()
        plt.savefig(file + "polaire" + format)
        plt.show()
        return fmax

    alpha = [-10, 20]
    pousse_max([3000, 10000], [0.4, 0.9])
    coeff_Cl(alpha, [-30, 20])
    coeff_Cm(alpha, [-0.1, 0, 0.2, 1])
    dphre(alpha, [-0.1, 0, 0.2, 1], [0.9 * Vt, Vt, 1.1 * Vt])
    coeff_CLe(alpha, [0.2, 1])
    polaire(alpha, [0.2, 1])
    print(polaire(alpha, [0.2, 1]))
Esempio n. 34
0
# Pour une masse donnée, à chaque vitesse de vol correspond une incidence de vol et donc une position
#  de la gouverne de profondeur. À chaque changement de vitesse, l'incidence change,
# ainsi il faut compenser à nouveau (ou trimer) pour garder cette nouvelle incidence.
# Le trim correspond à une incidence et donc une vitesse, pour une masse donnée de l'avion.

# on choisit le point de trim numéro 16 pour lequel on a :
h = 11000.
mac = 0.8
km = 0.9
ms = 1.

# intialisation de l'avion
P.set_mass_and_static_margin(km, ms)  # km masse avion, ms : marge statique

# calcul de va en m/s
va = dy.va_of_mach(mac, h)

# calcul de rho
rho = ut.isa(h)[1]

args = {}
args['h'] = h
args['va'] = dy.va_of_mach(mac, h)  # conv mach en m/s
X, U = dy.trim(P, args)
alpha16 = X[3]  # alpha en radians
dphr16 = U[0]  # delta PHR en radians
dth16 = U[1]  # thrust de 0 à 1

# calcul de la poussée pour le point de trim 16
F16 = dy.propulsion_model(X, U, P)
Esempio n. 35
0
    def q1():
        lh = np.linspace(h[0], h[1], 100)
        n = len(lh)
        for i, ms_i in enumerate(ms):
            for j, km_i in enumerate(km):
                PLANE.set_mass_and_static_margin(km_i, ms_i)
                alpha0 = np.zeros(n)
                dphr0 = np.zeros(n)
                dth0 = np.zeros(n)
                alpha1 = np.zeros(n)
                dphr1 = np.zeros(n)
                dth1 = np.zeros(n)
                for k, h_i in enumerate(lh):
                    va0 = dynamic.va_of_mach(Ma[0], h_i)
                    va1 = dynamic.va_of_mach(Ma[1], h_i)
                    alpha0[k] = dynamic.trim(PLANE, {
                        'va': va0,
                        'h': h_i
                    })[0][3]
                    dphr0[k] = dynamic.trim(PLANE, {'va': va0, 'h': h_i})[1][0]
                    dth0[k] = dynamic.trim(PLANE, {'va': va0, 'h': h_i})[1][1]
                    alpha1[k] = dynamic.trim(PLANE, {
                        'va': va1,
                        'h': h_i
                    })[0][3]
                    dphr1[k] = dynamic.trim(PLANE, {'va': va1, 'h': h_i})[1][0]
                    dth1[k] = dynamic.trim(PLANE, {'va': va1, 'h': h_i})[1][1]

                plt.figure("m_s={}, k_m={}".format(ms_i, km_i))
                plt.subplot(1, 3, 1)
                plt.title("$h \\mapsto \\alpha$")
                #plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.plot(lh, alpha0, label="$M_a=0.4$")
                plt.plot(lh, alpha1, label="$M_a=0.9$")
                plt.legend()
                #plt.xlabel("$h$")
                #plt.ylabel("$\\alpha$")
                #plt.show()

                #plt.figure()
                plt.subplot(1, 3, 2)
                #plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.title("$h \\mapsto \\delta_{{th}}$")
                plt.plot(lh, dth0, label="$M_a=0.4$")
                plt.plot(lh, dth1, label="$M_a=0.9$")
                #plt.legend()
                #plt.xlabel("$h$")
                #plt.ylabel("$\\delta_{{th}}$")
                #plt.show()

                #plt.figure()
                plt.subplot(1, 3, 3)
                #plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.title("$h \\mapsto \\delta_{{PHR}}$")
                plt.plot(lh, dphr0, label="$M_a=0.4$")
                plt.plot(lh, dphr1, label="$M_a=0.9$")
                #plt.xlabel("$h$")
                #plt.ylabel("$\\delta_{{PHR}}$")
                #plt.legend()
                plt.tight_layout(.5)
                plt.savefig(file + "q1_" + str(i) + str(j) + format)
                #plt.show()

        plt.show()
Esempio n. 36
0
    '''''' ''''''

    # questions 1-2
    # calcul des points de Trim

    alphatrim = np.zeros((len(ms), len(km), len(Ma), len(h1)))
    dphrtrim = np.zeros((len(ms), len(km), len(Ma), len(h1)))
    dthtrim = np.zeros((len(ms), len(km), len(Ma), len(h1)))
    prop = np.zeros((len(ms), len(km), len(Ma1), len(h)))

    for ib, i in enumerate(ms):
        for jb, j in enumerate(km):
            avion.set_mass_and_static_margin(j, i)
            for kb, k in enumerate(Ma):
                for lb, l in enumerate(h1):
                    va_h0 = dynamic.va_of_mach(k, l, k=1.4, Rs=287.05)
                    X, U = dynamic.trim(avion, {
                        'va': va_h0,
                        'gamm': 0.,
                        'h': l
                    })
                    alphatrim[ib, jb, kb, lb] = X[3]
                    dphrtrim[ib, jb, kb, lb] = U[0]
                    dthtrim[ib, jb, kb, lb] = U[1]
            for kbb, k in enumerate(Ma1):
                for lbb, l in enumerate(h):
                    va_h0b = dynamic.va_of_mach(k, l, k=1.4, Rs=287.05)
                    Xb, Ub = dynamic.trim(avion, {
                        'va': va_h0b,
                        'gamm': 0.,
                        'h': l
def evol_trym(P):
    for couple in couples:
        P.set_mass_and_static_margin(couple[1], couple[0])
        alpha1, alpha2, dphr1, dphr2, dth1, dth2 = [], [], [], [], [], []
        for h in hs:
            arg1 = {
                'va': dyn.va_of_mach(machs[0], h, k=1.4, Rs=287.05),
                'h': h
            }
            alpha1.append(ut.deg_of_rad(dyn.trim(P, arg1)[0][3]))
            dphr1.append(ut.deg_of_rad(dyn.trim(P, arg1)[1][0]))
            dth1.append(dyn.trim(P, arg1)[1][1] * 100)
            arg2 = {
                'va': dyn.va_of_mach(machs[1], h, k=1.4, Rs=287.05),
                'h': h
            }
            alpha2.append(ut.deg_of_rad(dyn.trim(P, arg2)[0][3]))
            dphr2.append(ut.deg_of_rad(dyn.trim(P, arg2)[1][0]))
            dth2.append(dyn.trim(P, arg2)[1][1] * 100)
        alphatab1.append(alpha1)
        alphatab2.append(alpha2)
        dthtab1.append(dth1)
        dthtab2.append(dth2)
        dphrtab1.append(dphr1)
        dphrtab2.append(dphr2)
    al1 = np.array(alphatab1)
    al2 = np.array(alphatab2)
    f, axarr = plt.subplots(4, 3)
    axarr[0, 0].plot(x, al1[0], 'b')
    axarr[0, 0].set_title('Alpha')
    axarr[1, 0].plot(x, al1[1], 'b')
    axarr[2, 0].plot(x, al1[2], 'b')
    axarr[3, 0].plot(x, al1[3], 'b')
    axarr[0, 0].plot(x, al2[0], 'r')
    axarr[1, 0].plot(x, al2[1], 'r')
    axarr[2, 0].plot(x, al2[2], 'r')
    axarr[3, 0].plot(x, al2[3], 'r')
    dp1 = np.array(dphrtab1)
    dp2 = np.array(dphrtab2)
    axarr[0, 1].plot(x, dp1[0], 'b')
    axarr[0, 1].set_title('Dphr')
    axarr[1, 1].plot(x, dp1[1], 'b')
    axarr[2, 1].plot(x, dp1[2], 'b')
    axarr[3, 1].plot(x, dp1[3], 'b')
    axarr[0, 1].plot(x, dp2[0], 'r')
    axarr[1, 1].plot(x, dp2[1], 'r')
    axarr[2, 1].plot(x, dp2[2], 'r')
    axarr[3, 1].plot(x, dp2[3], 'r')
    dt1 = np.array(dthtab1)
    dt2 = np.array(dthtab2)
    axarr[0, 2].plot(x, dt1[0], 'b')
    axarr[0, 2].set_title('Dth')
    axarr[1, 2].plot(x, dt1[1], 'b')
    axarr[2, 2].plot(x, dt1[2], 'b')
    axarr[3, 2].plot(x, dt1[3], 'b')
    axarr[0, 2].plot(x, dt2[0], 'r')
    axarr[1, 2].plot(x, dt2[1], 'r')
    axarr[2, 2].plot(x, dt2[2], 'r')
    axarr[3, 2].plot(x, dt2[3], 'r')
    f.suptitle(
        "Valeur de Alpha, Dphr et Dth pour un vol en palier en fonction de l'Altitude pour les couples \n [ms, km] suivants : [0.2, 0.1], [0.2, 0.9], [1., 0.1], [1., 0.9].      En bleu pour Mach = 0.5 et en rouge pour Mach = 0.8"
    )
    plt.show()
Esempio n. 38
0
def main():

    PLANE = dynamic.Param_737_800()
    Wh = 2  #m/s wind velocity
    h1, h2 = 10000, 3000
    Ma1, Ma2 = 0.9, 0.4
    ms1, ms2 = 0.5, 0.5
    km1, km2 = 1, 0.1
    va = dynamic.va_of_mach(Ma1, h1)
    pt_trim1 = [h1, Ma1, ms1, km1]
    pt_trim2 = [h2, Ma2, ms2, km2]

    def compare_lin(T, pt_trim):
        X, U, A, B = state(PLANE, pt_trim)
        time = np.arange(0, T, 0.1)
        val_p = np.linalg.eigvals(A[2:, 2:])
        add_wind = np.array([0, 0, 0, atan2(Wh, X[2]), 0, 0])
        x = integrate.odeint(dynamic.dyn, X + add_wind, time, args=(U, PLANE))
        dynamic.plot(time, x)
        plt.savefig(file + "nolin" + str(T) + format)
        plt.show()
        dU = np.zeros((4, ))
        dx = integrate.odeint(dynlin, add_wind, time, args=(dU, A, B))
        out = np.array([dxi + X for dxi in dx])
        for j, Xj in enumerate(out):
            out[j][0] += out[j][2] * time[j]
        dynamic.plot(time, out)
        plt.savefig(file + "lin" + str(T) + format)
        plt.show()
        dynamic.plot(time, abs(out - x))
        plt.savefig(file + "dif" + str(T) + format)
        plt.show()
        print([mode(val_p[i]) for i in range(len(val_p))])

    def q3(T, pt_trim1, pt_trim2):
        _, _, A, B = state(PLANE, pt_trim1)
        X, U, _, _ = state(PLANE, pt_trim2)
        add_wind = np.array([0, 0, 0, atan2(Wh, X[2]), 0, 0])
        time = np.arange(0, T, 0.1)
        x = integrate.odeint(dynamic.dyn, X + add_wind, time, args=(U, PLANE))
        dynamic.plot(time, x)
        plt.savefig(file + "otherpoint" + format)
        plt.show()
        dU = np.zeros((4, ))
        dx = integrate.odeint(dynlin, add_wind, time, args=(dU, A, B))
        out = np.array([dxi + X for dxi in dx])
        for j, Xj in enumerate(out):
            out[j][0] += out[j][2] * time[j]
        dynamic.plot(time, out)
        plt.savefig(file + "badlin" + format)
        plt.show()
        dynamic.plot(time, abs(out - x))
        plt.savefig(file + "badlindif" + format)
        plt.show()

    def modal_form(pt_trim):
        _, _, A, B = state(PLANE, pt_trim)
        A_4, B_4 = A[2:, 2:], B[2:, :2]
        val_p, M = np.linalg.eig(A_4)
        M_inv = np.linalg.inv(M)
        Am_4 = np.diag(val_p)
        Bm_4 = np.dot(M_inv, B_4)
        return Am_4, Bm_4

    def stability(pt_trim):
        _, _, A, B = state(PLANE, pt_trim)
        return np.linalg.eigvals(A[2:, 2:])

    def controllability(pt_trim):
        Am_4, Bm_4 = modal_form(pt_trim1)
        Q = np.zeros((4, 4 * 2))
        for i in range(3):
            Q[:, 2 * i:2 * (i + 1)] = np.dot(np.linalg.matrix_power(Am_4, i),
                                             Bm_4)
        return Q

    def transfer_function(pt_trim):
        _, _, A, B = state(PLANE, pt_trim)
        A_4, B_4 = A[2:, 2:], B[2:, :2][:, 0].reshape((4, 1))
        C_4 = np.array([0, 0, 1, 0])
        Acc_4 = np.zeros((4, 4))
        Bcc_4 = np.array([[0], [0], [0], [1]])
        val_p = np.linalg.eigvals(A_4)
        coef = np.poly(val_p)
        N = 4
        for i in range(3):
            Acc_4[3, N - 1 - i] = -coef[i + 1]
            Acc_4[i, i + 1] = 1
        Acc_4[3, 0] = -coef[N]
        Qccc = np.zeros((4, 4))
        Q = np.zeros((4, 4))
        for i in range(4):
            Qccc[:, i:i + 1] = np.dot(np.linalg.matrix_power(Acc_4, i), Bcc_4)
            Q[:, i:i + 1] = np.dot(np.linalg.matrix_power(A_4, i), B_4)
        Mcc = np.dot(Q, np.linalg.inv(Qccc))
        Ccc_4 = np.dot(C_4, Mcc)
        num = list(Ccc_4)
        num.reverse()
        den = list(-Acc_4[3, :])
        den.append(1.)
        den.reverse()
        return num, den, val_p

    def Pade_reduction(pt_trim):
        num, den, val_p = transfer_function(pt_trim)
        p = num[-1] / den[-1]
        q = (num[-2] - (num[-1] / den[-1]) * den[-2]) / den[-1]
        poles = sorted(val_p, key=lambda x: abs(x))
        pade_poles = poles[0:2]
        den_pade = np.poly(pade_poles)
        b_0 = den_pade[-1] * p
        b_1 = q * den_pade[-1] + b_0 * den_pade[-2] / den_pade[-1]
        num_pade = [b_1, b_0]
        return num_pade, den_pade

    compare_lin(240, pt_trim1)
    compare_lin(10, pt_trim1)
    q3(240, pt_trim1, pt_trim2)

    print("A_m = ", modal_form(pt_trim1)[0])
    print("B_m = ", modal_form(pt_trim1)[1])

    print("Les valeurs propres sont : ", stability(pt_trim1))

    print("La matrice de commandabilité est Q= ", controllability(pt_trim1))

    num, den, _ = transfer_function(pt_trim1)
    print("Les coefficients de la fonction de transfert sont : ")
    print("numérateur : ", num)
    print("dénominateur : ", den)
    num_pade, den_pade = Pade_reduction(pt_trim1)
    print("Les coefficients de la fonction de transfert réduite sont : ")
    print("numérateur : ", num_pade)
    print("dénominateur : ", den_pade)

    time = np.arange(0, 240, 0.2)
    plt.figure()
    step(num, den, time, "$F$")
    step(num_pade, den_pade, time, "$F_r$")
    plt.title("Réponse indicielle")
    plt.legend()
    plt.xlabel("time ($s$)")
    plt.ylabel("$\\theta$")
    plt.savefig(file + "reponse_indicielle" + format)
    plt.show()

    plt.figure()
    Bode([num, num_pade], [den, den_pade], ["$F$", "$F_r$"])
    plt.savefig(file + "Bode" + format)
    plt.show()
Esempio n. 39
0
def main():

    PLANE = dynamic.Param_737_800()

    h = [3000, 10000]
    Ma = [0.4, 0.9]
    ms = [-0.2, 0.5]
    km = [0.1, 1]
    va0 = dynamic.va_of_mach(Ma[0], 0)
    va1 = dynamic.va_of_mach(Ma[1], 0)

    def q1():
        lh = np.linspace(h[0], h[1], 100)
        n = len(lh)
        for i, ms_i in enumerate(ms):
            for j, km_i in enumerate(km):
                PLANE.set_mass_and_static_margin(km_i, ms_i)
                alpha0 = np.zeros(n)
                dphr0 = np.zeros(n)
                dth0 = np.zeros(n)
                alpha1 = np.zeros(n)
                dphr1 = np.zeros(n)
                dth1 = np.zeros(n)
                for k, h_i in enumerate(lh):
                    va0 = dynamic.va_of_mach(Ma[0], h_i)
                    va1 = dynamic.va_of_mach(Ma[1], h_i)
                    alpha0[k] = dynamic.trim(PLANE, {
                        'va': va0,
                        'h': h_i
                    })[0][3]
                    dphr0[k] = dynamic.trim(PLANE, {'va': va0, 'h': h_i})[1][0]
                    dth0[k] = dynamic.trim(PLANE, {'va': va0, 'h': h_i})[1][1]
                    alpha1[k] = dynamic.trim(PLANE, {
                        'va': va1,
                        'h': h_i
                    })[0][3]
                    dphr1[k] = dynamic.trim(PLANE, {'va': va1, 'h': h_i})[1][0]
                    dth1[k] = dynamic.trim(PLANE, {'va': va1, 'h': h_i})[1][1]

                plt.figure("m_s={}, k_m={}".format(ms_i, km_i))
                plt.subplot(1, 3, 1)
                plt.title("$h \\mapsto \\alpha$")
                #plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.plot(lh, alpha0, label="$M_a=0.4$")
                plt.plot(lh, alpha1, label="$M_a=0.9$")
                plt.legend()
                #plt.xlabel("$h$")
                #plt.ylabel("$\\alpha$")
                #plt.show()

                #plt.figure()
                plt.subplot(1, 3, 2)
                #plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.title("$h \\mapsto \\delta_{{th}}$")
                plt.plot(lh, dth0, label="$M_a=0.4$")
                plt.plot(lh, dth1, label="$M_a=0.9$")
                #plt.legend()
                #plt.xlabel("$h$")
                #plt.ylabel("$\\delta_{{th}}$")
                #plt.show()

                #plt.figure()
                plt.subplot(1, 3, 3)
                #plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.title("$h \\mapsto \\delta_{{PHR}}$")
                plt.plot(lh, dphr0, label="$M_a=0.4$")
                plt.plot(lh, dphr1, label="$M_a=0.9$")
                #plt.xlabel("$h$")
                #plt.ylabel("$\\delta_{{PHR}}$")
                #plt.legend()
                plt.tight_layout(.5)
                plt.savefig(file + "q1_" + str(i) + str(j) + format)
                #plt.show()

        plt.show()

    def q2():
        lm = np.linspace(Ma[0], Ma[1])
        n = len(lm)
        for i, ms_i in enumerate(ms):
            for j, km_i in enumerate(km):
                PLANE.set_mass_and_static_margin(km_i, ms_i)
                F0 = np.zeros(n)
                F1 = np.zeros(n)
                for k, m_i in enumerate(lm):
                    va0 = dynamic.va_of_mach(m_i, h[0])
                    va1 = dynamic.va_of_mach(m_i, h[1])
                    X0, U0 = dynamic.trim(PLANE, {'va': va0, 'h': h[0]})
                    X1, U1 = dynamic.trim(PLANE, {'va': va1, 'h': h[1]})
                    F0[k] = dynamic.propulsion_model(X0, U0, PLANE)
                    F1[k] = dynamic.propulsion_model(X1, U1, PLANE)
                plt.subplot(2, 2, i + 2 * j + 1)
                plt.plot(lm, F0, label="$h={}$".format(h[0]))
                plt.plot(lm, F1, label="$h={}$".format(h[1]))
                plt.legend()
                plt.title("$m_s={}, k_m={}$".format(ms_i, km_i))
                plt.xlabel("$M_a$")
                plt.ylabel("$F$")
        plt.tight_layout(.5)
        plt.savefig(file + "q2" + format)
        plt.show()

    def get_Cl():
        Va = dynamic.va_of_mach(Ma[1], h[1])
        PLANE.set_mass_and_static_margin(km[1], ms[1])
        rho = utils.isa(h[1])[1]
        Cl = (PLANE.m * PLANE.g) / (0.5 * rho * PLANE.S * Va**2)
        return Cl

    def get_dth():
        Cd = 0.030  # obtenu par lecture graphique à partir de la courbe polaire séance1
        # Cl = 0.3706 : fct get_Cl()
        # alpha_eq = 3.66° : courbe q5 séance 1
        # delat_THR_eq = -8.77° : courbe q4 séance1
        f = get_Cl() / Cd
        F = PLANE.m * PLANE.g / f
        rho0 = utils.isa(h[1])[1]
        rho = utils.isa(h[1])[1]
        dth = F / (PLANE.F0 * (rho / rho0)**(0.6) * (0.568 + 0.25 *
                                                     (1.2 - Ma[1])**3))
        return dth

    def get_dPHR_alpha_num():
        St_over_S = PLANE.St / PLANE.S
        CLta = PLANE.CLat
        CLwba = PLANE.CLa
        a0 = PLANE.a0
        CL0 = (St_over_S * 0.25 * CLta - CLwba) * a0
        CLa = CLwba + St_over_S * CLta * (1 - 0.25)
        #CLq = PLANE.lt*St_over_S*PLANE.CLat*PLANE.CLq
        CLdphr = St_over_S * CLta
        Cm0 = PLANE.Cm0
        Cma = -PLANE.ms * CLwba
        Cmdphr = PLANE.Cmd
        CL = get_Cl()
        alpha_eq = (Cm0 - Cma * a0 + Cmdphr *
                    (CL - CL0) / CLdphr) / (-Cma + Cmdphr * CLa / CLdphr)
        dphr_eq = (CL - CL0 - CLa * alpha_eq) / CLdphr
        return alpha_eq * 180 / pi, dphr_eq * 180 / pi

    def simu():
        time = np.arange(0, 100, 0.1)
        PLANE.set_mass_and_static_margin(km[1], Ma[1])
        va = dynamic.va_of_mach(Ma[1], h[1])
        Xtrim, Utrim = dynamic.trim(PLANE, {'va': va, 'h': h[1]})
        x = integrate.odeint(dynamic.dyn, Xtrim, time, args=(Utrim, PLANE))
        dynamic.plot(time, x)
        plt.savefig(file + "simu" + format)
        plt.show()

    def val_propre(n):
        vp = np.zeros((n, n, n, n, 4), dtype=complex)
        lh = np.linspace(h[0], h[1], n)
        lMa = np.linspace(Ma[0], Ma[1], n)
        lms = np.linspace(ms[0], ms[1], n)
        lkm = np.linspace(km[0], km[1], n)
        for i, h_i in enumerate(lh):
            for j, Ma_j in enumerate(lMa):
                for k, ms_k in enumerate(lms):
                    for l, km_l in enumerate(lkm):
                        PLANE.set_mass_and_static_margin(km_l, ms_k)
                        params = {
                            'va': dynamic.va_of_mach(Ma_j, h_i),
                            'h': h_i,
                            'gamma': 0
                        }
                        X, U = dynamic.trim(PLANE, params)
                        A, B = dynamic.ut.num_jacobian(X, U, PLANE,
                                                       dynamic.dyn)
                        A_4 = A[2:, 2:]
                        liste_vp = np.linalg.eigvals(A_4)
                        for m, ev in enumerate(liste_vp):
                            vp[i][j][k][l][m] = ev
        #print(A_4)
        #print(np.linalg.eigvals(A_4))
        return vp

    def plot_h(n, vp):
        for j, Ma_j in enumerate(Ma):
            for k, ms_k in enumerate(ms):
                for l, km_l in enumerate(km):
                    vp_Va = vp[:, j * (n - 1), k * (n - 1), l * (n - 1), 0]
                    vp_a = vp[:, j * (n - 1), k * (n - 1), l * (n - 1), 1]
                    vp_theta = vp[:, j * (n - 1), k * (n - 1), l * (n - 1), 2]
                    vp_q = vp[:, j * (n - 1), k * (n - 1), l * (n - 1), 3]
                    plt.figure()
                    plt.title("$M_a={}, m_s={}, k_m={}, h\in [{},{}]$".format(
                        Ma_j, ms_k, km_l, h[0], h[1]))
                    decorate(vp_Va, vp_a, vp_theta, vp_q)
                    if j == 0 and k == 1 and l == 1:
                        plt.savefig(file + "vp_h" + format)
        plt.show()

    def plot_Ma(n, vp):
        for i, h_i in enumerate(h):
            for k, ms_k in enumerate(ms):
                for l, km_l in enumerate(km):
                    vp_Va = vp[i * (n - 1), :, k * (n - 1), l * (n - 1), 0]
                    vp_a = vp[i * (n - 1), :, k * (n - 1), l * (n - 1), 1]
                    vp_theta = vp[i * (n - 1), :, k * (n - 1), l * (n - 1), 2]
                    vp_q = vp[i * (n - 1), :, k * (n - 1), l * (n - 1), 3]
                    plt.figure()
                    plt.title("$h={}, m_s={}, k_m={}, M_a\in [{},{}]$".format(
                        h_i, ms_k, km_l, Ma[0], Ma[1]))
                    decorate(vp_Va, vp_a, vp_theta, vp_q)
                    if i == 1 and k == 1 and l == 1:
                        plt.savefig(file + "vp_Ma" + format)
        plt.show()

    def plot_ms(n, vp):
        for i, h_i in enumerate(h):
            for j, Ma_j in enumerate(Ma):
                for l, km_l in enumerate(km):
                    vp_Va = vp[i * (n - 1), j * (n - 1), :, l * (n - 1), 0]
                    vp_a = vp[i * (n - 1), j * (n - 1), :, l * (n - 1), 1]
                    vp_theta = vp[i * (n - 1), j * (n - 1), :, l * (n - 1), 2]
                    vp_q = vp[i * (n - 1), j * (n - 1), :, l * (n - 1), 3]
                    plt.figure()
                    plt.title("$h={}, M_a={}, k_m={}, m_s\in [{},{}]$".format(
                        h_i, Ma_j, km_l, ms[0], ms[1]))
                    decorate(vp_Va, vp_a, vp_theta, vp_q)
                    if i == 1 and j == 0 and l == 1:
                        plt.savefig(file + "vp_ms" + format)
        plt.show()

    def plot_km(n, vp):
        for i, h_i in enumerate(h):
            for j, Ma_j in enumerate(Ma):
                for k, ms_k in enumerate(ms):
                    vp_Va = vp[i * (n - 1), j * (n - 1), k * (n - 1), :, 0]
                    vp_a = vp[i * (n - 1), j * (n - 1), k * (n - 1), :, 1]
                    vp_theta = vp[i * (n - 1), j * (n - 1), k * (n - 1), :, 2]
                    vp_q = vp[i * (n - 1), j * (n - 1), k * (n - 1), :, 3]
                    plt.figure()
                    plt.title("$h={}, M_a={}, m_s={}, k_m\in [{},{}]$".format(
                        h_i, Ma_j, ms_k, km[0], km[1]))
                    decorate(vp_Va, vp_a, vp_theta, vp_q)
                    if i == 1 and j == 0 and k == 1:
                        plt.savefig(file + "vp_km" + format)
        plt.show()

    #q1()
    #q2()
    print("Au point de trim (h, Ma, ms, km)=(10000, 0.9, 0.5, 1), Cl = " +
          str(get_Cl()))
    print("Lecture graphique")
    print(
        "Cd = 0.030 obtenu par lecture graphique à partir de la courbe polaire séance1"
    )
    print("alpha_eq = 3.66° : courbe q5 séance 1")
    print("delat_PHR_eq = -8.77° : courbe q4 séance1")
    print("on calcule dth : dth=" + str(get_dth()))
    print("Calcul numérique : ")
    print("dPHR = " + str(get_dPHR_alpha_num()[1]))
    print("alpha = " + str(get_dPHR_alpha_num()[0]))
    #simu()
    n = 10
    vp = val_propre(n)
    plot_h(n, vp)
    plot_Ma(n, vp)
    plot_ms(n, vp)
    plot_km(n, vp)