Last active
January 4, 2025 04:24
-
-
Save helo9/9954e836b470f267bf5b5825f9ff2a50 to your computer and use it in GitHub Desktop.
Revisions
-
helo9 revised this gist
Sep 29, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -150,7 +150,7 @@ def read_polar(infile): return data def delete_polar(infile): """ deletes polar file """ os.remove(infile) -
helo9 revised this gist
Sep 29, 2019 . 1 changed file with 46 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,42 +7,47 @@ def polar(afile, re, *args,**kwargs): """calculate airfoil polar and load results Parameters ---------- afile: string path to aifoil dat file re: float fixed reynoldsnumber for polar calculation *args, **kwargs have a look at calcpolar for further information Returns ------- dict airfoil polar """ calc_polar(afile, re,'polar.txt', *args, **kwargs) data = read_polar('polar.txt') delete_polar('polar.txt') return data def calc_polar(afile, re, polarfile, alfaseq=[], clseq=[], refine=False, max_iter=200, n=None): """run xfoil to generate polar file Parameters ---------- afile: string path to airfoil dat file re: float fixed reynoldsnumber alfaseq: iterateable, optional sequence of angles of attack clseq: iterateable, optional sequence of lift coefficients (either those or alfaseq must be defined) refine: bool shall xfoil refine airfoil maxiter: int maximal number of boundary layer iterations n: int boundary layer parameter """ import subprocess as sp @@ -101,11 +106,18 @@ def write2xfoil(string): pxfoil.communicate(str('quit').encode('ascii')) def read_polar(infile): """read xfoil polar results from file Parameters ---------- infile: string path to polar file Returns ------- dict airfoil polar splitted up into dictionary """ regex = re.compile('(?:\s*([+-]?\d*.\d*))') -
helo9 created this gist
Jun 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,144 @@ # -*- coding: utf-8 -*- import os import numpy as np import subprocess as sp import re def polar(afile, re, *args,**kwargs): """Berechnet Profilpolaren und liest diese ein. :param afile: Pfad zu Profilkoordinatendatei oder NACA4 Code :type afile: string :param re: Reynoldszahl :type re: int :param alfaseq: Sequenz von Anstellwinkeln :type alfaseq: iterateable :rtype: dict """ calcPolar(afile, re,'polar.txt', *args, **kwargs) data = readPolar('polar.txt') #raw_input('EnterKex') deletePolar('polar.txt') return data def calcPolar(afile, re, polarfile, alfaseq=[], clseq=[], refine=False, max_iter=200, n=None): """Führt XFOIL aus und lässt Profilpolaren generieren. :param afile: Pfad zu Profilkoordinatendatei oder NACA4 Code :type afile: string :param re: Reynoldszahl :type re: int :param polarfile: Ausgabedatei für XFOIL, darf nicht existieren :param alfaseq: Sequenz von Anstellwinkeln :type alfaseq: iterateable :param clseq: Sequenz von Auftriebsbeiwerten, Alternativparameter zu alfaseq :type clseq: iterateable :param refine: Soll XFOIL ein refinement des Profils durchführen :type refine: bool :param max_iter: Maximale Iterationsanzahl :type max_iter: int :param n: Grenzschichtparameter :type n: int :rtype: None """ import subprocess as sp import numpy as np import sys,os if(os.name == 'posix'): xfoilbin = 'xfoil' elif(os.name == 'nt'): xfoilbin = 'xfoil.exe' else: print('Betriebssystem %s wird nicht unterstützt'%os.name) pxfoil = sp.Popen([xfoilbin], stdin=sp.PIPE, stdout=None, stderr=None) def write2xfoil(string): if(sys.version_info > (3,0)): string = string.encode('ascii') pxfoil.stdin.write(string) if(afile.isdigit()): write2xfoil('NACA ' + afile + '\n') else: write2xfoil('LOAD ' + afile + '\n') if(refine): write2xfoil('GDES\n') write2xfoil('CADD\n') write2xfoil('\n') write2xfoil('\n') write2xfoil('\n') write2xfoil('X\n ') write2xfoil('\n') write2xfoil('PANEL\n') write2xfoil('OPER\n') if n != None: write2xfoil('VPAR\n') write2xfoil('N '+str(n)+'\n') write2xfoil('\n') write2xfoil('ITER '+str(max_iter)+'\n') write2xfoil('VISC\n') write2xfoil(str(re) + '\n') write2xfoil('PACC\n') write2xfoil('\n') write2xfoil('\n') for alfa in alfaseq: write2xfoil('A ' + str(alfa) + '\n') for cl in clseq: write2xfoil('CL ' + str(cl) + '\n') write2xfoil('PWRT 1\n') write2xfoil(polarfile + '\n') write2xfoil('\n') pxfoil.communicate(str('quit').encode('ascii')) def readPolar(infile): """ Liest XFOIL-Polarendatei ein. :param infile: Polarendatei :rtype: dict """ regex = re.compile('(?:\s*([+-]?\d*.\d*))') with open(infile) as f: lines = f.readlines() a = [] cl = [] cd = [] cdp = [] cm = [] xtr_top = [] xtr_bottom = [] for line in lines[12:]: linedata = regex.findall(line) a.append(float(linedata[0])) cl.append(float(linedata[1])) cd.append(float(linedata[2])) cdp.append(float(linedata[3])) cm.append(float(linedata[4])) xtr_top.append(float(linedata[5])) xtr_bottom.append(float(linedata[6])) data = {'a': np.array(a), 'cl': np.array(cl) , 'cd': np.array(cd), 'cdp': np.array(cdp), 'cm': np.array(cm), 'xtr_top': np.array(xtr_top), 'xtr_bottom': np.array(xtr_bottom)} return data def deletePolar(infile): """ Löscht Datei. """ os.remove(infile)