t minus 13 weeks: Codename Fraunhofer Flakes

Regelmäßige GitLab und Mattermost Downtime am Mittwoch, den 21.10.21 ab 17 Uhr bis 20 Uhr. Bitte meldet euch im dem Wartungszeitfenster ab, da es sonst zu Datenverlust kommen kann. | Fraunhofer GitLab and Mattermost will be down for scheduled maintenance from Wednesday, 21.10.21, 5:00 pm (CET/UTC+2) until 20:00 am (CET/UTC+2). Please log off during the maintenance, otherwise data loss may occur.

Commit 6b168133 authored by Wojciech Popko's avatar Wojciech Popko
Browse files

First Commit

parents
#!/usr/bin/env python
# python
import sys
import subprocess as sp
from math import *
import numpy as np
import time
import os
import shutil
import matplotlib.pyplot as plt
from scipy.interpolate import splev, splrep, interp1d
from scipy.misc import comb
from scipy.optimize import leastsq
import tempfile
import string
# subroutine for deleting a file or directory
def rm(fileOrDir):
os.system("rm -r " +str(fileOrDir)+ " 2>/dev/null")
# subroutine for copying a file or directory
def cp(src, dst):
os.system("cp -r " +str(src)+ " " +str(dst)+ " 2>/dev/null")
# subroutine for replacing line containing "strA" by "strB" in file
def replaceLine( strA, strB, file):
f = open(file, "r")
lines = f.readlines()
f.close()
f = open(file, "w")
for line in lines:
if line.find(strA)>0:
f.write(strB)
else:
f.write(line)
f.close()
def sed(strAOld,strANew,strBOld,strBNew,strCOld,strCNew,strDOld,strDNew,strEOld,strENew,fileOld,fileNew):
os.system("sed 's/" +str(strAOld)+"/"+str(strANew)+"/g' "+str(fileOld)+" > tmp.test")
os.system("sed -i 's/" +str(strBOld)+"/"+str(strBNew)+"/g' tmp.test")
os.system("sed -i 's/" +str(strCOld)+"/"+str(strCNew)+"/g' tmp.test")
os.system("sed -i 's/" +str(strDOld)+"/"+str(strDNew)+"/g' tmp.test")
os.system("sed 's/" +str(strEOld)+"/"+str(strENew)+"/g' tmp.test > "+str(fileNew))
os.system("rm tmp.test")
def sedWin(findString, replaceString, fileOld, fileNew):
for k in range(len(findString)):
f = open(fileOld)
n = open("polar.tmp",'w')
## newfile = tempfile.mkdtemp()
for i in f:
if i.find(findString[k]) == -1:
n.write(i)
continue
find = findString[k]
replace = replaceString[k]
j = string.replace(i, str(find), str(replace))
print(i)
print(j)
n.write(j)
f.close()
n.close()
fileOld = "polar.tmp1"
shutil.copy("polar.tmp", fileOld)
shutil.move("polar.tmp",fileNew)
os.remove(fileOld)
def sed3(strAOld,strANew,strBOld,strBNew,strCOld,strCNew,fileOld,fileNew):
os.system("sed 's/" +str(strAOld)+"/"+str(strANew)+"/g' "+str(fileOld)+" > tmp.test")
os.system("sed -i 's/" +str(strBOld)+"/"+str(strBNew)+"/g' tmp.test")
os.system("sed 's/" +str(strCOld)+"/"+str(strCNew)+"/g' tmp.test > "+str(fileNew))
os.system("rm -r tmp.test 2>/dev/null")
def readData(fileName):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
x = []
f = []
for i in range(1,rows): # 7 depends on the file format: it is not general!!!
line = data[i].split()
# print line
if not line: break
x.append(float(line[0]))
f.append(float(line[1]))
file.close()
return x,f
def readExp(fileName,skipHeader):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
aoa = []
cl = []
cd = []
cm = []
for i in range(skipHeader,rows): # 7 depends on the file format: it is not general!!!
line = data[i].split()
# print line
if not line: break
aoa.append(float(line[0]))
cl.append(float(line[1]))
cd.append(float(line[2]))
cm.append(float(line[3]))
file.close()
return aoa, cl, cd, cm
def readXfoilPolar(fileName):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
aoa = []
cl = []
cd = []
cdp = []
cm = []
xtrt = []
xtrb = []
for i in range(14,rows): # 14 depends on the file format: it is not general!!!
line = data[i].split()
# print line
if not line: break
aoa.append(float(line[0]))
cl.append(float(line[1]))
cd.append(float(line[2]))
cdp.append(float(line[3]))
cm.append(float(line[4]))
xtrt.append(float(line[5]))
xtrb.append(float(line[6]))
file.close()
return aoa, cl, cd, cdp, cm, xtrt, xtrb
def writeDeltas(listFile,DeltaTau,DeltaCamber,fileName):
# write maximum thickness and camber differences
print("writeDeltas...")
file = open(fileName, "w")
file.write("# position / mm \t DeltaTau / - \t DeltaCamber / - \n")
for i in range(0, len(listFile)):
thisFile = listFile[i]
strFile = os.path.splitext(thisFile)[0]
position = strFile[-5:len(strFile)]
file.write( position + "\t" + str(DeltaTau[i]) + "\t" + str(DeltaCamber[i]) + "\n")
file.close
return
def readDeltas(fileName):
# read numeric data from file
print("readDeltas...")
# initialize
tau = []
camber = []
# uniqueness constraint
lines_seen = set() # holds lines already seen
i = 0
for line in open(fileName, "r"):
if i == 0:
i = 1
continue
else:
if line not in lines_seen: # not a duplicate
data = line.split()
tau.append(float(data[1]))
camber.append(float(data[2]))
lines_seen.add(line)
return tau, camber
def readRfoilPolar(fileName):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
aoa = [] # angle of attack, deg
cl = [] # lift coefficient, n.d
cd = [] # drag coefficient, n.d
re = [] # Reynolds number, n.d
cm = [] # moment coefficient, n.d
xtrt = [] # top side transition onset, n.d
xtrb = [] # bottom side transition onset, n.d
cdp = [] # pressure drag coefficient, n.d
for i in range(13,rows): # it depends on the file format: it is not general!!!
line = data[i].split()
# print line
if not line: break
aoa.append(float(line[0]))
cl.append(float(line[1]))
cd.append(float(line[2]))
re.append(float(line[3]))
cm.append(float(line[4]))
xtrt.append(float(line[5]))
xtrb.append(float(line[6]))
cdp.append(float(line[7]))
file.close()
return aoa, cl, cd, re, cm, xtrt, xtrb, cdp
def mergeRfoilPolars(up,down,merge):
# it merges two polar portions for positive and negative angle into a file "merge".
# it checkes for non unique values as well at 0 deg angle of attack.
# read positive
aoaU, clU, cdU, reU, cmU, xtrtU, xtrbU, cdpU = readRfoilPolar(up)
# read negative
aoaD, clD, cdD, reD, cmD, xtrtD, xtrbD, cdpD = readRfoilPolar(down)
# open file to determine simulating conditions
file = open(up, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
file.close
# open file for merged polars
file = open(merge, "w")
# prepare header
for i in range(13):
file.write(data[i] + "\n")
# add negative polar sorted with ascending angle of attack
for i in range(len(aoaD)):
file.write( "\t" + str(round(aoaD[-i - 1],3)) + "\t" + str(round(clD[-i - 1],4)) + "\t" + str(round(cdD[-i - 1],5)) + "\t" + str(round(reD[-i - 1],5)) + "\t" + str(round(cmD[-i - 1],4)) + "\t" + str(round(xtrtD[-i - 1],4)) + "\t" + str(round(xtrbD[-i - 1],4)) + "\t"+ str(round(cdpD[-i - 1],5)) + "\n")
# add positive polar sorted with ascending angle of attack
for i in range(len(aoaU)):
if (aoaU[i]>aoaD[0]):
file.write( "\t" + str(round(aoaU[i],3)) + "\t" + str(round(clU[i],4)) + "\t" + str(round(cdU[i],5)) + "\t" + str(round(reU[i],5)) + "\t" + str(round(cmU[i],4)) + "\t" + str(round(xtrtU[i],4)) + "\t" + str(round(xtrbU[i],4)) + "\t"+ str(round(cdpU[i],5)) + "\n")
file.close
return
####################################################################################################
print("\nRunning "+ __file__+"...\n")
XFOILPath="XFOIL6.99/xfoil.exe" # Xfoil 6.99
RFOILPath="RFOIL1.1/rfoilb.exe" # Rfoil Version 1.1. batch, from IWES MuS
listIST = []
for file in os.listdir("Airfoils-Original"):
if file.endswith(".dat"):
listIST.append(file)
# Reynolds number
# read from data derived from Excel file for the rotating cases
renoValue= np.loadtxt('RE_orig_rot.dat', skiprows=0)
# section no
# read from data derived from Excel file
listPOS = []
for i in range(0, len(listIST)):
listPOS.append(listIST[i][0:-4])
#np.linspace(1, len(rotRenoValue), num=len(rotRenoValue))
for i in range(0, len(listPOS)):
if not os.path.exists("Airfoils-Original/"+str(listPOS[i])):
os.makedirs("Airfoils-Original/"+str(listPOS[i]))
for i in range(len(listPOS)):
os.system("del Airfoils-Original/"+str(listPOS[i])+"/*.dat")
os.system("del Airfoils-Original/"+str(listPOS[i])+"/*.test")
os.system("del Airfoils-Original/"+str(listPOS[i])+"/*.pol")
# RFOIL for loop over variables for rotating cases
for i in range(len(listPOS)):
for j in range(len(renoValue[0])):
if (renoValue[i][j]==0.0):
print("\nFor this section all needed polar have been already computed!")
break
polarNewUp = "Airfoils-Original/"+str(int(listPOS[i]))+"/rRe"+str(j)+"u.pol"
polarNewDown = "Airfoils-Original/"+str(int(listPOS[i]))+"/rRe"+str(j)+"d.pol"
polarNew = "Airfoils-Original/"+listPOS[i]+"/rRe"+str(j)+".pol"
# up polar
print("\npreparing file based on:")
print("Section:\t",int(listPOS[i]))
print("Airfoil:\t",listIST[i])
print("Re:\t",round(renoValue[i][j]/1e6,1),"e6")
print("Polar:\t",polarNewUp)
ps = sp.Popen([RFOILPath],
stdin=sp.PIPE,
stdout=None,
stderr=None)
res = ps.communicate( string.join(["LOAD ",
"Airfoils-Original/"+listIST[i],
"Section#"+ str(int(listPOS[i])),
"OPER",
"VISC",
str(renoValue[i][j]),
"VPAR",
"XTR",
"0.01",
"0.01",
"",
"PACC",
polarNewUp,
"",
"ASEQ",
"0",
"25",
"0.5",
"",
"QUIT"],'\n') )
print(res)
# down polar
print("\npreparing file based on:")
print("Section:\t",int(listPOS[i]))
print("Airfoil:\t",listIST[i])
print("Re:\t",round(renoValue[i][j]/1e6,1),"e6")
print("Polar:\t",polarNewDown)
ps = sp.Popen([RFOILPath],
stdin=sp.PIPE,
stdout=None,
stderr=None)
res = ps.communicate( string.join(["LOAD ",
"Airfoils-Original/"+listIST[i],
"Section#"+ str(int(listPOS[i])),
"OPER",
"VISC",
str(renoValue[i][j]),
"VPAR",
"XTR",
"0.01",
"0.01",
"",
"PACC",
polarNewDown,
"",
"ASEQ",
"0",
"-25",
"-0.5",
"",
"QUIT"],'\n') )
print(res)
print("Polar merged:\t",polarNew)
mergeRfoilPolars(polarNewUp,polarNewDown,polarNew)
print("\nEnd of "+ __file__+"...\n")
#!/usr/bin/env python
# python
import sys
import subprocess as sp
from math import *
import numpy as np
import time
import os
import shutil
import matplotlib.pyplot as plt
from scipy.interpolate import splev, splrep, interp1d
from scipy.misc import comb
from scipy.optimize import leastsq
import tempfile
import string
# subroutine for deleting a file or directory
def rm(fileOrDir):
os.system("rm -r " +str(fileOrDir)+ " 2>/dev/null")
# subroutine for copying a file or directory
def cp(src, dst):
os.system("cp -r " +str(src)+ " " +str(dst)+ " 2>/dev/null")
# subroutine for replacing line containing "strA" by "strB" in file
def replaceLine( strA, strB, file):
f = open(file, "r")
lines = f.readlines()
f.close()
f = open(file, "w")
for line in lines:
if line.find(strA)>0:
f.write(strB)
else:
f.write(line)
f.close()
def sed(strAOld,strANew,strBOld,strBNew,strCOld,strCNew,strDOld,strDNew,strEOld,strENew,fileOld,fileNew):
os.system("sed 's/" +str(strAOld)+"/"+str(strANew)+"/g' "+str(fileOld)+" > tmp.test")
os.system("sed -i 's/" +str(strBOld)+"/"+str(strBNew)+"/g' tmp.test")
os.system("sed -i 's/" +str(strCOld)+"/"+str(strCNew)+"/g' tmp.test")
os.system("sed -i 's/" +str(strDOld)+"/"+str(strDNew)+"/g' tmp.test")
os.system("sed 's/" +str(strEOld)+"/"+str(strENew)+"/g' tmp.test > "+str(fileNew))
os.system("rm tmp.test")
def sedWin(findString, replaceString, fileOld, fileNew):
for k in range(len(findString)):
f = open(fileOld)
n = open("polar.tmp",'w')
## newfile = tempfile.mkdtemp()
for i in f:
if i.find(findString[k]) == -1:
n.write(i)
continue
find = findString[k]
replace = replaceString[k]
j = string.replace(i, str(find), str(replace))
print(i)
print(j)
n.write(j)
f.close()
n.close()
fileOld = "polar.tmp1"
shutil.copy("polar.tmp", fileOld)
shutil.move("polar.tmp",fileNew)
os.remove(fileOld)
def sed3(strAOld,strANew,strBOld,strBNew,strCOld,strCNew,fileOld,fileNew):
os.system("sed 's/" +str(strAOld)+"/"+str(strANew)+"/g' "+str(fileOld)+" > tmp.test")
os.system("sed -i 's/" +str(strBOld)+"/"+str(strBNew)+"/g' tmp.test")
os.system("sed 's/" +str(strCOld)+"/"+str(strCNew)+"/g' tmp.test > "+str(fileNew))
os.system("rm -r tmp.test 2>/dev/null")
def readData(fileName):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
x = []
f = []
for i in range(1,rows): # 7 depends on the file format: it is not general!!!
line = data[i].split()
# print line
if not line: break
x.append(float(line[0]))
f.append(float(line[1]))
file.close()
return x,f
def readExp(fileName,skipHeader):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
aoa = []
cl = []
cd = []
cm = []
for i in range(skipHeader,rows): # 7 depends on the file format: it is not general!!!
line = data[i].split()
# print line
if not line: break
aoa.append(float(line[0]))
cl.append(float(line[1]))
cd.append(float(line[2]))
cm.append(float(line[3]))
file.close()
return aoa, cl, cd, cm
def readXfoilPolar(fileName):
file = open(fileName, "r")
readFile = file.read()
# splits each time it encounters a line break
data = readFile.split("\n")
# prints number of rows
rows = len(data)
aoa = []
cl = []
cd = []
cdp = []