def call_avl(avl_object): import sys import time import subprocess import SUAVE.Plugins.VyPy.tools.redirect as redirect log_file = avl_object.settings.filenames.log_filename err_file = avl_object.settings.filenames.err_filename if isinstance(log_file,str): purge_files(log_file) if isinstance(err_file,str): purge_files(err_file) avl_call = avl_object.settings.filenames.avl_bin_name geometry = avl_object.settings.filenames.features in_deck = avl_object.current_status.deck_file with redirect.output(log_file,err_file): ctime = time.ctime() # Current date and time stamp sys.stdout.write("Log File of System stdout from AVL Run \n{}\n\n".format(ctime)) sys.stderr.write("Log File of System stderr from AVL Run \n{}\n\n".format(ctime)) with open(in_deck,'r') as commands: avl_run = subprocess.Popen([avl_call,geometry],stdout=sys.stdout,stderr=sys.stderr,stdin=subprocess.PIPE) for line in commands: avl_run.stdin.write(line) avl_run.wait() exit_status = avl_run.returncode ctime = time.ctime() sys.stdout.write("\nProcess finished: {0}\nExit status: {1}\n".format(ctime,exit_status)) sys.stderr.write("\nProcess finished: {0}\nExit status: {1}\n".format(ctime,exit_status)) return exit_status
def call_avl(avl_object): """ This function calls the AVL executable and executes analyses Assumptions: None Source: None Inputs: avl_object Outputs: exit_status Properties Used: N/A """ avl_regression_flag = avl_object.regression_flag if avl_regression_flag: exit_status = 0 else: log_file = avl_object.settings.filenames.log_filename err_file = avl_object.settings.filenames.err_filename if isinstance(log_file,str): purge_files(log_file) if isinstance(err_file,str): purge_files(err_file) avl_call = avl_object.settings.filenames.avl_bin_name geometry = avl_object.settings.filenames.features in_deck = avl_object.current_status.deck_file with redirect.output(log_file,err_file): ctime = time.ctime() # Current date and time stamp with open(in_deck,'r') as commands: print_output = False # Initialize suppression of console window output if print_output == False: devnull = open(os.devnull,'w') sys.stdout = devnull # Run AVL avl_run = subprocess.Popen([avl_call,geometry],stdout=sys.stdout,stderr=sys.stderr,stdin=subprocess.PIPE) for line in commands: avl_run.stdin.write(line.encode('utf-8')) avl_run.stdin.flush() # Terminate suppression of console window output if print_output == False: sys.stdout = sys.__stdout__ avl_run.wait() exit_status = avl_run.returncode ctime = time.ctime() return exit_status
def call_avl(avl_object): import sys import time import subprocess log_file = avl_object.settings.filenames.log_filename err_file = avl_object.settings.filenames.err_filename if isinstance(log_file,str): purge_files(log_file) if isinstance(err_file,str): purge_files(err_file) avl_call = avl_object.settings.filenames.avl_bin_name geometry = avl_object.settings.filenames.features in_deck = avl_object.current_status.deck_file with redirect.output(log_file,err_file): ctime = time.ctime() # Current date and time stamp sys.stdout.write("Log File of System stdout from AVL Run \n{}\n\n".format(ctime)) sys.stderr.write("Log File of System stderr from AVL Run \n{}\n\n".format(ctime)) with open(in_deck,'r') as commands: avl_run = subprocess.Popen([avl_call,geometry],stdout=sys.stdout,stderr=sys.stderr,stdin=subprocess.PIPE) for line in commands: avl_run.stdin.write(line) avl_run.wait() exit_status = avl_run.returncode ctime = time.ctime() sys.stdout.write("\nProcess finished: {0}\nExit status: {1}\n".format(ctime,exit_status)) sys.stderr.write("\nProcess finished: {0}\nExit status: {1}\n".format(ctime,exit_status)) return exit_status
def write_avl_airfoil_file(suave_airfoil_filename): """ This function writes the standard airfoil file format from Airfoil tools to avl file format Assumptions: None Source: Inputs: filename Outputs: airfoil.dat Properties Used: N/A """ # unpack avl_inputs avl_airfoil_filename = suave_airfoil_filename.split(".")[-2].split( "/")[-1] + '.dat' # purge file purge_files([avl_airfoil_filename]) # read airfoil file header origin = os.getcwd() os_path = os.path.split(origin)[0] f_path = os_path + '/' + suave_airfoil_filename f = open(f_path) data_block = f.readlines() f.close() airfoil_name = data_block[0].strip() # import airfoil coordinates airfoil_geometry_data = import_airfoil_geometry([f_path]) dim = len(airfoil_geometry_data.x_coordinates[0]) # write file with open(avl_airfoil_filename, 'w') as afile: afile.write(airfoil_name + "\n") for i in range(dim - 1): if i == int(dim / 2): pass elif airfoil_geometry_data.y_coordinates[0][i] < 0.0: case_text = '\t' + format( airfoil_geometry_data.x_coordinates[0][i], '.7f') + " " + format( airfoil_geometry_data.y_coordinates[0][i], '.7f') + "\n" afile.write(case_text) else: case_text = '\t' + format( airfoil_geometry_data.x_coordinates[0][i], '.7f') + " " + format( airfoil_geometry_data.y_coordinates[0][i], '.7f') + "\n" afile.write(case_text) afile.close() return avl_airfoil_filename
def write_mass_file(avl_object, run_conditions): """This function writes the translated aircraft mass into text file read by AVL when it is called """ # unpack inputs mass_file = avl_object.settings.filenames.mass_file aircraft = avl_object.geometry # Open the mass file after purging if it already exists purge_files([mass_file]) mass_file_script = open(mass_file, 'w') with open(mass_file, 'w') as mass_file_script: """This function writes the header using the template required for the AVL executable to read """ # mass file template base_text = \ ''' #------------------------------------------------- # {0} # # Dimensional unit and parameter data. # Mass & Inertia breakdown. #------------------------------------------------- # Names and scalings for units to be used for trim and eigenmode calculations. # The Lunit and Munit values scale the mass, xyz, and inertia table data below. # Lunit value will also scale all lengths and areas in the AVL input file. Lunit = 1.0 m Munit = 1.0 kg Tunit = 1.0 s #------------------------- # Gravity and density to be used as default values in trim setup. # Must be in the units given above. g = {1} rho = {2} #------------------------- # Mass & Inertia breakdown. # x y z is location of item's own CG. # Ixx... are item's inertias about item's own CG. # # x,y,z system here must be exactly the same one used in the AVL input file # (same orientation, same origin location, same length units) # # mass x y z Ixx Iyy Izz Component Name # {3} {4} {5} {6} {7} {8} {9} ! {0} ''' # Unpack inputs name = avl_object.geometry._base.tag density = run_conditions.freestream.density gravity = run_conditions.freestream.gravity if aircraft.mass_properties.mass == 0: mass = aircraft.mass_properties.max_takeoff elif aircraft.mass_properties.max_takeoff == 0: mass = aircraft.mass_properties.mass else: raise AttributeError("Specify Vehicle Mass") x = aircraft.mass_properties.center_of_gravity[0][0] y = aircraft.mass_properties.center_of_gravity[0][1] z = aircraft.mass_properties.center_of_gravity[0][2] Ixx = aircraft.mass_properties.moments_of_inertia.tensor[0][0] Iyy = aircraft.mass_properties.moments_of_inertia.tensor[1][1] Izz = aircraft.mass_properties.moments_of_inertia.tensor[2][2] # Insert inputs into the template text = base_text.format(name, gravity, density, mass, x, y, z, Ixx, Iyy, Izz) mass_file_script.write(text) return
def write_run_cases(avl_object, trim_aircraft): """ This function writes the run cases used in the AVL batch analysis Assumptions: None Source: Drela, M. and Youngren, H., AVL, http://web.mit.edu/drela/Public/web/avl Inputs: avl_object.current_status.batch_file [-] avl_object.geometry.mass_properties.center_of_gravity [meters] Outputs: None Properties Used: N/A """ # unpack avl_inputs aircraft = avl_object.geometry batch_filename = avl_object.current_status.batch_file base_case_text = \ ''' --------------------------------------------- Run case {0}: {1} alpha -> {2} = {3} beta -> beta = {4} pb/2V -> pb/2V = 0.00000 qc/2V -> qc/2V = 0.00000 rb/2V -> rb/2V = 0.00000 {5} alpha = {6} beta = 0.00000 deg pb/2V = 0.00000 qc/2V = 0.00000 rb/2V = 0.00000 CL = {7} CDo = {8} bank = 0.00000 deg elevation = 0.00000 deg heading = 0.00000 deg Mach = {9} velocity = {10} m/s density = {11} kg/m^3 grav.acc. = {12} m/s^2 turn_rad. = 0.00000 m load_fac. = 0.00000 X_cg = {13} m Y_cg = {14} m Z_cg = {15} m mass = {16} kg Ixx = {17} kg-m^2 Iyy = {18} kg-m^2 Izz = {19} kg-m^2 Ixy = {20} kg-m^2 Iyz = {21} kg-m^2 Izx = {22} kg-m^2 visc CL_a = 0.00000 visc CL_u = 0.00000 visc CM_a = 0.00000 visc CM_u = 0.00000 '''#{4} is a set of control surface inputs that will vary depending on the control surface configuration # Open the geometry file after purging if it already exists purge_files([batch_filename]) with open(batch_filename, 'w') as runcases: # extract C.G. coordinates and moment of intertia tensor x_cg = aircraft.mass_properties.center_of_gravity[0] y_cg = aircraft.mass_properties.center_of_gravity[1] z_cg = aircraft.mass_properties.center_of_gravity[2] mass = aircraft.mass_properties.mass moments_of_inertia = aircraft.mass_properties.moments_of_inertia.tensor Ixx = moments_of_inertia[0][0] Iyy = moments_of_inertia[1][1] Izz = moments_of_inertia[2][2] Ixy = moments_of_inertia[0][1] Iyz = moments_of_inertia[1][2] Izx = moments_of_inertia[2][0] for case_name in avl_object.current_status.cases: # extract flight conditions case = avl_object.current_status.cases[case_name] index = case.index name = case.tag CL = case.conditions.aerodynamics.flight_CL AoA = case.conditions.aerodynamics.angle_of_attack CDp = 0. beta = case.conditions.aerodynamics.side_slip_angle mach = round(case.conditions.freestream.mach, 4) vel = round(case.conditions.freestream.velocity, 4) rho = round(case.conditions.freestream.density, 4) g = case.conditions.freestream.gravitational_acceleration if trim_aircraft == False: # this flag sets up a trim analysis if one is declared by the boolean "trim_aircraft" controls_text = '' if CL is None: # if angle of attack is specified without trim, the appropriate fields are filled toggle_idx = 'alpha' toggle_val = AoA alpha_val = '0.00000 deg' CL_val = '0.00000' elif AoA is None: # if flight lift coefficient is specified without trim, the appropriate fields are filled toggle_idx = 'CL ' toggle_val = CL alpha_val = '0.00000 deg' CL_val = '0.00000' elif trim_aircraft: # trim is specified if CL is None: # if angle of attack is specified with trim, the appropriate fields are filled with the trim AoA toggle_idx = 'alpha' toggle_val = AoA alpha_val = AoA CL_val = '0.00000' elif AoA is None: # if flight lift coefficient is specified with trim, the appropriate fields are filled with the trim CL toggle_idx = 'CL' toggle_val = CL alpha_val = '0.00000 deg' CL_val = CL controls = [] if case.stability_and_control.number_control_surfaces != 0: # write control surface text in .run file if there is any controls = make_controls_case_text( case.stability_and_control.control_surface_names, case.stability_and_control.control_surface_functions) controls_text = ''.join(controls) # write the .run file using template and the extracted vehicle properties and flight condition case_text = base_case_text.format( index, name, toggle_idx, toggle_val, beta, controls_text, alpha_val, CL_val, CDp, mach, vel, rho, g, x_cg, y_cg, z_cg, mass, Ixx, Iyy, Izz, Ixy, Iyz, Izx, ) runcases.write(case_text)