def transonic_airfoil():
    #x0 = array([0.119087477, 0.160950359,0.203634413,0.192468212,-0.200580639, -0.126010045, 0.107256400e-18])
    x0 = array([0.17042532,0.14831629,0.14576823,0.134351,-0.15162484,-0.13875406,-0.14055989])
    tol  = 1.0e-4
    gtol = 1.0e-4
    maxIter = 50
    xDoe = read_samples('LHC_transonic_af.txt')
    aa = AirfoilAnalysis()
    aa._upd_cst(x0)
    lb = x0 - 0.075
    ub = x0 + 0.075
    err = tol+1.
    niter = 0
    gConverged = False
    xConverged = False
    delta = min([min(xu-x,x-xl) for x,xu,xl in zip(x0,ub,lb)])
    trustRegion = TrustRegionManagement(delta, 0.25, 0.75, 1.25, 0.3, 2.0)

    xDoe = denormalize(xDoe,lb,ub,0)
    fscaled = ScaledFunction(aa.fLow, aa.fHigh,0,'add')
    gscaled = ScaledFunction(aa.gLow, aa.gHigh,0,'add')

    fscaled._initialize_by_doe_points(xDoe)
    #gscaled._initialize_by_doe_points(xDoe)
    def print_header():
        print '\nx1\tx2\tf\trho\tdelta\terr\tgScaled\tgHigh'
    while err>tol:
        fscaled.construct_scaling_model(x0)
        #gscaled.construct_scaling_model(x0)
        bnds = get_bounds(x0,delta,lb,ub)
        cnstr = ({'type':'ineq','fun':aa.g3},{'type':'ineq','fun':aa.g2},)
        rslt = minimize(fscaled,x0,method='SLSQP',bounds=bnds,constraints=cnstr,tol=1e-10,jac=aa.fLowDeriv)
        #rslt = minimize(fscaled,x0,method='SLSQP',bounds=bnds,tol=1e-10)
        xnew = rslt.x
        fnew = rslt.fun
        #gScaledNew = gscaled(xnew)
        rho1, fHighNew = fscaled.get_trust_region_ratio(xnew)
        #rho2, gHighNew = gscaled.get_trust_region_ratio(xnew)
        #rho = min([rho1,rho2])
        rho = rho1
        err = np.linalg.norm([x0-xnew])

        delta = trustRegion.adjust(rho,err)
        x0 = xnew
        #print '\n%.4f\t%.4f\t%.4f\t'%(x0[0],x0[1],fnew),'%.2f\t%.2e\t'%(rho,delta),'%.2e'%err
        print '\n',fnew, rho, delta, err
        niter += 1

#        if (-gtol<=gHighNew<=gtol and gScaledNew<=gtol) or (gHighNew>=0.0 and gScaledNew>gtol):
#            gConverged = True
#        else:
#            gConverged = False
    fscaled.funcHi.display()
    fscaled.funcLo.display()
    gscaled.funcHi.display()
    gscaled.funcLo.display()
示例#2
0
 def _upd_cst(self,x,_norm=True):
     if _norm:
         x = denormalize(x,self.lb,self.ub)
     n = len(x)
     if n%2==0:
         Au = x[:n/2]
         Al = x[n/2:]
     else:
         Au = x[:int(n/2)+1]
         Al = hstack([-x[0],x[int(n/2)+1:]])
     self.af = Af.cst(Au,Al,25,'cos')
     self.thickness = self.af.thickness
示例#3
0
def generate_igs_files():
    import miscTools as mt
    xOpt = array([0.136949,0.196987,0.067111,0.166011,0.006532,0.035718])
    gap = array([0.5,2.5]) / 100.0
    overlap = array([-2.0,2.0]) / 100.0
    doe = array([[-1,1.],[0,1],[1,1],[-1,0],[0,0],[1,0],[1,-1]])
    doe = (doe + 1.0) / 2.0

    lb = array([gap[0],overlap[0]])
    ub = array([gap[1],overlap[1]])
    xDenorm = array([mt.denormalize(xx,lb,ub) for xx in doe])
    i = 0
    for x in xDenorm:
        i += 1
        xdoe = hstack([xOpt[:-2],x])
        print xdoe
        fg.save_javafoil_igs(xdoe,i)
def run_full_table_analysis(wdir):
    X,lb,ub,fc = get_initial_data()
    
    pathDOE = os.getcwd() + '\\' + wdir + '\\1. input.txt'
    pathOutput = os.getcwd() + '\\' + wdir + '\\2. outputAero.txt'
    clcruise = 0.4
    
    fid = open(pathOutput,'wt')
    fid.write('Au0\tAu1\tAu2\tAu3\tAu4\tAl0\tAl1\tAl2\tAl3\tAl4\tLDmax\talphaLDmax\tClmax\talphaClmax\tCdAtLDmax\tLD32max\tthickness\tcdcruise\n')
    fid.close()
    #designs = read_doe(pathDOE)
    designs = read_tabulated_data_without_header(pathDOE)
    for i,design in enumerate(designs):
        design = denormalize(design,lb,ub)
        af = airfoil.cst(design[0:5],design[5:10])
        filename = wdir + 'polar_%d.txt'%(i+1)
        result = aero_analysis(af, fc, filename)
        write_output(design,result,pathOutput,clcruise)
        af.write_txt(wdir + 'coordinates_%d.txt'%(i+1))
