Skip to content

Commit bfea194

Browse files
MNT: compute the reference-area factor on demand in one helper
Rocket and its prints computed the same factor inline. The test pins that changing a surface's rocket_radius after adding it moves the static margin. Related to #1209 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDW574AQLHTSeBM9K172TX
1 parent 18c22ef commit bfea194

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎rocketpy/prints/rocket_prints.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def rocket_aerodynamics_quantities(self):
106106
if isinstance(surface, GenericSurface):
107107
continue
108108
name = surface.name
109-
# ref_factor corrects lift for different reference areas
110-
ref_factor = (surface.rocket_radius / self.rocket.radius) ** 2
109+
ref_factor = self.rocket._reference_area_factor(surface)
111110
print(
112111
f"{name} Lift Coefficient Derivative: "
113112
f"{ref_factor * surface.clalpha(0):.3f}/rad"

‎rocketpy/rocket/rocket.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,7 @@ def evaluate_center_of_pressure(self):
670670
for aero_surface, position in self.aerodynamic_surfaces:
671671
if isinstance(aero_surface, GenericSurface):
672672
continue
673-
# ref_factor corrects lift for different reference areas
674-
ref_factor = (aero_surface.rocket_radius / self.radius) ** 2
673+
ref_factor = self._reference_area_factor(aero_surface)
675674
self.total_lift_coeff_der += ref_factor * aero_surface.clalpha
676675
self.cp_position += (
677676
ref_factor
@@ -683,6 +682,11 @@ def evaluate_center_of_pressure(self):
683682
self.cp_position /= self.total_lift_coeff_der
684683
return self.cp_position
685684

685+
def _reference_area_factor(self, surface):
686+
"""Scales a surface's lift coefficient from its own reference area to
687+
the rocket's. Computed on demand so it follows later radius changes."""
688+
return (surface.rocket_radius / self.radius) ** 2
689+
686690
def evaluate_surfaces_cp_to_cdm(self):
687691
"""Calculates the relative position of each aerodynamic surface center
688692
of pressure to the rocket's center of dry mass in Body Axes Coordinate

‎tests/unit/rocket/test_rocket.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import warnings
23
from itertools import product
34
from unittest.mock import patch
@@ -1125,3 +1126,35 @@ def test_evaluate_reduced_mass_with_motor(calisto):
11251126
for t in [0.0, 1.0, 2.0, 3.0]:
11261127
expected = prop_mass(t) * dry_mass / (prop_mass(t) + dry_mass)
11271128
assert reduced_mass(t) == pytest.approx(expected)
1129+
1130+
1131+
def test_static_margin_follows_surface_radius_changed_after_adding(
1132+
calisto_motorless,
1133+
):
1134+
"""A surface's reference-area factor must reflect its current
1135+
rocket_radius, not the one it had when it was added."""
1136+
1137+
def add_aero(rocket, nose_radius):
1138+
nose = NoseCone(
1139+
length=0.55829,
1140+
kind="vonkarman",
1141+
base_radius=nose_radius,
1142+
rocket_radius=nose_radius,
1143+
)
1144+
rocket.add_surfaces(nose, 1.278)
1145+
rocket.add_trapezoidal_fins(
1146+
4, root_chord=0.120, tip_chord=0.060, span=0.110, position=-1.04956
1147+
)
1148+
return nose
1149+
1150+
fresh = copy.deepcopy(calisto_motorless)
1151+
add_aero(fresh, 0.0635)
1152+
1153+
changed = calisto_motorless
1154+
nose = add_aero(changed, 0.03)
1155+
nose.base_radius = 0.0635
1156+
nose.rocket_radius = 0.0635
1157+
changed.evaluate_center_of_pressure()
1158+
changed.evaluate_static_margin()
1159+
1160+
assert changed.static_margin(0) == pytest.approx(fresh.static_margin(0))

0 commit comments

Comments
 (0)