Beispiel #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
Beispiel #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()
Beispiel #3
0
def calculate_flap_moment(x, y, alpha, x_hinge, deflection):    
    """For a given airfoil with coordinates x and y at angle of attack
    alpha, calculate the moment coefficient around the joint at x_hinge
    and deflection """

    def separate_upper_lower(x, y, Cp = None, i_separator=None):
        """Return dictionaries with upper and lower keys with respective
        coordiantes. It is assumed the leading edge is frontmost point at
        alpha=0"""
        #TODO: when using list generated by xfoil, there are two points for
        #the leading edge
        def separate(variable_list, i_separator):
            if type(i_separator) == int:
                variable_dictionary = {'upper': variable_list[0:i_separator+1],
                                       'lower': variable_list[i_separator+1:]}
            elif type(i_separator) == list:
                i_upper = i_separator[0]
                i_lower = i_separator[1]
                
                variable_dictionary = {'upper': variable_list[0:i_upper],
                                       'lower': variable_list[i_lower:]}
            return variable_dictionary
        #If i is not defined, separate upper and lower surface from the
        # leading edge
        if i_separator == None:
            i_separator = x.index(min(x))

        if Cp == None:
            x = separate(x, i_separator)
            y = separate(y, i_separator)
            return x, y
        else:
            x = separate(x, i_separator)
            y = separate(y, i_separator)
            Cp = separate(Cp, i_separator)
            return x, y, Cp
    # If x and y are not dictionaries with keys upper and lower, make them
    # be so
    if type(x) == list:
        x, y = separate_upper_lower(x, y)
    
    upper = {'x': x['upper'], 'y': y['upper']}
    lower = {'x': x['lower'], 'y': y['lower']}
    
    #Determining hinge
    hinge = af.find_hinge(x_hinge, upper, lower)
    
    upper_static, upper_flap = af.find_flap(upper, hinge)
    lower_static, lower_flap = af.find_flap(lower, hinge, lower = True)
    
    upper_rotated, lower_rotated = af.rotate(upper_flap, lower_flap, hinge, deflection)
    
    flapped_airfoil, i_separator = af.clean(upper_static, upper_rotated, lower_static, 
                            lower_rotated, hinge, deflection, N = 5, 
                            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 = separate_upper_lower(x = Data['x'], y = Data['y'], 
                                    Cp = Data['Cp'], i_separator = i_separator)
    Cm = ar.calculate_moment_coefficient(x, y, Cp, alpha = alpha, c = 1., 
                                         x_ref = x_hinge, y_ref = 0.)
    print Cm
Beispiel #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
Beispiel #5
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
Beispiel #6
0
def calculate_flap_coefficients(
    x,
    y,
    alpha,
    x_hinge,
    deflection,
    Reynolds=0,
):
    """For a given airfoil with coordinates x and y at angle of attack
    alpha, calculate the moment coefficient around the joint at x_hinge
    and deflection """
    def separate_upper_lower(x, y, Cp=None, i_separator=None):
        """Return dictionaries with upper and lower keys with respective
        coordiantes. It is assumed the leading edge is frontmost point at
        alpha=0"""

        #TODO: when using list generated by xfoil, there are two points for
        #the leading edge
        def separate(variable_list, i_separator):
            if type(i_separator) == int:
                variable_dictionary = {
                    'upper': variable_list[0:i_separator + 1],
                    'lower': variable_list[i_separator + 1:]
                }
            elif type(i_separator) == list:
                i_upper = i_separator[0]
                i_lower = i_separator[1]

                variable_dictionary = {
                    'upper': variable_list[0:i_upper],
                    'lower': variable_list[i_lower:]
                }
            return variable_dictionary

        #If i is not defined, separate upper and lower surface from the
        # leading edge
        if i_separator == None:
            i_separator = x.index(min(x))

        if Cp == None:
            x = separate(x, i_separator)
            y = separate(y, i_separator)
            return x, y
        else:
            x = separate(x, i_separator)
            y = separate(y, i_separator)
            Cp = separate(Cp, i_separator)
            return x, y, Cp

    # If x and y are not dictionaries with keys upper and lower, make them
    # be so
    if type(x) == list:
        x, y = separate_upper_lower(x, y)

    upper = {'x': x['upper'], 'y': y['upper']}
    lower = {'x': x['lower'], 'y': y['lower']}

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

    upper_static, upper_flap = af.find_flap(upper, hinge)
    lower_static, lower_flap = af.find_flap(lower, hinge, lower=True)

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

    flapped_airfoil, i_separator = af.clean(upper_static,
                                            upper_rotated,
                                            lower_static,
                                            lower_rotated,
                                            hinge,
                                            deflection,
                                            N=5,
                                            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_coefficients('flapped',
                                alpha,
                                NACA=False,
                                Reynolds=Reynolds,
                                iteration=500)

    return Data