示例#5
0
def vcm_airfoil_optimization():
    aa = AirfoilAnalysis()
    xdoe,f = read_xls_doe()

    eta1 = 0.25
    eta2 = 0.75
    eta3 = 1.25
    c1 = 0.3
    c2 = 2.0
    tol = 1e-6
    gtol = 1e-6
    err = tol+1
    iterMax = 20
    nIter = 0
    delta = 0.4
    # baseline
    #x0 = array([0.18723832, 0.2479892, 0.26252777, 0.31606257, 0.0819584, -0.11217863, -0.14363534, -0.06480575, -0.27817776, -0.09874038])
    x0 = array([0.1670, 0.3340, 0.2601, 0.1971, -0.0713, -0.1951, -0.0498])
    dxu = zeros(len(x0))+0.05
    dxl = zeros(len(x0))-0.05
    #dxu[9] = 0.005
    #dxl[4] = -0.005
    aa.ub = x0+dxu
    aa.lb = x0+dxl
    
    x0 = normalize(x0,aa.lb,aa.ub)
    aa._upd_cst(x0)
    #aa.af.plot()
    gscaled = ScaledFunction(aa.gLow, aa.gHigh,5,scalingType='add')
    #gscaled._initialize_by_doe_points(xdoe,f-aa._clmax)
    
    histFile = 'KLA100//airfoil_root_history_20141206_AVCM.txt'
    fid = open(histFile,'wt')
    fid.write('Iter\tfval\tgHi\tgLow\tgScaled\trho\tdelta\terror\tx\n')
    f0 = aa.fLow(x0)
    g0 = aa.gLow(x0)
    g0h = aa.gHigh(x0)
    out = '%d\t%.6f\t%.4f\t%.4f\t%.4f\t%.4f\t%.2e\t%.2e\t'%(0,f0,g0+aa._clmax,g0h+aa._clmax,g0h+aa._clmax,0,delta,err)
    for xx in denormalize(x0,aa.lb,aa.ub):
        out += '%.4f\t'%xx
    fid.write(out)
    fid.write('\n')
    fid.close()
    ifevLow = 0
    while err>tol and nIter<iterMax:
        print '--> iteration started'
        nIter += 1
        gscaled.construct_scaling_model(x0)
        bnds = tuple()
        for _x,_xu,_xl in zip(x0,aa.ub,aa.lb):
            bndU = min([_x+delta, _xu])
            bndL = max([_x-delta, _xl])
            bnds += ((bndL, bndU),)
        cnstr = ({'type':'ineq','fun':gscaled},{'type':'ineq','fun':aa.g2},
                 {'type':'ineq','fun':aa.g3})
        rslt = minimize(aa.fLow,x0,method='SLSQP',bounds=bnds,constraints=cnstr,
                        tol=1e-6,jac=aa.fLowDeriv, options={'disp':False})
        xnew = rslt.x
        fnew = rslt.fun
        ifevLow += rslt.nfev
        g0 = gscaled(x0)
        goptScaled = gscaled(xnew)
        goptHigh = gscaled.funcHi(xnew)
        f0 = aa.fLow(x0)
        rho = get_trust_region_ratio(f0,fnew,fnew,g0,goptScaled,goptHigh)
        if goptHigh>=0.0:
            err = 0.0
        else:
            err = norm(x0-xnew)
        if rho<=eta1 or rho>=eta3:
            delta *= c1
        elif eta1<rho<eta2:
            delta = delta
        else:
            if err==delta:
                delta *= c2
            else:
                delta = delta
        #print nIter,'\t','%.6f\t'%err,fnew,rho,delta
        fid = open(histFile,'a')
        #print nIter, fnew, gHinew, aa._clmax, gscaled.funcLo(xnew), gscaled(xnew), rho, delta, err
        out = '%d\t%.6f\t%.4f\t%.4f\t%.4f\t%.4f\t%.2e\t%.2e\t'%(nIter,fnew,goptHigh+aa._clmax,gscaled.funcLo(xnew)+aa._clmax,gscaled(xnew)+aa._clmax,rho,delta,err)
        for xx in denormalize(xnew,aa.lb,aa.ub):
            out += '%.4f\t'%xx
        fid.write(out)
        fid.write('\n')
        fid.close()
        print out
        print 'lowfi calls: %d, total: %d'%(rslt.nfev, ifevLow)
        if rho>=0:
            x0 = xnew
    
    aa._upd_cst(xnew)
    gscaled.funcHi.display()
    gscaled.funcLo.display()
    print rslt
    print aa.af.thickness
    print aa.gHigh(xnew) + aa._clmax
    #pol1 = aa.af.get_J_polar(0.09,2.7e6)
    pol2 = aa.af.get_X_polar(0.17,4.4e6)
    #pol1.display()
    pol2.display()
    aa.af.plot()