def cl_inv_analysis(airfoil, cl_i, cl_f, cl_step, max_iter, id): """Inviscid analysis over range of angle of attacks.""" # Initializes airfoil and assigns NACA xf = XFoil() xf.naca(airfoil) xf.max_iter = max_iter # Collects values a, cl, cd, cm, cp = xf.cseq(cl_i, cl_f, cl_step) x, cp_0 = xf.get_cp_distribution() # Plots all the data plot(a, cl, cd, cm, cp, x, cp_0, id)
def cl_visc_analysis(airfoil, cl_i, cl_f, cl_step, re, mach, max_iter, id): """Viscous analysis over range of lift coefficients.""" # Initializes airfoil and assigns NACA xf = XFoil() xf.naca(airfoil) xf.max_iter = max_iter xf.Re = re xf.M = mach # Collects values a, cl, cd, cm, cp = xf.cseq(cl_i, cl_f, cl_step) x, cp_0 = xf.get_cp_distribution() # Plots all the data plot(a, cl, cd, cm, cp, x, cp_0, id)
def evaluate(individual): global code_division #---------------------------------- #遺伝子にも続いて新翼型を生成 #---------------------------------- #遺伝子をデコード ratios = decoder(individual, code_division) #遺伝子に基づき翼型を混合して、新しい翼型を作る datlist_list = [fc.read_datfile(file) for file in datfiles] datlist_shaped_list = [fc.shape_dat(datlist) for datlist in datlist_list] newdat = fc.interpolate_dat(datlist_shaped_list,ratios) #翼型の形に関する情報を取得する #foilpara == [最大翼厚、最大翼厚位置、最大キャンバ、最大キャンバ位置、S字の強さ] foil_para = fc.get_foil_para(newdat) #新しい翼型をAerofoilオブジェクトに適用 datx = np.array([ax[0] for ax in newdat]) daty = np.array([ax[1] for ax in newdat]) newfoil = Airfoil(x = datx, y = daty) mt, mta, mc, mca, s = foil_para #---------------------------------- #翼の形に関する拘束条件 #---------------------------------- penalty = 0 print('===================') if(mc<0): print("out of the border") print("reverse_cmaber") penalty -= mc if(mt<0.08): print("out of the border") print("too_thin") penalty += 0.08-mt if(mt>0.11): print("out of the border") print("too_fat") penalty += mt-0.11 #if(foil_para[4]>0.03): # print("out of the border") # print("peacock") # print('===================') # return (1.0+(foil_para[4]-0.03),)*NOBJ if(mta<0.23): print("out of the border") print("Atama Dekkachi!") penalty += 0.23 - mta if(mta>0.3): print("out of the border") print("Oshiri Dekkachi!") penalty += mta - 0.3 #---------------------------------- #新翼型の解析 #---------------------------------- xf = XFoil() xf.airfoil = newfoil #レイノルズ数の設定 xf.Re = 1.5e5 #境界要素法計算時1ステップにおける計算回数 xf.max_iter = 60 #座標整形 xf.repanel(n_nodes = 300) xf.print = False #計算結果格納 a, cl, cd, cm, cp = xf.cseq(0.4, 1.1, 0.1) lr = [l/d for l, d in zip(cl,cd)] #---------------------------------- #目的値 #---------------------------------- try: #揚抗比の逆数を最小化 obj1 = 1/lr[1] #揚抗比のピークを滑らかに(安定性の最大化) maxlr = max(lr) maxlr_index = lr.index(maxlr) obj2 = abs(maxlr - lr[maxlr_index+1]) #下面の反りを最小化(製作再現性の最大化) obj3 = foil_para[4] except Exception as e: obj1,obj2,obj3=[1.0]*NOBJ traceback.print_exc() if (np.isnan(obj1) or obj1 > 1): obj1 = 1 if (np.isnan(obj2) or obj2 > 1): obj2 = 1 if (np.isnan(obj3) or obj3 > 1): obj3 = 1 obj1 += penalty obj2 += penalty obj3 += penalty print("individual",individual) print("evaluate",obj1,obj2,obj3) print("max_thickness",foil_para[0]) print("at",foil_para[1]) print("max_camber",foil_para[2]) print("at",foil_para[3]) print("S",foil_para[4]) print('===================') return [obj1, obj2, obj3]
def evaluate(self,individual): #---------------------------------- #遺伝子に基づいて新翼型を生成 #---------------------------------- #遺伝子をデコード ratios = self.decoder(individual, self.code_division) #遺伝子に基づき翼型を混合して、新しい翼型を作る datlist_list = [fc.read_datfile(file) for file in self.datfiles] datlist_shaped_list = [fc.shape_dat(datlist) for datlist in datlist_list] newdat = fc.interpolate_dat(datlist_shaped_list,ratios) #翼型の形に関する情報を取得する #foilpara == [最大翼厚、最大翼厚位置、最大キャンバ、最大キャンバ位置、S字の強さ] foil_para = fc.get_foil_para(newdat) #新しい翼型をAerofoilオブジェクトに適用 datx = np.array([ax[0] for ax in newdat]) daty = np.array([ax[1] for ax in newdat]) newfoil = Airfoil(x = datx, y = daty) mt, mta, mc, mca, s = foil_para #---------------------------------- #翼の形に関する拘束条件 #---------------------------------- """ penalty = 0 for g, p in zip(self.gs, self.penalties): if(not g): penalty += p """ penalty = 0 print('===================') if(mc<0): print("out of the border") print("reverse_cmaber") penalty -= mc if(mt<0.08): print("out of the border") print("too_thin") penalty += 0.08-mt if(mt>0.11): print("out of the border") print("too_fat") penalty += mt-0.11 #if(foil_para[4]>0.03): # print("out of the border") # print("peacock") # print('===================') # return (1.0+(foil_para[4]-0.03),)*NOBJ if(mta<0.23): print("out of the border") print("Atama Dekkachi!") penalty += 0.23 - mta if(mta>0.3): print("out of the border") print("Oshiri Dekkachi!") penalty += mta - 0.3 #---------------------------------- #新翼型の解析 #---------------------------------- xf = XFoil() xf.airfoil = newfoil #レイノルズ数の設定 xf.Re = self.re #境界要素法計算時1ステップにおける計算回数 xf.max_iter = 60 #print("hi") #print(vars) #scope = locals() #var0, var1, var2, var3, var4, var5, var6, var7 = [0 if var == None or var == '' else eval(var,scope) for var in self.vars] #計算結果格納 a, cl, cd, cm, cp = xf.cseq(0.4, 1.1, 0.1) lr = [l/d for l, d in zip(cl,cd)] #---------------------------------- #目的値 #---------------------------------- """ try: obj1,obj2,obj3 = [eval(o) for o in Os] except Exception as e: obj1,obj2,obj3=[1.0]*self.NOBJ traceback.print_exc() """ try: #揚抗比の逆数を最小化 obj1 = 1/lr[1] #揚抗比のピークを滑らかに(安定性の最大化) maxlr = max(lr) maxlr_index = lr.index(maxlr) obj2 = abs(maxlr - lr[maxlr_index+1]) #下面の反りを最小化(製作再現性の最大化) obj3 = s except Exception as e: obj1,obj2,obj3=[1.0]*self.NOBJ traceback.print_exc() if (np.isnan(obj1) or obj1 > 1): obj1 = 1 if (np.isnan(obj2) or obj2 > 1): obj2 = 1 if (np.isnan(obj3) or obj3 > 1): obj3 = 1 obj1 += penalty obj2 += penalty obj3 += penalty return [obj1, obj2, obj3]
def evaluate(self, individual): #解析が発散した際の評価値 DELTA = 1e10 #---------------------------------- #遺伝子に基づいて新翼型を生成 #---------------------------------- #遺伝子をデコード ratios = self.decoder(individual, self.code_division) #遺伝子に基づき翼型を混合して、新しい翼型を作る datlist_list = [fc.read_datfile(file) for file in self.datfiles] datlist_shaped_list = [ fc.shape_dat(datlist) for datlist in datlist_list ] newdat = fc.interpolate_dat(datlist_shaped_list, ratios) #翼型の形に関する情報を取得する mt, mta, mc, mca, s, crossed, bd, bt, bc, smooth, td = fc.get_foil_para( newdat) #新しい翼型をAerofoilオブジェクトに適用 datx = np.array([ax[0] for ax in newdat]) daty = np.array([ax[1] for ax in newdat]) newfoil = Airfoil(x=datx, y=daty) #---------------------------------- #翼の形に関する拘束条件 #---------------------------------- penalty = 0 #キャンバに関する拘束条件 if (mc < 0): penalty -= mc #最大翼厚に関する拘束条件 if (mt < 0.08): penalty += 0.08 - mt if (mt > 0.11): penalty += mt - 0.11 #最大翼厚位置に関する拘束条件 if (mta < 0.23): penalty += 0.23 - mta if (mta > 0.3): penalty += mta - 0.3 #---------------------------------- #新翼型の解析 #---------------------------------- xf = XFoil() xf.airfoil = newfoil #レイノルズ数の設定 xf.Re = self.re #境界要素法計算時1ステップにおける計算回数 xf.max_iter = 60 xf.print = False #計算結果格納 a, cl, cd, cm, cp = xf.cseq(0.4, 1.1, 0.1) #---------------------------------- #目的値 #---------------------------------- try: #揚抗比の逆数を最小化 obj1 = 1 / lr[1] #揚抗比のピークを滑らかに(安定性の最大化) maxlr = max(lr) maxlr_index = lr.index(maxlr) obj2 = abs(maxlr - lr[maxlr_index + 1]) #下面の反りを最小化(製作再現性の最大化) obj3 = s except Exception as e: obj1, obj2, obj3 = [DELTA] * self.NOBJ traceback.print_exc() if (np.isnan(obj1) or obj1 > 1): obj1 = DELTA if (np.isnan(obj2) or obj2 > 1): obj2 = DELTA if (np.isnan(obj3) or obj3 > 1): obj3 = DELTA obj1 += penalty obj2 += penalty obj3 += penalty return [obj1, obj2, obj3]