示例#1
0
def plot_flap(x, y, x_J, theta, image):
    """
    Plot flap with actuators. theta is clockwise positive.
    @Author: Endryws (modified by Pedro Leal)
    
    Created on Fri Mar 18 14:26:54 2016
    """
    x_dict, y_dict = af.separate_upper_lower(x, y)
    
    # Below I create the dictionarys used to pass to the function find_hinge
    upper = {'x': x_dict['upper'], 'y': y_dict['upper']} # x and y upper points
    lower = {'x': x_dict['lower'], 'y': y_dict['lower']} # x and y lower points
    hinge = af.find_hinge(x_J, upper, lower) 
    
    #=======================================================================
    # With the Joint (hinge) point, i can use the find flap function to
    # found the points of the flap in the airfoil.
    #=======================================================================
    
    data = {'x': x, 'y': y}
    static_data, flap_data = af.find_flap(data, hinge)
    R = hinge['y_upper']
    theta_list = np.linspace(3*math.pi/2, math.pi/2, 50)
    x_circle_list = hinge['x'] + R*np.cos(theta_list)
    y_circle_list = hinge['y'] + R*np.sin(theta_list)

    n_upper = len(flap_data['x'])/2
    
    # Ploting the flap in the original position
#    plt.plot(flap_data['x'][:n_upper],flap_data['y'][:n_upper],'k--')
#    plt.plot(flap_data['x'][n_upper:],flap_data['y'][n_upper:],'k--')         
    # Rotate and plot
    upper = {'x': np.concatenate((flap_data['x'][:n_upper], x_circle_list)),
             'y': np.concatenate((flap_data['y'][:n_upper], y_circle_list))}
    lower = {'x':(flap_data['x'][n_upper:]),
             'y':(flap_data['y'][n_upper:])}
            
    rotated_upper, rotated_lower = af.rotate(upper, lower, hinge, theta, 
                                             unit_theta = 'rad')
    image2 = plt.plot(static_data['x'], static_data['y'],'k')
    
    image3 = plt.plot(rotated_upper['x'], rotated_upper['y'],'k')
    image4 = plt.plot(rotated_lower['x'], rotated_lower['y'],'k')

    image += image2 + image3 + image4
    return image
示例#2
0
    def plot_flap(x, y, x_J, y_J = None, theta = 0):
        """
        Plot flap with actuators. theta is clockwise positive.
        @Author: Endryws (modified by Pedro Leal)
        
        Created on Fri Mar 18 14:26:54 2016
        """
        import matplotlib.pyplot as plt
        plt.figure()
        x_dict, y_dict = af.separate_upper_lower(x, y)
        
        # Below I create the dictionarys used to pass to the function find_hinge
        upper = {'x': x_dict['upper'], 'y': y_dict['upper']} # x and y upper points
        lower = {'x': x_dict['lower'], 'y': y_dict['lower']} # x and y lower points
        hinge = af.find_hinge(x_J, upper, lower) 
        
        #=======================================================================
        # With the Joint (hinge) point, i can use the find flap function to
        # found the points of the flap in the airfoil.
        #=======================================================================
        
        data = {'x': x, 'y': y}
        static_data, flap_data = af.find_flap(data, hinge)
        R = hinge['y_upper']
        theta_list = np.linspace(3*math.pi/2, math.pi/2, 50)
        x_circle_list = hinge['x'] + R*np.cos(theta_list)
        y_circle_list = hinge['y'] + R*np.sin(theta_list)

        n_upper = len(flap_data['x'])/2
        
        # Ploting the flap in the original position
        plt.plot(flap_data['x'][:n_upper],flap_data['y'][:n_upper],'k--')
        plt.plot(flap_data['x'][n_upper:],flap_data['y'][n_upper:],'k--')         
        # Rotate and plot
        upper = {'x': np.concatenate((flap_data['x'][:n_upper], x_circle_list)),
                 'y': np.concatenate((flap_data['y'][:n_upper], y_circle_list))}
        lower = {'x':(flap_data['x'][n_upper:]),
                 'y':(flap_data['y'][n_upper:])}
                
        rotated_upper, rotated_lower = af.rotate(upper, lower, hinge, theta, 
                                                 unit_theta = 'rad')
        plt.plot(static_data['x'], static_data['y'],'k')
        
        plt.plot(rotated_upper['x'], rotated_upper['y'],'k')
        plt.plot(rotated_lower['x'], rotated_lower['y'],'k')
        plt.axes().set_aspect('equal')
        
        l.plot_actuator()
        s.plot_actuator()
        
        
        if y_J != None:
            for i in range(y_J):
                plt.scatter(x_J , y_J[i])
        plt.grid()
        plt.locator_params(axis = 'y', nbins=6)
        plt.xlabel('${}_{I}x + x_J$')
        plt.ylabel('${}_{I}y$')
        border = 0.05
        plt.xlim(-border, 1+border)
        plt.savefig( str(np.floor(100*abs(theta))) + "_configuration.png")
        plt.close()
