公开更多 AMESim 组件并接入信号机械闭环
This commit is contained in:
1 parent
db4bdb4b70
commit
3f51a124d6
28 files changed
+3397
-58
No files matched your search
@@ -0,0 +1,101 @@
|
||||
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_pnl0001_project() -> ReactFlowProjectPayload:
|
||||
return ReactFlowProjectPayload(
|
||||
name="amesim-pnl0001-smoke",
|
||||
nodes=[
|
||||
component_node(
|
||||
"cylinder_1",
|
||||
"cylinder",
|
||||
[physical_port("port_b", "outlet", "right")],
|
||||
{"volume": 0.01, "p0": 500000.0, "T0": 300.0},
|
||||
),
|
||||
component_node(
|
||||
"pnl_1",
|
||||
"amesim_pnl0001",
|
||||
[
|
||||
physical_port("port_1", "bidirectional", "left"),
|
||||
physical_port("port_2", "bidirectional", "right"),
|
||||
],
|
||||
{
|
||||
"diam": 0.01,
|
||||
"le": 1.0,
|
||||
"rr": 1.0e-5,
|
||||
"k": 1.35,
|
||||
"kth": 0.0,
|
||||
"extemp": 300.0,
|
||||
"gi": 1.0,
|
||||
"mode": 2.0,
|
||||
"p0": 300000.0,
|
||||
"T0": 300.0,
|
||||
},
|
||||
),
|
||||
component_node(
|
||||
"resistance_1",
|
||||
"amesim_pnl00r",
|
||||
[
|
||||
physical_port("port_1", "bidirectional", "left"),
|
||||
physical_port("port_2", "bidirectional", "right"),
|
||||
],
|
||||
{"diam": 0.01, "le": 0.5, "rr": 1.0e-5, "gi": 1.0},
|
||||
),
|
||||
component_node(
|
||||
"tank_1",
|
||||
"tank",
|
||||
[physical_port("port_a", "inlet", "left")],
|
||||
{"volume": 0.1, "p0": 100000.0, "T0": 300.0},
|
||||
),
|
||||
],
|
||||
edges=[
|
||||
physical_edge("edge-1", "cylinder_1", "port_b", "pnl_1", "port_1"),
|
||||
physical_edge("edge-2", "pnl_1", "port_2", "resistance_1", "port_1"),
|
||||
physical_edge("edge-3", "resistance_1", "port_2", "tank_1", "port_a"),
|
||||
],
|
||||
simulation={
|
||||
"t_start": 0.0,
|
||||
"t_stop": 0.002,
|
||||
"step": 0.001,
|
||||
"max_step": 0.001,
|
||||
"method": "BDF",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class AmesimPnl0001XmlTests(unittest.TestCase):
|
||||
def test_pnl0001_reactflow_project_compiles(self) -> None:
|
||||
network = compile_reactflow_network(amesim_pnl0001_project())
|
||||
|
||||
self.assertIn("pnl_1", network.components)
|
||||
self.assertEqual(network.components["pnl_1"].model_type, "amesim_pnl0001")
|
||||
self.assertTrue(network.pressure_flow_structure_dict()["isSquare"])
|
||||
|
||||
def test_pnl0001_system_xml_validates_and_simulates(self) -> None:
|
||||
xml = build_reactflow_system_xml(amesim_pnl0001_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("pnl_1.port_1.m_flow", result["series"])
|
||||
self.assertIn("pnl_1.re", result["series"])
|
||||
self.assertIn("pnl_1.m", result["series"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user