Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/simulation/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)


Expand Down
24 changes: 24 additions & 0 deletions tests/unit/environment/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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