Skip to content

Commit 7cd5a33

Browse files
committed
Initial commit
0 parents  commit 7cd5a33

File tree

711 files changed

+179714
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

711 files changed

+179714
-0
lines changed

CHANGES.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--------------------
2+
Python-importAirfoil
3+
Python Airfoil coordinates import function.
4+
--------------------
5+
6+
Release 1.0.0, 06.01.2022.
7+
8+
- Initial release
9+
10+
--------------------

LICENSE

+674
Large diffs are not rendered by default.

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Python Airfoil coordinates import function
2+
3+
Airfoil coordinates import function in Python.
4+
5+
<p align="center">
6+
<img src="https://vazmfb.com/web/img/github/importAirfoil_PY.png" width="800">
7+
</p>
8+
9+
10+
## Requirements
11+
[Python](https://www.python.org/)<br>
12+
13+
Provided code is tested with **Python 3.10.1 **.
14+
15+
## Usage
16+
17+
Use `importAirfoil` function with the full path to document with airfoil data as only input argument.
18+
19+
Please check provided test in `test/_App` folder. In order to run the test first run CreateApp.cmd file (with adjusted input variables).
20+
21+
## Airfoil file parsing rules
22+
23+
- The file is read a line at a time starting from the top.
24+
- Blank lines are discarded.
25+
- The first line that is not discarded is the line on which function `scanf()` finds two float numbers, with the first number in the range [-0.1, 1.1] and the second in the range [-1.1, 1.1].
26+
- All subsequent lines on which function `scanf()` finds two float numbers are taken into the account.
27+
- If any value is greater than 1.1 all values are divided by 100 (see NACA file format).
28+
- If there is one change in x value gradient, flip data that is after the change of gradient (see Lednicer file format).
29+
30+
## Airfoil file formats
31+
32+
> - [Siegel](https://m-selig.ae.illinois.edu/ads.html)
33+
34+
Lists points from the trailing edge, goes over the upper surface, then over the lower surface, to go back to the trailing edge (or in other direction, first lower and then upper surface).
35+
36+
> - Lednicer
37+
38+
Lists points on the upper surface (from leading edge to trailing edge), then points on the lower surface (from leading edge to trailing edge).
39+
40+
> - OpenVSP .af
41+
42+
Same as the Siegel format but with the additional header.
43+
44+
> - NACA (as in Report No. 824)
45+
46+
Same as the Lednicer format but multiplied by 100.
47+
48+
## License
49+
Copyright (C) 2022 Miloš Petrašinović <[email protected]>
50+
51+
This program is free software: you can redistribute it and/or modify
52+
it under the terms of the GNU General Public License as
53+
published by the Free Software Foundation, either version 3 of the
54+
License, or (at your option) any later version.
55+
56+
This program is distributed in the hope that it will be useful,
57+
but WITHOUT ANY WARRANTY; without even the implied warranty of
58+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59+
GNU General Public License for more details.
60+
61+
You should have received a copy of the GNU General Public License
62+
along with this program. If not, see <https://www.gnu.org/licenses/>.

importAirfoil.py

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Airfoil coordinates import function
2+
# Author: Milos D. Petrasinovic <[email protected]>
3+
# Structural Analysis of Flying Vehicles
4+
# Faculty of Mechanical Engineering, University of Belgrade
5+
# Department of Aerospace Engineering, Flying structures
6+
# https://vazmfb.com
7+
# Belgrade, 2022
8+
# ----- INPUTS -----
9+
# file - full path to document with airfoil data
10+
# ----- OUTPUTS -----
11+
# af - airfoil coordinates
12+
# ---------------
13+
#
14+
# Copyright (C) 2022 Milos Petrasinovic <[email protected]>
15+
#
16+
# This program is free software: you can redistribute it and/or modify
17+
# it under the terms of the GNU General Public License as
18+
# published by the Free Software Foundation, either version 3 of the
19+
# License, or (at your option) any later version.
20+
#
21+
# This program is distributed in the hope that it will be useful,
22+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
# GNU General Public License for more details.
25+
#
26+
# You should have received a copy of the GNU General Public License
27+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
28+
# --------------------
29+
import subprocess
30+
import sys
31+
import os
32+
import re
33+
34+
# Import numpy
35+
try:
36+
import numpy as np
37+
except ImportError:
38+
subprocess.check_call([sys.executable, "-m", "pip", "install", 'numpy'])
39+
finally:
40+
import numpy as np
41+
42+
def scanf(l):
43+
# scanf('%f %f', l)
44+
found = re.compile('([-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?)\\s+([-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?)').search(l)
45+
casts = [float, float]
46+
if found:
47+
groups = found.groups()
48+
return tuple([casts[i](groups[i]) for i in range(len(groups))])
49+
50+
def importAirfoil(file):
51+
af = [];
52+
if(os.path.isfile(file)):
53+
with open(file) as f:
54+
ls = [line.strip() for line in f]
55+
56+
x = []
57+
y = []
58+
h = 1
59+
for l in ls:
60+
if l:
61+
data = scanf(l);
62+
if(h and data and len(data) == 2 and data[0] > -0.1
63+
and data[0] < 1.1 and data[1] > -1.1
64+
and data[1] < 1.1):
65+
# First coordinate if there is both x and y data
66+
# Range for x is [-0.1, 1.1] and for y is [-1.1, 1.1]
67+
h = 0;
68+
x.append(data[0])
69+
y.append(data[1])
70+
elif(not h and data and len(data) == 2):
71+
x.append(data[0])
72+
y.append(data[1])
73+
74+
if(len(x) > 0):
75+
if(any(xi >= 1.1 for xi in x)):
76+
# Data is probably multiplied by 100
77+
x = np.divide(x, 100)
78+
y = np.divide(y, 100)
79+
80+
d = np.diff(x)
81+
if(sum([di < 0 for di in d]) == 1):
82+
# Lednicer format
83+
i = np.where(d < 0)[0][0]
84+
x = [*np.flip(x[:i+1]).tolist(), *x[i+1:]]
85+
y = [*np.flip(y[:i+1]).tolist(), *y[i+1:]]
86+
87+
af = np.array([x[1:-1], y[1:-1]])
88+
_, idx = np.unique(af, axis=1, return_index=True)
89+
af = [[x[0], *af[0][np.sort(idx)].tolist(), x[-1]],
90+
[y[0], *af[1][np.sort(idx)].tolist(), y[-1]]]
91+
return af

importAirfoil_PY.png

59.9 KB
Loading

test/_App/CreateApp.cmd

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
:: CreateApp.cmd
2+
:: Author: Milos D. Petrasinovic <[email protected]>
3+
:: Structural Analysis of Flying Vehicles
4+
:: Faculty of Mechanical Engineering, University of Belgrade
5+
:: Department of Aerospace Engineering, Flying structures
6+
:: https://vazmfb.com
7+
:: Belgrade, 2022
8+
:: --- INPUTS ---
9+
:: appFileName - name of python app file
10+
:: pythonPath - path to python used for app
11+
:: appCommands - aditional commands to execute
12+
:: --------------------
13+
::
14+
:: Copyright (C) 2022 Milos Petrasinovic <[email protected]>
15+
::
16+
:: This program is free software: you can redistribute it and/or modify
17+
:: it under the terms of the GNU General Public License as
18+
:: published by the Free Software Foundation, either version 3 of the
19+
:: License, or (at your option) any later version.
20+
::
21+
:: This program is distributed in the hope that it will be useful,
22+
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
:: GNU General Public License for more details.
25+
::
26+
:: You should have received a copy of the GNU General Public License
27+
:: along with this program. If not, see <https://www.gnu.org/licenses/>.
28+
::
29+
:: --------------------
30+
@echo off
31+
set appFileName="test_importAirfoil.py"
32+
set pythonPath="%USERPROFILE%/AppData/Local/Programs/Python/Python310/python.exe"
33+
set appCommands="pip install scanf & pip install matplotlib"
34+
35+
:: --------------------
36+
:: Set directory
37+
setlocal
38+
set realPath=%~dp0
39+
cd /d %realPath%
40+
41+
:: Get admin rights
42+
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
43+
if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... ) else ( goto gotAdmin )
44+
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
45+
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
46+
"%temp%\getadmin.vbs"
47+
exit /B
48+
:gotAdmin
49+
50+
:: Execute commands
51+
cmd /k "cd ../ & python -m pip install -U pip & pip install virtualenv & virtualenv --python=%pythonPath:"=% . & Scripts\activate & %appCommands:"=% & cd %realPath% & python %appFileName%"
52+
:: --------------------

test/_App/RunApp.cmd

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
:: RunApp.cmd
2+
:: Author: Milos D. Petrasinovic <[email protected]>
3+
:: Structural Analysis of Flying Vehicles
4+
:: Faculty of Mechanical Engineering, University of Belgrade
5+
:: Department of Aerospace Engineering, Flying structures
6+
:: https://vazmfb.com
7+
:: Belgrade, 2022
8+
:: --- INPUTS ---
9+
:: appFileName - name of python app file
10+
:: pythonPath - path to python used for app
11+
:: appCommands - aditional commands to execute
12+
:: --------------------
13+
::
14+
:: Copyright (C) 2022 Milos Petrasinovic <[email protected]>
15+
::
16+
:: This program is free software: you can redistribute it and/or modify
17+
:: it under the terms of the GNU General Public License as
18+
:: published by the Free Software Foundation, either version 3 of the
19+
:: License, or (at your option) any later version.
20+
::
21+
:: This program is distributed in the hope that it will be useful,
22+
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
:: GNU General Public License for more details.
25+
::
26+
:: You should have received a copy of the GNU General Public License
27+
:: along with this program. If not, see <https://www.gnu.org/licenses/>.
28+
::
29+
:: --------------------
30+
@echo off
31+
set appFileName="test_importAirfoil.py"
32+
33+
:: --------------------
34+
:: Set directory
35+
setlocal
36+
set realPath=%~dp0
37+
cd /d %realPath%
38+
39+
:: Get admin rights
40+
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
41+
if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... ) else ( goto gotAdmin )
42+
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
43+
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
44+
"%temp%\getadmin.vbs"
45+
exit /B
46+
:gotAdmin
47+
48+
:: Execute commands
49+
cmd /k "cd ../ & Scripts\activate & cd %realPath% & python %appFileName%"
50+
:: --------------------

