验收四路模型并优化拓扑求解性能

This commit is contained in:
huojiarong committed 2026-08-12 11:57:42 +00:00
1 parent caca32a513
commit 456c29b3b6
20 files changed
+1085 -137

No files matched your search

@@ -1,6 +1,7 @@
from __future__ import annotations
import unittest
from math import log10
from app.simulation.components.amesim.flow.pipes import AmesimPnl0002, AmesimPnl0003
from app.simulation.core.medium import IdealGasMedium
@@ -45,6 +46,20 @@ class AmesimPnl0002ComponentTests(unittest.TestCase):
self.assertGreater(forward, 0.0)
self.assertLess(reverse, 0.0)
def test_exact_repeated_pipe_flow_inversion_is_cached(self) -> None:
pipe = AmesimPnl0002("pnl_2", self.medium, p0=100000.0, T0=293.15)
pipe._one_way_pn2pipefr_mass_flow.cache_clear()
first = pipe.mass_flow(15.3e6, 10.0e6, 293.15)
after_first = pipe._one_way_pn2pipefr_mass_flow.cache_info()
second = pipe.mass_flow(15.3e6, 10.0e6, 293.15)
after_second = pipe._one_way_pn2pipefr_mass_flow.cache_info()
self.assertEqual(second, first)
self.assertEqual(after_first.misses, 1)
self.assertEqual(after_second.misses, 1)
self.assertEqual(after_second.hits, 1)
def test_external_upstream_flow_uses_connected_stream_temperature(self) -> None:
pipe = AmesimPnl0002("pnl_2", self.medium, p0=100000.0, T0=350.0)
center = pipe.properties()
@@ -78,6 +93,23 @@ class AmesimPnl0002ComponentTests(unittest.TestCase):
self.assertAlmostEqual(flow, expected)
self.assertNotAlmostEqual(flow, center_temperature_flow)
def test_fully_rough_limit_matches_nikuradse_colebrook_asymptote(self) -> None:
relative_roughness = 0.045 / 20.0
pipe = AmesimPnl0002(
"pnl_2",
self.medium,
diam=0.02,
le=2.0,
rr=relative_roughness,
)
expected = 1.0 / (-2.0 * log10(relative_roughness / 3.7)) ** 2
self.assertAlmostEqual(
pipe.friction_factor(1.0e12),
expected,
delta=1.0e-10,
)
def test_missing_stream_cache_preserves_center_temperature_fallback(self) -> None:
pipe = AmesimPnl0002("pnl_2", self.medium, p0=100000.0, T0=350.0)
center = pipe.properties()