Exemple #1
0
def run_test3():
    xmin, xmax = -5.0, 5.0
    ymin, ymax = -5.0, 5.0
    func = stybtang
    xDOE = mt.read_tabulated_data_without_header('LHS10.txt')
    xDOE = np.vstack([xDOE, [-5,-5]])
    yDOE = np.array([func(xi) for xi in xDOE])
    
    X1 = np.arange(xmin,xmax,0.25)
    X2 = np.arange(ymin,ymax,0.25)
    X1, X2 = np.meshgrid(X1,X2)
    
    X = np.vstack([X1.flatten(),X2.flatten()])
    X = np.transpose(X)
    Y = np.array([t.jackknifing(xDOE,yDOE,xi) for xi in X])
    Y = np.reshape(Y,X1.shape)
    
    Y2 = np.array([t.jackknifing(xDOE,yDOE,xi) for xi in xDOE])
    
    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111, projection='3d')
    ax1.hold(True)
    ax1.plot_surface(X1,X2,Y,cmap=cm.jet,rstride=1, cstride=1)
    ax1.plot(xDOE[:,0],xDOE[:,1],Y2,'ro')
    
    plt.show()
 def __init__(self, path):
     #self.data = mt.read_tabulated_data_without_header('ClarkY-C81-lowfiCFD.txt',1)
     self.data = mt.read_tabulated_data_without_header(path,1)
     self.xl = np.array([0.2, -20.0]) #Mach, alpha
     self.xu = np.array([0.8, 20.0])
     self.norm = mt.Normalization(self.xl, self.xu,-1.0,1.0)
     #self.norm = mt.Normalization([-10,-10],[10,10])
     x = self.norm.normalize(self.data[:,:2])
     #x = (self.data[:,:2] + np.array([-0.2, 20.0])) / np.array([0.3, 20.0]) - np.array([1.0, 1.0])
     self.modelCL = mt.RbfMod(x, self.data[:,2],f='thin_plate')
     self.modelCD = mt.RbfMod(x, self.data[:,3],f='thin_plate')
     self.modelCM = mt.RbfMod(x, self.data[:,4],f='thin_plate')
     self.x = x
Exemple #3
0
def run_test2():
    xmin, xmax = -2.0, 2.0
    ymin, ymax = -2.0, 2.0
    func = mt.NormalizedFunction(tf.ackley,[xmin,ymin],[xmax,ymax])
    
    npop = 3
    spread = 0.5
    ndim = 2
    itrMax = 10
    errFilterRatio = 0.0
    
    # --- func evaluation ---
    xLHS = mt.read_tabulated_data_without_header('LHS20.txt')
    xFFD = np.array([[-5.0,-5],[5,5],[-5,5],[5,-5]])
    xDOE = np.vstack([xFFD,xLHS])
    yDOE = np.array([func(xi) for xi in xDOE])
    
    nskip = len(xFFD)
    err, SE, MSE = t.cross_validation(xDOE,yDOE,nskip)
    
    for i in range(itrMax):
        print len(xDOE), MSE, np.max(SE)
        model = mt.RbfMod(xDOE,SE)
        fig = plt.figure(1)
        ax1 = fig.add_subplot(111,projection='3d')
        ax1.hold(True)
        ax1.set_xlabel('X1')
        ax1.set_ylabel('X2')
        x,y,z = t.get_points_for_2d_plot(model,xmin,xmax,ymin,ymax)
        ax1.plot_surface(x,y,z,cmap=cm.jet,rstride=1, cstride=1)
        ax1.plot(xDOE[:,0],xDOE[:,1],SE,'ro')
        
        fig2 = plt.figure(2)
        ax2 = fig2.add_subplot(111,projection='3d')
        ax2.hold(True)
        model2 = mt.RbfMod(xDOE,yDOE)
        x1,y1,z1 = t.get_points_for_2d_plot(func,xmin,xmax,ymin,ymax)
        x2,y2,z2 = t.get_points_for_2d_plot(model2,xmin,xmax,ymin,ymax)
        ax2.plot_wireframe(x1,y1,z1,color='b')
        ax2.plot_wireframe(x2,y2,z2,color='r')
        ax2.plot(xDOE[:,0],xDOE[:,1],yDOE,'go')
        plt.show()

        xDOEadd = get_new_samples(xDOE, SE, npop,spread)
        xDOE = np.vstack([xDOE, xDOEadd])
        yDOE = np.array([stybtang(xi) for xi in xDOE])
        err, SE, MSE = t.cross_validation(xDOE,yDOE,nskip)
