Ejemplo n.º 1
0
def run_cfd_wing_analysis():
    Mach = 0.7
    altitude = 1e4 # m

    ac = DesignFormulation()
    ac.load_xls('Baseline1')
    ac.setup()

    paths.myPaths.set_file_prefix('fw_debug')
    igsPath = paths.myPaths.get_tmp_file('igs')
    symCasPath = paths.myPaths.get_tmp_file('cas','_sym')
    nonsymCasPath = paths.myPaths.get_tmp_file('cas','_nonsym')

    create_catia_wing(ac,igsPath)
    create_fw_cmesh(ac,igsPath,symCasPath, nonsymCasPath)
    #os.remove(igsPath)

    # under development
    fc = FlightConditions(Mach, altitude)
    run_wing_half(nonsymCasPath, fc)
Ejemplo n.º 2
0
def create_input_files():
    from ucav_design_1 import DesignFormulation
    # Longitudinal (half wing)
    doePath = r'D:\1. Current work\2014 - UAV performance code\Results\norm_results.txt'
    #DOE = read_tabulated_data_without_header('LHS_dvar9_sample30.txt')
    DOE = read_tabulated_data_without_header(doePath)
    ac = DesignFormulation()
    ac.load_xls('Baseline1')
    ac.setup()
    startCase = 30
#    Mach = ac.designGoals.cruiseMach
#    altitude = ac.designGoals.cruiseAltitude
    yplus = .5
    wdir = 'D:\CFD'
    alpha = [-2,0,2]
#    beta = 2.0
    niter = 5000
    
    batFileLongitudinal = '%s\\batchCFD.bat'%wdir
    fid = open(batFileLongitudinal,'at')
    pathFluent = r'C:\Program Files\Ansys Inc\v130\fluent\ntbin\win64\fluent.exe'
    for i,xnorm in enumerate(DOE):
        if i>0:
            name = '%s\\case%d'%(wdir,i+startCase)
            caseName = 'case%d'%(i+startCase)
            print name
            ac.set_x(xnorm,False)
            print ac.xCurrent
            raw_input()
            #FIXME: this part adds section for payload on top
            #ac._adjust_root_airfoil()
            ac.save_2d_figure('%s.png'%name)
            igsPath = '%s.igs'%name
            symCasPath = '%s_sym.cas'%name
            nonsymCasPath = '%s_half.cas'%name
            glfPath = '%s.glf'%name
            #create_catia_wing(ac,igsPath)
            create_fw_cmesh(ac,igsPath,symCasPath,nonsymCasPath,yplus,glfPath)
            Sref = ac.wing.area/2.0
            Cref = ac.wing.MAC
            #Lref = ac.wing.span
            ac._restore_root_airfoil()
            CG = ac.get_cg()
            #a = 2.0
    #        outPrefix = '%s\\results\\case%d_sym_a%d_b%d'%(wdir,i+1,a*100,beta*100)
    #        journalFileRel = 'case%d_sym_a%d_b%d.jou'%(i+1, a*100,beta*100)
    #        journalFile = '%s_sym_a%d_b%d.jou'%(name, a*100, beta*100)
            #run_wing_half(symCasPath, outPrefix, ac.designGoals.fc, a, beta, Sref, Lref, CG, journalFile, niter)
            for a in alpha:
                outPrefix = '%s\\results\\%s_half_a%d'%(wdir,caseName,a*100)
                journalFileRel = '%s_half_a%d.jou'%(name, a*100)
                journalFile = '%s_half_a%d.jou'%(name, a*100)
                run_wing_half(nonsymCasPath, outPrefix, ac.designGoals.fc, a, 0, 
                              Sref, Cref, CG,journalFile,niter)
            fid.write('\"%s\" 3ddp -t8 -i %s -wait\n'%(pathFluent, journalFileRel))
    fid.close()
