-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfins.py
More file actions
208 lines (166 loc) · 6.76 KB
/
fins.py
File metadata and controls
208 lines (166 loc) · 6.76 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import logging
from .._helpers import _dict_to_string
logger = logging.getLogger(__name__)
def search_trapezoidal_fins(bs, elements):
"""Search for trapezoidal fins in the bs and return the settings as a dict.
It is flexible in the sense that it can handle multiple trapezoidal fin sets.
Parameters
----------
bs : BeautifulSoup
The BeautifulSoup object of the open rocket file.
elements : dict
Dictionary with the settings for the elements of the rocket.
Returns
-------
settings : dict
Dictionary with the settings for the trapezoidal fins. The keys are
integers and the values are dicts containing the settings for each
trapezoidal fin set. The keys of the trapezoidal fin set dicts are:
"name", "number", "root_chord", "tip_chord", "span", "position",
"sweep_length", "sweep_angle", "cant_angle", "section".
"""
settings = {}
fins = bs.find_all("trapezoidfinset")
logger.info("A total of %d trapezoidal fin sets were detected", len(fins))
if len(fins) == 0:
logger.info("No trapezoidal fins were detected, returning empty dictionary")
return settings
for idx, fin in enumerate(fins):
logger.info(
"Starting collecting the settings for the trapezoidal fin set number '%d'",
idx,
)
label = fin.find("name").text
try:
def get_element_by_name(name):
for element in elements.values():
if element["name"] == name:
return element
return None
element = get_element_by_name(label)
logger.info("Found the element '%s' in the elements dictionary.", label)
except KeyError:
message = (
f"Couldn't find the element '{label}' in the elements dictionary. It is"
" possible that the process_elements_position() function got an error."
)
logger.error(message)
raise KeyError(message)
n_fin = int(fin.find("fincount").text)
logger.info("Number of fins retrieved: %d", n_fin)
root_chord = float(fin.find("rootchord").text)
logger.info("Root chord retrieved: %f", root_chord)
tip_chord = float(fin.find("tipchord").text)
logger.info("Tip chord retrieved: %f", tip_chord)
span = float(fin.find("height").text)
logger.info("Span retrieved: %f", span)
sweep_length = (
float(fin.find("sweeplength").text) if fin.find("sweeplength") else None
)
sweep_angle = (
float(fin.find("sweepangle").text) if fin.find("sweepangle") else None
)
logger.info(
"Sweep length and angle retrieved: %s, %s", sweep_length, sweep_angle
)
cant_angle = float(fin.find("cant").text)
logger.info("Cant angle retrieved: %f", cant_angle)
section = fin.find("crosssection").text
logger.info("Crosssection format retrieved")
fin_settings = {
"name": label,
"number": n_fin,
"root_chord": root_chord,
"tip_chord": tip_chord,
"span": span,
"position": element["position"],
"sweep_length": sweep_length,
"sweep_angle": sweep_angle,
"cant_angle": cant_angle,
"section": section,
}
settings[idx] = fin_settings
logger.info(
"Trapezoidal fin set number '%d' was defined:\n%s",
idx,
_dict_to_string(fin_settings, indent=23),
)
logger.info("Finished collecting all the trapezoidal fins.")
return settings
def search_elliptical_fins(bs, elements):
"""Search for elliptical fins in the bs and return the settings as a dict.
It is flexible in the sense that it can handle multiple elliptical fin sets.
Parameters
----------
bs : BeautifulSoup
The BeautifulSoup object of the open rocket file.
elements : dict
Dictionary with the settings for the elements of the rocket.
Returns
-------
settings : dict
Dictionary with the settings for the elliptical fins. The keys are
integers and the values are dicts containing the settings for each
elliptical fin set. The keys of the elliptical fin set dicts are:
"name", "number", "root_chord", "span", "position", "cant_angle",
"section".
"""
settings = {}
fins = bs.find_all("ellipticalfinset")
logger.info("A total of %d elliptical fin sets were detected", len(fins))
if len(fins) == 0:
logger.info(
"Since no elliptical fins were detected, returning empty dictionary"
)
return settings
for idx, fin in enumerate(fins):
logger.info(
"Starting collecting the settings for the elliptical fin set number '%d'",
idx,
)
label = fin.find("name").text
try:
def get_element_by_name(name):
for element in elements.values():
if element["name"] == name:
return element
return None
element = get_element_by_name(label)
logger.info("Found the element '%s' in the elements dictionary.", label)
except KeyError:
message = (
f"Couldn't find the element '{label}' in the elements dictionary. It is"
" possible that the process_elements_position() function got an error."
)
logger.error(message)
raise KeyError(message)
n_fin = int(fin.find("fincount").text)
logger.info("Number of fins retrieved: %d", n_fin)
root_chord = float(fin.find("rootchord").text)
logger.info("Root chord retrieved: %f", root_chord)
span = float(fin.find("height").text)
logger.info("Span retrieved: %f", span)
cant_angle = float(fin.find("cant").text)
logger.info("Cant angle retrieved: %f", cant_angle)
section = fin.find("crosssection").text
logger.info("Crosssection format retrieved")
fin_settings = {
"name": label,
"number": n_fin,
"root_chord": root_chord,
"span": span,
"position": element["position"],
"cant_angle": cant_angle,
"section": section,
}
settings[idx] = fin_settings
logger.info(
"Elliptical fin set number '%d' was defined:\n%s",
idx,
_dict_to_string(fin_settings, indent=23),
)
logger.info("Finished collecting all the elliptical fins.")
return settings
def search_free_form_fins(bs, elements): # pylint: disable=unused-argument
return {}
# TODO: support for tubefinset (low priority)