Exemple #4
0
def run_test1():
    # styblinski-tang function
    X1 = np.arange(-5,5,0.25)
    X2 = np.arange(-5,5,0.25)
    X1, X2 = np.meshgrid(X1,X2)
    Y = stybtang([X1,X2])
    
    # DOE points
    xLHS = mt.read_tabulated_data_without_header('LHS10.txt')
    xFFD = np.array([[-5.0,-5],[5,5],[-5,5],[5,-5]])
    xDOE = np.vstack([xFFD,xLHS])
    yDOE = np.array([stybtang(xi) for xi in xDOE])
    rbf  = mt.RbfMod(xDOE,yDOE)
    
    X = np.vstack([X1.flatten(),X2.flatten()])
    yRbf = rbf(X)
    Y2 = np.reshape(yRbf,X1.shape)
    err = t.cross_validation(xDOE,yDOE,4)
    err = err*err
    err[0:4] = np.zeros(4)
    rbfErr = mt.RbfMod(xDOE,err)
    errRbf = rbfErr(X)

    
    # plot area
    fig = plt.figure(1)
    ax = fig.add_subplot(111, projection='3d')
    ax.hold = True
    ax.plot_wireframe(X1,X2,Y)
    ax.plot_wireframe(X1,X2,Y2,color='r')
    
    
    fig2 = plt.figure(2)
    ax2 = fig2.add_subplot(111)
    ax2.plot(xDOE[:,0],xDOE[:,1],'ro')
    
    fig3 = plt.figure(3)
    ax3 = fig3.add_subplot(111, projection='3d')
    ax3.plot_surface(X1,X2,np.reshape(errRbf,X1.shape),cmap=cm.jet,rstride=1, cstride=1)
    #ax3.plot_wireframe(X1,X2,(Y-Y2)**2)
    ax3.plot(xDOE[:,0],xDOE[:,1],err,'ro')
    plt.show()
Exemple #5
0
def get_DOE_data():
    xDOE = mt.read_tabulated_data_without_header('LHS20.txt')
    xDOE += 5.0
    xDOE *= 0.1
    return xDOE
