From 15c8d406385543a2b7b407a603037b1a1f5cb924 Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 4 Jan 2016 01:43:12 +0100 Subject: [PATCH 1/8] Add Cessna310.py unfinished Cessna310.py is added unfinished, Lat_Aero_Coefficients, gets_forces and gets moments are missing. --- src/pyfme/aircrafts/Cessna310.py | 128 +++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/pyfme/aircrafts/Cessna310.py diff --git a/src/pyfme/aircrafts/Cessna310.py b/src/pyfme/aircrafts/Cessna310.py new file mode 100644 index 0000000..bc0c55a --- /dev/null +++ b/src/pyfme/aircrafts/Cessna310.py @@ -0,0 +1,128 @@ +# -*- coding: utf-8 -*- +""" +Created on Sun Jan 3 18:44:39 2016 + +@author:olrosales@gmail.com + +@AeroPython +""" + +## Aircraft = Cessna 310 + + +import numpy as np + +def Geometric_Data(): + + """ Provides the value of some geometric data. + + Data + ---- + + Sw Surface (m^2) + c Mean Aerodynamic Chord (m2) + b Wing Span (m2) + + References + ---------- + AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) + page 589 + """ + #falta expresar el valor de conversión entre el libro y el SI + Sw = 16.258 + c = 0.4450056 + b = 3.428122 + + return Sw, c, b + +def Mass_and_Inertial_Data(): + + """ Provides the value of some mass and inertial data. + + Data + ----- + m mass (lb * 0.453592 = kg) + Ixxb Moment of Inertia x-axis ( slug * ft2 * 1.3558179 = Kg * m2) + Iyyb Moment of Inertia y-axis ( slug * ft2 * 1.3558179 = Kg * m2) + Izzb Moment of Inertia z-axis ( slug * ft2 * 1.3558179 = Kg * m2) + Ixzb Product of Inertia xz-plane ( slug * ft2 * 1.3558179 = Kg * m2) + + References + ---------- + AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) + page 589 + """ + + m = 4600 * 0.453592 + Ixxb = 8884 * 1.3558179 + Iyyb = 1939 * 1.3558179 + Izzb = 11001 * 1.3558179 + Ixzb = 0 * 1.3558179 + + I_matrix = np.diag([Ixxb,Iyyb,Izzb]) + + return m, I_matrix + +def Long_Aero_Coefficients(): + + """Long_Aero_coefficients assigns the value of the coefficients + of stability and order them in a matrix. + + Coefficients + ------------ + + CL0 is the lift coefficient evaluated at the initial condition + CLa is the lift stability derivative with respect to the angle of attack + CLde is the lift stability derivative with respect to the elevator + deflection + CLdih is the lift stability derivative with respect to the stabilator + deflection + + CD0 is the drag coefficiente evaluated at the initial condition + CDa is the drag stability derivative with respect to the angle of attack + + Cm0 is the pitching moment coefficient evaluated at the condition + (alpha0 = deltaE = deltaih = 0º) + Cma is the pitching moment stability derivative with respect to the angle + of attack + Cmde is the pitching moment stability derivative with respect to the + elevator deflection + Cmdih is the pitching moment stability derivative with respect to the + stabilator deflection + + References + ---------- + AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) + page 589 + """ + + + + + CL0 = 0.288 + CLa = 4.58 + CLde = 0.81 + CLdih = 0 + + CD0 = 0.029 + CDa = 0.160 + + Cm0 = 0.07 + Cma = -0.137 + Cmde = -2.26 + Cmdih = 0 + + Long_coef_matrix = np.array([ + [CL0, CLa, CLde, CLdih], + [CD0, CDa, 0, 0], + [Cm0, Cma, Cmde, Cmdih] + ]) + + return Long_coef_matrix + + + + + + + From 6f18fc098c978c8e8785d90d70eb4e4d9a1ab571 Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 4 Jan 2016 12:17:48 +0100 Subject: [PATCH 2/8] Add Cessna310.py completed Cessna310.py is completed but it needs to be reviewed again Cessnat310.py provide forces and moments --- src/pyfme/aircrafts/Cessna310.py | 219 ++++++++++++++++++++++++++++++- 1 file changed, 214 insertions(+), 5 deletions(-) diff --git a/src/pyfme/aircrafts/Cessna310.py b/src/pyfme/aircrafts/Cessna310.py index bc0c55a..631fcab 100644 --- a/src/pyfme/aircrafts/Cessna310.py +++ b/src/pyfme/aircrafts/Cessna310.py @@ -66,7 +66,7 @@ def Mass_and_Inertial_Data(): def Long_Aero_Coefficients(): """Long_Aero_coefficients assigns the value of the coefficients - of stability and order them in a matrix. + of stability in cruise conditions and order them in a matrix. Coefficients ------------ @@ -113,16 +113,225 @@ def Long_Aero_Coefficients(): Cmdih = 0 Long_coef_matrix = np.array([ - [CL0, CLa, CLde, CLdih], - [CD0, CDa, 0, 0], - [Cm0, Cma, Cmde, Cmdih] - ]) + [CL0, CLa, CLde, CLdih], + [CD0, CDa, 0, 0], + [Cm0, Cma, Cmde, Cmdih] + ]) return Long_coef_matrix +def Lat_Aero_Coefficients(): + """Long_Aero_coefficients assigns the value of the coefficients + of stability in cruise conditions and order them in a matrix. + + Coefficients + ------------ + + CYb is the side force stability derivative with respect to the + angle of sideslip + CYda is the side force stability derivative with respect to the + aileron deflection + CYdr is the side force stability derivative with respect to the + rudder deflection + + Clb is the rolling moment stability derivative with respect to + angle of sideslip + Clda is the rolling moment stability derivative with respect to + the aileron deflection + Cldr is the rolling moment stability derivative with respect to + the rudder deflection + + Cnb is the yawing moment stability derivative with respect to the + angle of sideslip + Cnda is the yawing moment stability derivative with respect to the + aileron deflection + Cndr is the yawing moment stability derivative with respect to the + rudder deflection + + + References + ---------- + AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) + page 590 + """ + + CYb = -0.698 + CYda = 0 + CYdr = 0.230 + + Clb = -0.1096 + Clda = 0.172 + Cldr = 0.0192 + + Cnb = 0.1444 + Cnda = -0.0168 + Cndr = -0.1152 + + Lat_coef_matrix = np.array([ + [CYb, CYda, CYdr], + [Clb, Clda, Cldr], + [Cnb, Cnda, Cndr] + ]) + + return Lat_coef_matrix + +def q (U,rho): + + """ Calculates the dinamic pressure q = 0.5*rho*U^2 + + Parameters + ---------- + + rho : float + density (SI) + U : flota + velocity (SI) + + returns + ------- + + q : float + dinamic pressure + + """ + #Aquí falta asegurarse que la densidad y la velocidad que entra son correctas + + q = 0.5 * rho * (U ** 2) + + return q + + + +def get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar): + + + """ Calculates forces + + Parameters + ---------- + + rho = float + density (SI) + U = flota + velocity (SI) + + alpha : float + attack angle (rad). + beta : float + sideslip angle (rad). + deltae : float + elevator deflection (rad). + ih : float + stabilator deflection (rad). + deltaail : float + aileron deflection (rad). + deltar : float + rudder deflection (rad). + + + + + returns + ------- + + forces : array_like + 3 dimensional vector with (Fxs, Fys, Fzs) forces in stability axes. + + References + ---------- + AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) + chapter 3 and 4 + """ + long_control = np.array(1, alpha, deltae, ih) + Long_coef_matrix = Long_Aero_Coefficients() + + lat_control = np.array(beta, deltaail, deltar) + Lat_coef_matrix = Lat_Aero_Coefficients() + + CLfull = np.dot(Long_coef_matrix[0,:],long_control) + CDfull = np.dot(Long_coef_matrix[1,:],long_control) + CYfull = np.dot(Lat_coef_matrix[0,:],lat_control) + + + forces = q(U,rho)*Geometric_Data()[0] * np.array([-CDfull, -CLfull, CYfull]) + + return forces + + +def get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar): + + + """ Calculates forces + + Parameters + ---------- + + rho = float + density (SI) + U = flota + velocity (SI) + + alpha : float + attack angle (rad). + beta : float + sideslip angle (rad). + deltae : float + elevator deflection (rad). + ih : float + stabilator deflection (rad). + deltaail : float + aileron deflection (rad). + deltar : float + rudder deflection (rad). + + + + + returns + ------- + + moments : array_like + 3 dimensional vector with (Mxs, Mys, Mzs) forces in stability axes. + + References + ---------- + AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) + chapter 3 and 4 + """ + long_control = np.array(1, alpha, deltae, ih) + Long_coef_matrix = Long_Aero_Coefficients() + + lat_control = np.array(beta, deltaail, deltar) + Lat_coef_matrix = Lat_Aero_Coefficients() + + Cmfull = np.dot(Long_coef_matrix[2,:],long_control) + Clfull = np.dot(Lat_coef_matrix[1,:],lat_control) + Cnfull = np.dot(Lat_coef_matrix[2,:],lat_control) + moments = q(U,rho)*Geometric_Data()[0] * np.array([Clfull*Geometric_Data[2], + Cmfull*Geometric_Data[1], + Cnfull*Geometric_Data[2] + ]) + + return moments + + + + + + + + + + + + + + + + From d4ce7a1e3fd8291fce298e276ed50570bace36b1 Mon Sep 17 00:00:00 2001 From: Oscar Date: Sun, 10 Jan 2016 15:17:28 +0100 Subject: [PATCH 3/8] Adds tests and corrects style --- src/pyfme/aircrafts/Cessna310.py | 56 +++++++++++-------- src/pyfme/aircrafts/__init__.py | 2 + src/pyfme/aircrafts/test/test_Cessna310.py | 64 ++++++++++++++++++++++ 3 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 src/pyfme/aircrafts/__init__.py create mode 100644 src/pyfme/aircrafts/test/test_Cessna310.py diff --git a/src/pyfme/aircrafts/Cessna310.py b/src/pyfme/aircrafts/Cessna310.py index 631fcab..0d1578c 100644 --- a/src/pyfme/aircrafts/Cessna310.py +++ b/src/pyfme/aircrafts/Cessna310.py @@ -16,7 +16,7 @@ def Geometric_Data(): """ Provides the value of some geometric data. - Data + Returns ---- Sw Surface (m^2) @@ -39,7 +39,7 @@ def Mass_and_Inertial_Data(): """ Provides the value of some mass and inertial data. - Data + Returns ----- m mass (lb * 0.453592 = kg) Ixxb Moment of Inertia x-axis ( slug * ft2 * 1.3558179 = Kg * m2) @@ -65,7 +65,7 @@ def Mass_and_Inertial_Data(): def Long_Aero_Coefficients(): - """Long_Aero_coefficients assigns the value of the coefficients + """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. Coefficients @@ -123,7 +123,7 @@ def Long_Aero_Coefficients(): def Lat_Aero_Coefficients(): - """Long_Aero_coefficients assigns the value of the coefficients + """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. Coefficients @@ -189,7 +189,7 @@ def q (U,rho): U : flota velocity (SI) - returns + Returns ------- q : float @@ -233,7 +233,7 @@ def get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar): - returns + Returns ------- forces : array_like @@ -244,18 +244,24 @@ def get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar): AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) chapter 3 and 4 """ - long_control = np.array(1, alpha, deltae, ih) + Long_coef_matrix = Long_Aero_Coefficients() - - lat_control = np.array(beta, deltaail, deltar) Lat_coef_matrix = Lat_Aero_Coefficients() - CLfull = np.dot(Long_coef_matrix[0,:],long_control) - CDfull = np.dot(Long_coef_matrix[1,:],long_control) - CYfull = np.dot(Lat_coef_matrix[0,:],lat_control) + + CL0, CLa, CLde, CLdih = Long_coef_matrix[0,:] + CD0, CDa, CDde, CDdih = Long_coef_matrix[1,:] + CYb, CYda, CYdr = Lat_coef_matrix[0,:] + + + + + CLfull = CL0 + CLa * alpha + CLde * deltae + CLdih * ih + CDfull = CD0 + CDa * alpha + CDde * deltae + CDdih * ih + CYfull = CYb * beta + CYda* deltaail + CYdr * deltar - forces = q(U,rho)*Geometric_Data()[0] * np.array([-CDfull, -CLfull, CYfull]) + forces = q(U,rho) * Geometric_Data()[0] * np.array([-CDfull, -CLfull, CYfull]) return forces @@ -300,19 +306,23 @@ def get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar): AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) chapter 3 and 4 """ - long_control = np.array(1, alpha, deltae, ih) + Long_coef_matrix = Long_Aero_Coefficients() - - lat_control = np.array(beta, deltaail, deltar) Lat_coef_matrix = Lat_Aero_Coefficients() + - Cmfull = np.dot(Long_coef_matrix[2,:],long_control) - Clfull = np.dot(Lat_coef_matrix[1,:],lat_control) - Cnfull = np.dot(Lat_coef_matrix[2,:],lat_control) + Cm0, Cma, Cmde, Cmdih = Long_coef_matrix[2,:] + Clb, Clda, Cldr = Lat_coef_matrix[1,:] + Cnb, Cnda, Cndr = Lat_coef_matrix[2,:] + + + Cmfull = Cm0 + Cma * alpha + Cmde * deltae + Cmdih * ih + Clfull = Clb * beta + Clda* deltaail + Cldr * deltar + Cnfull = Cnb * beta + Cnda* deltaail + Cndr * deltar - moments = q(U,rho)*Geometric_Data()[0] * np.array([Clfull*Geometric_Data[2], - Cmfull*Geometric_Data[1], - Cnfull*Geometric_Data[2] + moments = q(U,rho) * Geometric_Data()[0] * np.array([Clfull * Geometric_Data()[2], + Cmfull * Geometric_Data()[1], + Cnfull * Geometric_Data()[2] ]) return moments @@ -320,7 +330,7 @@ def get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar): - +a = get_moments(100, 1.225, 0, 0 , 0 ,0, 0 ,0) diff --git a/src/pyfme/aircrafts/__init__.py b/src/pyfme/aircrafts/__init__.py new file mode 100644 index 0000000..139597f --- /dev/null +++ b/src/pyfme/aircrafts/__init__.py @@ -0,0 +1,2 @@ + + diff --git a/src/pyfme/aircrafts/test/test_Cessna310.py b/src/pyfme/aircrafts/test/test_Cessna310.py new file mode 100644 index 0000000..a474648 --- /dev/null +++ b/src/pyfme/aircrafts/test/test_Cessna310.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Jan 9 23:56:51 2016 + +@author:olrosales@gmail.com + +@AeroPython +""" + +import pytest + +import numpy as np + +from numpy.testing import (assert_array_almost_equal, assert_almost_equal) + +from pyfme.aircrafts.Cessna310 import (Mass_and_Inertial_Data, + q, get_forces, get_moments) + + + + +def test_q(): + + U = 100 + rho = 1.225 + q_expected = 6125 + + dinamyc_pressure = q(U, rho) + + assert_almost_equal(dinamyc_pressure, q_expected) + +def test_get_forces(): + + U = 100 + rho = 1.225 + alpha = 0 + beta = 0 + deltae = 0 + ih = 0 + deltaail = 0 + deltar = 0 + forces_expected = np.array([-2887.82725, -28679.112, 0]) + + forces = get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar) + + assert_array_almost_equal(forces, forces_expected) + +def test_get_moments(): + + U = 100 + rho = 1.225 + alpha = 0 + beta = 0 + deltae = 0 + ih = 0 + deltaail = 0 + deltar = 0 + moments_expected = np.array([0, 3101.963823, 0]) + + moments = get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar) + + assert_array_almost_equal(moments, moments_expected) + + \ No newline at end of file From c4fb7df7cc5c3f6527c42f8deeb24f1a3895067f Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 13 Jan 2016 21:22:20 +0100 Subject: [PATCH 4/8] Adds some changes in Cessna310.py and test_cessna310.py --- src/pyfme/aircrafts/Cessna310.py | 278 +++++++++++---------- src/pyfme/aircrafts/test/test_Cessna310.py | 14 +- 2 files changed, 151 insertions(+), 141 deletions(-) diff --git a/src/pyfme/aircrafts/Cessna310.py b/src/pyfme/aircrafts/Cessna310.py index 0d1578c..cd92fc5 100644 --- a/src/pyfme/aircrafts/Cessna310.py +++ b/src/pyfme/aircrafts/Cessna310.py @@ -19,19 +19,22 @@ def Geometric_Data(): Returns ---- - Sw Surface (m^2) - c Mean Aerodynamic Chord (m2) - b Wing Span (m2) + Sw : float + Wing surface (ft2 * 0.3048 * 0.3048 = m2) + c : foat + Mean aerodynamic Chord (ft * 0.3048 = m) + b : float + Wing span (ft * 0.3048 = m) References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 589 """ - #falta expresar el valor de conversión entre el libro y el SI - Sw = 16.258 - c = 0.4450056 - b = 3.428122 + + Sw = 175 * 0.3048 * 0.3048 # m2 + c = 4.79 * 0.3048 # m + b = 36.9 * 0.3048 # m return Sw, c, b @@ -40,26 +43,33 @@ def Mass_and_Inertial_Data(): """ Provides the value of some mass and inertial data. Returns - ----- - m mass (lb * 0.453592 = kg) - Ixxb Moment of Inertia x-axis ( slug * ft2 * 1.3558179 = Kg * m2) - Iyyb Moment of Inertia y-axis ( slug * ft2 * 1.3558179 = Kg * m2) - Izzb Moment of Inertia z-axis ( slug * ft2 * 1.3558179 = Kg * m2) - Ixzb Product of Inertia xz-plane ( slug * ft2 * 1.3558179 = Kg * m2) - + ------ + m : float + mass (lb * 0.453592 = kg) + I_xx_b : float + Moment of Inertia x-axis ( slug * ft2 * 1.3558179 = Kg * m2) + I_yy_b : float + Moment of Inertia y-axis ( slug * ft2 * 1.3558179 = Kg * m2) + I_zz_b : float + Moment of Inertia z-axis ( slug * ft2 * 1.3558179 = Kg * m2) + I_xz_b : float + Product of Inertia xz-plane ( slug * ft2 * 1.3558179 = Kg * m2) + I_matrix : array_like + I_xx_b,I_yy_b,I_zz_b] + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 589 """ - m = 4600 * 0.453592 - Ixxb = 8884 * 1.3558179 - Iyyb = 1939 * 1.3558179 - Izzb = 11001 * 1.3558179 - Ixzb = 0 * 1.3558179 + m = 4600 * 0.453592 # kg + I_xx_b = 8884 * 1.3558179 # Kg * m2 + I_yy_b = 1939 * 1.3558179 # Kg * m2 + I_zz_b = 11001 * 1.3558179 # Kg * m2 + I_xz_b = 0 * 1.3558179 # Kg * m2 - I_matrix = np.diag([Ixxb,Iyyb,Izzb]) + I_matrix = np.diag([I_xx_b,I_yy_b,I_zz_b]) return m, I_matrix @@ -67,112 +77,122 @@ def Long_Aero_Coefficients(): """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. + - Coefficients - ------------ - - CL0 is the lift coefficient evaluated at the initial condition - CLa is the lift stability derivative with respect to the angle of attack - CLde is the lift stability derivative with respect to the elevator + C_L_0 is the lift coefficient evaluated at the initial condition + C_L_a is the lift stability derivative with respect to the angle of attack + C_L_de is the lift stability derivative with respect to the elevator deflection - CLdih is the lift stability derivative with respect to the stabilator + C_L_dih is the lift stability derivative with respect to the stabilator deflection - CD0 is the drag coefficiente evaluated at the initial condition - CDa is the drag stability derivative with respect to the angle of attack + C_D_0 is the drag coefficient evaluated at the initial condition + C_D_a is the drag stability derivative with respect to the angle of attack - Cm0 is the pitching moment coefficient evaluated at the condition + C_m_0 is the pitching moment coefficient evaluated at the condition (alpha0 = deltaE = deltaih = 0º) - Cma is the pitching moment stability derivative with respect to the angle + C_m_a is the pitching moment stability derivative with respect to the angle of attack - Cmde is the pitching moment stability derivative with respect to the + C_m_de is the pitching moment stability derivative with respect to the elevator deflection - Cmdih is the pitching moment stability derivative with respect to the + C_m_dih is the pitching moment stability derivative with respect to the stabilator deflection + + Returns + ------- + + Long_coef_matrix : array_like + [ + [C_L_0, C_L_a, C_L_de, C_L_dih], + [C_D_0, C_D_a, 0, 0], + [C_m_0, C_m_a, C_m_de, C_m_dih] + ] + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 589 """ + C_L_0 = 0.288 + C_L_a = 4.58 + C_L_de = 0.81 + C_L_dih = 0 + C_D_0 = 0.029 + C_D_a = 0.160 - - - CL0 = 0.288 - CLa = 4.58 - CLde = 0.81 - CLdih = 0 - - CD0 = 0.029 - CDa = 0.160 - - Cm0 = 0.07 - Cma = -0.137 - Cmde = -2.26 - Cmdih = 0 + C_m_0 = 0.07 + C_m_a = -0.137 + C_m_de = -2.26 + C_m_dih = 0 Long_coef_matrix = np.array([ - [CL0, CLa, CLde, CLdih], - [CD0, CDa, 0, 0], - [Cm0, Cma, Cmde, Cmdih] + [C_L_0, C_L_a, C_L_de, C_L_dih], + [C_D_0, C_D_a, 0, 0], + [C_m_0, C_m_a, C_m_de, C_m_dih] ]) return Long_coef_matrix - - + def Lat_Aero_Coefficients(): """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. - Coefficients - ------------ - - CYb is the side force stability derivative with respect to the + C_Y_b is the side force stability derivative with respect to the angle of sideslip - CYda is the side force stability derivative with respect to the + C_Y_da is the side force stability derivative with respect to the aileron deflection - CYdr is the side force stability derivative with respect to the + C_Y_dr is the side force stability derivative with respect to the rudder deflection - Clb is the rolling moment stability derivative with respect to + C_l_b is the rolling moment stability derivative with respect to angle of sideslip - Clda is the rolling moment stability derivative with respect to + C_l_da is the rolling moment stability derivative with respect to the aileron deflection - Cldr is the rolling moment stability derivative with respect to + C_l_dr is the rolling moment stability derivative with respect to the rudder deflection - Cnb is the yawing moment stability derivative with respect to the + C_n_b is the yawing moment stability derivative with respect to the angle of sideslip - Cnda is the yawing moment stability derivative with respect to the + C_n_da is the yawing moment stability derivative with respect to the aileron deflection - Cndr is the yawing moment stability derivative with respect to the + C_n_dr is the yawing moment stability derivative with respect to the rudder deflection - + returns + ------- + Long_coef_matrix : array_like + [ + [CYb, CYda, CYdr], + [Clb, Clda, Cldr], + [Cnb, Cnda, Cndr] + ] + + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 590 """ - CYb = -0.698 - CYda = 0 - CYdr = 0.230 + C_Y_b = -0.698 + C_Y_da = 0 + C_Y_dr = 0.230 - Clb = -0.1096 - Clda = 0.172 - Cldr = 0.0192 + C_l_b = -0.1096 + C_l_da = 0.172 + C_l_dr = 0.0192 - Cnb = 0.1444 - Cnda = -0.0168 - Cndr = -0.1152 + C_n_b = 0.1444 + C_n_da = -0.0168 + C_n_dr = -0.1152 Lat_coef_matrix = np.array([ - [CYb, CYda, CYdr], - [Clb, Clda, Cldr], - [Cnb, Cnda, Cndr] + [C_Y_b, C_Y_da, C_Y_dr], + [C_l_b, C_l_da, C_l_dr], + [C_n_b, C_n_da, C_n_dr] ]) return Lat_coef_matrix @@ -204,40 +224,36 @@ def q (U,rho): -def get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar): - +def get_aerodynamic_forces( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): """ Calculates forces Parameters ---------- - rho = float - density (SI) - U = flota - velocity (SI) + rho : float + density (kg/(m3)) + U : float + velocity (m/s) alpha : float attack angle (rad). beta : float sideslip angle (rad). - deltae : float + delta_e : float elevator deflection (rad). ih : float stabilator deflection (rad). - deltaail : float + delta_ail : float aileron deflection (rad). - deltar : float + delta_r : float rudder deflection (rad). - - - - + Returns ------- forces : array_like - 3 dimensional vector with (Fxs, Fys, Fzs) forces in stability axes. + 3 dimensional vector with (F_x_s, F_y_s, F_z_s) forces in stability axes. References ---------- @@ -247,54 +263,48 @@ def get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar): Long_coef_matrix = Long_Aero_Coefficients() Lat_coef_matrix = Lat_Aero_Coefficients() - - - CL0, CLa, CLde, CLdih = Long_coef_matrix[0,:] - CD0, CDa, CDde, CDdih = Long_coef_matrix[1,:] - CYb, CYda, CYdr = Lat_coef_matrix[0,:] - - - - - CLfull = CL0 + CLa * alpha + CLde * deltae + CLdih * ih - CDfull = CD0 + CDa * alpha + CDde * deltae + CDdih * ih - CYfull = CYb * beta + CYda* deltaail + CYdr * deltar + + C_L_0, C_L_a, C_L_de, C_L_dih = Long_coef_matrix[0,:] + C_D_0, C_D_a, C_D_de, C_D_dih = Long_coef_matrix[1,:] + C_Y_b, C_Y_da, C_Y_dr = Lat_coef_matrix[0,:] + + C_L_full = C_L_0 + C_L_a * alpha + C_L_de * delta_e + C_L_dih * ih + C_D_full = C_D_0 + C_D_a * alpha + C_D_de * delta_e + C_D_dih * ih + C_Y_full = C_Y_b * beta + C_Y_da* delta_ail + C_Y_dr * delta_r + + b = Geometric_Data()[2] + c = Geometric_Data()[1] + Sw = Geometric_Data()[0] - - forces = q(U,rho) * Geometric_Data()[0] * np.array([-CDfull, -CLfull, CYfull]) - - return forces - - -def get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar): + aerodynamic_forces = q(U,rho) * Sw * np.array([-C_D_full, C_Y_full, -C_L_full]) #N + return aerodynamic_forces + +def get_aerodynamic_moments( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): """ Calculates forces Parameters ---------- - rho = float - density (SI) - U = flota - velocity (SI) + rho : float + density (kg/m3) + U : float + velocity (m/s) alpha : float attack angle (rad). beta : float sideslip angle (rad). - deltae : float + delta_e : float elevator deflection (rad). ih : float stabilator deflection (rad). - deltaail : float + delta_ail : float aileron deflection (rad). - deltar : float + delta_r : float rudder deflection (rad). - - - - + returns ------- @@ -306,31 +316,31 @@ def get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar): AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) chapter 3 and 4 """ - Long_coef_matrix = Long_Aero_Coefficients() Lat_coef_matrix = Lat_Aero_Coefficients() - Cm0, Cma, Cmde, Cmdih = Long_coef_matrix[2,:] - Clb, Clda, Cldr = Lat_coef_matrix[1,:] - Cnb, Cnda, Cndr = Lat_coef_matrix[2,:] + C_m_0, C_m_a, C_m_de, C_m_dih = Long_coef_matrix[2,:] + C_l_b, C_l_da, C_l_dr = Lat_coef_matrix[1,:] + C_n_b, C_n_da, C_n_dr = Lat_coef_matrix[2,:] + + C_m_full = C_m_0 + C_m_a * alpha + C_m_de * delta_e + C_m_dih * ih + C_l_full = C_l_b * beta + C_l_da* delta_ail + C_l_dr * delta_r + C_n_full = C_n_b * beta + C_n_da* delta_ail + C_n_dr * delta_r - Cmfull = Cm0 + Cma * alpha + Cmde * deltae + Cmdih * ih - Clfull = Clb * beta + Clda* deltaail + Cldr * deltar - Cnfull = Cnb * beta + Cnda* deltaail + Cndr * deltar + b = Geometric_Data()[2] + c = Geometric_Data()[1] + Sw = Geometric_Data()[0] - moments = q(U,rho) * Geometric_Data()[0] * np.array([Clfull * Geometric_Data()[2], - Cmfull * Geometric_Data()[1], - Cnfull * Geometric_Data()[2] - ]) + aerodynamic_moments = q(U,rho) * Sw * np.array([C_l_full * b,C_m_full * c,C_n_full * b]) + + return aerodynamic_moments - return moments -a = get_moments(100, 1.225, 0, 0 , 0 ,0, 0 ,0) diff --git a/src/pyfme/aircrafts/test/test_Cessna310.py b/src/pyfme/aircrafts/test/test_Cessna310.py index a474648..011c556 100644 --- a/src/pyfme/aircrafts/test/test_Cessna310.py +++ b/src/pyfme/aircrafts/test/test_Cessna310.py @@ -14,7 +14,7 @@ from numpy.testing import (assert_array_almost_equal, assert_almost_equal) from pyfme.aircrafts.Cessna310 import (Mass_and_Inertial_Data, - q, get_forces, get_moments) + q, get_aerodynamic_forces, get_aerodynamic_moments) @@ -39,11 +39,11 @@ def test_get_forces(): ih = 0 deltaail = 0 deltar = 0 - forces_expected = np.array([-2887.82725, -28679.112, 0]) + aerodynamic_forces_expected = np.array([-2887.82725, -28679.112, 0]) - forces = get_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar) + aerodynamic_forces = get_aerodynamic_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar) - assert_array_almost_equal(forces, forces_expected) + assert_array_almost_equal(aerodynamic_forces, aerodynamic_forces_expected) def test_get_moments(): @@ -55,10 +55,10 @@ def test_get_moments(): ih = 0 deltaail = 0 deltar = 0 - moments_expected = np.array([0, 3101.963823, 0]) + aerodynamic_moments_expected = np.array([0, 3101.963823, 0]) - moments = get_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar) + aerodynamic_moments = get_aerodynamic_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar) - assert_array_almost_equal(moments, moments_expected) + assert_array_almost_equal(aerodynamic_moments, aerodynamic_moments_expected) \ No newline at end of file From db5b0b0156a2d10c264fecc4ef4825b90ba9729c Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 18 Jan 2016 09:39:31 +0100 Subject: [PATCH 5/8] Added get_engine_force --- src/pyfme/aircrafts/Cessna310.py | 263 ++++++++++++--------- src/pyfme/aircrafts/test/test_Cessna310.py | 51 ++-- 2 files changed, 180 insertions(+), 134 deletions(-) diff --git a/src/pyfme/aircrafts/Cessna310.py b/src/pyfme/aircrafts/Cessna310.py index cd92fc5..ff28c15 100644 --- a/src/pyfme/aircrafts/Cessna310.py +++ b/src/pyfme/aircrafts/Cessna310.py @@ -12,7 +12,7 @@ import numpy as np -def Geometric_Data(): +def geometric_Data(): """ Provides the value of some geometric data. @@ -23,7 +23,7 @@ def Geometric_Data(): Wing surface (ft2 * 0.3048 * 0.3048 = m2) c : foat Mean aerodynamic Chord (ft * 0.3048 = m) - b : float + span : float Wing span (ft * 0.3048 = m) References @@ -34,27 +34,27 @@ def Geometric_Data(): Sw = 175 * 0.3048 * 0.3048 # m2 c = 4.79 * 0.3048 # m - b = 36.9 * 0.3048 # m + span = 36.9 * 0.3048 # m - return Sw, c, b + return Sw, c, span -def Mass_and_Inertial_Data(): +def mass_and_Inertial_Data(): """ Provides the value of some mass and inertial data. Returns ------ - m : float - mass (lb * 0.453592 = kg) - I_xx_b : float + mass : float + mass (lb * 0.453592 = kg) + Ixx_b : float Moment of Inertia x-axis ( slug * ft2 * 1.3558179 = Kg * m2) - I_yy_b : float + Iyy_b : float Moment of Inertia y-axis ( slug * ft2 * 1.3558179 = Kg * m2) - I_zz_b : float + Izz_b : float Moment of Inertia z-axis ( slug * ft2 * 1.3558179 = Kg * m2) - I_xz_b : float + Ixz_b : float Product of Inertia xz-plane ( slug * ft2 * 1.3558179 = Kg * m2) - I_matrix : array_like + inertia : array_like I_xx_b,I_yy_b,I_zz_b] References @@ -63,39 +63,39 @@ def Mass_and_Inertial_Data(): page 589 """ - m = 4600 * 0.453592 # kg - I_xx_b = 8884 * 1.3558179 # Kg * m2 - I_yy_b = 1939 * 1.3558179 # Kg * m2 - I_zz_b = 11001 * 1.3558179 # Kg * m2 - I_xz_b = 0 * 1.3558179 # Kg * m2 + mass = 4600 * 0.453592 # kg + Ixx_b = 8884 * 1.3558179 # Kg * m2 + Iyy_b = 1939 * 1.3558179 # Kg * m2 + Izz_b = 11001 * 1.3558179 # Kg * m2 + Ixz_b = 0 * 1.3558179 # Kg * m2 - I_matrix = np.diag([I_xx_b,I_yy_b,I_zz_b]) + inertia = np.diag([Ixx_b,Iyy_b,Izz_b]) - return m, I_matrix + return mass, inertia -def Long_Aero_Coefficients(): +def long_Aero_Coefficients(): """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. - C_L_0 is the lift coefficient evaluated at the initial condition - C_L_a is the lift stability derivative with respect to the angle of attack - C_L_de is the lift stability derivative with respect to the elevator + CL_0 is the lift coefficient evaluated at the initial condition + CL_a is the lift stability derivative with respect to the angle of attack + CL_de is the lift stability derivative with respect to the elevator deflection - C_L_dih is the lift stability derivative with respect to the stabilator + CL_dih is the lift stability derivative with respect to the stabilator deflection - C_D_0 is the drag coefficient evaluated at the initial condition - C_D_a is the drag stability derivative with respect to the angle of attack + CD_0 is the drag coefficient evaluated at the initial condition + CD_a is the drag stability derivative with respect to the angle of attack - C_m_0 is the pitching moment coefficient evaluated at the condition + Cm_0 is the pitching moment coefficient evaluated at the condition (alpha0 = deltaE = deltaih = 0º) - C_m_a is the pitching moment stability derivative with respect to the angle + Cm_a is the pitching moment stability derivative with respect to the angle of attack - C_m_de is the pitching moment stability derivative with respect to the + Cm_de is the pitching moment stability derivative with respect to the elevator deflection - C_m_dih is the pitching moment stability derivative with respect to the + Cm_dih is the pitching moment stability derivative with respect to the stabilator deflection Returns @@ -103,9 +103,9 @@ def Long_Aero_Coefficients(): Long_coef_matrix : array_like [ - [C_L_0, C_L_a, C_L_de, C_L_dih], - [C_D_0, C_D_a, 0, 0], - [C_m_0, C_m_a, C_m_de, C_m_dih] + [CL_0, CL_a, CL_de, CL_dih], + [CD_0, CD_a, 0, 0], + [Cm_0, Cm_a, Cm_de, Cm_dih] ] @@ -114,60 +114,60 @@ def Long_Aero_Coefficients(): AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 589 """ - C_L_0 = 0.288 - C_L_a = 4.58 - C_L_de = 0.81 - C_L_dih = 0 - - C_D_0 = 0.029 - C_D_a = 0.160 - - C_m_0 = 0.07 - C_m_a = -0.137 - C_m_de = -2.26 - C_m_dih = 0 - - Long_coef_matrix = np.array([ - [C_L_0, C_L_a, C_L_de, C_L_dih], - [C_D_0, C_D_a, 0, 0], - [C_m_0, C_m_a, C_m_de, C_m_dih] + CL_0 = 0.288 + CL_a = 4.58 + CL_de = 0.81 + CL_dih = 0 + + CD_0 = 0.029 + CD_a = 0.160 + + Cm_0 = 0.07 + Cm_a = -0.137 + Cm_de = -2.26 + Cm_dih = 0 + + long_coef_matrix = np.array([ + [CL_0, CL_a, CL_de, CL_dih], + [CD_0, CD_a, 0, 0], + [Cm_0, Cm_a, Cm_de, Cm_dih] ]) - return Long_coef_matrix + return long_coef_matrix -def Lat_Aero_Coefficients(): +def lat_Aero_Coefficients(): """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. - C_Y_b is the side force stability derivative with respect to the + CY_b is the side force stability derivative with respect to the angle of sideslip - C_Y_da is the side force stability derivative with respect to the + CY_da is the side force stability derivative with respect to the aileron deflection - C_Y_dr is the side force stability derivative with respect to the + CY_dr is the side force stability derivative with respect to the rudder deflection - C_l_b is the rolling moment stability derivative with respect to + Cl_b is the rolling moment stability derivative with respect to angle of sideslip - C_l_da is the rolling moment stability derivative with respect to + Cl_da is the rolling moment stability derivative with respect to the aileron deflection - C_l_dr is the rolling moment stability derivative with respect to + Cl_dr is the rolling moment stability derivative with respect to the rudder deflection - C_n_b is the yawing moment stability derivative with respect to the + Cn_b is the yawing moment stability derivative with respect to the angle of sideslip - C_n_da is the yawing moment stability derivative with respect to the + Cn_da is the yawing moment stability derivative with respect to the aileron deflection - C_n_dr is the yawing moment stability derivative with respect to the + Cn_dr is the yawing moment stability derivative with respect to the rudder deflection returns ------- Long_coef_matrix : array_like [ - [CYb, CYda, CYdr], - [Clb, Clda, Cldr], - [Cnb, Cnda, Cndr] + [CY_b, CY_da, CY_dr], + [Cl_b, Cl_da, Cl_dr], + [Cn_b, Cn_da, Cn_dr] ] @@ -177,27 +177,27 @@ def Lat_Aero_Coefficients(): page 590 """ - C_Y_b = -0.698 - C_Y_da = 0 - C_Y_dr = 0.230 - - C_l_b = -0.1096 - C_l_da = 0.172 - C_l_dr = 0.0192 - - C_n_b = 0.1444 - C_n_da = -0.0168 - C_n_dr = -0.1152 - - Lat_coef_matrix = np.array([ - [C_Y_b, C_Y_da, C_Y_dr], - [C_l_b, C_l_da, C_l_dr], - [C_n_b, C_n_da, C_n_dr] + CY_b = -0.698 + CY_da = 0 + CY_dr = 0.230 + + Cl_b = -0.1096 + Cl_da = 0.172 + Cl_dr = 0.0192 + + Cn_b = 0.1444 + Cn_da = -0.0168 + Cn_dr = -0.1152 + + lat_coef_matrix = np.array([ + [CY_b, CY_da, CY_dr], + [Cl_b, Cl_da, Cl_dr], + [Cn_b, Cn_da, Cn_dr] ]) - return Lat_coef_matrix + return lat_coef_matrix -def q (U,rho): +def q (TAS,rho): """ Calculates the dinamic pressure q = 0.5*rho*U^2 @@ -215,16 +215,15 @@ def q (U,rho): q : float dinamic pressure - """ - #Aquí falta asegurarse que la densidad y la velocidad que entra son correctas + """ - q = 0.5 * rho * (U ** 2) + q = 0.5 * rho * (TAS ** 2) return q -def get_aerodynamic_forces( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): +def get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): """ Calculates forces @@ -233,7 +232,7 @@ def get_aerodynamic_forces( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_r rho : float density (kg/(m3)) - U : float + TAS : float velocity (m/s) alpha : float @@ -261,26 +260,26 @@ def get_aerodynamic_forces( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_r chapter 3 and 4 """ - Long_coef_matrix = Long_Aero_Coefficients() - Lat_coef_matrix = Lat_Aero_Coefficients() + long_coef_matrix = long_Aero_Coefficients() + lat_coef_matrix = lat_Aero_Coefficients() - C_L_0, C_L_a, C_L_de, C_L_dih = Long_coef_matrix[0,:] - C_D_0, C_D_a, C_D_de, C_D_dih = Long_coef_matrix[1,:] - C_Y_b, C_Y_da, C_Y_dr = Lat_coef_matrix[0,:] + CL_0, CL_a, CL_de, CL_dih = long_coef_matrix[0,:] + CD_0, CD_a, CD_de, CD_dih = long_coef_matrix[1,:] + CY_b, CY_da, CY_dr = lat_coef_matrix[0,:] - C_L_full = C_L_0 + C_L_a * alpha + C_L_de * delta_e + C_L_dih * ih - C_D_full = C_D_0 + C_D_a * alpha + C_D_de * delta_e + C_D_dih * ih - C_Y_full = C_Y_b * beta + C_Y_da* delta_ail + C_Y_dr * delta_r + CL_full = CL_0 + CL_a * alpha + CL_de * delta_e + CL_dih * ih + CD_full = CD_0 + CD_a * alpha + CD_de * delta_e + CD_dih * ih + CY_full = CY_b * beta + CY_da * delta_ail + CY_dr * delta_r - b = Geometric_Data()[2] - c = Geometric_Data()[1] - Sw = Geometric_Data()[0] + span = geometric_Data()[2] + c = geometric_Data()[1] + Sw = geometric_Data()[0] - aerodynamic_forces = q(U,rho) * Sw * np.array([-C_D_full, C_Y_full, -C_L_full]) #N + aerodynamic_forces = q(TAS,rho) * Sw * np.array([-CD_full, CY_full, -CL_full]) #N return aerodynamic_forces -def get_aerodynamic_moments( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): +def get_aerodynamic_moments( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): """ Calculates forces @@ -289,7 +288,7 @@ def get_aerodynamic_moments( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_ rho : float density (kg/m3) - U : float + TAS : float velocity (m/s) alpha : float @@ -316,26 +315,62 @@ def get_aerodynamic_moments( U, rho, alpha, beta, delta_e, ih, delta_ail, delta_ AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) chapter 3 and 4 """ - Long_coef_matrix = Long_Aero_Coefficients() - Lat_coef_matrix = Lat_Aero_Coefficients() + + long_coef_matrix = long_Aero_Coefficients() + lat_coef_matrix = lat_Aero_Coefficients() - C_m_0, C_m_a, C_m_de, C_m_dih = Long_coef_matrix[2,:] - C_l_b, C_l_da, C_l_dr = Lat_coef_matrix[1,:] - C_n_b, C_n_da, C_n_dr = Lat_coef_matrix[2,:] + Cm_0, Cm_a, Cm_de, Cm_dih = long_coef_matrix[2,:] + Cl_b, Cl_da, Cl_dr = lat_coef_matrix[1,:] + Cn_b, Cn_da, Cn_dr = lat_coef_matrix[2,:] - C_m_full = C_m_0 + C_m_a * alpha + C_m_de * delta_e + C_m_dih * ih - C_l_full = C_l_b * beta + C_l_da* delta_ail + C_l_dr * delta_r - C_n_full = C_n_b * beta + C_n_da* delta_ail + C_n_dr * delta_r + Cm_full = Cm_0 + Cm_a * alpha + Cm_de * delta_e + Cm_dih * ih + Cl_full = Cl_b * beta + Cl_da* delta_ail + Cl_dr * delta_r + Cn_full = Cn_b * beta + Cn_da* delta_ail + Cn_dr * delta_r + + span = geometric_Data()[2] + c = geometric_Data()[1] + Sw = geometric_Data()[0] + + aerodynamic_moments = q(TAS,rho) * Sw * np.array([Cl_full * span,Cm_full * c,Cn_full * span]) - b = Geometric_Data()[2] - c = Geometric_Data()[1] - Sw = Geometric_Data()[0] + return aerodynamic_moments - aerodynamic_moments = q(U,rho) * Sw * np.array([C_l_full * b,C_m_full * c,C_n_full * b]) +def get_engine_force(delta_t): + + """ Calculates forces + + Parameters + ---------- + + delta_t : float + trust_lever (0 = 0 Newton, 1 = CT) + + + returns + ------- + + engine_force : float + Trust (N) + + References + ---------- + Airplane Flight Dyanamics and Automatic Flight Controls part I - Jan Roskam + """ + + + Ct = 0.031 * delta_t + + q_cruise = 91.2 * 47.880172 #Pa + + Sw = geometric_Data()[0] + + engine_force = Ct * Sw * q_cruise # N + + return engine_force - return aerodynamic_moments + diff --git a/src/pyfme/aircrafts/test/test_Cessna310.py b/src/pyfme/aircrafts/test/test_Cessna310.py index 011c556..1b437a4 100644 --- a/src/pyfme/aircrafts/test/test_Cessna310.py +++ b/src/pyfme/aircrafts/test/test_Cessna310.py @@ -13,52 +13,63 @@ from numpy.testing import (assert_array_almost_equal, assert_almost_equal) -from pyfme.aircrafts.Cessna310 import (Mass_and_Inertial_Data, - q, get_aerodynamic_forces, get_aerodynamic_moments) +from pyfme.aircrafts.Cessna310 import (mass_and_Inertial_Data, + q, get_aerodynamic_forces, + get_aerodynamic_moments, get_engine_force) def test_q(): - U = 100 + TAS = 100 rho = 1.225 q_expected = 6125 - dinamyc_pressure = q(U, rho) + dinamyc_pressure = q(TAS, rho) assert_almost_equal(dinamyc_pressure, q_expected) -def test_get_forces(): +def test_get_aerodynamic_forces(): - U = 100 + TAS = 100 rho = 1.225 alpha = 0 beta = 0 - deltae = 0 + delta_e = 0 ih = 0 - deltaail = 0 - deltar = 0 - aerodynamic_forces_expected = np.array([-2887.82725, -28679.112, 0]) + delta_ail = 0 + delta_r = 0 + aerodynamic_forces_expected = np.array([-2887.832934, 0, -28679.16845]) - aerodynamic_forces = get_aerodynamic_forces( U, rho, alpha, beta, deltae, ih, deltaail, deltar) + aerodynamic_forces = get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r) - assert_array_almost_equal(aerodynamic_forces, aerodynamic_forces_expected) + assert_array_almost_equal(aerodynamic_forces, aerodynamic_forces_expected, decimal = 4) -def test_get_moments(): +def test_get_aerodynamic_moments(): - U = 100 + TAS = 100 rho = 1.225 alpha = 0 beta = 0 - deltae = 0 + delta_e = 0 ih = 0 - deltaail = 0 - deltar = 0 - aerodynamic_moments_expected = np.array([0, 3101.963823, 0]) + delta_ail = 0 + delta_r = 0 + aerodynamic_moments_expected = np.array([0, 10177.06582, 0]) - aerodynamic_moments = get_aerodynamic_moments( U, rho, alpha, beta, deltae, ih, deltaail, deltar) + aerodynamic_moments = get_aerodynamic_moments( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r) - assert_array_almost_equal(aerodynamic_moments, aerodynamic_moments_expected) + assert_array_almost_equal(aerodynamic_moments, aerodynamic_moments_expected, decimal = 4) + +def test_get_engine_force(): + + delta_t = 0.5 + + trust_expected = 1100.399064 + + trust = get_engine_force(delta_t) + + assert_almost_equal(trust, trust_expected, decimal = 4) \ No newline at end of file From 55e1b71808d5bc5e83143f54eb7318af5b43877a Mon Sep 17 00:00:00 2001 From: Oscar Date: Thu, 21 Jan 2016 15:17:37 +0100 Subject: [PATCH 6/8] changed the style and added dependence with anemometry.py --- .../aircrafts/{Cessna310.py => cessna_310.py} | 47 ++++++------------- .../test_cessna_310.py} | 25 ++++------ 2 files changed, 24 insertions(+), 48 deletions(-) rename src/pyfme/aircrafts/{Cessna310.py => cessna_310.py} (89%) rename src/pyfme/aircrafts/{test/test_Cessna310.py => tests/test_cessna_310.py} (79%) diff --git a/src/pyfme/aircrafts/Cessna310.py b/src/pyfme/aircrafts/cessna_310.py similarity index 89% rename from src/pyfme/aircrafts/Cessna310.py rename to src/pyfme/aircrafts/cessna_310.py index ff28c15..bc42917 100644 --- a/src/pyfme/aircrafts/Cessna310.py +++ b/src/pyfme/aircrafts/cessna_310.py @@ -12,6 +12,8 @@ import numpy as np +from pyfme.utils.anemometry import calculate_dynamic_pressure + def geometric_Data(): """ Provides the value of some geometric data. @@ -197,31 +199,6 @@ def lat_Aero_Coefficients(): return lat_coef_matrix -def q (TAS,rho): - - """ Calculates the dinamic pressure q = 0.5*rho*U^2 - - Parameters - ---------- - - rho : float - density (SI) - U : flota - velocity (SI) - - Returns - ------- - - q : float - dinamic pressure - - """ - - q = 0.5 * rho * (TAS ** 2) - - return q - - def get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): @@ -275,7 +252,7 @@ def get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta c = geometric_Data()[1] Sw = geometric_Data()[0] - aerodynamic_forces = q(TAS,rho) * Sw * np.array([-CD_full, CY_full, -CL_full]) #N + aerodynamic_forces = calculate_dynamic_pressure(rho,TAS) * Sw * np.array([-CD_full, CY_full, -CL_full]) #N return aerodynamic_forces @@ -333,7 +310,8 @@ def get_aerodynamic_moments( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delt c = geometric_Data()[1] Sw = geometric_Data()[0] - aerodynamic_moments = q(TAS,rho) * Sw * np.array([Cl_full * span,Cm_full * c,Cn_full * span]) + aerodynamic_moments = calculate_dynamic_pressure (rho,TAS) * Sw\ + * np.array([Cl_full * span,Cm_full * c,Cn_full * span]) return aerodynamic_moments @@ -358,21 +336,24 @@ def get_engine_force(delta_t): ---------- Airplane Flight Dyanamics and Automatic Flight Controls part I - Jan Roskam """ + if delta_t >= 0 and delta_t <= 1 : + Ct = 0.031 * delta_t - Ct = 0.031 * delta_t + q_cruise = 91.2 * 47.880172 #Pa - q_cruise = 91.2 * 47.880172 #Pa - - Sw = geometric_Data()[0] + Sw = geometric_Data()[0] - engine_force = Ct * Sw * q_cruise # N + engine_force = Ct * Sw * q_cruise #N + else: + raise ValueError('delta_t must be between 0 and 1') + return engine_force - + diff --git a/src/pyfme/aircrafts/test/test_Cessna310.py b/src/pyfme/aircrafts/tests/test_cessna_310.py similarity index 79% rename from src/pyfme/aircrafts/test/test_Cessna310.py rename to src/pyfme/aircrafts/tests/test_cessna_310.py index 1b437a4..52b4e27 100644 --- a/src/pyfme/aircrafts/test/test_Cessna310.py +++ b/src/pyfme/aircrafts/tests/test_cessna_310.py @@ -13,22 +13,9 @@ from numpy.testing import (assert_array_almost_equal, assert_almost_equal) -from pyfme.aircrafts.Cessna310 import (mass_and_Inertial_Data, - q, get_aerodynamic_forces, +from pyfme.aircrafts.cessna_310 import (mass_and_Inertial_Data, + get_aerodynamic_forces, get_aerodynamic_moments, get_engine_force) - - - - -def test_q(): - - TAS = 100 - rho = 1.225 - q_expected = 6125 - - dinamyc_pressure = q(TAS, rho) - - assert_almost_equal(dinamyc_pressure, q_expected) def test_get_aerodynamic_forces(): @@ -72,4 +59,12 @@ def test_get_engine_force(): assert_almost_equal(trust, trust_expected, decimal = 4) + wrong_value_0 = -0.5 + wrong_value_1 = 2 + + with pytest.raises(ValueError): + + get_engine_force(wrong_value_0) + get_engine_force(wrong_value_1) + \ No newline at end of file From 2324a5a16b4eef790526b4cc1c2eec87ecbbb09c Mon Sep 17 00:00:00 2001 From: Oscar Date: Tue, 26 Jan 2016 16:06:41 +0100 Subject: [PATCH 7/8] Added PEP8 style --- src/pyfme/aircrafts/cessna_310.py | 297 ++++++++++--------- src/pyfme/aircrafts/tests/test_cessna_310.py | 59 ++-- 2 files changed, 185 insertions(+), 171 deletions(-) diff --git a/src/pyfme/aircrafts/cessna_310.py b/src/pyfme/aircrafts/cessna_310.py index bc42917..aa1dc0b 100644 --- a/src/pyfme/aircrafts/cessna_310.py +++ b/src/pyfme/aircrafts/cessna_310.py @@ -2,48 +2,50 @@ """ Created on Sun Jan 3 18:44:39 2016 -@author:olrosales@gmail.com +@author:olrosales@gmail.com @AeroPython """ -## Aircraft = Cessna 310 +# Aircraft = Cessna 310 import numpy as np from pyfme.utils.anemometry import calculate_dynamic_pressure + def geometric_Data(): - + """ Provides the value of some geometric data. - + Returns ---- - + Sw : float Wing surface (ft2 * 0.3048 * 0.3048 = m2) c : foat Mean aerodynamic Chord (ft * 0.3048 = m) - span : float + span : float Wing span (ft * 0.3048 = m) - + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 589 """ - + Sw = 175 * 0.3048 * 0.3048 # m2 c = 4.79 * 0.3048 # m span = 36.9 * 0.3048 # m - + return Sw, c, span + def mass_and_Inertial_Data(): - + """ Provides the value of some mass and inertial data. - + Returns ------ mass : float @@ -58,7 +60,7 @@ def mass_and_Inertial_Data(): Product of Inertia xz-plane ( slug * ft2 * 1.3558179 = Kg * m2) inertia : array_like I_xx_b,I_yy_b,I_zz_b] - + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) @@ -70,47 +72,48 @@ def mass_and_Inertial_Data(): Iyy_b = 1939 * 1.3558179 # Kg * m2 Izz_b = 11001 * 1.3558179 # Kg * m2 Ixz_b = 0 * 1.3558179 # Kg * m2 - - inertia = np.diag([Ixx_b,Iyy_b,Izz_b]) - + + inertia = np.diag([Ixx_b, Iyy_b, Izz_b]) + return mass, inertia + def long_Aero_Coefficients(): - + """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. - + CL_0 is the lift coefficient evaluated at the initial condition CL_a is the lift stability derivative with respect to the angle of attack - CL_de is the lift stability derivative with respect to the elevator + CL_de is the lift stability derivative with respect to the elevator deflection - CL_dih is the lift stability derivative with respect to the stabilator + CL_dih is the lift stability derivative with respect to the stabilator deflection - + CD_0 is the drag coefficient evaluated at the initial condition CD_a is the drag stability derivative with respect to the angle of attack - - Cm_0 is the pitching moment coefficient evaluated at the condition + + Cm_0 is the pitching moment coefficient evaluated at the condition (alpha0 = deltaE = deltaih = 0º) Cm_a is the pitching moment stability derivative with respect to the angle of attack - Cm_de is the pitching moment stability derivative with respect to the + Cm_de is the pitching moment stability derivative with respect to the elevator deflection - Cm_dih is the pitching moment stability derivative with respect to the + Cm_dih is the pitching moment stability derivative with respect to the stabilator deflection - Returns - ------- - + Returns + ------- + Long_coef_matrix : array_like [ [CL_0, CL_a, CL_de, CL_dih], [CD_0, CD_a, 0, 0], [Cm_0, Cm_a, Cm_de, Cm_dih] ] - - + + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) @@ -120,49 +123,50 @@ def long_Aero_Coefficients(): CL_a = 4.58 CL_de = 0.81 CL_dih = 0 - + CD_0 = 0.029 CD_a = 0.160 - + Cm_0 = 0.07 Cm_a = -0.137 Cm_de = -2.26 - Cm_dih = 0 - + Cm_dih = 0 + long_coef_matrix = np.array([ [CL_0, CL_a, CL_de, CL_dih], [CD_0, CD_a, 0, 0], [Cm_0, Cm_a, Cm_de, Cm_dih] ]) - + return long_coef_matrix - + + def lat_Aero_Coefficients(): - + """Assigns the value of the coefficients of stability in cruise conditions and order them in a matrix. - - CY_b is the side force stability derivative with respect to the + + CY_b is the side force stability derivative with respect to the angle of sideslip - CY_da is the side force stability derivative with respect to the + CY_da is the side force stability derivative with respect to the aileron deflection - CY_dr is the side force stability derivative with respect to the + CY_dr is the side force stability derivative with respect to the rudder deflection - - Cl_b is the rolling moment stability derivative with respect to + + Cl_b is the rolling moment stability derivative with respect to angle of sideslip - Cl_da is the rolling moment stability derivative with respect to + Cl_da is the rolling moment stability derivative with respect to the aileron deflection - Cl_dr is the rolling moment stability derivative with respect to + Cl_dr is the rolling moment stability derivative with respect to the rudder deflection - - Cn_b is the yawing moment stability derivative with respect to the + + Cn_b is the yawing moment stability derivative with respect to the angle of sideslip - Cn_da is the yawing moment stability derivative with respect to the + Cn_da is the yawing moment stability derivative with respect to the aileron deflection - Cn_dr is the yawing moment stability derivative with respect to the + Cn_dr is the yawing moment stability derivative with respect to the rudder deflection - + returns ------- Long_coef_matrix : array_like @@ -171,47 +175,48 @@ def lat_Aero_Coefficients(): [Cl_b, Cl_da, Cl_dr], [Cn_b, Cn_da, Cn_dr] ] - - + + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) page 590 """ - + CY_b = -0.698 CY_da = 0 CY_dr = 0.230 - + Cl_b = -0.1096 Cl_da = 0.172 Cl_dr = 0.0192 - + Cn_b = 0.1444 Cn_da = -0.0168 Cn_dr = -0.1152 - + lat_coef_matrix = np.array([ [CY_b, CY_da, CY_dr], [Cl_b, Cl_da, Cl_dr], [Cn_b, Cn_da, Cn_dr] ]) - + return lat_coef_matrix - - -def get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): - - """ Calculates forces - + + +def get_aerodynamic_forces(TAS, rho, alpha, beta, delta_e, ih, delta_ail, + delta_r): + + """ Calculates forces + Parameters ---------- - + rho : float density (kg/(m3)) TAS : float velocity (m/s) - + alpha : float attack angle (rad). beta : float @@ -224,50 +229,52 @@ def get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta aileron deflection (rad). delta_r : float rudder deflection (rad). - + Returns ------- - + forces : array_like - 3 dimensional vector with (F_x_s, F_y_s, F_z_s) forces in stability axes. - + 3 dimensional vector with (F_x_s, F_y_s, F_z_s) forces + in stability axes. + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) - chapter 3 and 4 + chapter 3 and 4 """ - + long_coef_matrix = long_Aero_Coefficients() lat_coef_matrix = lat_Aero_Coefficients() - - CL_0, CL_a, CL_de, CL_dih = long_coef_matrix[0,:] - CD_0, CD_a, CD_de, CD_dih = long_coef_matrix[1,:] - CY_b, CY_da, CY_dr = lat_coef_matrix[0,:] - + + CL_0, CL_a, CL_de, CL_dih = long_coef_matrix[0, :] + CD_0, CD_a, CD_de, CD_dih = long_coef_matrix[1, :] + CY_b, CY_da, CY_dr = lat_coef_matrix[0, :] + CL_full = CL_0 + CL_a * alpha + CL_de * delta_e + CL_dih * ih - CD_full = CD_0 + CD_a * alpha + CD_de * delta_e + CD_dih * ih + CD_full = CD_0 + CD_a * alpha + CD_de * delta_e + CD_dih * ih CY_full = CY_b * beta + CY_da * delta_ail + CY_dr * delta_r - - span = geometric_Data()[2] - c = geometric_Data()[1] + Sw = geometric_Data()[0] - - aerodynamic_forces = calculate_dynamic_pressure(rho,TAS) * Sw * np.array([-CD_full, CY_full, -CL_full]) #N - + + aerodynamic_forces = calculate_dynamic_pressure(rho, TAS) *\ + Sw * np.array([-CD_full, CY_full, -CL_full]) # N + return aerodynamic_forces - -def get_aerodynamic_moments( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r): - - """ Calculates forces - + + +def get_aerodynamic_moments(TAS, rho, alpha, beta, delta_e, ih, delta_ail, + delta_r): + + """ Calculates forces + Parameters ---------- - + rho : float density (kg/m3) TAS : float velocity (m/s) - + alpha : float attack angle (rad). beta : float @@ -280,94 +287,94 @@ def get_aerodynamic_moments( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delt aileron deflection (rad). delta_r : float rudder deflection (rad). - + returns ------- - + moments : array_like - 3 dimensional vector with (Mxs, Mys, Mzs) forces in stability axes. - + 3 dimensional vector with (Mxs, Mys, Mzs) forces + in stability axes. + References ---------- AIRCRAFT DYNAMICS From modelling to simulation (Marcello R. Napolitano) - chapter 3 and 4 + chapter 3 and 4 """ - + long_coef_matrix = long_Aero_Coefficients() lat_coef_matrix = lat_Aero_Coefficients() - - Cm_0, Cm_a, Cm_de, Cm_dih = long_coef_matrix[2,:] - Cl_b, Cl_da, Cl_dr = lat_coef_matrix[1,:] - Cn_b, Cn_da, Cn_dr = lat_coef_matrix[2,:] - - + Cm_0, Cm_a, Cm_de, Cm_dih = long_coef_matrix[2, :] + Cl_b, Cl_da, Cl_dr = lat_coef_matrix[1, :] + Cn_b, Cn_da, Cn_dr = lat_coef_matrix[2, :] + Cm_full = Cm_0 + Cm_a * alpha + Cm_de * delta_e + Cm_dih * ih - Cl_full = Cl_b * beta + Cl_da* delta_ail + Cl_dr * delta_r - Cn_full = Cn_b * beta + Cn_da* delta_ail + Cn_dr * delta_r - + Cl_full = Cl_b * beta + Cl_da * delta_ail + Cl_dr * delta_r + Cn_full = Cn_b * beta + Cn_da * delta_ail + Cn_dr * delta_r + span = geometric_Data()[2] c = geometric_Data()[1] Sw = geometric_Data()[0] - aerodynamic_moments = calculate_dynamic_pressure (rho,TAS) * Sw\ - * np.array([Cl_full * span,Cm_full * c,Cn_full * span]) - - return aerodynamic_moments + aerodynamic_moments = calculate_dynamic_pressure(rho, TAS) * Sw\ + * np.array([Cl_full * span, Cm_full * c, Cn_full * span]) + + return aerodynamic_moments + def get_engine_force(delta_t): - - """ Calculates forces - + + """ Calculates forces + Parameters ---------- - + delta_t : float - trust_lever (0 = 0 Newton, 1 = CT) - - + trust_lever (0 = 0 Newton, 1 = CT) + + returns ------- - + engine_force : float Trust (N) - + References ---------- Airplane Flight Dyanamics and Automatic Flight Controls part I - Jan Roskam """ - if delta_t >= 0 and delta_t <= 1 : - + if delta_t >= 0 and delta_t <= 1: + Ct = 0.031 * delta_t - - q_cruise = 91.2 * 47.880172 #Pa - + + q_cruise = 91.2 * 47.880172 # Pa + Sw = geometric_Data()[0] - engine_force = Ct * Sw * q_cruise #N - + engine_force = Ct * Sw * q_cruise # N + else: raise ValueError('delta_t must be between 0 and 1') - + return engine_force - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/pyfme/aircrafts/tests/test_cessna_310.py b/src/pyfme/aircrafts/tests/test_cessna_310.py index 52b4e27..955b11b 100644 --- a/src/pyfme/aircrafts/tests/test_cessna_310.py +++ b/src/pyfme/aircrafts/tests/test_cessna_310.py @@ -13,12 +13,13 @@ from numpy.testing import (assert_array_almost_equal, assert_almost_equal) -from pyfme.aircrafts.cessna_310 import (mass_and_Inertial_Data, - get_aerodynamic_forces, - get_aerodynamic_moments, get_engine_force) - +from pyfme.aircrafts.cessna_310 import (get_aerodynamic_forces, + get_aerodynamic_moments, + get_engine_force) + + def test_get_aerodynamic_forces(): - + TAS = 100 rho = 1.225 alpha = 0 @@ -28,13 +29,17 @@ def test_get_aerodynamic_forces(): delta_ail = 0 delta_r = 0 aerodynamic_forces_expected = np.array([-2887.832934, 0, -28679.16845]) - - aerodynamic_forces = get_aerodynamic_forces( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r) - - assert_array_almost_equal(aerodynamic_forces, aerodynamic_forces_expected, decimal = 4) - + + aerodynamic_forces = get_aerodynamic_forces(TAS, rho, alpha, + beta, delta_e, ih, delta_ail, + delta_r) + + assert_array_almost_equal(aerodynamic_forces, aerodynamic_forces_expected, + decimal=4) + + def test_get_aerodynamic_moments(): - + TAS = 100 rho = 1.225 alpha = 0 @@ -44,27 +49,29 @@ def test_get_aerodynamic_moments(): delta_ail = 0 delta_r = 0 aerodynamic_moments_expected = np.array([0, 10177.06582, 0]) - - aerodynamic_moments = get_aerodynamic_moments( TAS, rho, alpha, beta, delta_e, ih, delta_ail, delta_r) - - assert_array_almost_equal(aerodynamic_moments, aerodynamic_moments_expected, decimal = 4) - + + aerodynamic_moments = get_aerodynamic_moments(TAS, rho, alpha, beta, + delta_e, ih, delta_ail, + delta_r) + + assert_array_almost_equal(aerodynamic_moments, + aerodynamic_moments_expected, decimal=4) + + def test_get_engine_force(): - + delta_t = 0.5 - + trust_expected = 1100.399064 - + trust = get_engine_force(delta_t) - - assert_almost_equal(trust, trust_expected, decimal = 4) - + + assert_almost_equal(trust, trust_expected, decimal=4) + wrong_value_0 = -0.5 wrong_value_1 = 2 - + with pytest.raises(ValueError): - + get_engine_force(wrong_value_0) get_engine_force(wrong_value_1) - - \ No newline at end of file From fd0e3c23b8218cfdf55bbbee0a84a829c3912744 Mon Sep 17 00:00:00 2001 From: Oscar Date: Tue, 26 Jan 2016 16:21:32 +0100 Subject: [PATCH 8/8] Deleted final line cessna_310.py --- src/pyfme/aircrafts/cessna_310.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/pyfme/aircrafts/cessna_310.py b/src/pyfme/aircrafts/cessna_310.py index aa1dc0b..ae7cfb0 100644 --- a/src/pyfme/aircrafts/cessna_310.py +++ b/src/pyfme/aircrafts/cessna_310.py @@ -356,25 +356,4 @@ def get_engine_force(delta_t): else: raise ValueError('delta_t must be between 0 and 1') - return engine_force - - - - - - - - - - - - - - - - - - - - - + return engine_force \ No newline at end of file