forked from ngoiz/pazy-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aero.py
165 lines (137 loc) · 7.19 KB
/
aero.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import numpy as np
import h5py as h5
import sharpy.utils.geo_utils as geo_utils
class PazyAero:
def __init__(self, main_ea, pazy_structure, **kwargs):
self.m = kwargs.get('surface_m', 4)
self.n_surfaces = kwargs.get('num_surfaces', 2)
assert pazy_structure.mirrored is True, 'Pazy beam not mirrored'
self.num_elem_tot = pazy_structure.n_elem
self.num_elem_surf = self.num_elem_tot // self.n_surfaces
self.num_node_tot = pazy_structure.n_node + 1
self.num_node_surf = pazy_structure.n_node // self.n_surfaces + 1
self.main_chord = 0.1
self.num_node_elem = pazy_structure.num_node_elem
# elastic axis location::: changes with skin
self.main_ea = main_ea
# Aerofoil shape: root and tip
self.root_airfoil_P = 0
self.root_airfoil_M = 0
self.tip_airfoil_P = 0
self.tip_airfoil_M = 0
self.conn_surf = pazy_structure.connectivities[:self.num_elem_surf, :]
self.surface_number = pazy_structure.beam_number
self.airfoils_surf = None
self.airfoil_distribution = None
### others
self.aero_node = None
self.surface_m = None
self.twist = None
self.chord = None # for .aero.h5 file in (num_elem, 3) format
self.elastic_axis = None # for .aero.h5 file in (num_elem, 3) format
#control surface parameters
self.pct_flap = 0.2
cs_deflection = [0, 0]
self.n_control_surfaces = len(cs_deflection)
self.control_surface = np.zeros((self.num_elem_tot, 3), dtype=int) - 1
self.control_surface_deflection = np.zeros(self.n_control_surfaces, dtype=float)
for i in range(len(cs_deflection)):
self.control_surface_deflection[i] = cs_deflection[i] * np.pi / 180
self.control_surface_chord = self.m // 2 * np.ones(self.n_control_surfaces, dtype=int)
self.control_surface_type = np.zeros(self.n_control_surfaces, dtype=int)
def generate_aero(self):
n_surfaces = self.n_surfaces
num_node_surf = self.num_node_surf
num_node_tot = self.num_node_tot
num_elem_surf = self.num_elem_surf
num_elem_tot = self.num_elem_tot
pct_flap = self.pct_flap
control_surface = self.control_surface
### Generate aerofoil profiles. Only on surf 0.
airfoils_surf = []
if n_surfaces == 2:
for inode in range(num_node_surf):
eta = inode / num_node_surf
airfoils_surf.append(
np.column_stack(
geo_utils.interpolate_naca_camber(
eta,
self.root_airfoil_M, self.root_airfoil_P,
self.tip_airfoil_M, self.tip_airfoil_P)))
# if inode >= num_node_surf // 2:
ws_elem = 0
for i_surf in range(2):
for i_elem in range(num_elem_surf):
for i_local_node in range(self.num_node_elem):
if i_elem >= int(num_elem_surf * (1 - pct_flap)):
if i_surf == 0:
control_surface[ws_elem + i_elem, i_local_node] = 0 # Right flap
else:
control_surface[ws_elem + i_elem, i_local_node] = 0 # Left flap
ws_elem += num_elem_surf
# control_surface[i_elem, i_local_node] = 0
airfoil_distribution_surf = self.conn_surf
airfoil_distribution = np.concatenate([airfoil_distribution_surf,
airfoil_distribution_surf[::-1, [1, 0, 2]]])
control_surface[-num_elem_surf:] = control_surface[-num_elem_surf:, :][::-1]
elif n_surfaces == 1:
num_node_half = (num_node_surf + 1) // 2
for inode in range(num_node_half):
eta = inode / num_node_half
airfoils_surf.append(
np.column_stack(
geo_utils.interpolate_naca_camber(
eta,
self.root_airfoil_M, self.root_airfoil_P,
self.tip_airfoil_M, self.tip_airfoil_P)))
airfoil_distribution_surf = self.conn_surf[:num_elem_surf // 2, :]
airfoil_distribution = np.concatenate([
airfoil_distribution_surf[::-1, [1, 0, 2]],
airfoil_distribution_surf])
else:
raise Exception('number of surfaces should be 1 or 2')
self.airfoils_surf = airfoils_surf
self.airfoil_distribution = airfoil_distribution
### others
self.aero_node = np.ones((num_node_tot,), dtype=bool)
self.surface_m = self.m * np.ones((n_surfaces,), dtype=int)
self.twist = np.zeros((num_elem_tot, 3))
self.chord = self.main_chord * np.ones((num_elem_tot, 3))
self.elastic_axis = self.main_ea * np.ones((num_elem_tot, 3,))
self.control_surface = control_surface
def save_files(self, case_name, case_route='./'):
filepath = case_route + '/{}.aero.h5'.format(case_name)
with h5.File(case_route + '/' + case_name + '.aero.h5', 'w') as h5file:
airfoils_group = h5file.create_group('airfoils')
# add one airfoil
for aa in range(len(self.airfoils_surf)):
airfoils_group.create_dataset('%d' % aa, data=self.airfoils_surf[aa])
chord_input = h5file.create_dataset('chord', data=self.chord)
dim_attr = chord_input.attrs['units'] = 'm'
twist_input = h5file.create_dataset('twist', data=self.twist)
dim_attr = twist_input.attrs['units'] = 'rad'
# airfoil distribution
airfoil_distribution_input = h5file.create_dataset(
'airfoil_distribution', data=self.airfoil_distribution)
surface_distribution_input = h5file.create_dataset(
'surface_distribution', data=self.surface_number)
surface_m_input = h5file.create_dataset(
'surface_m', data=self.surface_m)
m_distribution_input = h5file.create_dataset(
'm_distribution', data='uniform'.encode('ascii', 'ignore'))
aero_node_input = h5file.create_dataset(
'aero_node', data=self.aero_node)
elastic_axis_input = h5file.create_dataset(
'elastic_axis', data=self.elastic_axis)
if self.control_surface is not None:
control_surface_input = h5file.create_dataset(
'control_surface', data=self.control_surface)
control_surface_type_input = h5file.create_dataset(
'control_surface_type', data=self.control_surface_type)
control_surface_deflection_input = h5file.create_dataset(
'control_surface_deflection', data=self.control_surface_deflection)
control_surface_chord_input = h5file.create_dataset(
'control_surface_chord', data=self.control_surface_chord)
# if airfoil_efficiency is not None:
# a_eff_handle = h5file.create_dataset(
# 'airfoil_efficiency', data=airfoil_efficiency)