def results():
    path1 = 'ClarkY-C81.txt'
    path2 = 'ClarkY-ad.txt'
    path3 = 'aDOE_results.txt'
    n = 50
    
    data1 = mt.read_tabulated_data_without_header(path1,1)
    data2 = mt.read_tabulated_data_without_header(path2)
    data3 = mt.read_tabulated_data_without_header(path3)
    
    xl = np.array([0.2, -20.0]) #Mach, alpha
    xu = np.array([0.8, 20.0])
    
    norm = mt.Normalization(xl, xu,-1.0,1.0)
    x1 = norm.normalize(data1[:,:2])
    modelCL1 = mt.RbfMod(x1, data1[:,2],f='cubic')
    modelCD1 = mt.RbfMod(x1, data1[:,3],f='cubic')
    modelCM1 = mt.RbfMod(x1, data1[:,4],f='cubic')
    
    x2 = norm.normalize(data2[:,:2])
    modelCL2 = mt.RbfMod(x2, data2[:,2],f='cubic')
    modelCD2 = mt.RbfMod(x2, data2[:,3],f='cubic')
    modelCM2 = mt.RbfMod(x2, data2[:,4],f='cubic')
    
    X1, X2 = t.get_2d_grid(n, [-1.0, -1.0], [1.0, 1.0])
    X1r,X2r = t.get_2d_grid(n, xl, xu)
    X      = t.get_ffd_2d(n, [-1.0, -1.0], [1.0, 1.0])
    Ym11d   = np.array([modelCL1(xi) for xi in X])
    Ym11   = np.reshape(Ym11d,X1.shape)
    Ym21d   = np.array([modelCD1(xi) for xi in X])
    Ym21   = np.reshape(Ym21d,X1.shape)
    Ym31d   = np.array([modelCM1(xi) for xi in X])
    Ym31   = np.reshape(Ym31d,X1.shape)
    
    Ym12d   = np.array([modelCL2(xi) for xi in X])
    Ym12   = np.reshape(Ym12d,X1.shape)
    Ym22d   = np.array([modelCD2(xi) for xi in X])
    Ym22   = np.reshape(Ym22d,X1.shape)
    Ym32d   = np.array([modelCM2(xi) for xi in X])
    Ym32   = np.reshape(Ym32d,X1.shape)
    
    
    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111, projection='3d')
    ax1.hold(True)
    #ax1.plot_wireframe(X1,X2,Ym11,color='b')
    ax1.plot_surface(X1r,X2r,Ym12,cmap=cm.jet, rstride=1, cstride=1)
    ax1.plot(data2[:,0],data2[:,1],data2[:,2],'rs')
    ax1.set_xlabel('Mach')
    ax1.set_ylabel('Angle of attack, deg')
    ax1.set_zlabel('Lift coefficient')
    #ax1.legend(['Sample points','Exact function','Approximation'])

    
    fig2 = plt.figure(2)
    ax2 = fig2.add_subplot(111, projection='3d')
    ax2.hold(True)
    #ax2.plot_wireframe(X1,X2,Ym21,color='b')
    ax2.plot_surface(X1r,X2r,Ym22,cmap=cm.jet, rstride=1, cstride=1)
    ax2.plot(data2[:,0],data2[:,1],data2[:,3],'rs')
    ax2.set_xlabel('Mach')
    ax2.set_ylabel('Angle of attack, deg')
    ax2.set_zlabel('Drag coefficient')
    
    fig3 = plt.figure(3)
    ax3 = fig3.add_subplot(111, projection='3d')
    ax3.hold(True)
    #ax3.plot_wireframe(X1,X2,Ym31,color='b')
    ax3.plot_surface(X1r,X2r,Ym32,cmap=cm.jet, rstride=1, cstride=1)
    ax3.plot(data2[:,0],data2[:,1],data2[:,4],'rs')
    ax3.set_xlabel('Mach')
    ax3.set_ylabel('Angle of attack, deg')
    ax3.set_zlabel('Moment coefficient')
    
    fig4 = plt.figure(4)
    ax4 = fig4.add_subplot(111)
    ax4.plot(data2[:,0],data2[:,1],'ro')
    ax4.set_xlabel('Mach')
    ax4.set_ylabel('Angle of attack, deg')
    plt.show()
Exemple #7
0
def get_DOE_data(path='LHS10.txt'):
    xDOE = mt.read_tabulated_data_without_header(path)
    xDOE += 5.0
    xDOE *= 0.1
    return xDOE
