Skip to content

Commit 18c22ef

Browse files
Revert "MNT: store ref_factor on rocket aero surface components (#561) (#1129)"
This reverts commit bc3fe73.
1 parent cc9520b commit 18c22ef

12 files changed

Lines changed: 31 additions & 146 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Attention: The newest changes should be on top -->
5252
### Changed
5353

5454
- ENH: Number the simulations of a serial Monte Carlo run from zero, as the parallel path already did — the two used to name the same simulation `1, 2, 3` and `0, 1, 2`. The `index` field written into the inputs and outputs rows shifts by one for serial runs, so code reading indices off those files has to expect a run of `n` simulations to be numbered `0` to `n - 1`. An append onto a study written before this release is refused rather than continued, since its rows do not record which root drew them. [#1187](https://github.com/RocketPy-Team/RocketPy/pull/1187)
55-
- MNT: Store the reference-area correction factor on each rocket aero surface component, so it is carried with the surface instead of being recomputed at every lift evaluation. `Rocket.aerodynamic_surfaces`, `rail_buttons` and `sensors` now yield `(component, position, ref_factor)`, so code that unpacks a pair from them (`for surface, position in rocket.aerodynamic_surfaces`) has to take the third field or absorb it. Simulation results are unchanged, and `.rpy` files written before this still load. [#1129](https://github.com/RocketPy-Team/RocketPy/pull/1129) [#561](https://github.com/RocketPy-Team/RocketPy/issues/561)
5655
- ENH: Compute the rocket static margin lazily [#1135](https://github.com/RocketPy-Team/RocketPy/pull/1135) [#780](https://github.com/RocketPy-Team/RocketPy/issues/780)
5756
- DOC: Tighten the comments that came with the sampler seed groups [#1154](https://github.com/RocketPy-Team/RocketPy/pull/1154)
5857
- CI: make the Gemini PR reviewer actually review [#1140](https://github.com/RocketPy-Team/RocketPy/pull/1140)

‎rocketpy/plots/flight_plots.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def _rocket_axial_display_coordinate(self, value, display_length):
939939
"""Map a rocket axial coordinate onto the centered display model."""
940940
coordinates = [
941941
float(position.z)
942-
for _surface, position, _ref_factor in self.flight.rocket.aerodynamic_surfaces
942+
for _surface, position in self.flight.rocket.aerodynamic_surfaces
943943
]
944944
coordinates.extend(
945945
[

‎rocketpy/plots/rocket_plots.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def _draw_aerodynamic_surfaces(self, ax, vis_args, plane, surfaces):
243243
# diameter changes. The final point of the last surface is the final
244244
# point of the last tube
245245

246-
for surface, position, _ref_factor in surfaces:
246+
for surface, position in surfaces:
247247
if isinstance(surface, NoseCone):
248248
self._draw_nose_cone(ax, surface, position.z, drawn_surfaces, vis_args)
249249
elif isinstance(surface, Tail):
@@ -645,7 +645,7 @@ def _draw_nozzle_tube(self, last_radius, last_x, nozzle_position, ax, vis_args):
645645
def _draw_rail_buttons(self, ax, vis_args):
646646
"""Draws the rail buttons of the rocket."""
647647
try:
648-
buttons, pos, _ref_factor = self.rocket.rail_buttons[0]
648+
buttons, pos = self.rocket.rail_buttons[0]
649649
lower = pos.z
650650
upper = lower + buttons.buttons_distance * self.rocket._csys
651651
ax.scatter(

‎rocketpy/prints/rocket_prints.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,19 @@ def rocket_aerodynamics_quantities(self):
102102
None
103103
"""
104104
print("\nAerodynamics Lift Coefficient Derivatives\n")
105-
for surface, _position, ref_factor in self.rocket.aerodynamic_surfaces:
105+
for surface, _ in self.rocket.aerodynamic_surfaces:
106106
if isinstance(surface, GenericSurface):
107107
continue
108108
name = surface.name
109109
# ref_factor corrects lift for different reference areas
110+
ref_factor = (surface.rocket_radius / self.rocket.radius) ** 2
110111
print(
111112
f"{name} Lift Coefficient Derivative: "
112113
f"{ref_factor * surface.clalpha(0):.3f}/rad"
113114
)
114115

115116
print("\nCenter of Pressure\n")
116-
for surface, position, _ref_factor in self.rocket.aerodynamic_surfaces:
117+
for surface, position in self.rocket.aerodynamic_surfaces:
117118
name = surface.name
118119
cpz = surface.cp[2] # relative to the user defined coordinate system
119120
print(

‎rocketpy/rocket/components.py‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ class Components:
1515
A list of named tuples representing all the components and their
1616
positions relative to the rocket.
1717
component_tuple : namedtuple
18-
A named tuple representing a component, its position within the
19-
rocket, and an optional reference-area correction factor.
18+
A named tuple representing a component and its position within the
19+
rocket.
2020
"""
2121

2222
def __init__(self):
2323
"""Initialize an empty components list instance."""
24-
self.component_tuple = namedtuple(
25-
"component_tuple", "component position ref_factor", defaults=(1.0,)
26-
)
24+
self.component_tuple = namedtuple("component_tuple", "component position")
2725
self._components = []
2826

2927
# List of components and their positions to avoid extra for loops in
@@ -36,7 +34,6 @@ def __repr__(self):
3634
components_str = "\n".join(
3735
[
3836
f"\tComponent: {str(c.component):80} Position: {c.position}"
39-
f" Ref Factor: {c.ref_factor}"
4037
for c in self._components
4138
]
4239
)
@@ -55,7 +52,7 @@ def __iter__(self):
5552
"""Return an iterator over the list of components."""
5653
return iter(self._components)
5754

58-
def add(self, component, position, ref_factor=1.0):
55+
def add(self, component, position):
5956
"""Add a component to the list of components.
6057
6158
Parameters
@@ -65,17 +62,14 @@ def add(self, component, position, ref_factor=1.0):
6562
position : int, float
6663
The position of the component relative to the rocket's
6764
coordinate system origin.
68-
ref_factor : int, float, optional
69-
Reference-area correction factor associating the component to the
70-
rocket reference area. Defaults to 1.0 when not applicable.
7165
7266
Returns
7367
-------
7468
None
7569
"""
7670
self.__component_list.append(component)
7771
self.__position_list.append(position)
78-
self._components.append(self.component_tuple(component, position, ref_factor))
72+
self._components.append(self.component_tuple(component, position))
7973

8074
def get_by_type(self, component_type):
8175
"""Search the list of components and return a list with all the
@@ -213,11 +207,7 @@ def sort_by_position(self, reverse=False):
213207
def to_dict(self, **kwargs): # pylint: disable=unused-argument
214208
return {
215209
"components": [
216-
{
217-
"component": c.component,
218-
"position": c.position,
219-
"ref_factor": c.ref_factor,
220-
}
210+
{"component": c.component, "position": c.position}
221211
for c in self._components
222212
]
223213
}
@@ -226,9 +216,5 @@ def to_dict(self, **kwargs): # pylint: disable=unused-argument
226216
def from_dict(cls, data):
227217
components = cls()
228218
for component in data["components"]:
229-
components.add(
230-
component["component"],
231-
component["position"],
232-
ref_factor=component.get("ref_factor", 1.0),
233-
)
219+
components.add(component["component"], component["position"])
234220
return components

‎rocketpy/rocket/rocket.py‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,11 @@ def evaluate_center_of_pressure(self):
667667

668668
# Calculate total lift coefficient derivative and center of pressure
669669
if len(self.aerodynamic_surfaces) > 0:
670-
for aero_surface, position, ref_factor in self.aerodynamic_surfaces:
670+
for aero_surface, position in self.aerodynamic_surfaces:
671671
if isinstance(aero_surface, GenericSurface):
672672
continue
673673
# ref_factor corrects lift for different reference areas
674+
ref_factor = (aero_surface.rocket_radius / self.radius) ** 2
674675
self.total_lift_coeff_der += ref_factor * aero_surface.clalpha
675676
self.cp_position += (
676677
ref_factor
@@ -693,7 +694,7 @@ def evaluate_surfaces_cp_to_cdm(self):
693694
Dictionary mapping the relative position of each aerodynamic
694695
surface center of pressure to the rocket's center of mass.
695696
"""
696-
for surface, position, _ref_factor in self.aerodynamic_surfaces:
697+
for surface, position in self.aerodynamic_surfaces:
697698
self.__evaluate_single_surface_cp_to_cdm(surface, position)
698699
return self.surfaces_cp_to_cdm
699700

@@ -818,7 +819,7 @@ def warn_if_unstable(self):
818819
"""
819820
has_generic_surface = any(
820821
isinstance(aero_surface, GenericSurface)
821-
for aero_surface, _position, _ref_factor in self.aerodynamic_surfaces
822+
for aero_surface, _position in self.aerodynamic_surfaces
822823
)
823824
if has_generic_surface:
824825
return False
@@ -1193,12 +1194,7 @@ def __add_single_surface(self, surface, position):
11931194
self.rail_buttons = Components()
11941195
self.rail_buttons.add(surface, position)
11951196
else:
1196-
# ref_factor corrects lift for different reference areas
1197-
if getattr(surface, "rocket_radius", None) is not None:
1198-
ref_factor = (surface.rocket_radius / self.radius) ** 2
1199-
else:
1200-
ref_factor = 1.0
1201-
self.aerodynamic_surfaces.add(surface, position, ref_factor=ref_factor)
1197+
self.aerodynamic_surfaces.add(surface, position)
12021198
self.__evaluate_single_surface_cp_to_cdm(surface, position)
12031199

12041200
def add_surfaces(self, surfaces, positions):
@@ -2371,14 +2367,10 @@ def from_dict(cls, data):
23712367
position=data["motor_position"],
23722368
)
23732369

2374-
# The trailing star reads entries of either length: files written
2375-
# before ref_factor was stored carry two fields and newer ones three.
2376-
# The factor is not read back in any case, since add_surfaces derives
2377-
# it from the surface's own radius.
2378-
for surface, position, *_ in data["aerodynamic_surfaces"]:
2370+
for surface, position in data["aerodynamic_surfaces"]:
23792371
rocket.add_surfaces(surfaces=surface, positions=position)
23802372

2381-
for button, position, *_ in data["rail_buttons"]:
2373+
for button, position in data["rail_buttons"]:
23822374
rocket.set_rail_buttons(
23832375
upper_button_position=position[2] + button.buttons_distance,
23842376
lower_button_position=position[2],
@@ -2389,7 +2381,7 @@ def from_dict(cls, data):
23892381
for parachute in data["parachutes"]:
23902382
rocket.parachutes.append(parachute)
23912383

2392-
for sensor, position, *_ in data["sensors"]:
2384+
for sensor, position in data["sensors"]:
23932385
rocket.add_sensor(sensor, position)
23942386

23952387
for air_brake in data["air_brakes"]:

‎rocketpy/simulation/flight.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def __measure_sensors(self, component_sensors, u_dot, t=None, y_sol=None):
889889
Parameters
890890
----------
891891
component_sensors : list
892-
List of (sensor, position, ref_factor) component tuples.
892+
List of (sensor, position) tuples.
893893
u_dot : array_like
894894
State derivative vector.
895895
t : float, optional
@@ -902,7 +902,7 @@ def __measure_sensors(self, component_sensors, u_dot, t=None, y_sol=None):
902902
if y_sol is None:
903903
y_sol = self.y_sol
904904

905-
for sensor, position, _ref_factor in component_sensors:
905+
for sensor, position in component_sensors:
906906
relative_position = position - self.rocket._csys * Vector(
907907
[0, 0, self.rocket.center_of_dry_mass_position]
908908
)
@@ -2338,7 +2338,7 @@ def u_dot(self, t, u, post_processing=False): # pylint: disable=too-many-locals
23382338
# Calculate lift and moment for each component of the rocket
23392339
velocity_in_body_frame = Vector([vx_b, vy_b, vz_b])
23402340
w = Vector([omega1, omega2, omega3])
2341-
for aero_surface, _, _ref_factor in self.rocket.aerodynamic_surfaces:
2341+
for aero_surface, _ in self.rocket.aerodynamic_surfaces:
23422342
# Component cp relative to CDM in body frame
23432343
comp_cp = self.rocket.surfaces_cp_to_cdm[aero_surface]
23442344
# Component absolute velocity in body frame
@@ -2594,7 +2594,7 @@ def u_dot_generalized_3dof(self, t, u, post_processing=False):
25942594
# Velocity in body frame
25952595
vb_body = Kt @ v
25962596

2597-
for surface, _, _ref_factor in self.rocket.aerodynamic_surfaces:
2597+
for surface, _ in self.rocket.aerodynamic_surfaces:
25982598
cp = self.rocket.surfaces_cp_to_cdm[surface]
25992599
vb_component = vb_body + (w ^ cp)
26002600

@@ -2866,7 +2866,7 @@ def u_dot_generalized(self, t, u, post_processing=False): # pylint: disable=too
28662866
# Get rocket velocity in body frame
28672867
velocity_in_body_frame = Kt @ v
28682868
# Calculate lift and moment for each component of the rocket
2869-
for aero_surface, _, _ref_factor in self.rocket.aerodynamic_surfaces:
2869+
for aero_surface, _ in self.rocket.aerodynamic_surfaces:
28702870
# Component cp relative to CDM in body frame
28712871
comp_cp = self.rocket.surfaces_cp_to_cdm[aero_surface]
28722872
# Component absolute velocity in body frame

‎rocketpy/stochastic/stochastic_rocket.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def __reset_components(self, components, root):
233233
input component.
234234
"""
235235
new_components = Components()
236-
for stochastic_obj, _position, _ref_factor in components:
236+
for stochastic_obj, _ in components:
237237
stochastic_obj_position_info = self.__components_map[stochastic_obj]
238238
stochastic_obj._set_stochastic(_seed_sequence_to_int(root.spawn(1)[0]))
239239
new_components.add(

‎tests/unit/rocket/test_components.py‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎tests/unit/rocket/test_rocket.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,7 @@ def test_add_trapezoidal_fins_two_fins_warns_but_succeeds(calisto):
994994
fins = calisto.add_trapezoidal_fins(
995995
2, span=0.1, root_chord=0.12, tip_chord=0.04, position=-1.0
996996
)
997-
assert fins in [
998-
surface for surface, _position, _ref_factor in calisto.aerodynamic_surfaces
999-
]
997+
assert fins in [surface for surface, _ in calisto.aerodynamic_surfaces]
1000998

1001999

10021000
def test_unstable_rocket_warning_raised(calisto):

0 commit comments

Comments
 (0)