Skip to content

Commit 5a47616

Browse files
committed
MNT: make format and renaming 3 dof example
- MNT: make format changes to flight.py - MNT: "3_DOF_TRIAL.ipynb" renamed to "3_dof_trial_sim.ipynb"
1 parent 5b6d7e5 commit 5a47616

2 files changed

Lines changed: 56 additions & 53 deletions

File tree

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"import matplotlib.pyplot as plt\n",
1111
"import numpy as np\n",
1212
"from scipy.signal import savgol_filter\n",
13-
"from rocketpy.rocket.rocket import PointMassRocket\n",
14-
"from rocketpy import Flight, Environment, Function, PointMassMotor\n"
13+
"\n",
14+
"from rocketpy import Environment, Flight, Function, PointMassMotor\n",
15+
"from rocketpy.rocket.rocket import PointMassRocket"
1516
]
1617
},
1718
{
@@ -115,12 +116,13 @@
115116
"def thrust_profile(t):\n",
116117
" return 250 if 0 <= t <= 3 else 0\n",
117118
"\n",
119+
"\n",
118120
"motor = PointMassMotor(\n",
119121
" thrust_source=thrust_profile,\n",
120122
" dry_mass=1.0,\n",
121123
" propellant_initial_mass=0.5,\n",
122124
" propellant_final_mass=0.0,\n",
123-
" burn_time=3.0\n",
125+
" burn_time=3.0,\n",
124126
")"
125127
]
126128
},
@@ -159,11 +161,11 @@
159161
" environment=env,\n",
160162
" rail_length=5.0,\n",
161163
" inclination=85, # degrees from horizontal\n",
162-
" heading=90, # east\n",
164+
" heading=90, # east\n",
163165
" simulation_mode=\"3 DOF\",\n",
164166
" terminate_on_apogee=False,\n",
165167
" max_time=20,\n",
166-
" name=\"Test3DOF\"\n",
168+
" name=\"Test3DOF\",\n",
167169
")"
168170
]
169171
},
@@ -193,7 +195,7 @@
193195
"plt.ylabel(\"Altitude (m)\")\n",
194196
"plt.title(\"3 DOF Rocket Altitude vs Time\")\n",
195197
"plt.grid(True)\n",
196-
"plt.show()\n"
198+
"plt.show()"
197199
]
198200
},
199201
{
@@ -214,7 +216,7 @@
214216
"print(f\"Simulation Mode: {flight.simulation_mode}\")\n",
215217
"\n",
216218
"# Display additional details about the equations if available in the simulation object\n",
217-
"if hasattr(flight, 'equations_of_motion'):\n",
219+
"if hasattr(flight, \"equations_of_motion\"):\n",
218220
" print(f\"Equations of Motion: {flight.equations_of_motion}\")\n",
219221
"else:\n",
220222
" print(\"No explicit equations of motion found in flight class\")"

rocketpy/simulation/flight.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -764,27 +764,28 @@ def __simulate(self, verbose):
764764
index=phase_index + i,
765765
)
766766
i += 1
767-
# Create flight phase for time after inflation
767+
# Create flight phase for time after inflation
768768
callbacks = [
769-
lambda self, parachute_cd_s=parachute.cd_s: setattr(
770-
self, "parachute_cd_s", parachute_cd_s
771-
),
772-
lambda self, parachute_radius=parachute.radius: setattr(
773-
self, "parachute_radius", parachute_radius
774-
),
775-
lambda self, parachute_height=parachute.height: setattr(
776-
self, "parachute_height", parachute_height
777-
),
778-
lambda self, parachute_porosity=parachute.porosity: setattr(
779-
self, "parachute_porosity", parachute_porosity
780-
),
781-
lambda self,
782-
added_mass_coefficient=parachute.added_mass_coefficient: setattr(
783-
self,
784-
"parachute_added_mass_coefficient",
785-
added_mass_coefficient,
786-
),
787-
]
769+
lambda self, parachute_cd_s=parachute.cd_s: setattr(
770+
self, "parachute_cd_s", parachute_cd_s
771+
),
772+
lambda self, parachute_radius=parachute.radius: setattr(
773+
self, "parachute_radius", parachute_radius
774+
),
775+
lambda self, parachute_height=parachute.height: setattr(
776+
self, "parachute_height", parachute_height
777+
),
778+
lambda self,
779+
parachute_porosity=parachute.porosity: setattr(
780+
self, "parachute_porosity", parachute_porosity
781+
),
782+
lambda self,
783+
added_mass_coefficient=parachute.added_mass_coefficient: setattr(
784+
self,
785+
"parachute_added_mass_coefficient",
786+
added_mass_coefficient,
787+
),
788+
]
788789
self.flight_phases.add_phase(
789790
node.t + parachute.lag,
790791
self.u_dot_parachute,
@@ -1502,17 +1503,17 @@ def u_dot(self, t, u, post_processing=False): # pylint: disable=too-many-locals
15021503
# Thrust correction parameters
15031504
pressure = self.env.pressure.get_value_opt(z)
15041505
# Determine current behavior
1505-
if self.rocket.motor.burn_start_time < t < self.rocket.motor.burn_out_time:
1506+
if self.rocket.motor.burn_start_time < t < self.rocket.motor.burn_out_time:
15061507
# Motor burning
15071508
# Retrieve important motor quantities
1508-
# Inertias
1509-
motor_I_33_at_t = self.rocket.motor.I_33.get_value_opt(t)
1510-
motor_I_11_at_t = self.rocket.motor.I_11.get_value_opt(t)
1511-
motor_I_33_derivative_at_t = self.rocket.motor.I_33.differentiate(
1512-
t, dx=1e-6
1513-
)
1514-
motor_I_11_derivative_at_t = self.rocket.motor.I_11.differentiate(
1515-
t, dx=1e-6
1509+
# Inertias
1510+
motor_I_33_at_t = self.rocket.motor.I_33.get_value_opt(t)
1511+
motor_I_11_at_t = self.rocket.motor.I_11.get_value_opt(t)
1512+
motor_I_33_derivative_at_t = self.rocket.motor.I_33.differentiate(
1513+
t, dx=1e-6
1514+
)
1515+
motor_I_11_derivative_at_t = self.rocket.motor.I_11.differentiate(
1516+
t, dx=1e-6
15161517
)
15171518
# Mass
15181519
mass_flow_rate_at_t = self.rocket.motor.mass_flow_rate.get_value_opt(t)
@@ -1530,20 +1531,20 @@ def u_dot(self, t, u, post_processing=False): # pylint: disable=too-many-locals
15301531
else:
15311532
# Motor stopped
15321533
# Inertias
1533-
(
1534-
motor_I_33_at_t,
1535-
motor_I_11_at_t,
1536-
motor_I_33_derivative_at_t,
1537-
motor_I_11_derivative_at_t,
1534+
(
1535+
motor_I_33_at_t,
1536+
motor_I_11_at_t,
1537+
motor_I_33_derivative_at_t,
1538+
motor_I_11_derivative_at_t,
15381539
) = (0, 0, 0, 0)
15391540
# Mass
15401541
mass_flow_rate_at_t, propellant_mass_at_t = 0, 0
15411542
# thrust
15421543
net_thrust = 0
15431544

15441545
# Retrieve important quantities
1545-
# Inertias
1546-
rocket_dry_I_33 = self.rocket.dry_I_33
1546+
# Inertias
1547+
rocket_dry_I_33 = self.rocket.dry_I_33
15471548
rocket_dry_I_11 = self.rocket.dry_I_11
15481549
# Mass
15491550
rocket_dry_mass = self.rocket.dry_mass # already with motor's dry mass
@@ -1552,15 +1553,15 @@ def u_dot(self, t, u, post_processing=False): # pylint: disable=too-many-locals
15521553
propellant_mass_at_t + rocket_dry_mass
15531554
)
15541555
# Geometry
1555-
# b = -self.rocket.distance_rocket_propellant
1556-
b = (
1557-
-(
1558-
self.rocket.center_of_propellant_position.get_value_opt(0)
1559-
- self.rocket.center_of_dry_mass_position
1560-
)
1561-
* self.rocket._csys
1562-
)
1563-
c = self.rocket.nozzle_to_cdm
1556+
# b = -self.rocket.distance_rocket_propellant
1557+
b = (
1558+
-(
1559+
self.rocket.center_of_propellant_position.get_value_opt(0)
1560+
- self.rocket.center_of_dry_mass_position
1561+
)
1562+
* self.rocket._csys
1563+
)
1564+
c = self.rocket.nozzle_to_cdm
15641565
nozzle_radius = self.rocket.motor.nozzle_radius
15651566
# Prepare transformation matrix
15661567
a11 = 1 - 2 * (e2**2 + e3**2)
@@ -1611,7 +1612,7 @@ def u_dot(self, t, u, post_processing=False): # pylint: disable=too-many-locals
16111612
else:
16121613
R3 += air_brakes_force
16131614
# Off center moment
1614-
M1 += self.rocket.cp_eccentricity_y * R3
1615+
M1 += self.rocket.cp_eccentricity_y * R3
16151616
M2 -= self.rocket.cp_eccentricity_x * R3
16161617
# Get rocket velocity in body frame
16171618
vx_b = a11 * vx + a21 * vy + a31 * vz

0 commit comments

Comments
 (0)