def calcJpolar(self, Mach, Re, alphaStart, alphaEnd, alphaStep,flap=False): path = myPaths() path.setRandPrefix() tmpJournal = path.getTmpFile('jfscript') tmpAfFile = path.getTmpFile('dat','af') tmpPolar = path.getTmpFile('pol') if flap: afLib.writeFlap(tmpAfFile, self.airfoil) else: afLib.writeAirfoil(tmpAfFile,self.airfoil) self.M = Mach self.Re = Re jouFile = open(tmpJournal,'wt') jouFile.write('Options.Country(0)\nGeometry.Clear()\n') jouFile.write('Geometry.Open(\"%s\")\n' %tmpAfFile) jouFile.write('Options.MachNumber(%.4f)\n'%Mach) jouFile.write('Options.StallModel(0)\n') jouFile.write('Options.TransitionModel(1)\n') jouFile.write('Options.GroundEffect(0)\n') jouFile.write('Options.HeightOverSpan(0.5)\n') jouFile.write('Options.AspectRatio(0)\n') jouFile.write('Polar.Analyze(%.0f;%.0f;%.0f;%.0f;%.0f;%.0f;100;100;0;0)\n'%(Re,Re,0,alphaStart, alphaEnd, alphaStep)) jouFile.write('Polar.Save(\"%s\")\n'%tmpPolar) jouFile.write('Exit()') jouFile.close() cmd = ('\"\"%s\" -cp \"%s\" -jar \"%s\" Script=\"%s\"\"'%(path.java,path.mhclasses,path.javafoil,tmpJournal)) os.system(cmd) self.readJpolar(tmpPolar) os.remove(tmpJournal) os.remove(tmpAfFile) os.remove(tmpPolar)
def costFcn(X,deflection): airfoilPath = 'GA37A315mod.dat' node1 = ny.zeros([3,2]) node2 = ny.zeros([3,2]) vectLenRatio1 = ny.zeros([3]) node1[0,0] = X[0] node1[1,1] = X[1] node1[2,0] = X[2] node2[0,0] = X[3] vectLenRatio1[0] = X[4] vectLenRatio1[1] = X[5] vectLenRatio1[2] = X[6] theta = X[7] overlap = X[8] gap = X[9] zTE = 0.002 #deflection = 35 node1[1,0] = 0.7 #flap chord ratio Mach = 0.16 Re = 4e6 alphaStart = -20 alphaEnd = 10 alphaStep = 1 try: airfoil = flapGeom2.getFlap(airfoilPath, node1,node2, vectLenRatio1, theta, gap, overlap, deflection,zTE) polar = afAnalysis.polar(airfoil) #polar.calcJpolar(Mach,Re,alphaStart,alphaEnd,alphaStep,True) #f = -polar.CLmax #g = 5. - polar.ClmaxAlpha except: f = 100 f = [] h = [] g = [] wdir = r'D:\Documents\My Documents\1. Classes\5 Sem - Human Computer Interaction for MDO\term project\DoE' filename1 = ('flap overlap%.2f gap%.2f defl%.2f.txt'%(100*X[8],100*X[9],deflection)) filename2 = ('flap overlap%.2f gap%.2f defl%.2f.iges'%(100*X[8],100*X[9],deflection)) filepath1 = wdir + '\\' + filename1 filepath2 = wdir + '\\' + filename2 afLib.writeFlap(filepath1,airfoil) polar.saveAsIgs(filepath2,airfoil,True) plt.figure(1) plt.axis([0,1.2,-.5,.5]) plt.grid(True) plt.hold(True) plt.plot(airfoil.mainSec[:,0],airfoil.mainSec[:,1]) plt.plot(airfoil.flap[:,0],airfoil.flap[:,1]) plt.show() return f,g,h
def saveAsIgs(self,filename,airfoil,flap=False): path = myPaths() path.setRandPrefix() tmpJournal = path.getTmpFile('jfscript') tmpAfFile = path.getTmpFile('dat','af') if flap: afLib.writeFlap(tmpAfFile, self.airfoil) else: afLib.writeAirfoil(tmpAfFile,self.airfoil) jouFile = open(tmpJournal,'wt') jouFile.write('Options.Country(0)\nGeometry.Clear()\n') jouFile.write('Geometry.Open(\"%s\")\n' %tmpAfFile) jouFile.write('Geometry.Save(\"%s\")\n' %filename) jouFile.write('Exit()') jouFile.close() cmd = ('\"\"%s\" -cp \"%s\" -jar \"%s\" Script=\"%s\"\"'%(path.java,path.mhclasses,path.javafoil,tmpJournal)) os.system(cmd) os.remove(tmpJournal) os.remove(tmpAfFile)