公开更多 AMESim 组件并接入信号机械闭环
This commit is contained in:
1 parent
db4bdb4b70
commit
3f51a124d6
28 files changed
+3397
-58
No files matched your search
@@ -0,0 +1,93 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.main import (
|
||||
ReactFlowProjectPayload,
|
||||
build_reactflow_system_xml,
|
||||
compile_reactflow_network,
|
||||
run_system_xml_simulation,
|
||||
)
|
||||
from app.system_xml import validate_system_xml_document
|
||||
from tests.test_generic_system_xml_simulation import component_node, physical_edge
|
||||
from tests.test_system_xml_protocol import physical_port
|
||||
|
||||
|
||||
def _pnpl_node(index: int) -> object:
|
||||
return component_node(
|
||||
f"boundary_{index}",
|
||||
"amesim_pnpl01",
|
||||
[physical_port("port_1", "bidirectional", "left")],
|
||||
{},
|
||||
)
|
||||
|
||||
|
||||
def amesim_pnch012_project() -> ReactFlowProjectPayload:
|
||||
return ReactFlowProjectPayload(
|
||||
name="amesim-pnch012-smoke",
|
||||
nodes=[
|
||||
component_node(
|
||||
"chamber_1",
|
||||
"amesim_pnch012",
|
||||
[
|
||||
physical_port("port_1", "bidirectional", "left"),
|
||||
physical_port("port_2", "bidirectional", "right"),
|
||||
physical_port("port_3", "bidirectional", "left"),
|
||||
physical_port("port_4", "bidirectional", "right"),
|
||||
],
|
||||
{
|
||||
"cvol0": 0.015,
|
||||
"kth": 0.0,
|
||||
"sth": 0.7,
|
||||
"extemp": 300.0,
|
||||
"gi": 1.0,
|
||||
"p0": 200000.0,
|
||||
"T0": 300.0,
|
||||
"vol1": 0.001,
|
||||
"vol2": 0.0,
|
||||
"vol3": 0.0,
|
||||
"vol4": 0.0,
|
||||
"dvol1": 0.0,
|
||||
"dvol2": 0.0,
|
||||
"dvol3": 0.0,
|
||||
"dvol4": 0.0,
|
||||
},
|
||||
),
|
||||
_pnpl_node(1),
|
||||
_pnpl_node(2),
|
||||
_pnpl_node(3),
|
||||
_pnpl_node(4),
|
||||
],
|
||||
edges=[
|
||||
physical_edge("edge-1", "chamber_1", "port_1", "boundary_1", "port_1"),
|
||||
physical_edge("edge-2", "chamber_1", "port_2", "boundary_2", "port_1"),
|
||||
physical_edge("edge-3", "chamber_1", "port_3", "boundary_3", "port_1"),
|
||||
physical_edge("edge-4", "chamber_1", "port_4", "boundary_4", "port_1"),
|
||||
],
|
||||
simulation={"t_start": 0.0, "t_stop": 0.002, "step": 0.001, "max_step": 0.001, "method": "BDF"},
|
||||
)
|
||||
|
||||
|
||||
class AmesimPnch012XmlTests(unittest.TestCase):
|
||||
def test_pnch012_reactflow_project_compiles(self) -> None:
|
||||
network = compile_reactflow_network(amesim_pnch012_project())
|
||||
|
||||
self.assertIn("chamber_1", network.components)
|
||||
self.assertEqual(network.components["chamber_1"].model_type, "amesim_pnch012")
|
||||
self.assertTrue(network.pressure_flow_structure_dict()["isSquare"])
|
||||
|
||||
def test_pnch012_system_xml_validates_and_simulates(self) -> None:
|
||||
xml = build_reactflow_system_xml(amesim_pnch012_project())
|
||||
report = validate_system_xml_document(xml)
|
||||
|
||||
self.assertTrue(report.valid, report.as_dict())
|
||||
result = run_system_xml_simulation(xml)
|
||||
|
||||
self.assertTrue(result["success"], result["message"])
|
||||
self.assertEqual(result["series"]["time"], [0.0, 0.001, 0.002])
|
||||
self.assertIn("chamber_1.port_1.m_flow", result["series"])
|
||||
self.assertIn("chamber_1.vol", result["series"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user