Skip to content

Commit 745c2c0

Browse files
committed
ENH: Moving initial volume calculation to Parachute class
Added a new parameter to parachute class
1 parent 5244c8c commit 745c2c0

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

rocketpy/rocket/parachute.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from inspect import signature
22

3+
import math
34
import numpy as np
45

56
from rocketpy.tools import from_hex_decode, to_hex_encode
@@ -98,6 +99,9 @@ class Parachute:
9899
Parachute.height : float, None
99100
Length of the unique semi-axis (height) of the inflated hemispheroid
100101
parachute in meters.
102+
Parachute.initial_radius : float, None
103+
Initial radius of the parachute on deployment in meters. Used to model the
104+
parachute inflation.
101105
Parachute.porosity : float
102106
Geometric porosity of the canopy (ratio of open area to total canopy area),
103107
in [0, 1]. Affects only the added-mass scaling during descent; it does
@@ -118,6 +122,7 @@ def __init__(
118122
noise=(0, 0, 0),
119123
radius=1.5,
120124
height=None,
125+
initial_radius=None,
121126
porosity=0.0432,
122127
):
123128
"""Initializes Parachute class.
@@ -179,6 +184,9 @@ def __init__(
179184
Length of the unique semi-axis (height) of the inflated hemispheroid
180185
parachute. Default value is the radius of the parachute.
181186
Units are in meters.
187+
initial_radius : float, optional
188+
Initial radius of the parachute on deployment in meters. Used to model the
189+
parachute inflation. Default value is the parachute radius (no inflation).
182190
porosity : float, optional
183191
Geometric porosity of the canopy (ratio of open area to total canopy area),
184192
in [0, 1]. Affects only the added-mass scaling during descent; it does
@@ -202,6 +210,13 @@ def __init__(
202210
self.noise_signal_function = Function(0)
203211
self.radius = radius
204212
self.height = height or radius
213+
self.initial_radius = initial_radius or radius
214+
self.initial_volume = (
215+
(4 / 3)
216+
* math.pi
217+
* (self.parachute_height / self.parachute_radius)
218+
* (min(self.parachute_radius, self.rocket.radius)) ** 3
219+
)
205220
self.porosity = porosity
206221
self.added_mass_coefficient = 1.068 * (
207222
1
@@ -308,6 +323,7 @@ def to_dict(self, **kwargs):
308323
"noise": self.noise,
309324
"radius": self.radius,
310325
"height": self.height,
326+
"initial_radius": self.initial_radius,
311327
"porosity": self.porosity,
312328
}
313329

@@ -341,6 +357,7 @@ def from_dict(cls, data):
341357
noise=data["noise"],
342358
radius=data.get("radius", 1.5),
343359
height=data.get("height", None),
360+
initial_radius=data.get("initial_radius", None),
344361
porosity=data.get("porosity", 0.0432),
345362
)
346363

rocketpy/rocket/rocket.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ def add_parachute(
14851485
noise=(0, 0, 0),
14861486
radius=1.5,
14871487
height=None,
1488+
initial_radius=None,
14881489
porosity=0.0432,
14891490
):
14901491
"""Creates a new parachute, storing its parameters such as
@@ -1552,6 +1553,9 @@ def add_parachute(
15521553
Length of the unique semi-axis (height) of the inflated hemispheroid
15531554
parachute. Default value is the radius of the parachute.
15541555
Units are in meters.
1556+
initial_radius : float, optional
1557+
Initial radius of the parachute on deployment in meters. Used to model the
1558+
parachute inflation. Default value is the parachute radius (no inflation).
15551559
porosity : float, optional
15561560
Geometric porosity of the canopy (ratio of open area to total canopy area),
15571561
in [0, 1]. Affects only the added-mass scaling during descent; it does
@@ -1567,15 +1571,16 @@ def add_parachute(
15671571
Flight simulation.
15681572
"""
15691573
parachute = Parachute(
1570-
name,
1571-
cd_s,
1572-
trigger,
1573-
sampling_rate,
1574-
lag,
1575-
noise,
1576-
radius,
1577-
height,
1578-
porosity,
1574+
name=name,
1575+
cd_s=cd_s,
1576+
trigger=trigger,
1577+
sampling_rate=sampling_rate,
1578+
lag=lag,
1579+
noise=noise,
1580+
radius=radius,
1581+
height=height,
1582+
initial_radius=initial_radius,
1583+
porosity=porosity,
15791584
)
15801585
self.parachutes.append(parachute)
15811586
return self.parachutes[-1]

rocketpy/simulation/flight.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,11 @@ def __simulate(self, verbose):
765765
"parachute_added_mass_coefficient",
766766
added_mass_coefficient,
767767
),
768-
lambda self: setattr(
768+
lambda self,
769+
initial_volume=parachute.initial_volume: setattr(
769770
self,
770771
"parachute_volume",
771-
(4 / 3)
772-
* math.pi
773-
* (self.parachute_height / self.parachute_radius)
774-
* (
775-
min(
776-
self.parachute_radius,
777-
self.rocket.radius,
778-
)
779-
)
780-
** 3,
772+
initial_volume,
781773
),
782774
lambda self: delattr(self, "__t0")
783775
if hasattr(self, "__t0")
@@ -1004,19 +996,10 @@ def __check_and_handle_parachute_triggers(
1004996
"parachute_added_mass_coefficient",
1005997
added_mass_coefficient,
1006998
),
1007-
lambda self: setattr(
999+
lambda self, initial_volume=parachute.initial_volume: setattr(
10081000
self,
10091001
"parachute_volume",
1010-
(4 / 3)
1011-
* math.pi
1012-
* (self.parachute_height / self.parachute_radius)
1013-
* (
1014-
min(
1015-
self.parachute_radius,
1016-
self.rocket.radius,
1017-
)
1018-
)
1019-
** 3,
1002+
initial_volume,
10201003
),
10211004
lambda self: delattr(self, "__t0") if hasattr(self, "__t0") else None,
10221005
]
@@ -2742,9 +2725,12 @@ def u_dot_parachute(self, t, u, post_processing=False):
27422725

27432726
# Initialize parachute geometrical parameters
27442727
inflated_radius = (
2745-
(3 * self.parachute_volume * self.parachute_radius) / (4 * math.pi * self.parachute_height)
2728+
(3 * self.parachute_volume * self.parachute_radius)
2729+
/ (4 * math.pi * self.parachute_height)
27462730
) ** (1 / 3)
2747-
inflated_height = inflated_radius * self.parachute_height / self.parachute_radius
2731+
inflated_height = (
2732+
inflated_radius * self.parachute_height / self.parachute_radius
2733+
)
27482734

27492735
# Calculate the surface area of the parachute
27502736
if self.parachute_radius > self.parachute_height:

0 commit comments

Comments
 (0)