def find_deflection(x_hinge, upper_cruise, lower_cruise, type='Match trailing edge', alpha=0, Reynolds=0, **kwargs): """ Function to calculate the flap deflection. Required inputs: :param x_hinge :param upper_cruise :param lower_cruise :param type: can be: - 'Match trailing edge': will find the deflection where the baseline's trailing edge matches that of the objective, i.e. match the the trailing edge of a traditional flap with a morphing conitunous flap. - 'Same Cl': will find deflection where Cl of flapped airfoil is equal to the the objective airfoil. - 'Range of deflection' kwrgs arguments for 'Match trailing edge': :param x_TE_objective :param y_TE_objective :param x_TE_baseline :param y_TE_baseline kwrgs arguments for 'Same Cl': :param Cl_objective kwrgs arguments for 'Same Cd': :param Cd_objective kwrgs arguments for 'Range of deflection' :param max_deflection Optional arguments: :param alpha :param Reynolds """ import xfoil_module as xf airfoil = 'flapped_airfoil' if type == 'Match trailing edge': x_TE_objective = kwargs['x_TE_objective'] y_TE_objective = kwargs['y_TE_objective'] x_TE_baseline = kwargs['x_TE_baseline'] y_TE_baseline = kwargs['y_TE_baseline'] elif type == 'Same Cl': Cl_objective = kwargs['Cl_objective'] elif type == 'Same Cd': Cd_objective = kwargs['Cd_objective'] elif type == 'Range of deflection': max_deflection = kwargs['max_deflection'] init_deflection = kwargs['init_deflection'] step = kwargs['step'] hinge = find_hinge(x_hinge, upper_cruise, lower_cruise) upper_static, upper_flap = find_flap(upper_cruise, hinge) lower_static, lower_flap = find_flap(lower_cruise, hinge) #============================================================================== # Find Deflection #============================================================================== if type == 'Match trailing edge': #Calculate deflection angle in radians deflection = np.arctan2(hinge['y'] - y_TE_objective, x_TE_objective - hinge['x']) - np.arctan2( hinge['y'] - y_TE_baseline, x_TE_baseline - hinge['x']) # Convet to degrees deflection = deflection * 180. / np.pi upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N=5) xf.create_input(airfoil, 'Type 3', airfoil=flapped_airfoil) xf.call(airfoil, alfas=alpha, Reynolds=Reynolds, iteration=100, GDES=True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient Cd = Data['CD'] Cl = Data['CL'] elif type == 'Same Cl': current_Cl = 0 current_Cd = 0 previous_Cl = 0 deflection = 2. history = [] # Rough search step = 2. while current_Cl < Cl_objective and deflection < 90.: # Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step print deflection upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N=5) xf.create_input(airfoil, 'Type 3', airfoil=flapped_airfoil) xf.call(airfoil, alfas=alpha, Reynolds=Reynolds, iteration=100, GDES=True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] for i in range(1, 6): # Fine search step = 0.5**i current_Cl = previous_Cl while current_Cl < Cl_objective and deflection < 90.: # Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) previous_flapped_airfoil = flapped_airfoil flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N=5) xf.create_input(airfoil, 'Type 3', airfoil=flapped_airfoil) xf.call(airfoil, alfas=alpha, Reynolds=Reynolds, iteration=100, GDES=True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] print current_Cl, deflection elif type == 'Same Cd': current_Cl = 0 current_Cd = 0 previous_Cl = 0 deflection = 2. history = [] # Rough search step = 2. while current_Cd < Cd_objective and deflection < 90.: # Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step print deflection upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N=5) xf.create_input(airfoil, 'Type 3', airfoil=flapped_airfoil) xf.call(airfoil, alfas=alpha, Reynolds=Reynolds, iteration=100, GDES=True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] for i in range(1, 6): # Fine search step = 0.5**i current_Cd = previous_Cd while current_Cd < Cd_objective or deflection < 90.: # Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) previous_flapped_airfoil = flapped_airfoil flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N=5) xf.create_input(airfoil, 'Type 3', airfoil=flapped_airfoil) xf.call(airfoil, alfas=alpha, Reynolds=Reynolds, iteration=1000, GDES=True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient print deflection current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] print current_Cd, deflection print history print Cd_objective deflection = previous_deflection Cd = previous_Cd Cl = previous_Cl flapped_airfoil = previous_flapped_airfoil elif type == 'Range of deflection': current_Cl = 0 current_Cd = 0 previous_Cl = 0 deflection = init_deflection history = {'CD': [], 'CL': [], 'deflection': []} # Rough search while deflection < max_deflection: # Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection deflection = deflection + step print deflection upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N=5) xf.create_input(airfoil, 'Type 3', airfoil=flapped_airfoil) xf.call(airfoil, alfas=alpha, Reynolds=Reynolds, iteration=300, GDES=True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient print deflection current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] if deflection <= max_deflection: history['CD'].append(current_Cd) history['CL'].append(current_Cl) history['deflection'].append(deflection) return history return deflection, Cd, Cl, flapped_airfoil
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
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
upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil, i_separator = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, return_flap_i=True, unit_deflection='deg') #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #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
def find_deflection(x_hinge, upper_cruise, lower_cruise, type = 'Match trailing edge', alpha=0, Reynolds = 0, **kwargs): """ Function to calculate the flap deflection. Required inputs: :param x_hinge :param upper_cruise :param lower_cruise :param type: can be: - 'Match trailing edge': will find the deflection where the baseline's trailing edge matches that of the objective, i.e. match the the trailing edge of a traditional flap with a morphing conitunous flap. - 'Same Cl': will find deflection where Cl of flapped airfoil is equal to the the objective airfoil. - 'Range of deflection' kwrgs arguments for 'Match trailing edge': :param x_TE_objective :param y_TE_objective :param x_TE_baseline :param y_TE_baseline kwrgs arguments for 'Same Cl': :param Cl_objective kwrgs arguments for 'Same Cd': :param Cd_objective kwrgs arguments for 'Range of deflection' :param max_deflection Optional arguments: :param alpha :param Reynolds """ import xfoil_module as xf airfoil = 'flapped_airfoil' if type == 'Match trailing edge': x_TE_objective = kwargs['x_TE_objective'] y_TE_objective = kwargs['y_TE_objective'] x_TE_baseline = kwargs['x_TE_baseline'] y_TE_baseline = kwargs['y_TE_baseline'] elif type == 'Same Cl': Cl_objective = kwargs['Cl_objective'] elif type == 'Same Cd': Cd_objective = kwargs['Cd_objective'] elif type == 'Range of deflection': max_deflection = kwargs['max_deflection'] init_deflection = kwargs['init_deflection'] step = kwargs['step'] hinge = find_hinge(x_hinge, upper_cruise, lower_cruise) upper_static, upper_flap = find_flap(upper_cruise, hinge) lower_static, lower_flap = find_flap(lower_cruise, hinge) #============================================================================== # Find Deflection #============================================================================== if type == 'Match trailing edge': #Calculate deflection angle in radians deflection = np.arctan2(hinge['y'] - y_TE_objective, x_TE_objective - hinge['x']) - np.arctan2(hinge['y'] - y_TE_baseline, x_TE_baseline - hinge['x']) # Convet to degrees deflection = deflection*180./np.pi upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N = 5) xf.create_input(airfoil, 'Type 3', airfoil = flapped_airfoil) xf.call(airfoil, alfas = alpha, Reynolds = Reynolds, iteration=100, GDES = True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient Cd = Data['CD'] Cl = Data['CL'] elif type == 'Same Cl': current_Cl = 0 current_Cd = 0 previous_Cl = 0 deflection = 2. history = [] # Rough search step = 2. while current_Cl < Cl_objective and deflection < 90.:# Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step print deflection upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N = 5) xf.create_input(airfoil, 'Type 3', airfoil = flapped_airfoil) xf.call(airfoil, alfas = alpha, Reynolds = Reynolds, iteration=100, GDES = True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] for i in range(1,6): # Fine search step = 0.5**i current_Cl = previous_Cl while current_Cl < Cl_objective and deflection < 90.:# Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) previous_flapped_airfoil = flapped_airfoil flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N = 5) xf.create_input(airfoil, 'Type 3', airfoil = flapped_airfoil) xf.call(airfoil, alfas = alpha, Reynolds = Reynolds, iteration=100, GDES = True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] print current_Cl, deflection elif type == 'Same Cd': current_Cl = 0 current_Cd = 0 previous_Cl = 0 deflection = 2. history = [] # Rough search step = 2. while current_Cd < Cd_objective and deflection < 90.:# Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step print deflection upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N = 5) xf.create_input(airfoil, 'Type 3', airfoil = flapped_airfoil) xf.call(airfoil, alfas = alpha, Reynolds = Reynolds, iteration=100, GDES = True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] for i in range(1,6): # Fine search step = 0.5**i current_Cd = previous_Cd while current_Cd < Cd_objective or deflection < 90.:# Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection history.append([previous_deflection, previous_Cl, previous_Cd]) deflection = deflection + step upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) previous_flapped_airfoil = flapped_airfoil flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N = 5) xf.create_input(airfoil, 'Type 3', airfoil = flapped_airfoil) xf.call(airfoil, alfas = alpha, Reynolds = Reynolds, iteration=1000, GDES = True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient print deflection current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] print current_Cd, deflection print history print Cd_objective deflection = previous_deflection Cd = previous_Cd Cl = previous_Cl flapped_airfoil = previous_flapped_airfoil elif type == 'Range of deflection': current_Cl = 0 current_Cd = 0 previous_Cl = 0 deflection = init_deflection history = {'CD':[], 'CL':[], 'deflection':[]} # Rough search while deflection < max_deflection:# Convet to degrees previous_Cl = current_Cl previous_Cd = current_Cd previous_deflection = deflection deflection = deflection + step print deflection upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, N = 5) xf.create_input(airfoil, 'Type 3', airfoil = flapped_airfoil) xf.call(airfoil, alfas = alpha, Reynolds = Reynolds, iteration=300, GDES = True, output='Polar') filename = xf.file_name(airfoil, alpha, output='Polar') Data = xf.output_reader(filename, output='Polar') #Rename to make more convenient print deflection current_Cd = Data['CD'][0] current_Cl = Data['CL'][0] if deflection <= max_deflection: history['CD'].append(current_Cd) history['CL'].append(current_Cl) history['deflection'].append(deflection) return history return deflection, Cd, Cl, flapped_airfoil
import numpy as np import matplotlib.pyplot as plt import xfoil_module as xf from CST_module import * from aero_module import Reynolds from airfoil_module import CST, create_x # Au = [0.23993240191629417, 0.34468227138908186, 0.18125405377549103, # 0.35371349126072665, 0.2440815012119143, 0.25724974995738387] # Al = [0.18889012559339036, -0.24686758992053115, 0.077569769493868401, # -0.547827192265256, -0.0047342206759065641, -0.23994805474814629] Au = [0.172802, 0.167353, 0.130747, 0.172053, 0.112797, 0.168891] Al = Au # c_avian = 0.36 #m # deltaz = 0.0093943568219451313*c_avian c_avian = 1. deltaz = 0 airfoil = 'avian' x = create_x(1., distribution='linear') y = CST(x, 1., [deltaz / 2., deltaz / 2.], Au=Au, Al=Al) # Create file for Xfoil to read coordinates xf.create_input(x, y['u'], y['l'], airfoil, different_x_upper_lower=False) print 'Reynolds: ', Reynolds(10000, 30, c_avian) Data = xf.find_coefficients(airfoil, 0., Reynolds=Reynolds(10000, 30, c_avian), iteration=100, NACA=False) print Data
upper = {'x': x['upper'], 'y': y['upper']} lower = {'x': x['lower'], 'y': y['lower']} x_hinge = 0.75 hinge = find_hinge(x_hinge, upper, lower) upper_static, upper_flap = find_flap(upper, hinge) lower_static, lower_flap = find_flap(lower, hinge, extra_points = 'lower') deflection = -90. upper_rotated, lower_rotated = rotate(upper_flap, lower_flap, hinge, deflection) flapped_airfoil, i_separator = clean(upper_static, upper_rotated, lower_static, lower_rotated, hinge, deflection, return_flap_i = True, unit_deflection = 'deg') #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #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
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
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