Exemple #8
0
def run_test1():
    fhigh = tf.ForresterND(0.40, 0.9, 2.0)
    flow  = tf.ForresterND(0.45, 1.0, 0.0)
    
    tolLow = 0.1
    tolHigh = 0.1
    
    minDistance = 0.05
    
    errHist = list()
    
    xDOE = mt.read_tabulated_data_without_header('LHS30.txt')
    xDOE += 5.0
    xDOE *= 0.1
    yl = np.array([flow(xi) for xi in xDOE])
    
    xl = np.array([0.0, 0.0])
    xu = np.array([1.0, 1.0])
    bnds = np.transpose(np.vstack([xl,xu]))
    
    X1 = np.linspace(xl[0],xu[0],50)
    X2 = np.linspace(xl[1],xu[1],50)
    X1, X2 = np.meshgrid(X1,X2)
    X = np.vstack([X1.flatten(),X2.flatten()])
    X = np.transpose(X)
    
    X1v = np.linspace(xl[0],xu[0],3)
    X2v = np.linspace(xl[1],xu[1],3)
    X1v, X2v = np.meshgrid(X1v,X2v)
    Xv = np.vstack([X1v.flatten(),X2v.flatten()])
    Xv = np.transpose(Xv)
    
    err = tolLow+1
    while err>tolLow:
        jn = np.array([t.jackknifing(xi, xDOE,yl) for xi in Xv])
        jnsortedIdx = np.argsort(jn)
        jnsortedIdx = np.flipud(jnsortedIdx)
        
        match = True
        idx = 0
        while match:
            x0 = Xv[jnsortedIdx[0]]
            #cnstr = ({'type':'ineq','fun':constraint,'args':(X,)})
            rslt = minimize(objective,x0,method='SLSQP',bounds=bnds,args=(xDOE,yl,))
             #               constraints=cnstr)
            xnew = rslt.x
            err = -rslt.fun
            
            dist = np.array([np.linalg.norm(xi-xnew) for xi in xDOE])
            dist = np.min(dist)
            
            if dist <= minDistance:
                match = True
                idx += 1
            else:
                match = False
        print err, xnew, x0, idx
        errHist.append(err)
        xDOE = np.vstack([xDOE,xnew])
        yl = np.array([flow(xi) for xi in xDOE])
    
    print len(xDOE)
    print get_avg_jackknife(xDOE,yl)
    
    Yl = np.array([flow(xi) for xi in X])
    model = mt.RbfMod(xDOE, yl)
    Ym = np.array([model(xi) for xi in X])
    Yl = np.reshape(Yl,X1.shape)
    Ym = np.reshape(Ym,X1.shape)
    
#    fig1 = plt.figure(1)
#    ax1 = fig1.add_subplot(111, projection='3d')
#    ax1.hold(True)
#    ax1.plot_wireframe(X1,X2,Yl,color='r')
#    ax1.plot_wireframe(X1,X2,Ym,color='b')
#    ax1.plot(xDOE[:,0],xDOE[:,1],yl,'ro')
#    ax1.set_xlabel('X1')
#    
#    fig2 = plt.figure(2)
#    ax2 = fig2.add_subplot(111)
#    ax2.plot(range(len(errHist)),errHist,'rs-')
#    ax2.set_yscale('log')
#    plt.show()
#    
    
    # variable fidelity model construction
    flowApprox = mt.RbfMod(xDOE,yl)
    
    xDOEh = mt.read_tabulated_data_without_header('LHS20.txt')
    xDOEh += 5.0
    xDOEh *= 0.1
    #xDOEh = np.array([[0.0,0.0], [0, 1], [1,1], [1,0], [0.5,0.5]])
    yh = np.array([fhigh(xi) for xi in xDOEh])
    yl = np.array([flowApprox(xi) for xi in xDOEh])
    gamma = yh - yl
    
    fscaling = HybridScaling(xDOEh,yh,yl,flowApprox,0.0)
    
    
    # --- vf DOE ---
    
    err = tolHigh+1.0
    while err>tolHigh:
        jn = np.array([t.jackknifing(xi, xDOEh,gamma) for xi in Xv])
        jnsortedIdx = np.argsort(jn)
        jnsortedIdx = np.flipud(jnsortedIdx)
        
        match = True
        idx = 0
        while match:
            x0 = Xv[jnsortedIdx[idx]]
            rslt = minimize(objective,x0,method='SLSQP',bounds=bnds,args=(xDOEh,gamma))
            xnew = rslt.x
            err = -rslt.fun
            
            dist = np.array([np.linalg.norm(xi-xnew) for xi in xDOEh])
            dist = np.min(dist)
            
            if dist <= minDistance:
                match = True
                idx += 1
            else:
                match = False
        print err, xnew, x0, idx
        errHist.append(err)
        xDOEh = np.vstack([xDOEh,xnew])
        yl = np.array([flow(xi) for xi in xDOEh])
        yh = np.array([fhigh(xi) for xi in xDOEh])
        gamma = yh-yl
    
    fscaling = HybridScaling(xDOEh,yh,yl,flowApprox,1.0)
    print len(xDOEh)
    
    
    # --- plot ---
    Yl = np.array([fhigh(xi) for xi in X])
    Ym = np.array([fscaling(xi) for xi in X])
    Yl = np.reshape(Yl,X1.shape)
    Ym = np.reshape(Ym,X1.shape)
    
    print get_avg_jackknife(xDOEh,gamma)

    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111, projection='3d')
    ax1.hold(True)
    ax1.plot_wireframe(X1,X2,Yl,color='r')
    ax1.plot_wireframe(X1,X2,Ym,color='b')
    ax1.plot(xDOEh[:,0],xDOEh[:,1],yh,'ro')
    ax1.legend(['high','scaled','samples-high'])
    ax1.set_xlim(0,1)
    ax1.set_ylim(0,1)
    ax1.set_zlim(0,5)
    ax1.set_xlabel('X1')
    ax1.set_ylabel('X2')
    plt.show()
