Skip to content

Commit 4dfa8e7

Browse files
committed
verified ruff check changes
1 parent 1c22e04 commit 4dfa8e7

File tree

28 files changed

+194
-170
lines changed

28 files changed

+194
-170
lines changed

aerosandbox/aerodynamics/aero_2D/airfoil_optimizer/airfoil_optimizer.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from aerosandbox.geometry.airfoil.airfoil_families import get_kulfan_coordinates
44
from scipy import optimize
55
import matplotlib.pyplot as plt
6+
from dataclasses import dataclass, field
67

78
if __name__ == "__main__":
89
### Design Conditions
@@ -101,9 +102,14 @@ def draw(
101102
plt.pause(0.001)
102103

103104
### Utilities for tracking the design vector and objective throughout the optimization run
104-
iteration = 0
105-
xs = []
106-
fs = []
105+
@dataclass
106+
class OptimizationState:
107+
"""Holds state for the optimization to avoid globals."""
108+
iteration: int = 0
109+
xs: list = field(default_factory=list)
110+
fs: list = field(default_factory=list)
111+
112+
state = OptimizationState()
107113

108114
def augmented_objective(x):
109115
"""
@@ -140,19 +146,18 @@ def augmented_objective(x):
140146
np.minimum(0, (airfoil.local_thickness(0.30) - 0.12) / 0.005) ** 2
141147
) # Spar thickness constraint
142148

143-
xs.append(x)
144-
fs.append(objective)
149+
state.xs.append(x)
150+
state.fs.append(objective)
145151

146152
return objective * (1 + penalty)
147153

148154
def callback(x):
149-
global iteration
150-
iteration += 1
151-
print(f"Iteration {iteration}: Cd = {fs[-1]:.6f}")
152-
if iteration % 1 == 0:
155+
state.iteration += 1
156+
print(f"Iteration {state.iteration}: Cd = {state.fs[-1]:.6f}")
157+
if state.iteration % 1 == 0:
153158
airfoil = make_airfoil(x)
154159
draw(airfoil)
155-
ax.set_title(f"Airfoil Optimization: Iteration {iteration}")
160+
ax.set_title(f"Airfoil Optimization: Iteration {state.iteration}")
156161
airfoil.write_dat("optimized_airfoil.dat")
157162

158163
draw(initial_airfoil)

aerosandbox/aerodynamics/aero_3D/lifting_line.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,6 @@ def draw(
12751275
if __name__ == "__main__":
12761276
import aerosandbox as asb
12771277
import aerosandbox.numpy as np
1278-
from aerosandbox.aerodynamics.aero_3D.test_aero_3D.geometries.conventional import (
1279-
airplane,
1280-
)
12811278
import matplotlib.pyplot as plt
12821279
import aerosandbox.tools.pretty_plots as p
12831280

aerosandbox/aerodynamics/aero_3D/test_aero_3D/test_aero_buildup/test_moment_validation/test_fuselage_moment_and_derivatives.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ def A(x): # cross-sectional area as a function of distance along fuselage, x
266266
# TODO add assertions
267267

268268
##### Slender body theory
269-
l = 1 # length of fuselage
269+
length = 1 # length of fuselage
270270
alpha_rad = np.radians(analysis.op_point.alpha)
271271

272272
from scipy import integrate
273273

274274
def alpha_tilde(x):
275275
return alpha_rad - dzdx(x)
276276

277-
CL = 2 / airplane.s_ref * A(l) * alpha_tilde(l)
277+
CL = 2 / airplane.s_ref * A(length) * alpha_tilde(length)
278278
print(f"CL_slb: {CL}")
279279
assert aero["CL"] == pytest.approx(CL, abs=0.01)
280280

@@ -283,9 +283,9 @@ def alpha_tilde(x):
283283
/ airplane.s_ref
284284
/ airplane.c_ref
285285
* (
286-
(fuselage.volume() - l * A(l)) * alpha_rad
287-
+ l * A(l) * dzdx(l)
288-
- integrate.quad(lambda xi: A(xi) * dzdx(xi), 0, l)[0]
286+
(fuselage.volume() - length * A(length)) * alpha_rad
287+
+ length * A(length) * dzdx(length)
288+
- integrate.quad(lambda xi: A(xi) * dzdx(xi), 0, length)[0]
289289
)
290290
)
291291

aerosandbox/atmosphere/atmosphere.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ def __getitem__(self, index) -> "Atmosphere":
7777
Returns: A new Atmosphere instance, where each attribute is subscripted at the given value, if possible.
7878
7979
"""
80-
l = len(self)
80+
self_length = len(self)
8181

8282
def get_item_of_attribute(a):
8383
if hasattr(a, "__len__") and hasattr(a, "__getitem__"):
8484
if len(a) == 1:
8585
return a[0]
86-
elif len(a) == l:
86+
elif len(a) == self_length:
8787
return a[index]
8888
else:
8989
try:
9090
return a[index]
9191
except IndexError:
9292
raise IndexError(
9393
f"A state variable could not be indexed; it has length {len(a)} while the"
94-
f"parent has length {l}."
94+
f"parent has length {self_length}."
9595
)
9696
else:
9797
return a

aerosandbox/dynamics/point_mass/common_point_mass.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,21 @@ def __getitem__(self, index: int | slice):
199199
Returns: A new Dynamics instance, where each attribute is subscripted at the given value, if possible.
200200
201201
"""
202-
l = len(self)
202+
self_length = len(self)
203203

204204
def get_item_of_attribute(a):
205205
if hasattr(a, "__len__") and hasattr(a, "__getitem__"):
206206
if len(a) == 1:
207207
return a[0]
208-
elif len(a) == l:
208+
elif len(a) == self_length:
209209
return a[index]
210210
else:
211211
try:
212212
return a[index]
213213
except IndexError:
214214
raise IndexError(
215215
f"A state variable could not be indexed; it has length {len(a)} while the"
216-
f"parent has length {l}."
216+
f"parent has length {self_length}."
217217
)
218218
else:
219219
return a

aerosandbox/geometry/airfoil/airfoil.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,40 +1337,40 @@ def set_TE_thickness(
13371337
y_adjustment = s_adjustment
13381338

13391339
### Decompose the existing airfoil coordinates to upper and lower sides, and x and y.
1340-
u = self.upper_coordinates()
1341-
ux = u[:, 0]
1342-
uy = u[:, 1]
1340+
upper = self.upper_coordinates()
1341+
upper_x = upper[:, 0]
1342+
upper_y = upper[:, 1]
13431343

1344-
le_x = ux[-1]
1344+
le_x = upper_x[-1]
13451345

1346-
l = self.lower_coordinates()[1:]
1347-
lx = l[:, 0]
1348-
ly = l[:, 1]
1346+
lower = self.lower_coordinates()[1:]
1347+
lower_x = lower[:, 0]
1348+
lower_y = lower[:, 1]
13491349

1350-
te_x = (ux[0] + lx[-1]) / 2
1350+
te_x = (upper_x[0] + lower_x[-1]) / 2
13511351

13521352
### Create modified versions of the upper and lower coordinates
1353-
new_u = np.stack(
1353+
new_upper = np.stack(
13541354
arrays=[
1355-
ux + x_adjustment * (ux - le_x) / (te_x - le_x),
1356-
uy + y_adjustment * (ux - le_x) / (te_x - le_x),
1355+
upper_x + x_adjustment * (upper_x - le_x) / (te_x - le_x),
1356+
upper_y + y_adjustment * (upper_x - le_x) / (te_x - le_x),
13571357
],
13581358
axis=1,
13591359
)
1360-
new_l = np.stack(
1360+
new_lower = np.stack(
13611361
arrays=[
1362-
lx - x_adjustment * (lx - le_x) / (te_x - le_x),
1363-
ly - y_adjustment * (lx - le_x) / (te_x - le_x),
1362+
lower_x - x_adjustment * (lower_x - le_x) / (te_x - le_x),
1363+
lower_y - y_adjustment * (lower_x - le_x) / (te_x - le_x),
13641364
],
13651365
axis=1,
13661366
)
13671367

13681368
### If the desired thickness is zero, ensure that is precisely reached.
13691369
if thickness == 0:
1370-
new_l[-1] = new_u[0]
1370+
new_lower[-1] = new_upper[0]
13711371

13721372
### Combine the upper and lower surface coordinates into a single array.
1373-
new_coordinates = np.concatenate([new_u, new_l], axis=0)
1373+
new_coordinates = np.concatenate([new_upper, new_lower], axis=0)
13741374

13751375
### Return a new Airfoil with the desired coordinates.
13761376
return Airfoil(name=self.name, coordinates=new_coordinates)

aerosandbox/library/aerodynamics/inviscid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def oswalds_efficiency(
5151
sweep = np.clip(sweep, 0, 90) # TODO input proper analytic continuation
5252

5353
def f(
54-
l,
54+
taper,
5555
): # f(lambda), given as Eq. 36 in the Nita and Scholz paper (see parent docstring).
56-
return 0.0524 * l**4 - 0.15 * l**3 + 0.1659 * l**2 - 0.0706 * l + 0.0119
56+
return 0.0524 * taper**4 - 0.15 * taper**3 + 0.1659 * taper**2 - 0.0706 * taper + 0.0119
5757

5858
delta_lambda = -0.357 + 0.45 * np.exp(-0.0375 * sweep)
5959
# Eq. 37 in Nita & Scholz.

aerosandbox/library/aerodynamics/unsteady.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def integrand(sigma, s, chord):
185185

186186
lift_coefficient = np.zeros_like(reduced_time)
187187
for i, s in enumerate(reduced_time):
188-
I = quad(integrand, 0, s, args=(s, chord))[0]
189-
lift_coefficient[i] = 2 * np.pi * I / plate_velocity
188+
integrated_value = quad(integrand, 0, s, args=(s, chord))[0]
189+
lift_coefficient[i] = 2 * np.pi * integrated_value / plate_velocity
190190

191191
return lift_coefficient
192192

@@ -235,9 +235,9 @@ def integrand(sigma, s):
235235
lift_coefficient = np.zeros_like(reduced_time)
236236

237237
for i, s in enumerate(reduced_time):
238-
I = quad(integrand, 0, s, args=s)[0]
239-
# print(I)
240-
lift_coefficient[i] = 2 * np.pi * (AoA_function(s) * wagners_function(0) + I)
238+
integrated_value = quad(integrand, 0, s, args=s)[0]
239+
# print(integrated_value)
240+
lift_coefficient[i] = 2 * np.pi * (AoA_function(s) * wagners_function(0) + integrated_value)
241241

242242
return lift_coefficient
243243

@@ -414,7 +414,7 @@ def linear_ramp_pitch(reduced_time: float) -> float:
414414
)
415415
ax2.set_ylabel("Angle of Attack, degrees")
416416
lns = ln1 + ln2 + ln3
417-
labs = [l.get_label() for l in lns]
417+
labs = [line.get_label() for line in lns]
418418
ax2.legend(lns, labs, loc="lower right")
419419
plt.title("Gust and pitch example profiles")
420420

aerosandbox/library/aerodynamics/viscous.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import aerosandbox.numpy as np
22
from typing import Literal
3+
import warnings
34

45

56
def Cd_cylinder(
@@ -196,9 +197,6 @@ def Cd_flat_plate_normal():
196197
return 2.202
197198

198199

199-
import warnings
200-
201-
202200
def Cl_2412(alpha, Re_c):
203201
# A curve fit I did to a NACA 2412 airfoil, 2D XFoil data
204202
# Within -2 < alpha < 12 and 10^5 < Re_c < 10^7, has R^2 = 0.9892
@@ -337,25 +335,19 @@ def Cd_wave_e216(Cl, mach, sweep=0.0):
337335
mach = np.fmax(mach, 0)
338336
mach_perpendicular = mach * np.cosd(sweep) # Relation from FVA Eq. 8.176
339337
Cl_perpendicular = Cl / np.cosd(sweep) ** 2 # Relation from FVA Eq. 8.177
340-
341-
# Coeffs
342-
c0 = 7.2685945744797997e-01
343-
c1 = -1.5483144040727698e-01
344-
c3 = 2.1305118052118968e-01
345-
c4 = 7.8812272501525316e-01
346-
c5 = 3.3888938102072169e-03
347-
l0 = 1.5298928303149546e00
348-
l1 = 5.2389999717540392e-01
349-
350-
m = mach_perpendicular
351-
l = Cl_perpendicular
352-
353-
Cd_wave = (
354-
np.fmax(m - (c0 + c1 * np.sqrt(c3 + (l - c4) ** 2) + c5 * l), 0) * (l0 + l1 * l)
338+
return (
339+
np.fmax(
340+
mach_perpendicular
341+
- (
342+
7.2685945744797997e-01
343+
+ -1.5483144040727698e-01 * np.sqrt(2.1305118052118968e-01 + (Cl_perpendicular - 7.8812272501525316e-01) ** 2)
344+
+ 3.3888938102072169e-03 * Cl_perpendicular
345+
),
346+
0
347+
)
348+
* (1.5298928303149546e00 + 5.2389999717540392e-01 * Cl_perpendicular)
355349
) ** 2
356350

357-
return Cd_wave
358-
359351

360352
def Cl_rae2822(alpha, Re_c):
361353
# A curve fit I did to a RAE2822 airfoil, 2D XFoil data. Incompressible flow.
@@ -451,20 +443,14 @@ def Cd_wave_rae2822(Cl, mach, sweep=0.0):
451443
mach = np.fmax(mach, 0)
452444
mach_perpendicular = mach * np.cosd(sweep) # Relation from FVA Eq. 8.176
453445
Cl_perpendicular = Cl / np.cosd(sweep) ** 2 # Relation from FVA Eq. 8.177
454-
455-
# Coeffs
456-
c2 = 4.5776476424519119e00
457-
mc0 = 9.5623337929607111e-01
458-
mc1 = 2.0552787101770234e-01
459-
mc2 = 1.1259268018737063e00
460-
mc3 = 1.9538856688443659e-01
461-
462-
m = mach_perpendicular
463-
l = Cl_perpendicular
464-
465-
Cd_wave = np.fmax(m - (mc0 - mc1 * np.sqrt(mc2 + (l - mc3) ** 2)), 0) ** 2 * c2
466-
467-
return Cd_wave
446+
return np.fmax(
447+
mach_perpendicular
448+
- (
449+
9.5623337929607111e-01
450+
- 2.0552787101770234e-01 * np.sqrt(1.1259268018737063e00 + (Cl_perpendicular - 1.9538856688443659e-01) ** 2)
451+
),
452+
0
453+
) ** 2 * 4.5776476424519119e00
468454

469455

470456
def fuselage_upsweep_drag_area(

aerosandbox/library/mass_structural.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ def mass_hpa_tail_boom(
183183
:param mean_tail_surface_area: mean of the areas of the tail surfaces (elevator, rudder)
184184
:return: mass of the tail boom [m]
185185
"""
186-
l = length_tail_boom
186+
length = length_tail_boom
187187
q = dynamic_pressure_at_manuever_speed
188188
area = mean_tail_surface_area
189-
w_tb = (l * 1.14e-1 + l**2 * 1.96e-2) * (1 + ((q * area) / 78.5 - 1) / 2)
189+
w_tb = (length * 1.14e-1 + length**2 * 1.96e-2) * (1 + ((q * area) / 78.5 - 1) / 2)
190190

191191
return w_tb
192192

0 commit comments

Comments
 (0)