Ejemplo n.º 3
0
def run_optimization_1():
    pathIn = "design_out4.txt"
    pathInSamples = "DOE_LHS250_FFD2_3_3.txt"
    learnData = read_tabulated_data_without_header(pathIn)
    xNorm = read_tabulated_data_without_header(pathInSamples)
    # xNorm = np.transpose(xNorm)
    learnData = np.transpose(learnData)

    WemptyMax = 3500.0
    CnbMin = 0.0001
    ClbMax = -0.05
    SMmin = -0.05
    SMmax = 0.10
    combatRadiusMin = 1000.0
    RCmin = 125.0
    VmaxMin = 0.90  # Mach

    LD = RbfMod(xNorm, learnData[0])
    We = RbfMod(xNorm, learnData[1])
    _Cnb = RbfMod(xNorm, (learnData[2]) * 1e3)
    Clb = RbfMod(xNorm, learnData[3])
    _SM = RbfMod(xNorm, learnData[4] * 1e3)
    Rcombat = RbfMod(xNorm, learnData[5])
    RC = RbfMod(xNorm, learnData[6])
    Vmax = RbfMod(xNorm, learnData[7])

    Cnb = lambda x: _Cnb(x) / 1e3
    SM = lambda x: _SM(x) / 1e3
    bnds = np.ones([9, 2])
    bnds[:, 0] = -bnds[:, 0]
    bnds[8, 0] = 0
    bnds[7, 0] = 0
    bnds = tuple(bnds)

    f = lambda x: -LD(x)
    g1 = lambda x: WemptyMax - We(x)
    g2 = lambda x: (Cnb(x) - CnbMin) * 1e3
    g3 = lambda x: ClbMax - Clb(x)
    g4 = lambda x: SMmax - SM(x)
    g5 = lambda x: SM(x) - SMmin
    g6 = lambda x: Rcombat(x) / 1e3 - combatRadiusMin
    g7 = lambda x: RC(x) - RCmin
    g8 = lambda x: Vmax(x) - VmaxMin

    cnstr = (
        {"type": "ineq", "fun": g1},
        {"type": "ineq", "fun": g2},
        {"type": "ineq", "fun": g3},
        {"type": "ineq", "fun": g4},
        {"type": "ineq", "fun": g5},
        {"type": "ineq", "fun": g6},
        {"type": "ineq", "fun": g7},
        {"type": "ineq", "fun": g8},
    )

    x0 = np.zeros(9)
    rslt = minimize(f, x0, method="SLSQP", constraints=cnstr, bounds=bnds)
    print rslt
    rslt2 = minimize(f, x0, constraints=cnstr, bounds=bnds, options={"maxiter": 10000})
    print rslt2
    xopt = rslt.x

    print g1(xopt), We(xopt)
    print g2(xopt), Cnb(xopt)
    print g3(xopt), Clb(xopt)
    print g4(xopt), SM(xopt)
    print g5(xopt), SM(xopt)
    print g6(xopt), Rcombat(xopt)
    print g7(xopt), RC(xopt)
    print g8(xopt), Vmax(xopt)

    ac = DesignFormulation()
    ac.load_xls("Baseline1")
    ac.setup()
    ac.set_x(ac.x0)
    x2dBaseline = ac.wing.x2d
    y2dBaseline = ac.wing.y2d
    print "Baseline"
    print ac.analysisData
    print "--->"
    normalize = Normalization(ac.lb, ac.ub)
    xoptDenorm = normalize.denormalize(xopt)

    print xoptDenorm
    ac.set_x(xoptDenorm)
    x2dOptimum = ac.wing.x2d
    y2dOptimum = ac.wing.y2d
    print ac.analysisData, "\n---"
    print (ac.analysisData[0] - LD(xopt)) / ac.analysisData[0]
    print (ac.analysisData[1] - We(xopt)) / ac.analysisData[1]
    print (ac.analysisData[2] - Cnb(xopt)) / ac.analysisData[2]
    print (ac.analysisData[3] - Clb(xopt)) / ac.analysisData[3]
    print (ac.analysisData[4] - SM(xopt)) / ac.analysisData[4]
    print (ac.analysisData[5] - Rcombat(xopt)) / ac.analysisData[5]
    print (ac.analysisData[6] - RC(xopt)) / ac.analysisData[6]
    print (ac.analysisData[7] - Vmax(xopt)) / ac.analysisData[7]

    plt.figure()
    plt.hold(True)
    plt.plot(x2dBaseline, y2dBaseline, "r-")
    plt.plot(x2dOptimum, y2dOptimum, "k-")
    plt.legend(["Baseline", "Low-fi Optimum"])
    plt.show()

    ac.display()
