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