|
1 | 1 | import datetime
|
2 | 2 |
|
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) |
10 | 10 |
|
11 | 11 | env = Environment(latitude=39.389700, longitude=-8.288964, elevation=113)
|
| 12 | +tomorrow = datetime.date.today() + datetime.timedelta(days=1) |
12 | 13 | env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
|
13 | 14 | env.set_atmospheric_model(type="Ensemble", file="GEFS")
|
14 | 15 |
|
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 | + |
30 | 23 | motor = SolidMotor(
|
31 | 24 | thrust_source="data/motors/Cesaroni_M1670.eng",
|
32 | 25 | dry_mass=1.815,
|
|
66 | 59 | nozzle_position=0.001,
|
67 | 60 | )
|
68 | 61 |
|
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 |
90 | 62 | rocket = Rocket(
|
91 | 63 | radius=127 / 2000,
|
92 | 64 | mass=14.426,
|
|
139 | 111 | noise=(0, 8.3, 0.5),
|
140 | 112 | )
|
141 | 113 |
|
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 | +) |
151 | 123 |
|
152 | 124 | mc_nose_cone = StochasticNoseCone(
|
153 | 125 | nosecone=nose_cone,
|
|
184 | 156 | lag=0.2,
|
185 | 157 | )
|
186 | 158 |
|
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) |
195 | 166 |
|
196 |
| -##### Flight |
197 | 167 | test_flight = Flight(
|
198 | 168 | rocket=rocket,
|
199 | 169 | environment=env,
|
|
202 | 172 | heading=133,
|
203 | 173 | )
|
204 | 174 |
|
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 | +) |
211 | 180 |
|
212 |
| -##### Step 2: Starting the Monte Carlo Simulations |
213 | 181 | 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", |
218 | 187 | )
|
219 | 188 |
|
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