优化压力流量求解并达到四路性能门槛

This commit is contained in:
huojiarong committed 2026-08-15 11:45:22 +00:00
1 parent 6572defaa4
commit 6a064892e2
20 files changed
+711 -175

No files matched your search

+71
View File
@@ -241,6 +241,77 @@ class IntegrateOdeTests(unittest.TestCase):
)
)
def test_segmented_solver_reports_implicit_work_by_event_segment(self) -> None:
import numpy as np
import scipy.integrate
class CountingBDF:
def __init__(self, _fun, t0, y0, t_bound, **_kwargs):
self.t = float(t0)
self.y = np.asarray(y0, dtype=float)
self.t_bound = float(t_bound)
self.status = "running"
self.nfev = 2
self.njev = 1
self.nlu = 0
def step(self):
self.t = self.t_bound
self.nfev += 3
self.nlu += 2
self.status = "finished"
return None
def dense_output(self):
state = self.y.copy()
return lambda _time: state.copy()
with patch.object(scipy.integrate, "BDF", CountingBDF):
result = integrate_ode(
rhs=lambda _time, _state: [0.0],
initial_state=[1.0],
config=SolveIVPConfig(
t_start=0.0,
t_stop=1.0,
method="BDF",
max_step=1.0,
),
t_eval=[0.0, 0.4, 1.0],
breakpoints=[0.4],
)
self.assertTrue(result.success, result.message)
self.assertEqual(len(result.solver_segments), 2)
self.assertEqual(
[segment.as_dict() for segment in result.solver_segments],
[
{
"startTime": 0.0,
"requestedStopTime": 0.4,
"simulatedUntil": 0.4,
"nfev": 5,
"njev": 1,
"nlu": 2,
"acceptedStepCount": 1,
"solverStartCount": 1,
"stateTransitionCount": 0,
"recoverableRetryCount": 0,
},
{
"startTime": 0.4,
"requestedStopTime": 1.0,
"simulatedUntil": 1.0,
"nfev": 5,
"njev": 1,
"nlu": 2,
"acceptedStepCount": 1,
"solverStartCount": 1,
"stateTransitionCount": 0,
"recoverableRetryCount": 0,
},
],
)
def test_segmented_solver_can_cancel_after_crossing_a_breakpoint(self) -> None:
callback_times: list[float] = []
cancellation_requested = False