Skip to content

Commit 3313e08

Browse files
authored
BUG: correct encoding for trapezoidal sweep length and angle. (#861)
1 parent 20dc3be commit 3313e08

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Attention: The newest changes should be on top -->
5252

5353
### Fixed
5454

55+
- BUG: correct encoding for trapezoidal sweep length and angle. [#861](https://github.com/RocketPy-Team/RocketPy/pull/861)
5556
- BUG: Fix no time initialization when passing initial_solution as array to Flight object [#844](https://github.com/RocketPy-Team/RocketPy/pull/844)
5657

5758

rocketpy/plots/monte_carlo_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import matplotlib.pyplot as plt
2-
from matplotlib.transforms import offset_copy
32
import numpy as np
3+
from matplotlib.transforms import offset_copy
44

55
from ..tools import generate_monte_carlo_ellipses, import_optional_dependency
66

rocketpy/rocket/aero_surface/fins/trapezoidal_fins.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ def __init__(
176176
sweep_length = np.tan(sweep_angle * np.pi / 180) * span
177177
elif sweep_length is None:
178178
sweep_length = root_chord - tip_chord
179-
else:
180-
# Sweep length is given
181-
pass
182179

183180
self._tip_chord = tip_chord
184181
self._sweep_length = sweep_length
@@ -351,12 +348,12 @@ def all_info(self):
351348
def to_dict(self, **kwargs):
352349
data = super().to_dict(**kwargs)
353350
data["tip_chord"] = self.tip_chord
351+
data["sweep_length"] = self.sweep_length
352+
data["sweep_angle"] = self.sweep_angle
354353

355354
if kwargs.get("include_outputs", False):
356355
data.update(
357356
{
358-
"sweep_length": self.sweep_length,
359-
"sweep_angle": self.sweep_angle,
360357
"shape_vec": self.shape_vec,
361358
"Af": self.Af,
362359
"AR": self.AR,
@@ -382,4 +379,5 @@ def from_dict(cls, data):
382379
cant_angle=data["cant_angle"],
383380
airfoil=data["airfoil"],
384381
name=data["name"],
382+
sweep_length=data.get("sweep_length"),
385383
)

tests/fixtures/surfaces/surface_fixtures.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,50 @@ def calisto_trapezoidal_fins():
6969
)
7070

7171

72+
@pytest.fixture
73+
def calisto_trapezoidal_fins_custom_sweep_length():
74+
"""The trapezoidal fins of the Calisto rocket with
75+
a custom sweep length.
76+
77+
Returns
78+
-------
79+
rocketpy.TrapezoidalFins
80+
The trapezoidal fins of the Calisto rocket.
81+
"""
82+
return TrapezoidalFins(
83+
n=4,
84+
span=0.100,
85+
root_chord=0.120,
86+
tip_chord=0.040,
87+
rocket_radius=0.0635,
88+
name="calisto_trapezoidal_fins_custom_sweep_length",
89+
cant_angle=0,
90+
sweep_length=0.1,
91+
)
92+
93+
94+
@pytest.fixture
95+
def calisto_trapezoidal_fins_custom_sweep_angle():
96+
"""The trapezoidal fins of the Calisto rocket with
97+
a custom sweep angle.
98+
99+
Returns
100+
-------
101+
rocketpy.TrapezoidalFins
102+
The trapezoidal fins of the Calisto rocket.
103+
"""
104+
return TrapezoidalFins(
105+
n=4,
106+
span=0.100,
107+
root_chord=0.120,
108+
tip_chord=0.040,
109+
rocket_radius=0.0635,
110+
name="calisto_trapezoidal_fins_custom_sweep_angle",
111+
cant_angle=0,
112+
sweep_angle=30,
113+
)
114+
115+
72116
@pytest.fixture
73117
def calisto_free_form_fins():
74118
"""The free form fins of the Calisto rocket.

tests/integration/test_encoding.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,41 @@ def test_rocket_encoder(rocket_name, request):
242242
)
243243

244244

245+
@pytest.mark.parametrize(
246+
"fin_name",
247+
[
248+
"calisto_trapezoidal_fins",
249+
"calisto_trapezoidal_fins_custom_sweep_length",
250+
"calisto_trapezoidal_fins_custom_sweep_angle",
251+
],
252+
)
253+
def test_trapezoidal_fins_encoder(fin_name, request):
254+
"""Test encoding a ``rocketpy.TrapezoidalFins``.
255+
256+
Parameters
257+
----------
258+
fin_name : str
259+
Name of the fin fixture to encode.
260+
request : pytest.FixtureRequest
261+
Pytest request object.
262+
"""
263+
fin_to_encode = request.getfixturevalue(fin_name)
264+
265+
json_encoded = json.dumps(fin_to_encode, cls=RocketPyEncoder)
266+
267+
fin_loaded = json.loads(json_encoded, cls=RocketPyDecoder)
268+
269+
assert isinstance(fin_loaded, type(fin_to_encode))
270+
assert fin_to_encode.n == fin_loaded.n
271+
assert np.isclose(fin_to_encode.span, fin_loaded.span)
272+
assert np.isclose(fin_to_encode.root_chord, fin_loaded.root_chord)
273+
assert np.isclose(fin_to_encode.tip_chord, fin_loaded.tip_chord)
274+
assert np.isclose(fin_to_encode.rocket_radius, fin_loaded.rocket_radius)
275+
assert np.isclose(fin_to_encode.sweep_length, fin_loaded.sweep_length)
276+
if fin_to_encode._sweep_angle is not None and fin_loaded._sweep_angle is not None:
277+
assert np.isclose(fin_to_encode.sweep_angle, fin_loaded.sweep_angle)
278+
279+
245280
@pytest.mark.parametrize("rocket_name", ["calisto_robust", "calisto_hybrid_modded"])
246281
def test_encoder_discretize(rocket_name, request):
247282
"""Test encoding the total mass of ``rocketpy.Rocket`` with

0 commit comments

Comments
 (0)