def write_geometry(avl_object): # unpack inputs aircraft = avl_object.features geometry_file = avl_object.settings.filenames.features # Open the geometry file after purging if it already exists purge_files([geometry_file]) geometry = open(geometry_file, 'w') with open(geometry_file, 'w') as geometry: header_text = make_header_text(avl_object) geometry.write(header_text) for w in aircraft.wings: avl_wing = translate_avl_wing(w) wing_text = make_surface_text(avl_wing) geometry.write(wing_text) for b in aircraft.fuselages: avl_body = translate_avl_body(b) body_text = make_body_text(avl_body) geometry.write(body_text) return
def make_case_command(avl_object, case): """ Makes commands for case execution in AVK Assumptions: None Source: None Inputs: case.index case.tag case.result_filename Outputs: case_command Properties Used: N/A """ base_case_command = \ '''{0} x {1} {2} ''' index = case.index case_tag = case.tag res_type = 'st' # This needs to change to multiple ouputs if you want to add the ability to read other types of results results_file = case.result_filename purge_files([results_file]) case_command = base_case_command.format(index, res_type, results_file) return case_command
def write_geometry(avl_object): # unpack inputs aircraft = avl_object.features geometry_file = avl_object.settings.filenames.features # Open the geometry file after purging if it already exists purge_files([geometry_file]) geometry = open(geometry_file, "w") with open(geometry_file, "w") as geometry: header_text = make_header_text(avl_object) geometry.write(header_text) for w in aircraft.wings: avl_wing = translate_avl_wing(w) wing_text = make_surface_text(avl_wing) geometry.write(wing_text) for b in aircraft.fuselages: avl_body = translate_avl_body(b) body_text = make_body_text(avl_body) geometry.write(body_text) return
def make_case_command(avl_object,case): """ Makes commands for case execution in AVK Assumptions: None Source: None Inputs: case.index case.tag case.result_filename Outputs: case_command Properties Used: N/A """ base_case_command = \ '''{0} x {1} {2} ''' index = case.index case_tag = case.tag res_type = 'st' # This needs to change to multiple ouputs if you want to add the ability to read other types of results results_file = case.result_filename purge_files([results_file]) case_command = base_case_command.format(index,res_type,results_file) return case_command #def make_eigen_mode_case_command(avl_object,case): #em_base_case_command = \ #''' #MODE #n #w #{0} #''' #em_results_file = case.eigen_result_filename #purge_files([em_results_file]) #em_case_command = em_base_case_command.format(em_results_file) #return em_case_command
def write_input_deck(avl_object): """ This fucntions writes the execution steps used in the AVL call Assumptions: None Source: Drela, M. and Youngren, H., AVL, http://web.mit.edu/drela/Public/web/avl Inputs: avl_object Outputs: None Properties Used: N/A """ open_runs = \ '''CASE {} ''' base_input = \ '''OPER ''' # unpack batch = avl_object.current_status.batch_file deck_filename = avl_object.current_status.deck_file # purge old versions and write the new input deck avl_regression_flag = avl_object.regression_flag if not avl_regression_flag: purge_files([deck_filename]) with open(deck_filename,'w') as input_deck: input_deck.write(open_runs.format(batch)) input_deck.write(base_input) for case_name in avl_object.current_status.cases: # write and store aerodynamic and static stability result files case = avl_object.current_status.cases[case_name] case_command = make_case_command(avl_object,case) input_deck.write(case_command) #----------------------------------------------------------------- # SUAVE-AVL dynamic stability analysis under development # # write store dynamics stability result files # em_case_command = make_eigen_mode_case_command(avl_object,case) # input_deck.write(em_case_command) # #----------------------------------------------------------------- input_deck.write('\n\nQUIT\n') return
def write_input_deck(avl_object): """ This fucntions writes the execution steps used in the AVL call Assumptions: None Source: Drela, M. and Youngren, H., AVL, http://web.mit.edu/drela/Public/web/avl Inputs: avl_object Outputs: None Properties Used: N/A """ open_runs = \ '''CASE {} ''' base_input = \ '''OPER ''' # unpack batch = avl_object.current_status.batch_file deck_filename = avl_object.current_status.deck_file # purge old versions and write the new input deck avl_regression_flag = avl_object.regression_flag if not avl_regression_flag: purge_files([deck_filename]) with open(deck_filename, 'w') as input_deck: input_deck.write(open_runs.format(batch)) input_deck.write(base_input) for case_name in avl_object.current_status.cases: # write and store aerodynamic and static stability result files case = avl_object.current_status.cases[case_name] case_command = make_case_command(avl_object, case) input_deck.write(case_command) #----------------------------------------------------------------- # SUAVE-AVL dynamic stability analysis under development # # write store dynamics stability result files # em_case_command = make_eigen_mode_case_command(avl_object,case) # input_deck.write(em_case_command) # #----------------------------------------------------------------- input_deck.write('\n\nQUIT\n')
def purge_directory(path, purge_subdirectories=False): """ Deletes the contents of a directory, then the directory itself. If purge_subdirectories is True, subdirectories of the directory will also be purged, recursively. In this case, the directory specified in the 'path' argument will always be removed at the end of this function. However, if purge_subdirectories is False, files in 'path' will be deleted, but subdirectories and their contents will be left untouched. In this case, the directory ('path' argument) will only be removed if it contains no subdirectories. Assumptions: None Source: None Inputs: None Outputs: None Properties Used: N/A """ contents = os.listdir(path) subdir = [] print contents for item in contents: print os.path.abspath(os.path.join(path, item)) if os.path.isdir(os.path.abspath(os.path.join(path, item))): subdir.append(item) contents.remove(item) print subdir, contents purge_files(contents, path) if purge_subdirectories: for sub in subdir: purge_directory(os.path.join(path, sub), True) contents = os.listdir(path) if contents: print "Directory contains subdirectories which were not specified for deletion. Directory not fully deleted." else: os.rmdir(path) return
def make_case_command(avl_object,case): base_case_command = \ '''{0} x {1} {2} ''' index = case.index case_tag = case.tag res_type = 'st' # This needs to change to multiple ouputs if you want to add the ability to read other types of results results_file = case.result_filename purge_files([results_file]) case_command = base_case_command.format(index,res_type,results_file) return case_command
def write_geometry(avl_object, spanwise_vortices_per_meter): """This function writes the translated aircraft geometry into text file read by AVL when it is called Assumptions: None Source: Drela, M. and Youngren, H., AVL, http://web.mit.edu/drela/Public/web/avl Inputs: avl_object Outputs: None Properties Used: N/A """ # unpack inputs aircraft = avl_object.geometry geometry_file = avl_object.settings.filenames.features # Open the geometry file after purging if it already exists purge_files([geometry_file]) geometry = open(geometry_file, 'w') with open(geometry_file, 'w') as geometry: header_text = make_header_text(avl_object) geometry.write(header_text) for w in aircraft.wings: avl_wing = translate_avl_wing(w) wing_text = make_surface_text(avl_wing, spanwise_vortices_per_meter) geometry.write(wing_text) for b in aircraft.fuselages: if b.tag == 'fuselage': avl_body = translate_avl_body(b) body_text = make_body_text(avl_body) geometry.write(body_text) return
def write_geometry(avl_object,spanwise_vortices_per_meter): """This function writes the translated aircraft geometry into text file read by AVL when it is called Assumptions: None Source: Drela, M. and Youngren, H., AVL, http://web.mit.edu/drela/Public/web/avl Inputs: avl_object Outputs: None Properties Used: N/A """ # unpack inputs aircraft = avl_object.geometry geometry_file = avl_object.settings.filenames.features # Open the geometry file after purging if it already exists purge_files([geometry_file]) geometry = open(geometry_file,'w') with open(geometry_file,'w') as geometry: header_text = make_header_text(avl_object) geometry.write(header_text) for w in aircraft.wings: avl_wing = translate_avl_wing(w) wing_text = make_surface_text(avl_wing,spanwise_vortices_per_meter) geometry.write(wing_text) for b in aircraft.fuselages: if b.tag == 'fuselage': avl_body = translate_avl_body(b) body_text = make_body_text(avl_body) geometry.write(body_text) return
def write_input_deck(avl_object): open_runs = \ '''CASE {} ''' base_input = \ '''OPER ''' # unpack batch = avl_object.current_status.batch_file deck_filename = avl_object.current_status.deck_file # purge old versions and write the new input deck purge_files([deck_filename]) with open(deck_filename,'w') as input_deck: input_deck.write(open_runs.format(batch)) input_deck.write(base_input) for case in avl_object.current_status.cases: case_command = make_case_command(avl_object,case) input_deck.write(case_command) input_deck.write('\n\nQUIT\n') return
def purge_directory(path,purge_subdirectories=False): """ Deletes the contents of a directory, then the directory itself. If purge_subdirectories is True, subdirectories of the directory will also be purged, recursively. In this case, the directory specified in the 'path' argument will always be removed at the end of this function. However, if purge_subdirectories is False, files in 'path' will be deleted, but subdirectories and their contents will be left untouched. In this case, the directory ('path' argument) will only be removed if it contains no subdirectories. """ contents = os.listdir(path) subdir = [] print contents for item in contents: print os.path.abspath(os.path.join(path,item)) if os.path.isdir(os.path.abspath(os.path.join(path,item))): subdir.append(item) contents.remove(item) print subdir, contents purge_files(contents,path) if purge_subdirectories: for sub in subdir: purge_directory(os.path.join(path,sub),True) contents = os.listdir(path) if contents: print "Directory contains subdirectories which were not specified for deletion. Directory not fully deleted." else: os.rmdir(path) return
def write_run_cases(avl_object): # imports from SUAVE.Methods.Aerodynamics.AVL.write_run_cases import make_controls_case_text # unpack avl_inputs batch_filename = avl_object.current_status.batch_file aircraft = avl_object.features base_case_text = \ ''' --------------------------------------------- Run case {0}: {1} alpha -> alpha = {2} beta -> beta = {3} pb/2V -> pb/2V = 0.00000 qc/2V -> qc/2V = 0.00000 rb/2V -> rb/2V = 0.00000 {4} alpha = 0.00000 deg beta = 0.00000 deg pb/2V = 0.00000 qc/2V = 0.00000 rb/2V = 0.00000 CL = 0.00000 CDo = 0.00000 bank = 0.00000 deg elevation = 0.00000 deg heading = 0.00000 deg Mach = {5} velocity = {6} m/s density = {7} kg/m^3 grav.acc. = {8} m/s^2 turn_rad. = 0.00000 m load_fac. = 0.00000 X_cg = {9} m Y_cg = {10} m Z_cg = {11} m mass = {12} kg Ixx = {13} kg-m^2 Iyy = {14} kg-m^2 Izz = {15} kg-m^2 Ixy = {16} kg-m^2 Iyz = {17} kg-m^2 Izx = {18} 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: x_cg = avl_object.features.mass_properties.center_of_gravity[0] y_cg = avl_object.features.mass_properties.center_of_gravity[1] z_cg = avl_object.features.mass_properties.center_of_gravity[2] mass = 0 #avl_object.default_case.mass TODO: FIGURE OUT WHAT TO DEFAULT MASS TO, AND WHERE TO STORE IT BEFORE ANALYSIS. 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 in avl_object.current_status.cases: index = case.index name = case.tag alpha = case.conditions.aerodynamics.angle_of_attack beta = case.conditions.aerodynamics.side_slip_angle mach = case.conditions.freestream.mach v = case.conditions.freestream.velocity rho = case.conditions.freestream.density g = case.conditions.freestream.gravitational_acceleration # form controls text controls = [] if case.stability_and_control.control_deflections: for cs in case.stability_and_control.control_deflections: cs_text = make_controls_case_text(cs) controls.append(cs_text) controls_text = ''.join(controls) case_text = base_case_text.format(index, name, alpha, beta, controls_text, mach, v, rho, g, x_cg, y_cg, z_cg, mass, Ixx, Iyy, Izz, Ixy, Iyz, Izx) runcases.write(case_text)
def write_run_cases(avl_object): """ 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 batch_filename = avl_object.current_status.batch_file aircraft = avl_object.geometry base_case_text = \ ''' --------------------------------------------- Run case {0}: {1} alpha -> alpha = {2} beta -> beta = {3} pb/2V -> pb/2V = 0.00000 qc/2V -> qc/2V = 0.00000 rb/2V -> rb/2V = 0.00000 {4} alpha = 0.00000 deg beta = 0.00000 deg pb/2V = 0.00000 qc/2V = 0.00000 rb/2V = 0.00000 CL = 0.00000 CDo = 0.00000 bank = 0.00000 deg elevation = 0.00000 deg heading = 0.00000 deg Mach = {5} velocity = 0.0000 m/s density = {6} kg/m^3 grav.acc. = {7} m/s^2 turn_rad. = 0.00000 m load_fac. = 0.00000 X_cg = {8} m Y_cg = {9} m Z_cg = {10} m mass = {11} kg Ixx = {12} kg-m^2 Iyy = {13} kg-m^2 Izz = {14} kg-m^2 Ixy = {15} kg-m^2 Iyz = {16} kg-m^2 Izx = {17} 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: 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 = 0 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: case = avl_object.current_status.cases[case_name] index = case.index name = case.tag alpha = case.conditions.aerodynamics.angle_of_attack beta = case.conditions.aerodynamics.side_slip_angle mach = case.conditions.freestream.mach rho = case.conditions.freestream.density g = case.conditions.freestream.gravitational_acceleration # form controls text controls = [] if case.stability_and_control.control_deflections: for cs in case.stability_and_control.control_deflections: cs_text = make_controls_case_text(cs) controls.append(cs_text)
def write_run_cases(avl_object): """ 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 batch_filename = avl_object.current_status.batch_file aircraft = avl_object.geometry base_case_text = \ ''' --------------------------------------------- Run case {0}: {1} alpha -> alpha = {2} beta -> beta = {3} pb/2V -> pb/2V = 0.00000 qc/2V -> qc/2V = 0.00000 rb/2V -> rb/2V = 0.00000 {4} alpha = 0.00000 deg beta = 0.00000 deg pb/2V = 0.00000 qc/2V = 0.00000 rb/2V = 0.00000 CL = 0.00000 CDo = 0.00000 bank = 0.00000 deg elevation = 0.00000 deg heading = 0.00000 deg Mach = {5} velocity = 0.0000 m/s density = {6} kg/m^3 grav.acc. = {7} m/s^2 turn_rad. = 0.00000 m load_fac. = 0.00000 X_cg = {8} m Y_cg = {9} m Z_cg = {10} m mass = {11} kg Ixx = {12} kg-m^2 Iyy = {13} kg-m^2 Izz = {14} kg-m^2 Ixy = {15} kg-m^2 Iyz = {16} kg-m^2 Izx = {17} 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: 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 = 0 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: case = avl_object.current_status.cases[case_name] index = case.index name = case.tag alpha = case.conditions.aerodynamics.angle_of_attack beta = case.conditions.aerodynamics.side_slip_angle mach = case.conditions.freestream.mach rho = case.conditions.freestream.density g = case.conditions.freestream.gravitational_acceleration # form controls text controls = [] if case.stability_and_control.control_deflections: for cs in case.stability_and_control.control_deflections: cs_text = make_controls_case_text(cs) controls.append(cs_text) controls_text = ''.join(controls) case_text = base_case_text.format(index,name,alpha,beta,controls_text, mach,rho,g,x_cg,y_cg,z_cg,mass, Ixx,Iyy,Izz,Ixy,Iyz,Izx) runcases.write(case_text) return
def write_run_cases(avl_object): # imports from SUAVE.Methods.Aerodynamics.AVL.write_run_cases import make_controls_case_text # unpack avl_inputs batch_filename = avl_object.current_status.batch_file aircraft = avl_object.features base_case_text = """ --------------------------------------------- Run case {0}: {1} alpha -> alpha = {2} beta -> beta = {3} pb/2V -> pb/2V = 0.00000 qc/2V -> qc/2V = 0.00000 rb/2V -> rb/2V = 0.00000 {4} alpha = 0.00000 deg beta = 0.00000 deg pb/2V = 0.00000 qc/2V = 0.00000 rb/2V = 0.00000 CL = 0.00000 CDo = 0.00000 bank = 0.00000 deg elevation = 0.00000 deg heading = 0.00000 deg Mach = {5} velocity = {6} m/s density = {7} kg/m^3 grav.acc. = {8} m/s^2 turn_rad. = 0.00000 m load_fac. = 0.00000 X_cg = {9} m Y_cg = {10} m Z_cg = {11} m mass = {12} kg Ixx = {13} kg-m^2 Iyy = {14} kg-m^2 Izz = {15} kg-m^2 Ixy = {16} kg-m^2 Iyz = {17} kg-m^2 Izx = {18} 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: x_cg = avl_object.features.mass_properties.center_of_gravity[0] y_cg = avl_object.features.mass_properties.center_of_gravity[1] z_cg = avl_object.features.mass_properties.center_of_gravity[2] mass = ( 0 ) # avl_object.default_case.mass TODO: FIGURE OUT WHAT TO DEFAULT MASS TO, AND WHERE TO STORE IT BEFORE ANALYSIS. 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 in avl_object.current_status.cases: index = case.index name = case.tag alpha = case.conditions.aerodynamics.angle_of_attack beta = case.conditions.aerodynamics.side_slip_angle mach = case.conditions.freestream.mach v = case.conditions.freestream.velocity rho = case.conditions.freestream.density g = case.conditions.freestream.gravitational_acceleration # form controls text controls = [] if case.stability_and_control.control_deflections: for cs in case.stability_and_control.control_deflections: cs_text = make_controls_case_text(cs) controls.append(cs_text) controls_text = "".join(controls) case_text = base_case_text.format( index, name, alpha, beta, controls_text, mach, v, rho, g, x_cg, y_cg, z_cg, mass, Ixx, Iyy, Izz, Ixy, Iyz, Izx, ) runcases.write(case_text) return