示例#3
0
def calculate_flap_moment(x, y, alpha, x_hinge, deflection,
                          unit_deflection = 'rad'):    
    """For a given airfoil with coordinates x and y at angle of attack
    alpha (degrees), calculate the moment coefficient around the joint at x_hinge
    and deflection in radians (unit_deflection = 'rad') or degrees 
    (unit_deflection = 'deg')"""

    # If x and y are not dictionaries with keys upper and lower, make them
    # be so
    if type(x) == list:
        x, y = af.separate_upper_lower(x, y)
    #Because parts of the program use keys 'u' and 'l', and other parts use
    #'upper' and 'lower'
    if 'u' in x.keys():
        upper = {'x': x['u'], 'y': y['u']}
        lower = {'x': x['l'], 'y': y['l']}    
    elif 'upper' in x.keys(): 
        upper = {'x': x['upper'], 'y': y['upper']}
        lower = {'x': x['lower'], 'y': y['lower']}
    
    hinge = af.find_hinge(x_hinge, upper, lower)
       
    if deflection > 0:
        upper_static, upper_flap = af.find_flap(upper, hinge)
        lower_static, lower_flap = af.find_flap(lower, hinge,
                                                extra_points = 'lower')
    elif deflection < 0:
        upper_static, upper_flap = af.find_flap(upper, hinge,
                                                extra_points = 'upper')
        lower_static, lower_flap = af.find_flap(lower, hinge)
    else:
       upper_static, upper_flap = af.find_flap(upper, hinge, 
                                               extra_points = None)
       lower_static, lower_flap = af.find_flap(lower, hinge,
                                               extra_points = None)

    upper_rotated, lower_rotated = af.rotate(upper_flap, lower_flap,
                                             hinge, deflection,
                                             unit_theta = unit_deflection)
     
    flapped_airfoil, i_separator = af.clean(upper_static, upper_rotated, lower_static, 
                            lower_rotated, hinge, deflection, N = None, 
                            return_flap_i = True)

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #Third step: get new values of pressure coefficient
    xf.create_input(x = flapped_airfoil['x'], y_u = flapped_airfoil['y'],
                    filename = 'flapped', different_x_upper_lower = True)

    Data = xf.find_pressure_coefficients('flapped', alpha, NACA = False)


    x, y, Cp = af.separate_upper_lower(x = Data['x'], y = Data['y'], 
                                        Cp = Data['Cp'], i_separator = i_separator)
    
    #At the hinges, the reaction moment has the opposite sign of the
    #actuated torque
    Cm = - ar.calculate_moment_coefficient(x, y, Cp, alpha = alpha, c = 1., 
                                         x_ref = x_hinge, y_ref = 0., 
                                         flap = True)
    return Cm
示例#4
0
def calculate_flap_moment(x,
                          y,
                          alpha,
                          x_hinge,
                          deflection,
                          unit_deflection='rad'):
    """For a given airfoil with coordinates x and y at angle of attack
    alpha (degrees), calculate the moment coefficient around the joint at x_hinge
    and deflection in radians (unit_deflection = 'rad') or degrees 
    (unit_deflection = 'deg')"""

    # If x and y are not dictionaries with keys upper and lower, make them
    # be so
    if type(x) == list:
        x, y = af.separate_upper_lower(x, y)
    #Because parts of the program use keys 'u' and 'l', and other parts use
    #'upper' and 'lower'
    if 'u' in x.keys():
        upper = {'x': x['u'], 'y': y['u']}
        lower = {'x': x['l'], 'y': y['l']}
    elif 'upper' in x.keys():
        upper = {'x': x['upper'], 'y': y['upper']}
        lower = {'x': x['lower'], 'y': y['lower']}

    hinge = af.find_hinge(x_hinge, upper, lower)

    if deflection > 0:
        upper_static, upper_flap = af.find_flap(upper, hinge)
        lower_static, lower_flap = af.find_flap(lower,
                                                hinge,
                                                extra_points='lower')
    elif deflection < 0:
        upper_static, upper_flap = af.find_flap(upper,
                                                hinge,
                                                extra_points='upper')
        lower_static, lower_flap = af.find_flap(lower, hinge)
    else:
        upper_static, upper_flap = af.find_flap(upper,
                                                hinge,
                                                extra_points=None)
        lower_static, lower_flap = af.find_flap(lower,
                                                hinge,
                                                extra_points=None)

    upper_rotated, lower_rotated = af.rotate(upper_flap,
                                             lower_flap,
                                             hinge,
                                             deflection,
                                             unit_theta=unit_deflection)

    flapped_airfoil, i_separator = af.clean(upper_static,
                                            upper_rotated,
                                            lower_static,
                                            lower_rotated,
                                            hinge,
                                            deflection,
                                            N=None,
                                            return_flap_i=True)

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #Third step: get new values of pressure coefficient
    xf.create_input(x=flapped_airfoil['x'],
                    y_u=flapped_airfoil['y'],
                    filename='flapped',
                    different_x_upper_lower=True)

    Data = xf.find_pressure_coefficients('flapped', alpha, NACA=False)

    x, y, Cp = af.separate_upper_lower(x=Data['x'],
                                       y=Data['y'],
                                       Cp=Data['Cp'],
                                       i_separator=i_separator)

    #At the hinges, the reaction moment has the opposite sign of the
    #actuated torque
    Cm = -ar.calculate_moment_coefficient(
        x, y, Cp, alpha=alpha, c=1., x_ref=x_hinge, y_ref=0., flap=True)
    return Cm