Assigning rocket.power_off_drag after the Rocket is built has no effect on the flight
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Start with rocketpy/rocket/rocket.py, where power_off_drag and power_on_drag are assigned, and trace how the constructor builds power_off_drag_7d and power_on_drag_7d for rocketpy/simulation/flight.py. Use the supplied reproduction to verify that post-construction assignment changes the plotting attribute but not the flight result; a focused test should cover both drag settings. Update docs/examples/bella_lui_flight_sim.ipynb to pass its drag table to the Rocket constructor, and verify the example uses the intended curve.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
If you build a Rocket and then set its drag curve by assigning to rocket.power_off_drag (or rocket.power_on_drag), the simulation ignores the new curve. The assignment raises no error and gives no warning, and rocket.power_off_drag even shows the new curve when you plot or print it. But Flight keeps using the drag the Rocket was built with.
The shipped example docs/examples/bella_lui_flight_sim.ipynb does exactly this. As a result, it flies a constant drag coefficient of 0.43, not the Mach-dependent drag table it displays.
Why it happens
The Rocket keeps two versions of its drag:
| Attribute | What it is | Who reads it |
|---|---|---|
power_off_drag_7d / power_on_drag_7d |
The drag the simulation uses: a function of (α, β, Mach, Reynolds, pitch, yaw, roll rates) | Flight (e.g. rocketpy/simulation/flight.py, the power_off_drag_7d(alpha, beta, mach, reynolds, …) calls in the equations of motion) |
power_off_drag / power_on_drag |
A Mach-only copy for plotting and printing. The docstring calls it an "Alias for power_off_drag_by_mach" |
Plots and prints only |
rocketpy/rocket/rocket.py (v1.13.0, lines 399–424) builds power_off_drag_7d from the constructor argument and then sets:
self.power_off_drag = self.power_off_drag_by_mach
self.power_on_drag = self.power_on_drag_by_mach
These are plain attributes with no setter. Assigning a new Function to rocket.power_off_drag replaces only the plotting copy, and power_off_drag_7d is never rebuilt.
Where the example hits it
In docs/examples/bella_lui_flight_sim.ipynb:
- The Rocket is built with
power_off_drag=0.43, power_on_drag=0.43(constants). - A later cell ("Define aerodynamic drag coefficients") assigns the measured drag table:
bella_lui.power_off_drag = Function([(0.01, 0.51), (0.02, 0.46), …, (0.49, 0.46)], …), and the same forpower_on_drag. - The next lines scale them:
bella_lui.power_off_drag *= parameters.get("power_off_drag")[0].
Steps 2 and 3 have no effect on the flight. The flight uses the constant 0.43 from step 1.
The visible impact on this example is tiny, because the table (0.43 to 0.51) is close to 0.43 everywhere except at the lowest speeds. Passing the same table to the constructor instead moves the Bella Lui apogee by 3 mm (867.570 → 867.567 m on 1.13.0). A user who copies the pattern with a very different drag curve gets no change at all, and no hint why: in the script below, assigning Cd 0.9 after construction leaves the apogee exactly where Cd 0.5 put it, 355 m above where a rocket built with Cd 0.9 goes.
To Reproduce
Self-contained (no data files; constant-thrust motor, standard atmosphere, no wind):
from rocketpy import Environment, SolidMotor, Rocket, Flight, Function
env = Environment(latitude=0, longitude=0, elevation=0) # standard atmosphere, no wind
def build(cd):
motor = SolidMotor(
thrust_source=1500, burn_time=3.0, dry_mass=1.8,
dry_inertia=(0.125, 0.125, 0.002), center_of_dry_mass_position=0.317,
grains_center_of_mass_position=0.397, grain_number=5, grain_separation=0.005,
grain_density=1815, grain_outer_radius=0.033, grain_initial_inner_radius=0.015,
grain_initial_height=0.12, nozzle_radius=0.033, throat_radius=0.011,
nozzle_position=0, coordinate_system_orientation="nozzle_to_combustion_chamber",
)
rocket = Rocket(
radius=0.0635, mass=14.4, inertia=(6.32, 6.32, 0.034),
power_off_drag=cd, power_on_drag=cd,
center_of_mass_without_motor=0, coordinate_system_orientation="tail_to_nose",
)
rocket.add_motor(motor, position=-1.255)
rocket.add_nose(length=0.55829, kind="vonKarman", position=1.278)
rocket.add_trapezoidal_fins(n=4, root_chord=0.120, tip_chord=0.060, span=0.110, position=-1.04956)
return rocket
def apogee(rocket):
return Flight(rocket=rocket, environment=env, rail_length=5.2, inclination=85,
heading=0, terminate_on_apogee=True).apogee
r_05 = build(0.5)
r_09 = build(0.9)
r_assigned = build(0.5)
r_assigned.power_off_drag = Function(lambda mach: 0.9)
r_assigned.power_on_drag = Function(lambda mach: 0.9)
print("power_off_drag(0.3) after assignment:", r_assigned.power_off_drag(0.3))
print("power_off_drag_7d(...) after assignment:", r_assigned.power_off_drag_7d(0, 0, 0.3, 1e6, 0, 0, 0))
print(f"apogee, built with Cd 0.5 : {apogee(r_05):.3f} m")
print(f"apogee, built with Cd 0.9 : {apogee(r_09):.3f} m")
print(f"apogee, built 0.5 then assign 0.9 : {apogee(r_assigned):.3f} m")
Output on 1.13.0:
power_off_drag(0.3) after assignment: 0.9
power_off_drag_7d(...) after assignment: 0.5
apogee, built with Cd 0.5 : 1927.493 m
apogee, built with Cd 0.9 : 1572.779 m
apogee, built 0.5 then assign 0.9 : 1927.493 m
On develop the three apogees are 1928.149, 1573.304 and 1928.149 m: the same bug.
In the Bella Lui notebook itself, run the cells up to and including "Define aerodynamic drag coefficients", then add:
print(bella_lui.power_off_drag(0.01)) # 0.51 (the new table)
print(bella_lui.power_off_drag_7d(0, 0, 0.01, 1e6, 0, 0, 0)) # 0.43 (what Flight uses)
This prints 0.51 and 0.43 on both 1.13.0 and develop, and the same for power_on_drag.
Expected behavior
One of these, in order of preference:
- Assigning
rocket.power_off_drag/rocket.power_on_dragupdates the drag the flight uses. For example, make them properties whose setter re-runs the same processing the constructor uses, sopower_off_drag_7dis rebuilt. - Or assignment raises a clear error ("set drag in the Rocket constructor, or use …"), so it can't fail silently.
Separately, the Bella Lui notebook should pass its drag table to the Rocket(...) constructor (power_off_drag=Function([...]), which the constructor accepts) instead of assigning it afterwards.
Additional context
- Ran on RocketPy 1.13.0 from PyPI and on
develop@ b389b43 installed from source; Python 3.15.2, macOS arm64 (2026-11-27). - Checked on v1.13.0 (
master@ 9bd6ad3) and ondevelop@ b389b43 (2026-11-23). The lines above are unchanged ondevelop(there atrocket.py:424–425), and the notebook cells are unchanged. - Related but different: #1238 (drag CSVs that do not form a regular grid).
- This report was prepared with the assistance of Claude Opus 5.5.
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 280
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của RocketPy-Team/RocketPy
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
RocketPy-Team/RocketPy#1255 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
RocketPy-Team/RocketPy#1241 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
RocketPy-Team/RocketPy#1202 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Monte Carlo test fixtures write their logs into the working directoryCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
RocketPy-Team/RocketPy#1189 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
RocketPy-Team/RocketPy#1171 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của RocketPy-Team/RocketPy
Issue tương tự
-
docs(contributing): the two things that silently block a PRCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởavailable documentation good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 95/100
Nixitov/Riptide-Native#944 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
JTHCode/secretguard#24 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: middleware documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainer thường phản hồi trong vòng 1 ngày