def compute(self, inputs, outputs): error = False self.bzFoil.r_le = inputs['r_le'] self.bzFoil.beta_te = inputs['beta_te'] #self.bzFoil.dz_te = inputs['dz_te'] self.bzFoil.x_t = inputs['x_t'] self.bzFoil.y_t = inputs['y_t'] self.bzFoil.gamma_le = inputs['gamma_le'] self.bzFoil.x_c = inputs['x_c'] self.bzFoil.y_c = inputs['y_c'] self.bzFoil.alpha_te = inputs['alpha_te'] self.bzFoil.z_te = inputs['z_te'] self.bzFoil.b_8 = inputs['b_8'] self.bzFoil.b_15 = inputs['b_15'] self.bzFoil.b_0 = inputs['b_0'] self.bzFoil.b_2 = inputs['b_2'] self.bzFoil.b_17 = inputs['b_17'] projectName = PROJECT_NAME_PREFIX + '_%09d' % self.executionCounter cfd = CFDrun(projectName) airFoilCoords = self.bzFoil.generate_airfoil(500, show_plot=False, save_plot_path=WORKING_DIR+'/'+projectName+'/airfoil.png', param_dump_file=WORKING_DIR+'/'+projectName+'/airfoil.txt') self.bzFoil.plot_airfoil_with_cabin(inputs['offsetFront'], cabinLength, inputs['cabin_height'], inputs['angle'], show_plot=False, save_plot_path=WORKING_DIR+'/'+projectName+'/airfoil_cabin.png') if not self.bzFoil.valid: #raise AnalysisError('AirfoilCFD: invalid BPAirfoil') print('ERROR: AirfoilCFD, invalid BPAirfoil') error = True else: top, buttom = self.bzFoil.get_cooridnates_top_buttom(500) #self.air.set_coordinates(top, buttom) cfd.set_airfoul_coords(top, buttom) cfd.c2d.pointsInNormalDir = 80 cfd.c2d.pointNrAirfoilSurface = 200 cfd.c2d.reynoldsNum = REYNOLD cfd.construct2d_generate_mesh(scale=SCALE, plot=False) cfd.su2_fix_mesh() cfd.su2_solve(config) #totalCL, totalCD, totalCM, totalE = cfd.su2_parse_results() results = cfd.su2_parse_iteration_result() cfd.clean_up() if float(results['CD']) <= 0. or float(results['CD']) > 100.: #raise AnalysisError('AirfoilCFD: c_d is out of range (cfd failed)') print('ERROR: AirfoilCFD, c_d is out of range (cfd failed)') error = True outputs['c_d'] = results['CD'] outputs['c_l'] = results['CL'] outputs['c_m'] = results['CMz'] print('c_l= ' + str(outputs['c_l'])) print('c_d= ' + str(outputs['c_d'])) print('c_m= ' + str(outputs['c_m'])) print('c_l/c_d= ' + str(results['CL/CD'])) print('cfdIterations= ' + str(results['Iteration'])) write_to_log(str(self.executionCounter) + ',' + datetime.now().strftime('%H:%M:%S') + ',' + str(outputs['c_l']) + ',' + str(outputs['c_d']) + ',' + str(outputs['c_m']) + ',' + str(results['CL/CD']) + ',' + str(results['Iteration']) + ',' + str(inputs['cabin_height']) + ',' + str(inputs['offsetFront']) + ',' + str(inputs['angle']) + ',' + str(inputs['r_le']) + ',' + str(inputs['beta_te']) + ',' + str(inputs['x_t']) + ',' + str(inputs['y_t']) + ',' + str(inputs['gamma_le']) + ',' + str(inputs['x_c']) + ',' + str(inputs['y_c']) + ',' + str(inputs['alpha_te']) + ',' + str(inputs['z_te']) + ',' + str(inputs['b_8']) + ',' + str(inputs['b_15']) + ',' + str(inputs['b_0']) + ',' + str(inputs['b_17']) + ',' + str(inputs['b_2'])) #workaround since raising an error seems to crash the optimization if error: outputs['c_d'] = 999. outputs['c_l'] = 0. outputs['c_m'] = 0. self.executionCounter += 1
def run_convergence_analysis_construct2d(): config = dict() config['PHYSICAL_PROBLEM'] = 'EULER' config['MACH_NUMBER'] = str(0.65) config['AOA'] = str(0.) config['FREESTREAM_PRESSURE'] = str(24999.8) # for altitude 10363 m config['FREESTREAM_TEMPERATURE'] = str(220.79) # for altitude 10363 m # config['GAS_CONSTANT'] = str(287.87) # config['REF_LENGTH'] = str(1.0) # config['REF_AREA'] = str(1.0) config['MARKER_EULER'] = '( airfoil )' config['MARKER_FAR'] = '( farfield )' config['EXT_ITER'] = str(1000) config['OUTPUT_FORMAT'] = 'PARAVIEW' config['MG_DAMP_RESTRICTION'] = str(0.75) config['MG_DAMP_PROLONGATION'] = str(0.75) #for construct 2d normalMeshDivider = [100] #range(60, 500, 10) secondParam = [250] cdList = np.zeros((len(normalMeshDivider), len(secondParam))) clList = np.zeros((len(normalMeshDivider), len(secondParam))) cmList = np.zeros((len(normalMeshDivider), len(secondParam))) eList = np.zeros((len(normalMeshDivider), len(secondParam))) ouputF = open(WORKING_DIR + '/' + 'convergenceResult.txt', 'w') ouputF.write( 'innerMeshSize,outerMeshSize,CL,CD,CM,E,Iterations,Time(min)\n') for iI in range(0, len(normalMeshDivider)): for iO in range(0, len(secondParam)): projectName = 'nacaMesh_i%06d_o%06d' % (int( normalMeshDivider[iI]), int(secondParam[iO])) projectDir = WORKING_DIR + '/' + projectName #create project dir if necessary if not os.path.isdir(projectDir): os.mkdir(projectDir) cfd = CFDrun(projectName, used_cores=SU2_USED_CORES) cfd.load_airfoil_from_file(INPUT_DIR + '/naca641-212.csv') cfd.c2d.pointsInNormalDir = normalMeshDivider[iI] #cfd.gmsh.outerMeshSize = outerMeshSize[iO] #cfd.gmsh_generate_mesh() cfd.construct2d_generate_mesh() cfd.su2_fix_mesh() cfd.su2_solve(config) results = cfd.su2_parse_iteration_result() #totalCL, totalCD, totalCM, totalE = cfd.su2_parse_results() totalCL = results['CL'] totalCD = results['CD'] totalCM = results['CMz'] totalE = results['CL/CD'] clList[iI][iO] = totalCL cdList[iI][iO] = totalCD cmList[iI][iO] = totalCM eList[iI][iO] = totalE ouputF.write( str(normalMeshDivider[iI]) + ',' + str(secondParam[iO]) + ',' + str(totalCL) + ',' + str(totalCD) + ',' + str(totalCM) + ',' + str(totalE) + ',' + str(results['Iteration']) + ',' + str(results['Time(min)']) + '\n') ouputF.flush() print('totalCL: ' + str(totalCL)) print('totalCD: ' + str(totalCD)) print('iI: ' + str(iI) + ' iO: ' + str(iO)) ouputF.close() plt.pcolor(normalMeshDivider, secondParam, clList) plt.colorbar() plt.show() print('done')
projectDir = WORKING_DIR + '/' + projectName #create project dir if necessary if not os.path.isdir(projectDir): os.mkdir(projectDir) cfd = CFDrun(projectName, used_cores=SU2_USED_CORES) #cfd.load_airfoil_from_file(INPUT_DIR + '/naca641-212.csv') cfd.load_airfoil_from_file(INPUT_DIR + '/bzTest.dat') cfd.c2d.pointsInNormalDir = 80 cfd.c2d.pointNrAirfoilSurface = 200 #cfd.c2d.farfieldRadius = 50. cfd.c2d.reynoldsNum = REYNOLD #cfd.c2d.farfieldRadius = 50. #cfd.c2d.pointsInNormalDir = 120 cfd.construct2d_generate_mesh(scale=SCALE, wake_extension=0, plot=True) cfd.su2_fix_mesh() cfd.su2_solve(config) results = cfd.su2_parse_iteration_result() totalCL = results['CL'] totalCD = results['CD'] totalCM = results['CMz'] totalE = results['CL/CD'] print('totalCL: ' + str(totalCL)) print('totalCD: ' + str(totalCD)) print('done')
for a in AOA: projectName = 'analysis_aoa_%0.4f' % (a) projectDir = WORKING_DIR + '/' + projectName #create project dir if necessary if not os.path.isdir(projectDir): os.mkdir(projectDir) cfd = CFDrun(projectName, used_cores=SU2_USED_CORES) cfd.load_airfoil_from_file(INPUT_DIR + '/airfoil.dat') #cfd.load_airfoil_from_file(INPUT_DIR + '/vfw-va2.dat') cfd.c2d.pointsInNormalDir = 80 cfd.c2d.pointNrAirfoilSurface = 200 cfd.c2d.reynoldsNum = REYNOLD cfd.construct2d_generate_mesh(scale=SCALE, plot=False) #cfd.gmsh_generate_mesh(scale=REF_LENGTH) cfd.su2_fix_mesh() config['AOA'] = str(a) cfd.su2_solve(config) results = cfd.su2_parse_iteration_result() cfd.clean_up() print('totalCL: ' + str(results['CL'])) print('totalCD: ' + str(results['CD'])) outputF.write( str(MACH_NR) + ',' + str(a) + ',' + str(results['CL']) + ',' + str(results['CD']) + ',' + str(results['CMz']) + ',' + str(results['CL/CD']) + ',' + str(results['Iteration']) + ',' +