Skip to content

Commit 9dd94aa

Browse files
committed
enh: remade position an input for the aeroSurfaces list
made position also save in the object
1 parent 4020cdd commit 9dd94aa

File tree

5 files changed

+47
-41
lines changed

5 files changed

+47
-41
lines changed

rocketpy/AeroSurfaces.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,25 @@
1111

1212

1313
class AeroSurfaces:
14-
"""Class used to hold multiple aerodynamic surfaces."""
14+
"""Class used to hold one or more aerodynamic surfaces."""
1515

1616
def __init__(self):
1717
self._aeroSurfaces = []
1818

19-
def append(self, aeroSurface):
20-
self._aeroSurfaces.append(aeroSurface)
19+
def append(self, aeroSurface, position=None):
20+
if position:
21+
self._aeroSurfaces.append((aeroSurface, position))
22+
else:
23+
self._aeroSurfaces.append(aeroSurface)
2124

2225
def remove(self, aeroSurface):
2326
for surface in self._aeroSurfaces:
24-
if surface == aeroSurface:
25-
self._aeroSurfaces.remove(aeroSurface)
27+
if isinstance(surface, tuple):
28+
if surface[0] == aeroSurface:
29+
self._aeroSurfaces.remove((surface[0], surface[1]))
30+
else:
31+
if surface == aeroSurface:
32+
self._aeroSurfaces.remove(surface)
2633

