Skip to content

Commit 82767ea

Browse files
authored
Merge pull request #422 from RocketPy-Team/enh/solid-ode-jacobian
FIX: Motors UnitTesting Warnings
2 parents 43fdd8a + 3651539 commit 82767ea

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

rocketpy/mathutils/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ def integral(self, a, b, numerical=False):
22422242
ans = np.trapz(y_integration_data, x_integration_data)
22432243
else:
22442244
# Integrate numerically
2245-
ans, _ = integrate.quad(self, a, b, epsabs=0.001, limit=10000)
2245+
ans, _ = integrate.quad(self, a, b, epsabs=1e-4, epsrel=1e-3, limit=1000)
22462246
return integration_sign * ans
22472247

22482248
def differentiate(self, x, dx=1e-6, order=1):

rocketpy/motors/solid_motor.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,35 @@ def evaluate_geometry(self):
469469

470470
density = self.grain_density
471471
rO = self.grain_outer_radius
472+
n_grain = self.grain_number
472473

473474
# Define system of differential equations
474475
def geometry_dot(t, y):
475-
grain_mass_dot = self.mass_flow_rate(t) / self.grain_number
476+
# Store physical parameters
477+
volume_diff = self.mass_flow_rate(t) / (n_grain * density)
478+
479+
# Compute state vector derivative
476480
rI, h = y
477-
rIDot = (
478-
-0.5 * grain_mass_dot / (density * np.pi * (rO**2 - rI**2 + rI * h))
479-
)
480-
hDot = (
481-
1.0 * grain_mass_dot / (density * np.pi * (rO**2 - rI**2 + rI * h))
482-
)
483-
return [rIDot, hDot]
481+
burn_area = 2 * np.pi * (rO**2 - rI**2 + rI * h)
482+
rI_dot = -volume_diff / burn_area
483+
h_dot = -2 * rI_dot
484+
485+
return [rI_dot, h_dot]
486+
487+
# Define jacobian of the system of differential equations
488+
def geometry_jacobian(t, y):
489+
# Store physical parameters
490+
volume_diff = self.mass_flow_rate(t) / (n_grain * density)
491+
492+
# Compute jacobian
493+
rI, h = y
494+
factor = volume_diff / (2 * np.pi * (rO**2 - rI**2 + rI * h) ** 2)
495+
drI_dot_drI = factor * (h - 2 * rI)
496+
drI_dot_dh = factor * rI
497+
dh_dot_drI = -2 * drI_dot_drI
498+
dh_dot_dh = -2 * drI_dot_dh
499+
500+
return [[drI_dot_drI, drI_dot_dh], [dh_dot_drI, dh_dot_dh]]
484501

485502
def terminate_burn(t, y):
486503
end_function = (self.grain_outer_radius - y[0]) * y[1]
@@ -494,6 +511,7 @@ def terminate_burn(t, y):
494511
geometry_dot,
495512
t_span,
496513
y0,
514+
jac=geometry_jacobian,
497515
events=terminate_burn,
498516
atol=1e-12,
499517
rtol=1e-11,

tests/acceptance/test_ndrt_2020_rocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_ndrt_2020_rocket_data_asserts_acceptance():
2727
"rocket_mass": (23.321 - 2.475 - 1, 0.010),
2828
# propulsion details
2929
"impulse": (4895.050, 0.033 * 4895.050),
30-
"burn_time": (3.51, 0.1),
30+
"burn_time": (3.45, 0.1),
3131
"nozzle_radius": (49.5 / 2000, 0.001),
3232
"throat_radius": (21.5 / 2000, 0.001),
3333
"grain_separation": (3 / 1000, 0.001),

tests/test_flight.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def test_liquid_motor_flight(mock_show, calisto_liquid_modded):
585585
rail_length=5,
586586
inclination=85,
587587
heading=0,
588+
max_time_step=0.25,
588589
)
589590

590591
assert test_flight.all_info() == None
@@ -609,6 +610,7 @@ def test_hybrid_motor_flight(mock_show, calisto_hybrid_modded):
609610
rail_length=5,
610611
inclination=85,
611612
heading=0,
613+
max_time_step=0.25,
612614
)
613615

614616
assert test_flight.all_info() == None

0 commit comments

Comments
 (0)