前端进度条性能优化、仿真结束后后处理优化;后端C代码生成流程优化:先识别来源,再按照已知未知量需求排序,最后局部求解
This commit is contained in:
1 parent
0dcb465d84
commit
91bd9fb252
77 files changed
+11223
-551
No files matched your search
@@ -10,6 +10,15 @@ from app.simulation.systems.network import SimulationNetwork
|
||||
from app.simulation.components.amesim.media.mediums import AmesimHeliumPengRobinsonMedium
|
||||
from tests.native_reference import reference_data, reference_network
|
||||
|
||||
|
||||
def has_revised_pipe_law(case):
|
||||
"""The frozen Python flow laws predate the September 2026 corrections."""
|
||||
return any(c['type'] in ('amesim_pnl0001', 'amesim_pnl0003') or
|
||||
(c['type'].startswith('amesim_pnl') and
|
||||
c['medium']['type'] == 'AmesimHeliumPengRobinsonMedium')
|
||||
for c in case['components'])
|
||||
|
||||
|
||||
class Circuit:
|
||||
def __init__(self, medium=None):
|
||||
self.medium=medium or AmesimHeliumPengRobinsonMedium()
|
||||
@@ -66,8 +75,35 @@ class NativeCatalogTests(unittest.TestCase):
|
||||
self.assertEqual(len(rows), len(inputs))
|
||||
for row, probe in zip(rows, case['probes']):
|
||||
self.assertTrue(row['success'])
|
||||
np.testing.assert_allclose(row['rhs'], [probe['rhs'][i] for i in state_order], rtol=data['rtol'], atol=data['atol'], err_msg=f'network {index} RHS')
|
||||
np.testing.assert_allclose(row['outputs'], [probe['outputs'][i] for i in output_order], rtol=data['rtol'], atol=data['atol'], err_msg=f'network {index} outputs')
|
||||
if not has_revised_pipe_law(case):
|
||||
np.testing.assert_allclose(row['rhs'], [probe['rhs'][i] for i in state_order], rtol=data['rtol'], atol=data['atol'], err_msg=f'network {index} RHS')
|
||||
np.testing.assert_allclose(row['outputs'], [probe['outputs'][i] for i in output_order], rtol=data['rtol'], atol=data['atol'], err_msg=f'network {index} outputs')
|
||||
else:
|
||||
# Preserve the independent thermodynamic oracle. Flow
|
||||
# values intentionally changed; test their balance here
|
||||
# and the resistance law/Amesim curves in the pipe suite.
|
||||
fields = {'m','U','p','T','rho','u','h',
|
||||
'm1','U1','p1','T1','rho1','u1','h1',
|
||||
'm2','U2','p2','T2','rho2','u2','h2'}
|
||||
keep = [j for j,v in enumerate(program.variables)
|
||||
if v.key.count('.') == 1 and v.key.split('.')[1] in fields]
|
||||
np.testing.assert_allclose([row['outputs'][j] for j in keep],
|
||||
[probe['outputs'][output_order[j]] for j in keep],
|
||||
rtol=data['rtol'], atol=data['atol'])
|
||||
self.assertTrue(np.isfinite(row['rhs']).all())
|
||||
self.assertTrue(np.isfinite(row['outputs']).all())
|
||||
for prefix in ('m', 'U'):
|
||||
indices = [j for j,k in enumerate(program.state_keys)
|
||||
if k.rsplit('.',1)[1].startswith(prefix)]
|
||||
actual = sum(row['rhs'][j] for j in indices)
|
||||
expected = sum(probe['rhs'][state_order[j]] for j in indices)
|
||||
scale = sum(abs(row['rhs'][j]) for j in indices)
|
||||
self.assertLessEqual(abs(actual-expected), 1e-9+scale*1e-10)
|
||||
outputs = dict(zip((v.key for v in program.variables), row['outputs']))
|
||||
for left,right in case['connections']:
|
||||
keys = ['.'.join(e)+'.m_flow' for e in (left,right)]
|
||||
if all(k in outputs for k in keys):
|
||||
self.assertAlmostEqual(sum(outputs[k] for k in keys),0,places=10)
|
||||
|
||||
def test_entire_registered_catalog_is_covered(self):
|
||||
from app.simulation.native_codegen.contracts import SUPPORTED_VERSIONS
|
||||
|
||||
Reference in new issue
Block a user