Пример #1
0
A = []
st = [0]
s = np.array(st)
Af = []
it = []


for i in range(Gen0):
    it.append(i)
#gen = 0

if gen == 0:
    print('Generation-%d STARTED'%gen)
    for i in range(Gen0):

        Airfoil.append(airfoil(0,i))
        Airfoil[i].ctrlPoints()
        Airfoil[i].bspline()
        Airfoil[i].write()
        Airfoil[i].savefig()
        Airfoil[i].show(gen, i)
        #Airfoil[i].camber(gen, i)

    def run(i):
        Airfoil[i].cfd()
        print(Airfoil[i].cost)
        #np.savetxt('../../cost-%d'%i, Airfoil[i].cost)

    y = Pool(5)
    #y.starmap(run, zip(itertools.repeat(Airfoil), it))
    y.map(run, range(Gen0))
#import the name of the airfoils from the webtry program
#Generate a new airfoil using constructor for every specie and evaluate cost
#!Rename the airfoil to airfoil.txt for evaluation!
#make a new folder for every airfoil imported with sub folders for generation and species
#save the plot of every generation and specie in their respective folder.

#only for upper array(the same can be repeated for lower array.)
#subtract Y values of corresponding elements and compute distance
#Minimize the inverse of the distance b/w points
#write code for choosing which x values to subrract from (possibility to add interpolation values)
#Apply same IWO GA to minimize (Decide on the number of generations and other constants based on experimentation.)
#from web_try import airfoils
from airfoil_Class import airfoil
airfoils = 's1210.dat'
Airfoil = airfoil(0, 1)

Airfoil.ctrlPoints()
Airfoil.bspline()
#Airfoil.write()
#Airfoil.savefig()
#Airfoil.show(0, 1)
Airfoil.error(airfoils)
print(airfoils)
Пример #3
0
def run(number):

    af = loaded_af[number]

    for i in range(Gen0):

        gen = 0
        s[0] = 0
        Airfoil.append(airfoil(0, i))
        Airfoil[i].ctrlPoints()
        Airfoil[i].bspline()
        Airfoil[i].write()
        #Airfoil[i].savefig()
        #Airfoil[i].show(gen, i)
        #Airfoil[i].camber(gen, i)

    for i in range(Gen0):
        #Airfoil[i].savefig()
        #Airfoil[i].xFoil()
        #Airfoil[i].cfd()
        try:
            Airfoil[i].error(af)
            gen = 1
        except IndexError:
            gen = maxIt

        except ValueError:
            gen = maxIt

        #print(Airfoil[i].cost)

    if __name__ == "__main__":

        while gen < maxIt:

            sigma = (((maxIt - float(gen - 1)) / maxIt)**
                     exponent) * (sigma_initial - sigma_final) + sigma_final

            #print('SIGMA')
            #print(sigma)

            Airfoil.sort(key=lambda Airfoil: Airfoil.cost, reverse=True)

            for i in range(len(Airfoil)):
                #print(Airfoil[i].cost)
                pass

            del Airfoil[nPop:]

            for i in range(len(Airfoil)):
                #print(Airfoil[i].cost)
                pass

            for k in range(nPop):
                Airfoil[k].copy(gen, s[0])
                Airfoil[k].copy_Results(gen, s[0])
                #Airfoil[k].show(gen, s[0])
                #Airfoil[k].camber(gen, s[0])
                s[0] += 1

            for x in range(len(Airfoil)):
                reproduction(Airfoil, gen, sigma, x, s, af)

            Airfoil.sort(key=lambda x: x.cost, reverse=True)

            gen += 1
            s[0] = 0

        if gen == maxIt:
            final_cost.append(Airfoil[0].cost)
            print('%s Done' % name)
def run(number):

    af = loaded_af[number]

    name = loaded_af[number]
    #print(name)

    os.mkdir('../fitting/%s' % name)
    os.chdir('../fitting/%s' % name)
    #os.mkdir('Plots')
    #os.mkdir('Camber')
    os.mkdir('error')
    t.sleep(2)

    Airfoil.clear()

    for i in range(Gen0):

        gen = 0
        s[0] = 0
        Airfoil.append(airfoil(0, i))
        Airfoil[i].ctrlPoints()
        Airfoil[i].bspline()
        Airfoil[i].write()
        #Airfoil[i].savefig()
        #Airfoil[i].show(gen, i)
        #Airfoil[i].camber(gen, i)

    for i in range(Gen0):
        #Airfoil[i].savefig()
        #Airfoil[i].xFoil()
        #Airfoil[i].cfd()
        try:
            Airfoil[i].error(af)
            gen = 1
        except IndexError:
            gen = maxIt

        except ValueError:
            gen = maxIt

        #print(Airfoil[i].cost)

    if __name__ == "__main__":

        while gen < maxIt:

            sigma = (((maxIt - float(gen - 1)) / maxIt)**
                     exponent) * (sigma_initial - sigma_final) + sigma_final

            #print('SIGMA')
            #print(sigma)

            Airfoil.sort(key=lambda Airfoil: Airfoil.cost, reverse=True)

            for i in range(len(Airfoil)):
                #print(Airfoil[i].cost)
                pass

            del Airfoil[nPop:]

            for i in range(len(Airfoil)):
                #print(Airfoil[i].cost)
                pass

            for k in range(nPop):
                Airfoil[k].copy(gen, s[0])
                Airfoil[k].copy_Results(gen, s[0])
                #Airfoil[k].show(gen, s[0])
                #Airfoil[k].camber(gen, s[0])
                s[0] += 1

            for x in range(len(Airfoil)):
                reproduction(Airfoil, gen, sigma, x, s, af)

            Airfoil.sort(key=lambda x: x.cost, reverse=True)

            gen += 1
            s[0] = 0

        if gen == maxIt:
            final_cost.append(Airfoil[0].cost)
            c.append(Airfoil[0].cost)
            np.savetxt('Airfoil-Cost.txt', c, fmt='%s')
            c.clear()
            print('%s Done' % name)

    os.chdir('../../optimisation_code')
    np.savetxt('Airfoil-Cost.txt', final_cost, fmt='%s')