From 01efe3e925e5cea2c72efe6392a0e0225a3d6d9c Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Mon, 2 Oct 2023 22:41:28 -0300 Subject: [PATCH] TST: implement parametrized test for motor coordinates. --- tests/conftest.py | 63 ++++++++++++++++++++++++-------------------- tests/test_rocket.py | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 29 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e9b0f71dc..e77799b3a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -111,16 +111,10 @@ def cesaroni_m1670(): # old name: solid_motor @pytest.fixture -def calisto(cesaroni_m1670): # old name: rocket +def calisto_motorless(): """Create a simple object of the Rocket class to be used in the tests. This - is the same rocket that has been used in the getting started guide for - years. The Calisto rocket is the Projeto Jupiter's project launched at the - 2019 Spaceport America Cup. - - Parameters - ---------- - cesaroni_m1670 : rocketpy.SolidMotor - An object of the SolidMotor class. This is a pytest fixture too. + is the same rocket that has been used in the getting started guide for years + but without a motor. Returns ------- @@ -136,17 +130,42 @@ def calisto(cesaroni_m1670): # old name: rocket center_of_mass_without_motor=0, coordinate_system_orientation="tail_to_nose", ) + return calisto + + +@pytest.fixture +def calisto(calisto_motorless, cesaroni_m1670): # old name: rocket + """Create a simple object of the Rocket class to be used in the tests. This + is the same rocket that has been used in the getting started guide for + years. The Calisto rocket is the Projeto Jupiter's project launched at the + 2019 Spaceport America Cup. + + Parameters + ---------- + calisto_motorless : rocketpy.Rocket + An object of the Rocket class. This is a pytest fixture too. + cesaroni_m1670 : rocketpy.SolidMotor + An object of the SolidMotor class. This is a pytest fixture too. + + Returns + ------- + rocketpy.Rocket + A simple object of the Rocket class + """ + calisto = calisto_motorless calisto.add_motor(cesaroni_m1670, position=-1.373) return calisto @pytest.fixture -def calisto_liquid_modded(liquid_motor): +def calisto_liquid_modded(calisto_motorless, liquid_motor): """Create a simple object of the Rocket class to be used in the tests. This is an example of the Calisto rocket with a liquid motor. Parameters ---------- + calisto_motorless : rocketpy.Rocket + An object of the Rocket class. This is a pytest fixture too. liquid_motor : rocketpy.LiquidMotor Returns @@ -154,26 +173,20 @@ def calisto_liquid_modded(liquid_motor): rocketpy.Rocket A simple object of the Rocket class """ - calisto = Rocket( - radius=0.0635, - mass=14.426, - inertia=(6.321, 6.321, 0.034), - power_off_drag="data/calisto/powerOffDragCurve.csv", - power_on_drag="data/calisto/powerOnDragCurve.csv", - center_of_mass_without_motor=0, - coordinate_system_orientation="tail_to_nose", - ) + calisto = calisto_motorless calisto.add_motor(liquid_motor, position=-1.373) return calisto @pytest.fixture -def calisto_hybrid_modded(hybrid_motor): +def calisto_hybrid_modded(calisto_motorless, hybrid_motor): """Create a simple object of the Rocket class to be used in the tests. This is an example of the Calisto rocket with a hybrid motor. Parameters ---------- + calisto_motorless : rocketpy.Rocket + An object of the Rocket class. This is a pytest fixture too. hybrid_motor : rocketpy.HybridMotor Returns @@ -181,15 +194,7 @@ def calisto_hybrid_modded(hybrid_motor): rocketpy.Rocket A simple object of the Rocket class """ - calisto = Rocket( - radius=0.0635, - mass=14.426, - inertia=(6.321, 6.321, 0.034), - power_off_drag="data/calisto/powerOffDragCurve.csv", - power_on_drag="data/calisto/powerOnDragCurve.csv", - center_of_mass_without_motor=0, - coordinate_system_orientation="tail_to_nose", - ) + calisto = calisto_motorless calisto.add_motor(hybrid_motor, position=-1.373) return calisto diff --git a/tests/test_rocket.py b/tests/test_rocket.py index 0eebdf1f7..d370379a1 100644 --- a/tests/test_rocket.py +++ b/tests/test_rocket.py @@ -379,6 +379,56 @@ def test_add_fins_assert_cp_cm_plus_fins(calisto, dimensionless_calisto, m): ) +@pytest.mark.parametrize( + """cdm_position, grain_cm_position, nozzle_position, coord_direction, + motor_position, expected_motor_cdm, expected_motor_cpp""", + [ + (0.317, 0.397, 0, "nozzle_to_combustion_chamber", -1.373, -1.056, -0.976), + (0, 0.08, -0.317, "nozzle_to_combustion_chamber", -1, -1, -0.92), + (-0.317, -0.397, 0, "combustion_chamber_to_nozzle", -1.373, -1.056, -0.976), + (0, -0.08, 0.317, "combustion_chamber_to_nozzle", -1, -1, -0.92), + (1.317, 1.397, 1, "nozzle_to_combustion_chamber", -2.373, -1.056, -0.976), + ], +) +def test_add_motor_coordinates( + calisto_motorless, + cdm_position, + grain_cm_position, + nozzle_position, + coord_direction, + motor_position, + expected_motor_cdm, + expected_motor_cpp, +): + example_motor = SolidMotor( + thrust_source="data/motors/Cesaroni_M1670.eng", + burn_time=3.9, + dry_mass=0, + dry_inertia=(0, 0, 0), + center_of_dry_mass_position=cdm_position, + nozzle_position=nozzle_position, + grain_number=5, + grain_density=1815, + nozzle_radius=33 / 1000, + throat_radius=11 / 1000, + grain_separation=5 / 1000, + grain_outer_radius=33 / 1000, + grain_initial_height=120 / 1000, + grains_center_of_mass_position=grain_cm_position, + grain_initial_inner_radius=15 / 1000, + interpolation_method="linear", + coordinate_system_orientation=coord_direction, + ) + calisto = calisto_motorless + calisto.add_motor(example_motor, position=motor_position) + + calculated_motor_cdm = calisto.motor_center_of_dry_mass_position + calculated_motor_cpp = calisto.center_of_propellant_position + + assert pytest.approx(expected_motor_cdm) == calculated_motor_cdm + assert pytest.approx(expected_motor_cpp) == calculated_motor_cpp(0) + + def test_add_cm_eccentricity_assert_properties_set(calisto): calisto.add_cm_eccentricity(x=4, y=5)