同步仿真框架并接入AMESim气动组件
This commit is contained in:
1 parent
420bafeb4e
commit
db4bdb4b70
109 files changed
+26920
-420
No files matched your search
@@ -0,0 +1,87 @@
|
||||
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 amesim_pnpl01_project() -> ReactFlowProjectPayload:
|
||||
return ReactFlowProjectPayload(
|
||||
name="amesim-pnpl01-smoke",
|
||||
nodes=[
|
||||
component_node(
|
||||
"chamber_1",
|
||||
"amesim_pnch023",
|
||||
[
|
||||
physical_port("port_1", "bidirectional", "left"),
|
||||
physical_port("port_2", "bidirectional", "right"),
|
||||
],
|
||||
{
|
||||
"cvol": 0.057,
|
||||
"kth": 0.0,
|
||||
"sth": 0.1,
|
||||
"extemp": 293.15,
|
||||
"gi": 1.0,
|
||||
"p0": 100000.0,
|
||||
"T0": 293.15,
|
||||
},
|
||||
),
|
||||
component_node(
|
||||
"plug_1",
|
||||
"amesim_pnpl01",
|
||||
[physical_port("port_1", "bidirectional", "left")],
|
||||
),
|
||||
component_node(
|
||||
"plug_2",
|
||||
"amesim_pnpl01",
|
||||
[physical_port("port_1", "bidirectional", "left")],
|
||||
),
|
||||
],
|
||||
edges=[
|
||||
physical_edge("edge-1", "chamber_1", "port_1", "plug_1", "port_1"),
|
||||
physical_edge("edge-2", "chamber_1", "port_2", "plug_2", "port_1"),
|
||||
],
|
||||
simulation={
|
||||
"t_start": 0.0,
|
||||
"t_stop": 0.002,
|
||||
"step": 0.001,
|
||||
"max_step": 0.001,
|
||||
"method": "BDF",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class AmesimPnpl01XmlTests(unittest.TestCase):
|
||||
def test_pnpl01_reactflow_project_compiles(self) -> None:
|
||||
network = compile_reactflow_network(amesim_pnpl01_project())
|
||||
|
||||
self.assertIn("plug_1", network.components)
|
||||
self.assertEqual(network.components["plug_1"].model_type, "amesim_pnpl01")
|
||||
self.assertTrue(network.pressure_flow_structure_dict()["isSquare"])
|
||||
|
||||
def test_pnpl01_system_xml_validates_and_simulates(self) -> None:
|
||||
xml = build_reactflow_system_xml(amesim_pnpl01_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.assertTrue(
|
||||
all(abs(value) < 1.0e-12 for value in result["series"]["plug_1.port_1.m_flow"])
|
||||
)
|
||||
self.assertIn("chamber_1.p", result["series"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user