Skip to content

Commit dc99084

Browse files
Merge pull request #581 from RocketPy-Team/mnt/flight-simulation-speed-up
ENH: Flight simulation speed up
2 parents 880afb1 + 80d85bb commit dc99084

File tree

14 files changed

+1262
-1202
lines changed

14 files changed

+1262
-1202
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3333
### Added
3434

3535
- ENH: Exponential backoff decorator (fix #449) [#588](https://github.com/RocketPy-Team/RocketPy/pull/588)
36+
- ENH: Function Validation Rework & Swap `np.searchsorted` to `bisect_left` [#582](https://github.com/RocketPy-Team/RocketPy/pull/582)
3637
- ENH: Add new stability margin properties to Flight class [#572](https://github.com/RocketPy-Team/RocketPy/pull/572)
3738
- ENH: adds `Function.remove_outliers` method [#554](https://github.com/RocketPy-Team/RocketPy/pull/554)
3839

3940
### Changed
4041

4142
- BLD: Change setup.py to pyproject.toml [#589](https://github.com/RocketPy-Team/RocketPy/pull/589)
42-
- DEP: delete deprecated rocketpy.tools.cached_property [#587](https://github.com/RocketPy-Team/RocketPy/pull/587)
43+
- DEP: delete deprecated rocketpy.tools.cached_property [#587](https://github.com/RocketPy-Team/RocketPy/pull/587)
44+
- ENH: Flight simulation speed up [#581] (https://github.com/RocketPy-Team/RocketPy/pull/581)
4345
- MNT: Modularize Rocket Draw [#580](https://github.com/RocketPy-Team/RocketPy/pull/580)
4446
- DOC: Improvements of Environment docstring phrasing [#565](https://github.com/RocketPy-Team/RocketPy/pull/565)
4547
- MNT: Refactor flight prints module [#579](https://github.com/RocketPy-Team/RocketPy/pull/579)

rocketpy/environment/environment.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,24 +1551,26 @@ def process_custom_atmosphere(
15511551
# Check maximum height of custom wind input
15521552
if not callable(self.wind_velocity_x.source):
15531553
max_expected_height = max(self.wind_velocity_x[-1, 0], max_expected_height)
1554-
if not callable(self.wind_velocity_y.source):
1555-
max_expected_height = max(self.wind_velocity_y[-1, 0], max_expected_height)
15561554

1557-
# Compute wind profile direction and heading
1558-
wind_heading = (
1559-
lambda h: np.arctan2(self.wind_velocity_x(h), self.wind_velocity_y(h))
1560-
* (180 / np.pi)
1561-
% 360
1562-
)
1555+
def wind_heading_func(h):
1556+
return (
1557+
np.arctan2(
1558+
self.wind_velocity_x.get_value_opt(h),
1559+
self.wind_velocity_y.get_value_opt(h),
1560+
)
1561+
* (180 / np.pi)
1562+
% 360
1563+
)
1564+
15631565
self.wind_heading = Function(
1564-
wind_heading,
1566+
wind_heading_func,
15651567
inputs="Height Above Sea Level (m)",
15661568
outputs="Wind Heading (Deg True)",
15671569
interpolation="linear",
15681570
)
15691571

15701572
def wind_direction(h):
1571-
return (wind_heading(h) - 180) % 360
1573+
return (wind_heading_func(h) - 180) % 360
15721574

15731575
self.wind_direction = Function(
15741576
wind_direction,
@@ -1578,7 +1580,10 @@ def wind_direction(h):
15781580
)
15791581

15801582
def wind_speed(h):
1581-
return np.sqrt(self.wind_velocity_x(h) ** 2 + self.wind_velocity_y(h) ** 2)
1583+
return np.sqrt(
1584+
self.wind_velocity_x.get_value_opt(h) ** 2
1585+
+ self.wind_velocity_y.get_value_opt(h) ** 2
1586+
)
15821587

15831588
self.wind_speed = Function(
15841589
wind_speed,
@@ -3197,22 +3202,26 @@ def add_wind_gust(self, wind_gust_x, wind_gust_y):
31973202
# Reset wind heading and velocity magnitude
31983203
self.wind_heading = Function(
31993204
lambda h: (180 / np.pi)
3200-
* np.arctan2(self.wind_velocity_x(h), self.wind_velocity_y(h))
3205+
* np.arctan2(
3206+
self.wind_velocity_x.get_value_opt(h),
3207+
self.wind_velocity_y.get_value_opt(h),
3208+
)
32013209
% 360,
32023210
"Height (m)",
32033211
"Wind Heading (degrees)",
32043212
extrapolation="constant",
32053213
)
32063214
self.wind_speed = Function(
3207-
lambda h: (self.wind_velocity_x(h) ** 2 + self.wind_velocity_y(h) ** 2)
3215+
lambda h: (
3216+
self.wind_velocity_x.get_value_opt(h) ** 2
3217+
+ self.wind_velocity_y.get_value_opt(h) ** 2
3218+
)
32083219
** 0.5,
32093220
"Height (m)",
32103221
"Wind Speed (m/s)",
32113222
extrapolation="constant",
32123223
)
32133224

3214-
return None
3215-
32163225
def info(self):
32173226
"""Prints most important data and graphs available about the
32183227
Environment.

0 commit comments

Comments
 (0)