-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
191 lines (158 loc) · 5.58 KB
/
setup.py
File metadata and controls
191 lines (158 loc) · 5.58 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import numpy as np
from itertools import product
class Step():
"""
Represents a numeric interval and provides evenly spaced samples.
"""
def __init__(
self,
x0:float,
x1:float | None=None,
step:int | None=None
) -> None:
self.x0 = x0
self.x1 = x0 if x1 is None else x1
self.step = 1 if step is None else step
def __repr__(self):
return f"Step(x0={self.x0}, x1={self.x1}, step={self.step})"
def __str__(self):
return self.__repr__()
def get(self):
"""
Generate an array of values from x0 to x1 with the specified number of steps.
Returns:
np.ndarray: Array of evenly spaced values.
"""
return np.linspace(self.x0, self.x1, num=self.step)
class Parameters():
"""
Store the simulation parameters.
"""
def __init__(self, ground_effect:bool=False, Vinf:float=1.0, Pinf:float=1e5, rho:float=1.225, h:float=0.0) -> None:
self.ground_effect = ground_effect
self.Vinf = Vinf
self.Pinf = Pinf
self.rho = rho
self.h = h
def __repr__(self) -> str:
lbl = f"Parameters(ground Effect={self.ground_effect}, Vinf={self.Vinf}, Pinf={self.Pinf}, rho={self.rho}, h={self.h})"
return lbl
def __str__(self):
return self.__repr__()
class FoilData():
"""
Store the data for a single foil in a specific configuration.
"""
def __init__(self, file:str, key_invert:bool, chord:float, aoa:float, dx:float, dy:float, clockwise:bool=True) -> None:
self.file = file
self.key_invert = key_invert
self.chord = chord
self.aoa = aoa
self.dx = dx
self.dy = dy
self.clockwise = clockwise
def __repr__(self) -> str:
lbl = f"Foil(name={self.file}, chord={self.chord}, aoa={self.aoa}, dx={self.dx}, dy={self.dy})"
return lbl
def __str__(self):
return self.__repr__()
class WingData():
"""
Store the data for a wing configuration consisting of multiple foils.
"""
def __init__(self, foils:list[FoilData]) -> None:
self.foils = foils
def __repr__(self) -> str:
lbl = "Wing(\n"
for i in range(len(self.foils)):
lbl += f" {str(self.foils[i])}\n"
lbl += ")"
return lbl
def __str__(self):
return self.__repr__()
def __len__(self):
return len(self.foils)
def __getitem__(self, index):
return self.foils[index]
def __iter__(self):
self.index = 0
return self
def __next__(self):
if self.index < len(self.foils):
item = self.foils[self.index]
self.index += 1
return item
else:
raise StopIteration
class FoilSetup():
"""
Store the setupdata for the configurations for a foil.
"""
def __init__(self, file:str, key_invert:bool, chord:float, aoa:float | Step, dx:float | Step, dy:float | Step, clockwise:bool=True) -> None:
self.file = file
self.key_invert = key_invert
self.chord = chord
self.aoa = aoa if isinstance(aoa, Step) else Step(aoa)
self.dx = dx if isinstance(dx, Step) else Step(dx)
self.dy = dy if isinstance(dy, Step) else Step(dy)
self.clockwise = clockwise
def __repr__(self) -> str:
lbl = f"FoilSetup(name={self.file}, chord={self.chord}, aoa={self.aoa}, dx={self.dx}, dy={self.dy})"
return lbl
def __str__(self):
return self.__repr__()
def __len__(self):
return self.aoa.step * self.dx.step * self.dy.step
class Setup():
"""
Store the overall setup for the simulation, each foils' setups and data.
"""
def __init__(self, reading_directory:str, foils_setup: list[FoilSetup], params:Parameters) -> None:
self.reading_directory = reading_directory
self.foils_setup = foils_setup
self.params = params
self.wings_data:list[WingData] = self.generate_setups()
def __repr__(self) -> str:
lbl = f"Number of Wings Setups: {len(self.wings_data)}\n"
lbl += "\n\nWingData(\n"
for i in self.wings_data:
lbl += f"{str(i)},\n"
lbl += ")"
return lbl
def __len__(self):
return len(self.wings_data)
@property
def n_flaps(self):
"""
Number of flaps in the wing setup.
"""
return len(self.wings_data.n)
def generate_setups(self):
"""
Generate all possible wing configurations based on all the foils' setups.
Returns:
list[WingData]: List of all possible wing configurations.
"""
all_foils = []
for foil_setup in self.foils_setup:
foils = []
for dx in foil_setup.dx.get():
for dy in foil_setup.dy.get():
for aoa in foil_setup.aoa.get():
foils.append(
FoilData(
file=foil_setup.file,
key_invert=foil_setup.key_invert,
chord=foil_setup.chord,
aoa=aoa,
dx=dx,
dy=dy,
clockwise=foil_setup.clockwise
)
)
all_foils.append(foils)
all_foils = product(*all_foils)
wings = []
for foils in all_foils:
wings.append(WingData(list(foils)))
return wings