diff --git a/tests/conftest.py b/tests/conftest.py index 3494a3bd9..3daed0cc8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,24 +1,20 @@ import pytest - -# Pytest configuration - pytest_plugins = [ "tests.fixtures.environment.environment_fixtures", "tests.fixtures.flight.flight_fixtures", "tests.fixtures.function.function_fixtures", + "tests.fixtures.motor.liquid_fixtures", "tests.fixtures.motor.hybrid_fixtures", "tests.fixtures.motor.solid_motor_fixtures", - "tests.fixtures.motor.liquid_fixtures", + "tests.fixtures.motor.tanks_fixtures", "tests.fixtures.motor.generic_motor_fixtures", "tests.fixtures.parachutes.parachute_fixtures", "tests.fixtures.rockets.rocket_fixtures", "tests.fixtures.surfaces.surface_fixtures", - "tests.fixtures.units.numerical_fixtures", + "tests.fixtures.units.numerical_fixtures" ] -# - def pytest_addoption(parser): """Add option to run slow tests. This is used to skip slow tests by default. diff --git a/tests/fixtures/motor/liquid_fixtures.py b/tests/fixtures/motor/liquid_fixtures.py index c6fa697ef..85a17e3a4 100644 --- a/tests/fixtures/motor/liquid_fixtures.py +++ b/tests/fixtures/motor/liquid_fixtures.py @@ -1,16 +1,6 @@ -import numpy as np import pytest -from rocketpy import ( - CylindricalTank, - Fluid, - Function, - LevelBasedTank, - LiquidMotor, - MassBasedTank, - SphericalTank, - UllageBasedTank, -) +from rocketpy import Fluid, LiquidMotor @pytest.fixture @@ -78,102 +68,6 @@ def oxidizer_fluid(): return Fluid(name="O2", density=1000) -@pytest.fixture -def pressurant_tank(pressurant_fluid): - """An example of a pressurant cylindrical tank with spherical - caps. - - Parameters - ---------- - pressurant_fluid : rocketpy.Fluid - Pressurizing fluid. This is a pytest fixture. - - Returns - ------- - rocketpy.MassBasedTank - An object of the CylindricalTank class. - """ - geometry = CylindricalTank(0.135 / 2, 0.981, spherical_caps=True) - pressurant_tank = MassBasedTank( - name="Pressure Tank", - geometry=geometry, - liquid_mass=0, - flux_time=(8, 20), - gas_mass="data/SEBLM/pressurantMassFiltered.csv", - gas=pressurant_fluid, - liquid=pressurant_fluid, - ) - - return pressurant_tank - - -@pytest.fixture -def fuel_tank(fuel_fluid, fuel_pressurant): - """An example of a fuel cylindrical tank with spherical - caps. - - Parameters - ---------- - fuel_fluid : rocketpy.Fluid - Fuel fluid of the tank. This is a pytest fixture. - fuel_pressurant : rocketpy.Fluid - Pressurizing fluid of the fuel tank. This is a pytest - fixture. - - Returns - ------- - rocketpy.UllageBasedTank - """ - geometry = CylindricalTank(0.0744, 0.8068, spherical_caps=True) - ullage = ( - -Function("data/SEBLM/test124_Propane_Volume.csv") * 1e-3 - + geometry.total_volume - ) - fuel_tank = UllageBasedTank( - name="Propane Tank", - flux_time=(8, 20), - geometry=geometry, - liquid=fuel_fluid, - gas=fuel_pressurant, - ullage=ullage, - ) - - return fuel_tank - - -@pytest.fixture -def oxidizer_tank(oxidizer_fluid, oxidizer_pressurant): - """An example of a oxidizer cylindrical tank with spherical - caps. - - Parameters - ---------- - oxidizer_fluid : rocketpy.Fluid - Oxidizer fluid of the tank. This is a pytest fixture. - oxidizer_pressurant : rocketpy.Fluid - Pressurizing fluid of the oxidizer tank. This is a pytest - fixture. - - Returns - ------- - rocketpy.UllageBasedTank - """ - geometry = CylindricalTank(0.0744, 0.8068, spherical_caps=True) - ullage = ( - -Function("data/SEBLM/test124_Lox_Volume.csv") * 1e-3 + geometry.total_volume - ) - oxidizer_tank = UllageBasedTank( - name="Lox Tank", - flux_time=(8, 20), - geometry=geometry, - liquid=oxidizer_fluid, - gas=oxidizer_pressurant, - ullage=ullage, - ) - - return oxidizer_tank - - @pytest.fixture def liquid_motor(pressurant_tank, fuel_tank, oxidizer_tank): """An example of a liquid motor with pressurant, fuel and oxidizer tanks. @@ -205,33 +99,3 @@ def liquid_motor(pressurant_tank, fuel_tank, oxidizer_tank): liquid_motor.add_tank(oxidizer_tank, position=0.711) return liquid_motor - - -@pytest.fixture -def spherical_oxidizer_tank(oxidizer_fluid, oxidizer_pressurant): - """An example of a oxidizer spherical tank. - - Parameters - ---------- - oxidizer_fluid : rocketpy.Fluid - Oxidizer fluid of the tank. This is a pytest fixture. - oxidizer_pressurant : rocketpy.Fluid - Pressurizing fluid of the oxidizer tank. This is a pytest - fixture. - - Returns - ------- - rocketpy.UllageBasedTank - """ - geometry = SphericalTank(0.05) - liquid_level = Function(lambda t: 0.1 * np.exp(-t / 2) - 0.05) - oxidizer_tank = LevelBasedTank( - name="Lox Tank", - flux_time=10, - geometry=geometry, - liquid=oxidizer_fluid, - gas=oxidizer_pressurant, - liquid_height=liquid_level, - ) - - return oxidizer_tank diff --git a/tests/fixtures/motor/tanks_fixtures.py b/tests/fixtures/motor/tanks_fixtures.py new file mode 100644 index 000000000..4238e1e1e --- /dev/null +++ b/tests/fixtures/motor/tanks_fixtures.py @@ -0,0 +1,137 @@ +import numpy as np +import pytest + +from rocketpy import ( + CylindricalTank, + Function, + LevelBasedTank, + MassBasedTank, + SphericalTank, + UllageBasedTank, +) + + +@pytest.fixture +def pressurant_tank(pressurant_fluid): + """An example of a pressurant cylindrical tank with spherical + caps. + + Parameters + ---------- + pressurant_fluid : rocketpy.Fluid + Pressurizing fluid. This is a pytest fixture. + + Returns + ------- + rocketpy.MassBasedTank + An object of the CylindricalTank class. + """ + geometry = CylindricalTank(0.135 / 2, 0.981, spherical_caps=True) + pressurant_tank = MassBasedTank( + name="Pressure Tank", + geometry=geometry, + liquid_mass=0, + flux_time=(8, 20), + gas_mass="data/SEBLM/pressurantMassFiltered.csv", + gas=pressurant_fluid, + liquid=pressurant_fluid, + ) + + return pressurant_tank + + +@pytest.fixture +def fuel_tank(fuel_fluid, fuel_pressurant): + """An example of a fuel cylindrical tank with spherical + caps. + + Parameters + ---------- + fuel_fluid : rocketpy.Fluid + Fuel fluid of the tank. This is a pytest fixture. + fuel_pressurant : rocketpy.Fluid + Pressurizing fluid of the fuel tank. This is a pytest + fixture. + + Returns + ------- + rocketpy.UllageBasedTank + """ + geometry = CylindricalTank(0.0744, 0.8068, spherical_caps=True) + ullage = ( + -Function("data/SEBLM/test124_Propane_Volume.csv") * 1e-3 + + geometry.total_volume + ) + fuel_tank = UllageBasedTank( + name="Propane Tank", + flux_time=(8, 20), + geometry=geometry, + liquid=fuel_fluid, + gas=fuel_pressurant, + ullage=ullage, + ) + + return fuel_tank + + +@pytest.fixture +def oxidizer_tank(oxidizer_fluid, oxidizer_pressurant): + """An example of a oxidizer cylindrical tank with spherical + caps. + + Parameters + ---------- + oxidizer_fluid : rocketpy.Fluid + Oxidizer fluid of the tank. This is a pytest fixture. + oxidizer_pressurant : rocketpy.Fluid + Pressurizing fluid of the oxidizer tank. This is a pytest + fixture. + + Returns + ------- + rocketpy.UllageBasedTank + """ + geometry = CylindricalTank(0.0744, 0.8068, spherical_caps=True) + ullage = ( + -Function("data/SEBLM/test124_Lox_Volume.csv") * 1e-3 + geometry.total_volume + ) + oxidizer_tank = UllageBasedTank( + name="Lox Tank", + flux_time=(8, 20), + geometry=geometry, + liquid=oxidizer_fluid, + gas=oxidizer_pressurant, + ullage=ullage, + ) + + return oxidizer_tank + + +@pytest.fixture +def spherical_oxidizer_tank(oxidizer_fluid, oxidizer_pressurant): + """An example of a oxidizer spherical tank. + + Parameters + ---------- + oxidizer_fluid : rocketpy.Fluid + Oxidizer fluid of the tank. This is a pytest fixture. + oxidizer_pressurant : rocketpy.Fluid + Pressurizing fluid of the oxidizer tank. This is a pytest + fixture. + + Returns + ------- + rocketpy.UllageBasedTank + """ + geometry = SphericalTank(0.05) + liquid_level = Function(lambda t: 0.1 * np.exp(-t / 2) - 0.05) + oxidizer_tank = LevelBasedTank( + name="Lox Tank", + flux_time=10, + geometry=geometry, + liquid=oxidizer_fluid, + gas=oxidizer_pressurant, + liquid_height=liquid_level, + ) + + return oxidizer_tank