xnew = rslt.x neval += rslt.nfev err = np.linalg.norm(x0-xnew) x0 = xnew dg += g2(rslt.x) - g2new(rslt.x) #print '%d\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f'%(i,xopt[-1][0],xopt[-1][1],dg,g2hval[-1],g2lval[-1],g2scval[-1],fopt[-1]) print np.linalg.norm(xnew-xexact) print fval[-1]-fexact xopt = np.transpose(np.vstack([x1,x2])) print neval print i out.write_array(itr,'itr') out.write_array(x1,'x1') out.write_array(x2,'x2') out.write_array(fval,'f') out.write_array(errorVal,'err') out.write_array(offset,'dg') out.write_array(g1val,'g1') out.write_array(g2hval,'g2h') out.write_array(g2lval,'g2l') out.write_array(g2aval,'g2new') out.write_array(g3val,'g3') out.close()
def plot_result_af(): x0 = array([0.1670, 0.3340, 0.2601, 0.1971, -0.0713, -0.1951, -0.0498]) x1 = [0.1839,0.3520,0.2512,0.1835,-0.0493,-0.2190,-0.0225] x2 = [0.1729,0.3482,0.2707,0.2045,-0.0774,-0.1563,-0.0498] rsltFile = SaveTextData('af_sub_20141207.txt') def print_polar(pol): print '-->' for i in range(len(pol.alpha)): print '%.2f\t%.6f\t%.6f\t%.6f'%(pol.alpha[i],pol.cl[i],pol.cd[i],pol.cm[i]) aa = AirfoilAnalysis() aa._upd_cst(x0,False) crd0 = copy(aa.af.coord) pol0 = aa._run_fluent(x0,False) pol0x = aa.af.get_X_polar(aa.Mldg,aa.landing.Re,alphaSeq=[-10,10,1]) print_polar(pol0) print_polar(pol0x) aa._upd_cst(x1,False) crd1 = copy(aa.af.coord) pol1 = aa._run_fluent(x1,False) pol1x = aa.af.get_X_polar(aa.Mldg,aa.landing.Re,alphaSeq=[-10,10,1]) print_polar(pol1) print_polar(pol1x) aa._upd_cst(x2,False) crd2 = copy(aa.af.coord) pol2 = aa._run_fluent(x2,False) pol2x = aa.af.get_X_polar(aa.Mldg,aa.landing.Re,alphaSeq=[-10,10,1]) print_polar(pol0) print_polar(pol0x) print_polar(pol1) print_polar(pol1x) print_polar(pol2) print_polar(pol2x) rsltFile.write_array(crd0[:,0],'x0') rsltFile.write_array(crd0[:,1],'y0') rsltFile.write_array(crd1[:,0],'x1') rsltFile.write_array(crd1[:,1],'y1') rsltFile.write_array(crd2[:,0],'x2') rsltFile.write_array(crd2[:,1],'y2') rsltFile.write_array(pol0x.cd,'cd0x') rsltFile.write_array(pol1x.cd,'cd1x') rsltFile.write_array(pol2x.cd,'cd2x') rsltFile.write_array(pol0x.cl,'cl0x') rsltFile.write_array(pol1x.cl,'cl1x') rsltFile.write_array(pol2x.cl,'cl2x') rsltFile.write_array(pol0.alpha,'a0') rsltFile.write_array(pol1.alpha,'a1') rsltFile.write_array(pol2.alpha,'a2') rsltFile.write_array(pol0.cl,'cl0') rsltFile.write_array(pol1.cl,'cl1') rsltFile.write_array(pol2.cl,'cl2') rsltFile.close() plt.figure(1) plt.hold(True) plt.grid(True) plt.plot(crd0[:,0],crd0[:,1],'k--',linewidth=2) plt.plot(crd1[:,0],crd1[:,1],'r-',linewidth=2) plt.plot(crd2[:,0],crd2[:,1],'b:',linewidth=2) plt.legend(['baseline','GVFM','VCM']) plt.figure(2) plt.hold(True) plt.grid(True) plt.axis([0.002, 0.012, -0.5, 1.0]) plt.plot(pol0x.cd, pol0x.cl, 'ks--',linewidth=2) plt.plot(pol1x.cd, pol1x.cl, 'ro-',linewidth=2) plt.plot(pol2x.cd, pol2x.cl, 'b^:',linewidth=2) plt.xlabel('Drag coefficient') plt.ylabel('Lift coefficient') plt.legend(['baseline','GVFM','VCM'],'lower right') plt.figure(3) plt.hold(True) plt.grid(True) plt.axis([0,20,0,1.8]) plt.plot(pol0.alpha, pol0.cl, 'ks--',linewidth=2) plt.plot(pol1.alpha, pol1.cl, 'ro-',linewidth=2) plt.plot(pol2.alpha, pol2.cl, 'b^:',linewidth=2) plt.xlabel('Angle of attack, deg') plt.ylabel('Lift coefficient') plt.legend(['baseline','GVFM','VCM'],'lower right') plt.show()