Skip to content

Commit

Permalink
enh: create nosecone, fins and tail attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano committed Feb 21, 2023
1 parent c803668 commit 4020cdd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
30 changes: 23 additions & 7 deletions rocketpy/AeroSurfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class AeroSurfaces:
"""Class used to hold multiple aerodynamic surfaces and their positions."""
"""Class used to hold multiple aerodynamic surfaces."""

def __init__(self):
self._aeroSurfaces = []
Expand All @@ -25,17 +25,25 @@ def remove(self, aeroSurface):
self._aeroSurfaces.remove(aeroSurface)

def pop(self, index=-1):
return self._aerosurfaces.pop(index)
return self._aeroSurfaces.pop(index)

def __repr__(self):
return self._aeroSurfaces.__str__
if len(self._aeroSurfaces) == 1:
return self._aeroSurfaces[0].__repr__()
return self._aeroSurfaces.__repr__()

def __len__(self):
return len(self._aeroSurfaces)

def __getitem__(self, index):
return self._aeroSurfaces[index]

def __getattr__(self, name):
if len(self._aeroSurfaces) == 1:
attr = getattr(self._aeroSurfaces[0], name)
return attr
return getattr(self._aeroSurfaces, name)

def __iter__(self):
return iter(self._aeroSurfaces)

Expand Down Expand Up @@ -78,7 +86,13 @@ class NoseCone:
"""

def __init__(
self, length, kind, position, baseRadius=None, rocketRadius=None, name="Nose Cone"
self,
length,
kind,
position,
baseRadius=None,
rocketRadius=None,
name="Nose Cone",
):
"""Initializes the nose cone. It is used to define the nose cone
length, kind, center of pressure and lift coefficient curve.
Expand Down Expand Up @@ -284,7 +298,7 @@ def allInfo(self):
-------
None
"""
self.geometricalInfo()
self.geometricalInfo()
self.aerodynamicInfo()

return None
Expand Down Expand Up @@ -1642,7 +1656,9 @@ class Tail:
"""

def __init__(self, topRadius, bottomRadius, length, position, rocketRadius, name="Tail"):
def __init__(
self, topRadius, bottomRadius, length, position, rocketRadius, name="Tail"
):
"""Initializes the tail object by computing and storing the most
important values.
Expand Down
15 changes: 12 additions & 3 deletions rocketpy/Rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ def __init__(

# Aerodynamic data initialization
self.aerodynamicSurfaces = AeroSurfaces()
self.nosecone = AeroSurfaces()
self.fins = AeroSurfaces()
self.tail = AeroSurfaces()
self.cpPosition = 0
self.staticMargin = Function(
lambda x: 0, inputs="Time (s)", outputs="Static Margin (c)"
Expand Down Expand Up @@ -482,8 +485,9 @@ def addTail(
# Create new tail as an object of the Tail class
tail = Tail(topRadius, bottomRadius, length, position, radius, name)

# Add tail to aerodynamic surfaces list
self.aerodynamicSurfaces.append(aeroSurface=tail)
# Add tail to aerodynamic surfaces and tail list
self.aerodynamicSurfaces.append(tail)
self.tail.append(tail)

# Refresh static margin calculation
self.evaluateStaticMargin()
Expand Down Expand Up @@ -522,6 +526,7 @@ def addNose(self, length, kind, position, name="Nose Cone"):

# Add nose to the list of aerodynamic surfaces
self.aerodynamicSurfaces.append(nose)
self.nosecone.append(nose)

# Refresh static margin calculation
self.evaluateStaticMargin()
Expand Down Expand Up @@ -634,6 +639,7 @@ def addTrapezoidalFins(

# Add fin set to the list of aerodynamic surfaces
self.aerodynamicSurfaces.append(finSet)
self.fins.append(finSet)

# Refresh static margin calculation
self.evaluateStaticMargin()
Expand Down Expand Up @@ -703,10 +709,13 @@ def addEllipticalFins(
radius = radius if radius is not None else self.radius

# Create a fin set as an object of EllipticalFins class
finSet = EllipticalFins(n, rootChord, span, position, radius, cantAngle, airfoil, name)
finSet = EllipticalFins(
n, rootChord, span, position, radius, cantAngle, airfoil, name
)

# Add fin set to the list of aerodynamic surfaces
self.aerodynamicSurfaces.append(finSet)
self.fins.append(finSet)

# Refresh static margin calculation
self.evaluateStaticMargin()
Expand Down

0 comments on commit 4020cdd

Please sign in to comment.