diff --git a/CHANGELOG.md b/CHANGELOG.md index b2de3b092..8de78d469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Attention: The newest changes should be on top --> ### Changed +- ENH: Resolve pressure_ISA discretization bounds TODO [#1056](https://github.com/RocketPy-Team/RocketPy/pull/1056) - ENH: Refactor flight.py latitude/longitude to use inverted_haversine [#1055](https://github.com/RocketPy-Team/RocketPy/pull/1055) ### Deprecated diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index c4c1ed298..e4774038a 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -2553,7 +2553,11 @@ def pressure_function(h): return P # Discretize this Function to speed up the trajectory simulation - altitudes = np.linspace(0, 80000, 100) # TODO: should be -2k instead of 0 + min_height = geopotential_height_to_geometric_height(-2000, earth_radius) + max_height = geopotential_height_to_geometric_height(80000, earth_radius) + altitudes_below = np.linspace(min_height, 0, 10, endpoint=False) + altitudes_above = np.linspace(0, max_height, 90) + altitudes = np.concatenate((altitudes_below, altitudes_above)) pressures = [pressure_function(h) for h in altitudes] return np.column_stack([altitudes, pressures]) diff --git a/tests/integration/simulation/test_flight.py b/tests/integration/simulation/test_flight.py index a69729e2f..5b870847b 100644 --- a/tests/integration/simulation/test_flight.py +++ b/tests/integration/simulation/test_flight.py @@ -460,7 +460,7 @@ def test_freestream_speed_at_apogee(example_plain_env, calisto): assert np.isclose( test_flight.stream_velocity_x(test_flight.apogee_time), - 0.4641492104717301, + 0.46416088113985227, atol=hard_atol, ) assert np.isclose( @@ -472,11 +472,11 @@ def test_freestream_speed_at_apogee(example_plain_env, calisto): ) assert np.isclose( test_flight.free_stream_speed(test_flight.apogee_time), - 0.4641492104717798, + 0.46416088113985277, atol=hard_atol, ) assert np.isclose( - test_flight.apogee_freestream_speed, 0.4641492104717798, atol=hard_atol + test_flight.apogee_freestream_speed, 0.46416088113985277, atol=hard_atol ) diff --git a/tests/unit/environment/test_environment.py b/tests/unit/environment/test_environment.py index d56332e27..249af9e9c 100644 --- a/tests/unit/environment/test_environment.py +++ b/tests/unit/environment/test_environment.py @@ -707,3 +707,27 @@ def test_pressure_conversion_factor_autodetect_by_model( None, None, model ) assert factor == expected_factor + + +def test_pressure_isa_discretization_bounds(example_plain_env): + """Test that pressure_ISA contains the expected range of altitudes + starting from the minimum geopotential height (-2000m) converted to + geometric height, up to the maximum (80000m) geopotential height converted to + geometric height. + """ + from rocketpy.tools import geopotential_height_to_geometric_height + + # Act + pressure_isa_function = example_plain_env.pressure_ISA + source_array = pressure_isa_function.source + altitudes = source_array[:, 0] + + # Expected min/max geometric heights + earth_radius = example_plain_env.earth_radius + expected_min_height = geopotential_height_to_geometric_height(-2000, earth_radius) + expected_max_height = geopotential_height_to_geometric_height(80000, earth_radius) + + # Assert + assert np.isclose(altitudes[0], expected_min_height) + assert np.isclose(altitudes[-1], expected_max_height) + assert len(altitudes) == 100