-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcross_section.py
55 lines (40 loc) · 1.38 KB
/
cross_section.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
array6409 = np.loadtxt("NACA6409.dat", skiprows=1)
array2412 = np.loadtxt("NACA2412.dat", skiprows=1)
def split_airfoil(np_arr):
x_cord = np_arr[:,0]
# find the index that x_cord == 0
ref_idx = list(x_cord).index(0)
# split airfoil into upper and lower part
upper = np_arr[:ref_idx+1]
lower = np_arr[ref_idx:]
return upper, lower
def get_area(arr):
enum = list(enumerate(arr))
# print(enum)
# [(0, array([1.0e+00, 9.4e-04])), (1, array([0.9928 , 0.00313])), (2, array([0.97989, 0.00699])), ... ]
small_sum = 0
large_sum = 0
for index, value in enum[:-1]:
small_sum += (value[0] - enum[index+1][1][0])*value[1]
# multiply x-cord difference and y-cord of current item
# print(value)
# [1.0e+00 9.4e-04]
# print(value[0])
# 1.0
# print(enum[index+1])
# (1, array([0.9928 , 0.00313]))
# print(enum[index+1][1])
# [0.9928 0.00313]
# print(enum[index+1][1][0])
# 0.9928
large_sum += (value[0] - enum[index+1][1][0])*enum[index+1][1][1]
# multiply x-cord difference and y-cord of next item
return 0.5*(small_sum + large_sum)
def cross_section(np_arr):
splited = split_airfoil(np_arr)
area = 0
for item in splited:
area += get_area(item)
return area
print(cross_section(array6409))