现有组件功能与Amesim组件比较对齐,补全功能;仿真服务启动环境检测,旧版json工程文件适配读取

This commit is contained in:
ljz committed 2026-09-13 20:01:56 +08:00
1 parent b6c22a54f8
commit 6fc9afe41d
119 files changed
+260114 -351

No files matched your search

+32 -3
View File
@@ -1,10 +1,11 @@
"""Native catalog regression against frozen, independent Python results."""
import json
import math
import subprocess
import unittest
import numpy as np
from app.simulation.native_codegen.extended import catalog_contracts, compile_extended_program
from app.simulation.native_codegen.compiler import compile_native_program
from app.simulation.native_codegen.compiler import compile_native_program, NativeCapabilityError
from app.simulation.native_codegen.build import build_native, toolchain
from app.simulation.systems.network import SimulationNetwork
from app.simulation.components.amesim.media.mediums import AmesimHeliumPengRobinsonMedium
@@ -61,6 +62,17 @@ class NativeCatalogTests(unittest.TestCase):
for index, case in enumerate(data['cases']):
with self.subTest(network=index):
net = reference_network(case)
invalid_friction = any(c['type']=='amesim_mecmas21' and c['parameters']['useFriction']==2
and c['parameters']['stoptype']!=3 and c['parameters']['fcoul']>c['parameters']['fstick']
for c in case['components'])
if invalid_friction:
# Three historical Python fixtures had fcoul=2, fstick=0.
# Amesim itself rejects that active configuration. Preserve
# the old files and verify explicit rejection in both paths.
for compiler in (compile_native_program,compile_extended_program):
with self.assertRaisesRegex(NativeCapabilityError,'fcoul'):
compiler(net)
continue
# Exercise the optimized compiler as well as the general catalog.
programs = [compile_extended_program(net)]
if index >= len(data['cases']) - 3:
@@ -78,8 +90,25 @@ class NativeCatalogTests(unittest.TestCase):
for row, probe in zip(rows, case['probes']):
self.assertTrue(row['success'])
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')
expected_rhs=list(probe['rhs']);expected_outputs=list(probe['outputs'])
# The frozen Python model incorrectly applied dry
# friction in restitution mode. Keep its bytes, but
# use Newton's law as the oracle for those two fields.
old=dict(zip(case['outputKeys'],probe['outputs']))
for component in case['components']:
if component['type']!='amesim_mecmas21':continue
params=component['parameters'];name=component['name']
if params['stoptype']!=3 or params['useFriction']!=2 or params['fcoul']==0:continue
velocity=old[name+'.v'];mass=params['mass']
self.assertTrue(params['xmin']<old[name+'.x']<params['xmax'])
acceleration=(old[name+'.port_1.f']+old[name+'.port_2.f']
-params['rvisc']*velocity-params['wind']*velocity*abs(velocity))/mass
acceleration+=9.80665*math.sin(math.radians(params['theta']))
expected_rhs[case['stateKeys'].index(name+'.v')]=acceleration
expected_outputs[case['outputKeys'].index(name+'.a')]=acceleration
expected_outputs[case['outputKeys'].index(name+'.Ffric')]=0
np.testing.assert_allclose(row['rhs'], [expected_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'], [expected_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