def create_aero_db():
    af = MyTools.airfoil.airfoil.Airfoil()
    
    af.read_txt('Clark-Y.txt')
    #af.create_naca4()
    
    #
    flow = AeroModel('ClarkY-adaptive.txt')
    flow.plot()
#    fhigh = AeroModel('aero_data_jfoil.txt')
    #flow.plot()
    #fhigh.plot()
    #fhigh = CFDrun(af)

    #fhigh.modelCL.rbf.epsilon = 1e-8
    #flow.plot()
    
    #fhigh.plot()
    
#    def func(x):
#        cl0, cd0, cm0 = flow(x)
#        cl1, cd1, cm1 = fhigh(x)
#        return cl1-cl0, cd1-cd0, cm1-cm0
    
    func = CFDrun(af)
    func.path = 'ClarkY-adaptive.txt'
#    func = AeroModel('ClarkY-C81.txt')
#    func.plot()
#    fhigh = AeroModel('ClarkY-adaptive.txt')
#    fhigh.plot()

    Mach = np.array([0.2, 0.8])
    alpha = np.array([-20.0, 20.0])
    DOEpath = 'LHS30.txt'
    tol          = np.array([0.05, 0.001, 0.01])
    runBudget    = 100
    minDistance  = 0.025
    kFold        = 1
    pOut         = 5
    xDOE0        = t.get_ffd_2d(51, [-1.0, -1], [1.,1.]) # trial initial points
    nptsPlot     = 50
    
    # --- ---
    
    bnds = np.array([[-0.0001,-0.0001],[1.0001,1.0001]])
    _xl = np.array([-1.0, -1.0])
    _xu = np.array([1.0, 1.0])
    xl = np.array([Mach[0], alpha[0]])
    xu = np.array([Mach[1], alpha[1]])
    
    norm = mt.Normalization(xl, xu)
    
    xDOE = mt.read_tabulated_data_without_header(DOEpath)
    #xDOE = t.get_ffd_2d(3,[-1.0, -1], [1.,1.])
    
    #get_aero_data(xDOE[10], af, norm)
    
    data = np.zeros([len(xDOE),3])
    dataNew = np.zeros(3)
    for i,xx in enumerate(xDOE):
        data[i,0], data[i,1], data[i,2] = func(xx)
        xreal = func.norm.denormalize(xx)
        out2 = '%.6f\t%.6f\t%.8f\t%.8f\t%.8f\n'%(xreal[0],xreal[1],data[i,0],data[i,1],data[i,2])
        fid2 = open('ClarkY-ad.txt','at')
        fid2.write(out2)
        fid2.close()