test/_App/RunEnv.cmd

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
:: RunEnv.cmd
2+
:: Author: Milos D. Petrasinovic <[email protected]>
3+
:: Structural Analysis of Flying Vehicles
4+
:: Faculty of Mechanical Engineering, University of Belgrade
5+
:: Department of Aerospace Engineering, Flying structures
6+
:: https://vazmfb.com
7+
:: Belgrade, 2022
8+
:: --------------------
9+
::
10+
:: Copyright (C) 2022 Milos Petrasinovic <[email protected]>
11+
::
12+
:: This program is free software: you can redistribute it and/or modify
13+
:: it under the terms of the GNU General Public License as
14+
:: published by the Free Software Foundation, either version 3 of the
15+
:: License, or (at your option) any later version.
16+
::
17+
:: This program is distributed in the hope that it will be useful,
18+
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
:: GNU General Public License for more details.
21+
::
22+
:: You should have received a copy of the GNU General Public License
23+
:: along with this program. If not, see <https://www.gnu.org/licenses/>.
24+
::
25+
:: --------------------
26+
@echo off
27+
28+
:: --------------------
29+
:: Set directory
30+
setlocal
31+
set realPath=%~dp0
32+
cd /d %realPath%
33+
34+
:: Get admin rights
35+
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
36+
if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... ) else ( goto gotAdmin )
37+
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
38+
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
39+
"%temp%\getadmin.vbs"
40+
exit /B
41+
:gotAdmin
42+
43+
:: Execute commands
44+
cmd /k "cd ../ & Scripts\activate & cd %realPath%"
45+
:: --------------------

