Skip to content

Commit 46f5f00

Browse files
committed
Enable both export modes for serial and parallel
1 parent 1b50e94 commit 46f5f00

File tree

2 files changed

+222
-199
lines changed

2 files changed

+222
-199
lines changed

docs/notebooks/monte_carlo_analysis/mc_example.py

+44-74
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
import datetime
22

3-
from rocketpy import Environment, Flight, MonteCarlo, Rocket, SolidMotor, Function
4-
from rocketpy.stochastic import (StochasticNoseCone, StochasticParachute,
5-
StochasticRailButtons, StochasticTail,
6-
StochasticTrapezoidalFins, StochasticSolidMotor)
7-
8-
##### Environment
9-
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
3+
from rocketpy import (Environment, Flight, Function, MonteCarlo, Rocket,
4+
SolidMotor)
5+
from rocketpy.stochastic import (StochasticEnvironment, StochasticFlight,
6+
StochasticNoseCone, StochasticParachute,
7+
StochasticRailButtons, StochasticRocket,
8+
StochasticSolidMotor, StochasticTail,
9+
StochasticTrapezoidalFins)
1010

1111
env = Environment(latitude=39.389700, longitude=-8.288964, elevation=113)
12+
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
1213
env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
1314
env.set_atmospheric_model(type="Ensemble", file="GEFS")
1415

15-
# mc_env = StochasticEnvironment(
16-
# environment=env,
17-
# ensemble_member=list(range(env.num_ensemble_members)),
18-
# wind_velocity_x_factor=(1.0, 0.33, "normal"),
19-
# wind_velocity_y_factor=(1.0, 0.33, "normal"),
20-
# )
21-
22-
sto_env_parameters = {
23-
"environment": env,
24-
"ensemble_member": list(range(env.num_ensemble_members)),
25-
"wind_velocity_x_factor": (1.0, 0.33, "normal"),
26-
"wind_velocity_y_factor": (1.0, 0.33, "normal"),
27-
}
28-
29-
##### Motor
16+
mc_env = StochasticEnvironment(
17+
environment=env,
18+
ensemble_member=list(range(env.num_ensemble_members)),
19+
wind_velocity_x_factor=(1.0, 0.33, "normal"),
20+
wind_velocity_y_factor=(1.0, 0.33, "normal"),
21+
)
22+
3023
motor = SolidMotor(
3124
thrust_source="data/motors/Cesaroni_M1670.eng",
3225
dry_mass=1.815,
@@ -66,27 +59,6 @@
6659
nozzle_position=0.001,
6760
)
6861

69-
70-
# sto_motor_parameters = {
71-
# "solid_motor": motor,
72-
# "thrust_source": [
73-
# "data/motors/Cesaroni_M1670.eng",
74-
# [[0, 6000], [1, 6000], [2, 6000], [3, 6000], [4, 6000]],
75-
# ],
76-
# "burn_start_time": (0, 0.1),
77-
# "grains_center_of_mass_position": 0.001,
78-
# "grain_density": 50,
79-
# "grain_separation": 1 / 1000,
80-
# "grain_initial_height": 1 / 1000,
81-
# "grain_initial_inner_radius": 0.375 / 1000,
82-
# "grain_outer_radius": 0.375 / 1000,
83-
# "total_impulse": (6500, 1000),
84-
# "throat_radius": 0.5 / 1000,
85-
# "nozzle_radius": 0.5 / 1000,
86-
# "nozzle_position": 0.001,
87-
# }
88-
89-
##### Rocket
9062
rocket = Rocket(
9163
radius=127 / 2000,
9264
mass=14.426,
@@ -139,15 +111,15 @@
139111
noise=(0, 8.3, 0.5),
140112
)
141113

142-
sto_rocket_parameters = {
143-
"rocket": rocket,
144-
"radius": 0.0127 / 2000,
145-
"mass": (15.426, 0.5, "normal"),
146-
"inertia_11": (6.321, 0),
147-
"inertia_22": 0.01,
148-
"inertia_33": 0.01,
149-
"center_of_mass_without_motor": 0,
150-
}
114+
mc_rocket = StochasticRocket(
115+
rocket=rocket,
116+
radius=0.0127 / 2000,
117+
mass=(15.426, 0.5, "normal"),
118+
inertia_11=(6.321, 0),
119+
inertia_22=0.01,
120+
inertia_33=0.01,
121+
center_of_mass_without_motor=0,
122+
)
151123

152124
mc_nose_cone = StochasticNoseCone(
153125
nosecone=nose_cone,
@@ -184,16 +156,14 @@
184156
lag=0.2,
185157
)
186158

187-
sto_rocket_parameters["motor"] = (mc_motor, 0.001)
188-
sto_rocket_parameters["nose"] = (mc_nose_cone, (1.134, 0.001))
189-
sto_rocket_parameters["trapezoidal_fins"] = (mc_fin_set, (0.001, "normal"))
190-
sto_rocket_parameters["rail_buttons"] = (mc_rail_buttons, (0.001, "normal"))
191-
sto_rocket_parameters["tail"] = mc_tail
192-
sto_rocket_parameters["parachute_main"] = mc_main
193-
sto_rocket_parameters["parachute_drogue"] = mc_drogue
194-
159+
mc_rocket.add_motor(mc_motor, position=0.001)
160+
mc_rocket.add_nose(mc_nose_cone, position=(1.134, 0.001))
161+
mc_rocket.add_trapezoidal_fins(mc_fin_set, position=(0.001, "normal"))
162+
mc_rocket.add_tail(mc_tail)
163+
mc_rocket.set_rail_buttons(mc_rail_buttons, lower_button_position=(0.001, "normal"))
164+
mc_rocket.add_parachute(mc_main)
165+
mc_rocket.add_parachute(mc_drogue)
195166

196-
##### Flight
197167
test_flight = Flight(
198168
rocket=rocket,
199169
environment=env,
@@ -202,20 +172,20 @@
202172
heading=133,
203173
)
204174

205-
sto_flight_parameters = {
206-
"flight": test_flight,
207-
"inclination": (84.7, 1),
208-
"heading": (53, 2),
209-
}
210-
175+
mc_flight = StochasticFlight(
176+
flight=test_flight,
177+
inclination=(84.7, 1),
178+
heading=(53, 2),
179+
)
211180

212-
##### Step 2: Starting the Monte Carlo Simulations
213181
test_dispersion = MonteCarlo(
214-
filename="monte_carlo_analysis_outputs/monte_carlo_class_example",
215-
environment_params=sto_env_parameters,
216-
rocket_params=sto_rocket_parameters,
217-
flight_params=sto_flight_parameters,
182+
filename="monte_carlo_class_example",
183+
environment=mc_env,
184+
rocket=mc_rocket,
185+
flight=mc_flight,
186+
batch_path="/home/sorban/Documents/code/RocketPy/mc_simulations",
218187
)
219188

220-
##### Running the Monte Carlo Simulations
221-
test_dispersion.simulate(number_of_simulations=50, append=False, parallel=True)
189+
test_dispersion.simulate(
190+
number_of_simulations=10, append=False, light_mode=False, parallel=True
191+
)

0 commit comments

Comments
 (0)