Skip to content

Commit a011c5a

Browse files
Merge pull request #585 from RocketPy-Team/enh/swap-diff-for-flow-rate
BUG: Swap `rocket.total_mass.differentiate` for `motor.total_mass_flow rate`
2 parents 624cc15 + 6b26f61 commit a011c5a

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4545

4646
### Fixed
4747

48+
- BUG: Swap rocket.total_mass.differentiate for motor.total_mass_flow rate [#585](https://github.com/RocketPy-Team/RocketPy/pull/585)
4849
- BUG: export_eng 'Motor' method would not work for liquid motors. [#559](https://github.com/RocketPy-Team/RocketPy/pull/559)
4950

5051
## [v1.2.2] - 2024-03-22

rocketpy/rocket/rocket.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class Rocket:
8181
Function of time expressing the total mass of the rocket,
8282
defined as the sum of the propellant mass and the rocket
8383
mass without propellant.
84+
Rocket.total_mass_flow_rate : Function
85+
Time derivative of rocket's total mass in kg/s as a function
86+
of time as obtained by the thrust source of the added motor.
8487
Rocket.thrust_to_weight : Function
8588
Function of time expressing the motor thrust force divided by rocket
8689
weight. The gravitational acceleration is assumed as 9.80665 m/s^2.
@@ -764,6 +767,7 @@ def add_motor(self, motor, position):
764767
self.motor.center_of_dry_mass_position * _ + self.motor_position
765768
)
766769
self.nozzle_position = self.motor.nozzle_position * _ + self.motor_position
770+
self.total_mass_flow_rate = self.motor.total_mass_flow_rate
767771
self.evaluate_dry_mass()
768772
self.evaluate_total_mass()
769773
self.evaluate_center_of_dry_mass()

rocketpy/simulation/flight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,8 @@ def u_dot_generalized(self, t, u, post_processing=False):
16451645
# Retrieve necessary quantities
16461646
rho = self.env.density.get_value_opt(z)
16471647
total_mass = self.rocket.total_mass.get_value_opt(t)
1648-
total_mass_dot = self.rocket.total_mass.differentiate(t)
1649-
total_mass_ddot = self.rocket.total_mass.differentiate(t, order=2)
1648+
total_mass_dot = self.rocket.total_mass_flow_rate.get_value_opt(t)
1649+
total_mass_ddot = self.rocket.total_mass_flow_rate.differentiate(t)
16501650
## CM position vector and time derivatives relative to CDM in body frame
16511651
r_CM_z = (
16521652
-1

tests/test_flight.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,12 @@ def test_max_values(flight_calisto_robust):
604604
calculated by hand, it was just copied from the test results. This is
605605
because the expected values are not easy to calculate by hand, and the
606606
results are not expected to change. If the results change, the test will
607-
fail, and the expected values must be updated. If if want to update the
608-
values, always double check if the results are really correct. Acceptable
609-
reasons for changes in the results are: 1) changes in the code that
610-
improve the accuracy of the simulation, 2) a bug was found and fixed. Keep
611-
in mind that other tests may be more accurate than this one, for example,
612-
the acceptance tests, which are based on the results of real flights.
607+
fail, and the expected values must be updated. If the values are updated,
608+
always double check if the results are really correct. Acceptable reasons
609+
for changes in the results are: 1) changes in the code that improve the
610+
accuracy of the simulation, 2) a bug was found and fixed. Keep in mind that
611+
other tests may be more accurate than this one, for example, the acceptance
612+
tests, which are based on the results of real flights.
613613
614614
Parameters
615615
----------
@@ -622,7 +622,7 @@ def test_max_values(flight_calisto_robust):
622622
assert pytest.approx(105.2774, abs=atol) == test.max_acceleration_power_on
623623
assert pytest.approx(105.2774, abs=atol) == test.max_acceleration
624624
assert pytest.approx(0.85999, abs=atol) == test.max_mach_number
625-
assert pytest.approx(285.90240, abs=atol) == test.max_speed
625+
assert pytest.approx(285.94948, abs=atol) == test.max_speed
626626

627627

628628
def test_rail_buttons_forces(flight_calisto_custom_wind):

0 commit comments

Comments
 (0)