test/_App/airfoils/CLARK Y-18.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
0.0000000 0.0000000
2+
0.0114900 0.0294000
3+
0.0234700 0.0444100
4+
0.0477800 0.0644400
5+
0.0723100 0.0780900
6+
0.0969400 0.0890300
7+
0.1463800 0.1052400
8+
0.1960200 0.1158400
9+
0.2957500 0.1236700
10+
0.3957600 0.1233100
11+
0.4960200 0.1155600
12+
0.5965000 0.1016200
13+
0.6971700 0.0822800
14+
0.7979800 0.0586500
15+
0.8989200 0.0315200
16+
0.9494300 0.0166600
17+
1.0000000 0.0009000
18+
19+
0.0000000 0.0000000
20+
0.0133500 -.0247400
21+
0.0261400 -.0330000
22+
0.0514700 -.0426300
23+
0.0766600 -.0481600
24+
0.1017900 -.0520000
25+
0.1519500 -.0566700
26+
0.2020000 -.0582500
27+
0.3019300 -.0561100
28+
0.4017800 -.0518800
29+
0.5015800 -.0460500
30+
0.6013400 -.0389100
31+
0.7010601 -.0306800
32+
0.8007400 -.0214500
33+
0.9004000 -.0115300
34+
0.9502200 -.0063100
35+
1.0000000 -.0009000

0 commit comments

Comments
 (0)