#    data = mt.read_tabulated_data_without_header(func.path)[:,2:]

    itr = 0
    err = tol+1.0
    npts = len(xDOE)
    while np.all(err>tol) and runBudget>npts:
        itr += 1
        dataSetIdx = itr%3
        ds = data[:,dataSetIdx]
        jn0 = np.array([objective(xi, xDOE, ds, None, pOut, kFold) for xi in xDOE0])
        xsort = xDOE0[np.argsort(jn0)]
        #xopt = np.zeros([nTrial,xDOE.shape[1]])
        pointFound = False
        i = 0
        while not pointFound:
            x0 = xsort[i]
            i += 0
            rslt = minimize(objective,x0,method='SLSQP',bounds=bnds,
                            args=(xDOE,ds,None,pOut, kFold,minDistance,))
            xopt = t.move_pt_to_bounds(rslt.x,_xl,_xu) #SLSQP bugfix
            pointFound = check_point(xopt, xDOE, minDistance)
        xDOE = mt.remove_duplicates(np.vstack([xopt,xDOE]))
        npts = len(xDOE)
        dataNew[0], dataNew[1], dataNew[2]   = func(xopt)
        data = np.vstack([dataNew, data])
        err1 = t.RRMSE(xDOE,data[:,0])
        err2 = t.RRMSE(xDOE,data[:,1])
        err3 = t.RRMSE(xDOE,data[:,2])
#        err1  = np.average(np.array([get_jn(xi, xDOE, data[:,0],None, pOut, kFold) for xi in xDOE]))
#        err2  = np.average(np.array([get_jn(xi, xDOE, data[:,1],None, pOut, kFold) for xi in xDOE]))
#        err3  = np.average(np.array([get_jn(xi, xDOE, data[:,2],None, pOut, kFold) for xi in xDOE]))
        err = np.array([err1,err2,err3])
        out = '%d\t%d\t%.4e\t%.4e\t%.4e\n'%(itr, len(xDOE), err[0], err[1], err[2])
        xreal = func.norm.denormalize(xDOE[0])
        out2 = '%.6f\t%.6f\t%.8f\t%.8f\t%.8f\n'%(xreal[0],xreal[1],dataNew[0],dataNew[1],dataNew[2])
        print out
        fid1 = open('aDOE_results.txt','at')
        fid1.write(out)
        fid1.close()
        fid2 = open('ClarkY-ad.txt','at')
        fid2.write(out2)
        fid2.close()

   #--- plot area
    iz = 0

    X1, X2 = t.get_2d_grid(nptsPlot, [-1.0, -1.0], [1.0, 1.0])
    X      = t.get_ffd_2d(nptsPlot, [-1.0, -1.0], [1.0, 1.0])
    X1r, X2r = t.get_2d_grid(nptsPlot, xl, xu)
    #Yl    = np.array([func(xi)[iz] for xi in X])
    #Yl    = np.reshape(Yl,X1.shape)
    xDOEreal = np.zeros(xDOE.shape)
    for i,xd in enumerate(xDOE):
        xDOEreal[i] = norm.denormalize(xd)
    
    Yobj = np.array([objective(xi, xDOE, data[:,iz],None,1, kFold) for xi in X])
    Yobj = np.reshape(Yobj,X1.shape)
    yobj = np.array([objective(xi, xDOE, data[:,iz],None,1, kFold) for xi in xDOE])

    model = mt.RbfMod(xDOE, data[:,iz])
    Ym1   = np.array([model(xi) for xi in X])
    Ym1   = np.reshape(Ym1,X1.shape)

    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111, projection='3d')
    ax1.hold(True)
    #.plot_wireframe(X1r,X2r,Yl,color='r')
    #ax1.plot_wireframe(X1,X2,Ym0,color='b')
    ax1.plot_wireframe(X1r,X2r,Ym1,color='b')
    ax1.plot(xDOEreal[:,0],xDOEreal[:,1],data[:,iz],'ro')
    #ax1.plot(xDOEinit[:,0],xDOEinit[:,1],ylinit,'bs')
    ax1.set_xlabel('X1')
    ax1.set_ylabel('X2')
    ax1.set_zlim([-1,1])

    fig2 = plt.figure(2)
    ax2 = fig2.add_subplot(111, projection='3d')
    ax2.hold(True)
    ax2.plot_wireframe(X1,X2,Yobj,color='r')
    ax2.plot(xDOE[:,0],xDOE[:,1],yobj,'ro')
    ax2.set_xlabel('X1')
    
    
    #lvls = np.linspace(-30,20,20)
    
    fig3 = plt.figure(3)
    ax3 = fig3.add_subplot(111)
    ax3.hold(True)
    ax3.plot(xDOE[:,0],xDOE[:,1],'ro')
    #ax3.plot(xDOEinit[:,0],xDOEinit[:,1],'bs')
    #CS = ax3.contourf(X1,X2, Yl, levels=lvls)
    #plt.colorbar(CS, ticks=lvls, format='%.4f')
    ax3.set_xlabel('X1')
    ax3.set_ylabel('X2')
    
    fig4 = plt.figure(4)
    ax4 = fig4.add_subplot(111)
    ax4.hold(True)
    ax4.plot(xDOE[:,0],xDOE[:,1],'ro')
    #ax4.plot(xDOEinit[:,0],xDOEinit[:,1],'bs')
    #CS1 = ax4.contourf(X1,X2, Ym1, levels=lvls)
    #plt.colorbar(CS1, ticks=lvls, format='%.4f')
    ax4.set_xlabel('X1')
    ax4.set_ylabel('X2')
    #ax3.clabel(CS, inline=1, fontsize=10)
    
    plt.show()