import numpy as np
import random as rd
from ucav_design_1 import DesignFormulation

np.random.seed(10)

param_file = 'ucav_sensitivity_input.txt'
pf = read_param_file(param_file)

param_values = saltelli.sample(25, pf['num_vars'], calc_second_order = False)


scale_samples(param_values, pf['bounds'])


ac = DesignFormulation()
ac.load_xls('Baseline1')
ac.setup()

Y = np.zeros([len(param_values),9])
fid = open('SGOutput2.txt','wt')
fid.close()
for i,param in enumerate(param_values):
    out = ac.run_full_analysis(param)
    Y[i] = out
    fid = open('SGOutput2.txt','at')
    for val in out:
        fid.write('%.10e '%val)
    fid.write('\n')
    fid.close()
Ejemplo n.º 5
0
def plot_results():
    ac = DesignFormulation()
    ac.load_xls('Baseline1')

    # baseline
    ac.setup()
    ac.gvfmAero = True
    x0 = ac.wing.x2d
    y0 = ac.wing.y2d
    cg0 = ac.get_cg()
    
    xbase = ac.x0norm
    ac.set_x(xbase)
    ac.show_results()
    print ac.get_drag()
    # low fidelity optimum
    xopt1 = np.array([ 0.20520747,-0.39226611,-0.47326701,-1.,0.14291925,0.98650447, 
                      0.37346922,  0.37756372,  0.65654722])

    print 'Low fidelity optimum\n==========='
    ac.set_x(xopt1)
    ac.show_results()
    print ac.get_drag()
  
    x1 = ac.wing.x2d
    y1 = ac.wing.y2d
    cg1 = ac.get_cg()
    
    xgvfm1 = np.array([-0.10127195,-0.10127187,-0.60597138,-0.99999966,-0.71421434,0.97300896,  1.00000803, 0.57455958,0.3130853])
    xgvfm2 = np.array([-0.04819471,-0.04819471,-0.59713618,-0.99999966,-1.,0.94601792,1.00000803,0.81889676,-0.3738294])
    xgvfm4 = np.array([-0.10676065, -0.10676065, -0.61007048, -1.00003353, -0.57133293,  0.9857291,  1.00000803,  0.56576939,  0.08997523])
    print np.linalg.norm(xgvfm1-xgvfm2)
    ac.set_x(xgvfm4)
    print ac.get_cg()
    print ac.wing.area
    print ac.wing.MAC
    print ac.wing.span
    ac.show_results()
    print ac.get_drag()
  
    x3 = ac.wing.x2d
    y3 = ac.wing.y2d
    cg3 = ac.get_cg()
    

    fig = plt.figure(1)
    ax1 = fig.add_subplot(111)
    ax1.hold(True)
    ax1.axis('equal')
    ax1.plot(x0,y0,'ko-',linewidth=2)
    ax1.plot(x1,y1,'b^:',linewidth=2)
    ax1.plot(x3,y3,'rs--',linewidth=2)
    #plt.plot(x2,y2,'k-')
    ax1.plot(0,-cg0[0],'ko')
    ax1.plot(0,-cg1[0],'b^')
    ax1.plot(0,-cg3[0],'rs')
    ax1.legend(['Baseline','Low-fi optimum','GVFM optimum'])
    #plt.plot(0,-cg2[0],'ko')
    plt.show()