Skip to content

Commit f2eb098

Browse files
committed
ENH: adapted run_dispersion
and deleted few unecessary and slow lines
1 parent b0086b2 commit f2eb098

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

rocketpy/Dispersion.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,8 @@ def run_dispersion(
11431143
flight=None,
11441144
motor=None,
11451145
rocket=None,
1146-
exported_variables=None,
1146+
distribution_type="normal",
1147+
export_list=None,
11471148
append=False,
11481149
):
11491150
"""Runs the given number of simulations and saves the data
@@ -1183,15 +1184,20 @@ def run_dispersion(
11831184
# Saving the arguments as attributes
11841185
self.number_of_simulations = number_of_simulations
11851186
self.dispersion_dictionary = dispersion_dictionary
1186-
self.environment = environment
1187-
self.motor = motor
1188-
self.rocket = rocket
11891187
if flight: # In case a flight object is passed
11901188
self.environment = flight.env
11911189
self.motor = flight.rocket.motor
11921190
self.rocket = flight.rocket
1193-
self.flight = flight
1194-
self.distribution_type = "normal" # TODO: Must be parametrized
1191+
self.flight = flight
1192+
if rocket:
1193+
self.rocket = rocket
1194+
self.motor = rocket.motor
1195+
if motor:
1196+
self.motor = motor
1197+
if environment:
1198+
self.environment = environment
1199+
1200+
self.distribution_type = distribution_type
11951201

11961202
# Check if there's enough object to start a flight:
11971203
## Raise an error in case of any troubles
@@ -1211,6 +1217,18 @@ def run_dispersion(
12111217
dispersion_input_file = open(f"{self.filename}.disp_inputs.txt", open_mode)
12121218
dispersion_output_file = open(f"{self.filename}.disp_outputs.txt", open_mode)
12131219

1220+
# Checks export_list
1221+
self.export_list = self.__check_export_list(export_list)
1222+
1223+
# Creates a copy of the environment
1224+
env_dispersion = self.environment
1225+
1226+
# Creates copy of motor
1227+
motor_dispersion = self.motor
1228+
1229+
# Creates copy of rocket
1230+
rocket_dispersion = self.rocket
1231+
12141232
# Initialize counter and timer
12151233
i = 0
12161234
initial_wall_time = time()
@@ -1224,9 +1242,6 @@ def run_dispersion(
12241242
self.start_time = process_time()
12251243
i += 1
12261244

1227-
# Creates a copy of the environment
1228-
env_dispersion = self.environment
1229-
12301245
# Apply environment parameters variations on each iteration if possible
12311246
env_dispersion.railLength = setting["railLength"]
12321247
env_dispersion.gravity = setting["gravity"]
@@ -1237,9 +1252,6 @@ def run_dispersion(
12371252
if env_dispersion.atmosphericModelType in ["Ensemble", "Reanalysis"]:
12381253
env_dispersion.selectEnsembleMember(setting["ensembleMember"])
12391254

1240-
# Creates copy of motor
1241-
motor_dispersion = self.motor
1242-
12431255
# Apply motor parameters variations on each iteration if possible
12441256
# TODO: add hybrid and liquid motor option
12451257
motor_dispersion = SolidMotor(
@@ -1256,9 +1268,6 @@ def run_dispersion(
12561268
reshapeThrustCurve=(setting["burnOutTime"], setting["totalImpulse"]),
12571269
)
12581270

1259-
# Creates copy of rocket
1260-
rocket_dispersion = self.rocket
1261-
12621271
# Apply rocket parameters variations on each iteration if possible
12631272
rocket_dispersion = Rocket(
12641273
motor=motor_dispersion,
@@ -1272,9 +1281,6 @@ def run_dispersion(
12721281
powerOnDrag=setting["powerOnDrag"],
12731282
)
12741283

1275-
# Clean up aerodynamic surfaces
1276-
rocket_dispersion.aerodynamicSurfaces = [] # Remove all surfaces
1277-
12781284
# Add rocket nose, fins and tail
12791285
# Nose
12801286
for nose in self.nose_names:
@@ -1289,12 +1295,11 @@ def run_dispersion(
12891295
for finSet in self.finSet_names:
12901296
# TODO: Allow elliptical fins as well
12911297
rocket_dispersion.addTrapezoidalFins(
1292-
n=setting[f"finSet_{finSet}_numberOfFins"],
1298+
n=setting[f"finSet_{finSet}_n"],
12931299
rootChord=setting[f"finSet_{finSet}_rootChord"],
12941300
tipChord=setting[f"finSet_{finSet}_tipChord"],
12951301
span=setting[f"finSet_{finSet}_span"],
12961302
distanceToCM=setting[f"finSet_{finSet}_distanceToCM"],
1297-
radius=setting[f"finSet_{finSet}_radius"],
12981303
airfoil=setting[f"finSet_{finSet}_airfoil"],
12991304
name=finSet,
13001305
)
@@ -1354,7 +1359,6 @@ def run_dispersion(
13541359
exec_time=process_time() - self.start_time,
13551360
dispersion_input_file=dispersion_input_file,
13561361
dispersion_output_file=dispersion_output_file,
1357-
variables=exported_variables,
13581362
)
13591363
except Exception as E:
13601364
print(E)

0 commit comments

Comments
 (0)