def get_DOE_data():
    xDOE = mt.read_tabulated_data_without_header('LHS20.txt')
    xDOE += 5.0
    xDOE *= 0.1
    xDOE = np.vstack([xDOE,[1,1]])
    return xDOE
Exemple #11
0
def main():
    Mach = 0.85
    alpha = 0.0
    variance = 0.025
    MachLow = Mach*(1.0-variance)
    MachUp = Mach*(1.0+variance)
    alphaLow = alpha-0.25
    alphaUp  = alpha+0.25
    inFileDOE = 'LHS9_100.txt'
    
    doe = mt.read_tabulated_data_without_header(inFileDOE)
    lb = np.array([MachLow, alphaLow, 0.04343078, 0.0900427, 0.0570076, 0.08289899, -0.06762751, -0.13041535, -0.02843321])
    ub = np.array([MachUp, alphaUp, 0.08343078, 0.1900427, 0.1570076, 0.18289899, 0.03237249, -0.03041535, 0.07156679])
    
    zTE = 0.005
    alt = 10000
    
    yplus = 1.0
    gridScaleL = 1.0
    gridScaleH = 4.0
    outputFile = inFileDOE[:-4] + '_CFD.txt'
    
    norm = mt.Normalization(lb,ub)
    xDOE = norm.denormalize(doe)
    
    case = 0
    fid = open(outputFile, 'wt')
    fid.write('Mach\talpha\t')
    for i in range(len(lb)-2):
        fid.write('A%d\t'%(i+1))
    #fid.write('clHigh\tcdHigh\tcmHigh\tclLow\tcdLow\tcmLow\tLDhigh\tLDlow\tthickness\n')
    fid.write('cl\tcd\tcm\ttc\n')
    fid.close()

    for i, xx in enumerate(xDOE):
        M = xx[0]
        a = xx[1]
        fc = cfd.flight_conditions.FlightConditions(M, alt)
        af = MyTools.airfoil.airfoil.cst_x(xx[2:], 101)
        af.set_trailing_edge(zTE)
        tc = af.thickness
        try:
#            case += 1
#            clH,cdH,cmH, gs = cfd.run_analysis(af, fc, a, yplus, gridScaleH, case)
            case += 1
            clL,cdL,cmL, gs = cfd.run_analysis(af, fc, a, yplus, gridScaleL, case)
            fid = open(outputFile, 'at')
            fid.write('%.6f\t%.6f\t'%(M,a))
            for _x in xx[2:]:
                fid.write('%.8f\t'%_x)
            #fid.write('%.8f\t%.8f\t%.8f\t%.8f\t%.8f\t%.8f\t%.8f\t%.8f\t%.6f\n'%(clH,cdH,cmH,clL,cdL,cmL,clH/cdH,clL/cdL,tc))
            fid.write('%.8f\t%.8f\t%.8f\t%.8f\n'%(clL,cdL,cmL,tc))
            fid.close()
        except IOError:
            case += 1
            fid = open(outputFile, 'at')
            fid.write('%.6f\t%.6f\t'%(M,a))
            for _x in xx[2:]:
                fid.write('%.8f\t'%_x)
            fid.write('calculation failed\n')
            fid.close()