2734
def pop(self, index=-1):
2835
return self._aeroSurfaces.pop(index)
@@ -89,7 +96,6 @@ def __init__(
8996
self,
9097
length,
9198
kind,
92-
position,
9399
baseRadius=None,
94100
rocketRadius=None,
95101
name="Nose Cone",
@@ -121,13 +127,13 @@ def __init__(
121127
"""
122128
self.cpy = 0
123129
self.cpx = 0
130+
self.position = None # in relation to rocket
124131

125132
self._rocketRadius = rocketRadius
126133
self._baseRadius = baseRadius
127134
self._length = length
128135
self.kind = kind
129136
self.name = name
130-
self.position = position
131137

132138
self.evaluateGeometricalParameters()
133139
self.evaluateLiftCoefficient()
@@ -258,7 +264,8 @@ def geometricalInfo(self):
258264
"""
259265
print("Nose Cone Geometric Information of Nose: {}".format(self.name))
260266
print("-------------------------------")
261-
print(f"Position: {self.position:.3f} m")
267+
if self.position:
268+
print(f"Position: {self.position:.3f} m")
262269
print(f"Length: {self.length:.3f} m")
263270
print(f"Kind: {self.kind}")
264271
print(f"Base Radius: {self.baseRadius:.3f} m")
@@ -385,7 +392,6 @@ def __init__(
385392
n,
386393
rootChord,
387394
span,
388-
position,
389395
rocketRadius,
390396
cantAngle=0,
391397
airfoil=None,
@@ -440,9 +446,9 @@ def __init__(
440446
self._rootChord = rootChord
441447
self._span = span
442448
self.name = name
443-
self.position = position
444449
self.d = d
445450
self.Aref = Aref # Reference area
451+
self.position = None # in relation to rocket
446452

447453
return None
448454

@@ -753,7 +759,8 @@ def geometricalInfo(self):
753759
print("Fin Type: Elliptical")
754760
print("Root Chord: {:.3f} m".format(self.rootChord))
755761
print("Span: {:.3f} m".format(self.span))
756-
print("Position: {:.3f} m".format(self.position))
762+
if self.position:
763+
print("Position: {:.3f} m".format(self.position))
757764
print("Cant Angle: {:.3f} °".format(self.cantAngle))
758765
print("Longitudinal Section Area: {:.3f} m".format(self.Af))
759766
print("Aspect Ratio: {:.3f} m".format(self.AR))
@@ -942,7 +949,6 @@ def __init__(
942949
rootChord,
943950
tipChord,
944951
span,
945-
position,
946952
rocketRadius,
947953
cantAngle=0,
948954
sweepLength=None,
@@ -1006,7 +1012,6 @@ def __init__(
10061012
n,
10071013
rootChord,
10081014
span,
1009-
position,
10101015
rocketRadius,
10111016
cantAngle,
10121017
airfoil,
@@ -1354,7 +1359,6 @@ def __init__(
13541359
n,
13551360
rootChord,
13561361
span,
1357-
position,
13581362
rocketRadius,
13591363
cantAngle=0,
13601364
airfoil=None,
@@ -1414,7 +1418,6 @@ def __init__(
14141418
n,
14151419
rootChord,
14161420
span,
1417-
position,
14181421
rocketRadius,
14191422
cantAngle,
14201423
airfoil,
@@ -1656,9 +1659,7 @@ class Tail:
16561659
16571660
"""
16581661

1659-
def __init__(
1660-
self, topRadius, bottomRadius, length, position, rocketRadius, name="Tail"
1661-
):
1662+
def __init__(self, topRadius, bottomRadius, length, rocketRadius, name="Tail"):
16621663
"""Initializes the tail object by computing and storing the most
16631664
important values.
16641665
@@ -1687,8 +1688,7 @@ def __init__(
16871688
self._length = length
16881689
self._rocketRadius = rocketRadius
16891690
self.name = name
1690-
self.position = position
1691-
# Calculate ratio between top and bottom radius
1691+
self.position = None # in relation to rocket
16921692

16931693
# Calculate geometrical parameters
16941694
self.evaluateGeometricalParameters()
@@ -1820,7 +1820,8 @@ def geometricalInfo(self):
18201820
"""
18211821

18221822
print(f"\nTail name: {self.name}")
1823-
print(f"Tail Position: {self.position:.3f} m")
1823+
if self.position:
1824+
print(f"Tail Position: {self.position:.3f} m")
18241825
print(f"Tail Top Radius: {self.topRadius:.3f} m")
18251826
print(f"Tail Bottom Radius: {self.bottomRadius:.3f} m")
18261827
print(f"Tail Length: {self.length:.3f} m")

rocketpy/Flight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,9 @@ def uDot(self, t, u, postProcessing=False):
14091409
vyB = a12 * vx + a22 * vy + a32 * vz
14101410
vzB = a13 * vx + a23 * vy + a33 * vz
14111411
# Calculate lift and moment for each component of the rocket
1412-
for aeroSurface in self.rocket.aerodynamicSurfaces:
1412+
for aeroSurface, position in self.rocket.aerodynamicSurfaces:
14131413
compCp = (
1414-
aeroSurface.position - self.rocket.centerOfDryMassPosition
1414+
position - self.rocket.centerOfDryMassPosition
14151415
) * self.rocket._csys - aeroSurface.cpz
14161416
surfaceRadius = aeroSurface.rocketRadius
14171417
referenceArea = np.pi * surfaceRadius**2

rocketpy/Rocket.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,14 @@ def evaluateStaticMargin(self):
390390

391391
# Calculate total lift coefficient derivative and center of pressure
392392
if len(self.aerodynamicSurfaces) > 0:
393-
for aeroSurface in self.aerodynamicSurfaces:
393+
for aeroSurface, position in self.aerodynamicSurfaces:
394394
self.totalLiftCoeffDer += Function(
395395
lambda alpha: aeroSurface.cl(alpha, 0)
396396
).differentiate(x=1e-2, dx=1e-3)
397397
self.cpPosition += Function(
398398
lambda alpha: aeroSurface.cl(alpha, 0)
399399
).differentiate(x=1e-2, dx=1e-3) * (
400-
aeroSurface.position - self._csys * aeroSurface.cpz
400+
position - self._csys * aeroSurface.cpz
401401
)
402402
self.cpPosition /= self.totalLiftCoeffDer
403403

@@ -483,10 +483,12 @@ def addTail(
483483
radius = self.radius if radius is None else radius
484484

485485
# Create new tail as an object of the Tail class
486-
tail = Tail(topRadius, bottomRadius, length, position, radius, name)
486+
tail = Tail(topRadius, bottomRadius, length, radius, name)
487+
# Saves position on object for practicality
488+
tail.position = position
487489

488490
# Add tail to aerodynamic surfaces and tail list
489-
self.aerodynamicSurfaces.append(tail)
491+
self.aerodynamicSurfaces.append(aeroSurface=tail, position=position)
490492
self.tail.append(tail)
491493

492494
# Refresh static margin calculation
@@ -522,10 +524,12 @@ def addNose(self, length, kind, position, name="Nose Cone"):
522524
Nose cone object created.
523525
"""
524526
# Create a nose as an object of NoseCone class
525-
nose = NoseCone(length, kind, position, self.radius, self.radius, name)
527+
nose = NoseCone(length, kind, self.radius, self.radius, name)
528+
# Saves position on object for practicality
529+
nose.position = position
526530

527531
# Add nose to the list of aerodynamic surfaces
528-
self.aerodynamicSurfaces.append(nose)
532+
self.aerodynamicSurfaces.append(aeroSurface=nose, position=position)
529533
self.nosecone.append(nose)
530534

531535
# Refresh static margin calculation
@@ -628,17 +632,18 @@ def addTrapezoidalFins(
628632
rootChord,
629633
tipChord,
630634
span,
631-
position,
632635
radius,
633636
cantAngle,
634637
sweepLength,
635638
sweepAngle,
636639
airfoil,
637640
name,
638641
)
642+
# Saves position on object for practicality
643+
finSet.position = position
639644

640645
# Add fin set to the list of aerodynamic surfaces
641-
self.aerodynamicSurfaces.append(finSet)
646+
self.aerodynamicSurfaces.append(aeroSurface=finSet, position=position)
642647
self.fins.append(finSet)
643648

644649
# Refresh static margin calculation
@@ -709,12 +714,12 @@ def addEllipticalFins(
709714
radius = radius if radius is not None else self.radius
710715

711716
# Create a fin set as an object of EllipticalFins class
712-
finSet = EllipticalFins(
713-
n, rootChord, span, position, radius, cantAngle, airfoil, name
714-
)
717+
finSet = EllipticalFins(n, rootChord, span, radius, cantAngle, airfoil, name)
718+
# Saves position on object for practicality
719+
finSet.position = position
715720

716721
# Add fin set to the list of aerodynamic surfaces
717-
self.aerodynamicSurfaces.append(finSet)
722+
self.aerodynamicSurfaces.append(aeroSurface=finSet, position=position)
718723
self.fins.append(finSet)
719724

720725
# Refresh static margin calculation

rocketpy/prints/rocket_prints.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,28 @@ def rocket_aerodynamics_quantities(self):
105105
"""
106106
print("\nAerodynamics Lift Coefficient Derivatives\n")
107107
for aerodynamicSurface in self.rocket.aerodynamicSurfaces:
108-
name = aerodynamicSurface.name
108+
name = aerodynamicSurface[0].name
109109
try:
110110
print(
111111
name
112112
+ " Lift Coefficient Derivative: {:.3f}".format(
113-
aerodynamicSurface.clalpha(0)
113+
aerodynamicSurface[0].clalpha(0)
114114
)
115115
+ "/rad"
116116
)
117117
except:
118118
print(
119119
name
120120
+ " Lift Coefficient Derivative: {:.3f}".format(
121-
aerodynamicSurface.clalpha
121+
aerodynamicSurface[0].clalpha
122122
)
123123
+ "/rad"
124124
)
125125

126126
print("\nAerodynamics Center of Pressure\n")
127127
for aerodynamicSurface in self.rocket.aerodynamicSurfaces:
128-
name = aerodynamicSurface.name
129-
cpz = aerodynamicSurface.cp[2]
128+
name = aerodynamicSurface[0].name
129+
cpz = aerodynamicSurface[0].cp[2]
130130
print(name + " Center of Pressure to CM: {:.3f}".format(cpz) + " m")
131131
print(
132132
"Distance - Center of Pressure to CM: "

tests/test_rocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def test_add_trapezoidal_fins_sweep_length(
512512
assert translate - rocket.cpPosition == pytest.approx(expected_cpz_cm, 0.01)
513513

514514
# Check if AeroSurfaces.__getitem__() works
515-
assert isinstance(rocket.aerodynamicSurfaces.__getitem__(0), NoseCone)
515+
assert isinstance(rocket.aerodynamicSurfaces.__getitem__(0)[0], NoseCone)
516516

517517

518518
def test_add_fins_assert_cp_cm_plus_fins(rocket, dimensionless_rocket, m):

0 commit comments

Comments
 (0)