Skip to content

Commit

Permalink
Better CI (#851)
Browse files Browse the repository at this point in the history
* Better CI

* Docs for Tsiolkovsky formula

* Fix naming

---------

Co-authored-by: Andrey Lekar <[email protected]>
  • Loading branch information
blackyblack and Andrey Lekar authored Jul 13, 2024
1 parent 5c9d82f commit b6ea0f0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,70 @@
validate_output,
)

## Law is: M2 / M1 = ((1 - (V / c)) / (1 + (V / c)))^(c / (2 * I)), where
## V - final speed of the rocket,
## I- specific impulse of a rocket engine,
## M1 - initial mass of the rocket,
## M2 - final mass of the rocket,
## c - speed of light.

speed = Symbol("speed", units.velocity)
"""
Final speed of the rocket
Symbol:
V
"""

exhaust_velocity = Symbol("exhaust_velocity", units.velocity)
"""
Effective exhaust velocity of a rocket engine
Symbol:
Ve
Latex:
:math:`V_e`
"""

specific_impulse = Symbol("specific_impulse", units.velocity)
initial_mass = clone_symbol(symbols.basic.mass, "initial_mass")
"""
Initial mass of the rocket
Symbol:
M1
Latex:
:math:`M_1`
"""

final_mass = clone_symbol(symbols.basic.mass, "final_mass")
"""
Final mass of the rocket
Symbol:
M2
Latex:
:math:`M_2`
"""

law = Eq(final_mass / initial_mass, ((1 - (speed / speed_of_light)) / (1 +
(speed / speed_of_light)))**(speed_of_light / (2 * specific_impulse)))
(speed / speed_of_light)))**(speed_of_light / (2 * exhaust_velocity)))
r"""
M2 / M1 = ((1 - (V / c)) / (1 + (V / c)))^(c / (2 * Ve))
Latex:
:math:`M_2 / M_1 = ((1 - (V / c)) / (1 + (V / c)))^{c / (2 * V_e)}`
"""


def print_law() -> str:
return print_expression(law)


@validate_input(specific_impulse_=specific_impulse,
@validate_input(exhaust_velocity_=exhaust_velocity,
initial_mass_=initial_mass,
final_mass_=final_mass)
@validate_output(speed)
def calculate_speed(specific_impulse_: Quantity, initial_mass_: Quantity,
def calculate_speed(exhaust_velocity_: Quantity, initial_mass_: Quantity,
final_mass_: Quantity) -> Quantity:
result_expr = solve(law, speed, dict=True)[0][speed]
result_expr = result_expr.subs({
specific_impulse: specific_impulse_,
exhaust_velocity: exhaust_velocity_,
initial_mass: initial_mass_,
final_mass: final_mass_
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,43 @@
from symplyphysics.laws.astronomy.relativistic import relative_speed_of_rocket_depends_on_mass_and_impulse as speed_law

# Description
## Let the specific impulse be equal to the speed of light. Then, with an initial mass of 72200 tons and
## Let the exhaust velocity be equal to the speed of light. Then, with an initial mass of 72200 tons and
## a final mass of 200 tons, the speed will be 299787857 meters per second.
## https://scask.ru/d_book_msp.php?id=164

Args = namedtuple("Args", ["specific_impulse", "initial_mass", "final_mass"])
Args = namedtuple("Args", ["exhaust_velocity", "initial_mass", "final_mass"])


@fixture(name="test_args")
def test_args_fixture() -> Args:
# specific_impulse = Quantity(270000 * units.meter / units.second)
specific_impulse = speed_of_light
exhaust_velocity = speed_of_light
initial_mass = Quantity(72200 * units.tonne)
final_mass = Quantity(200 * units.tonne)

return Args(specific_impulse=specific_impulse, initial_mass=initial_mass, final_mass=final_mass)
return Args(exhaust_velocity=exhaust_velocity, initial_mass=initial_mass, final_mass=final_mass)


def test_basic_speed(test_args: Args) -> None:
result = speed_law.calculate_speed(test_args.specific_impulse, test_args.initial_mass,
result = speed_law.calculate_speed(test_args.exhaust_velocity, test_args.initial_mass,
test_args.final_mass)
assert_equal(result, 299787857 * units.meter / units.second)


def test_bad_specific_impulse(test_args: Args) -> None:
specific_impulse = Quantity(1 * units.coulomb)
def test_bad_exhaust_velocity(test_args: Args) -> None:
exhaust_velocity = Quantity(1 * units.coulomb)
with raises(errors.UnitsError):
speed_law.calculate_speed(specific_impulse, test_args.initial_mass, test_args.final_mass)
speed_law.calculate_speed(exhaust_velocity, test_args.initial_mass, test_args.final_mass)
with raises(TypeError):
speed_law.calculate_speed(100, test_args.initial_mass, test_args.final_mass)


def test_bad_mass(test_args: Args) -> None:
bad_mass = Quantity(1 * units.coulomb)
with raises(errors.UnitsError):
speed_law.calculate_speed(test_args.specific_impulse, bad_mass, test_args.final_mass)
speed_law.calculate_speed(test_args.exhaust_velocity, bad_mass, test_args.final_mass)
with raises(TypeError):
speed_law.calculate_speed(test_args.specific_impulse, 100, test_args.final_mass)
speed_law.calculate_speed(test_args.exhaust_velocity, 100, test_args.final_mass)
with raises(errors.UnitsError):
speed_law.calculate_speed(test_args.specific_impulse, test_args.initial_mass, bad_mass)
speed_law.calculate_speed(test_args.exhaust_velocity, test_args.initial_mass, bad_mass)
with raises(TypeError):
speed_law.calculate_speed(test_args.specific_impulse, test_args.initial_mass, 100)
speed_law.calculate_speed(test_args.exhaust_velocity, test_args.initial_mass, 100)

0 comments on commit b6ea0f0

Please sign in to comment.