Skip to content

Commit fdc5085

Browse files
committed
enh: add setAttribute
1 parent 21407f3 commit fdc5085

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

rocketpy/AeroSurfaces.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ class Fins:
108108
nose cone.
109109
Fins.cantAngle : float
110110
Fins cant angle with respect to the rocket centerline, in degrees
111-
Fins.cantAngleList : list
112-
List of cant angles that fins are set to throughout a flight
113-
simulation. Useful for control systems
111+
Fins.changingAttributeDict : dict
112+
Dictionary that stores the name and the values of the attributes that may
113+
be changed during a simulation. Useful for control systems.
114114
Fins.cantAngleRad : float
115115
Fins cant angle with respect to the rocket centerline, in radians
116116
Fins.rootChord : float
@@ -252,15 +252,36 @@ def evaluateRollCoefficients(self):
252252
self.rollParameters = [clfDelta, cldOmega, self.cantAngleRad]
253253
return self.rollParameters
254254

255-
def changeCantAngle(self, cantAngle): # TODO: make it generic def ChangeParam
256-
self.cantAngleList.append(cantAngle)
255+
def setAttribute(self, name, value):
256+
"""Changes an existing attribute to a new value and
257+
reruns the evaluate methods.
257258
258-
self.cantAngle = cantAngle
259-
self.cantAngleRad = np.radians(cantAngle)
259+
Parameters
260+
----------
261+
name : strig
262+
Name of the attribute that will be changed.
263+
value : any
264+
value to which the attribute will be changed to.
260265
266+
Returns
267+
-------
268+
None
269+
"""
270+
# Changes attribute value
271+
self.__dict__[name] = value
272+
273+
# Add changed attribute to dict
274+
if self.changingAttributeDict.has_key(name):
275+
self.changingAttributeDict[name].append(value)
276+
else:
277+
self.changingAttributeDict[name] = [value]
278+
279+
# Rerun important calculations
280+
self.evaluateCenterOfPressure()
281+
self.evaluateLiftCoefficient()
261282
self.evaluateRollCoefficients()
262283

263-
return self
284+
return None
264285

265286
# Defines beta parameter
266287
def _beta(_, mach):
@@ -447,9 +468,9 @@ class TrapezoidalFins(Fins):
447468
nose cone.
448469
TrapezoidalFins.cantAngle : float
449470
Fins cant angle with respect to the rocket centerline, in degrees
450-
TrapezoidalFins.cantAngleList : list
451-
List of cant angles that fins are set to throughout a flight
452-
simulation. Useful for control systems
471+
TrapezoidalFins.changingAttributeDict : dict
472+
Dictionary that stores the name and the values of the attributes that may
473+
be changed during a simulation. Useful for control systems.
453474
TrapezoidalFins.cantAngleRad : float
454475
Fins cant angle with respect to the rocket centerline, in radians
455476
TrapezoidalFins.rootChord : float
@@ -601,7 +622,7 @@ def __init__(
601622
self.airfoil = airfoil
602623
self.distanceToCM = distanceToCM
603624
self.cantAngle = cantAngle
604-
self.cantAngleList = [cantAngle]
625+
self.changingAttributeDict = {}
605626
self.cantAngleRad = np.radians(cantAngle)
606627
self.rootChord = rootChord
607628
self.tipChord = tipChord
@@ -804,9 +825,9 @@ class EllipticalFins(Fins):
804825
nose cone.
805826
EllipticalFins.cantAngle : float
806827
Fins cant angle with respect to the rocket centerline, in degrees
807-
EllipticalFins.cantAngleList : list
808-
List of cant angles that fins are set to throughout a flight
809-
simulation. Useful for control systems
828+
EllipticalFins.changingAttributeDict : dict
829+
Dictionary that stores the name and the values of the attributes that may
830+
be changed during a simulation. Useful for control systems.
810831
EllipticalFins.cantAngleRad : float
811832
Fins cant angle with respect to the rocket centerline, in radians
812833
EllipticalFins.rootChord : float
@@ -937,7 +958,7 @@ def __init__(
937958
self.airfoil = airfoil
938959
self.distanceToCM = distanceToCM
939960
self.cantAngle = cantAngle
940-
self.cantAngleList = [cantAngle]
961+
self.changingAttributeDict = {}
941962
self.cantAngleRad = np.radians(cantAngle)
942963
self.rootChord = rootChord
943964
self.span = span

0 commit comments

Comments
 (0)