59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from app.simulation.components.amesim.boundary.sources import AmesimPnpl01
|
|
from app.simulation.components.amesim.flow.pipes import AmesimPnl0001, AmesimPnl0003
|
|
from app.simulation.core.medium import IdealGasMedium
|
|
from app.simulation.solvers.solver import SolveIVPConfig
|
|
from app.simulation.systems.generic import GenericFluidSystem, simulation_preparation_issues
|
|
from app.simulation.systems.network import SimulationNetwork
|
|
|
|
|
|
class IdealPneumaticStorageCouplingTests(unittest.TestCase):
|
|
def build_network(self) -> SimulationNetwork:
|
|
medium = IdealGasMedium()
|
|
network = SimulationNetwork("ideal-pipe-compliance-coupling")
|
|
for component in (
|
|
AmesimPnpl01("closed_1"),
|
|
AmesimPnl0001("pnl0001", medium, p0=15.3e6, T0=293.15),
|
|
AmesimPnl0003(
|
|
"pnl0003",
|
|
medium,
|
|
p1_0=15.3e6,
|
|
T1_0=293.15,
|
|
p2_0=15.3e6,
|
|
T2_0=293.15,
|
|
),
|
|
AmesimPnpl01("closed_2"),
|
|
):
|
|
network.add_component(component)
|
|
network.connect("closed_1", "port_1", "pnl0001", "port_1")
|
|
network.connect("pnl0001", "port_2", "pnl0003", "port_1")
|
|
network.connect("pnl0003", "port_2", "closed_2", "port_1")
|
|
return network
|
|
|
|
def test_supported_amesim_pipe_compliances_are_not_rejected(self) -> None:
|
|
issues = simulation_preparation_issues(self.build_network())
|
|
|
|
self.assertNotIn(
|
|
"IDEAL_STORAGE_COUPLING_UNSUPPORTED",
|
|
{issue.code for issue in issues},
|
|
)
|
|
|
|
def test_coupled_pipe_compliances_run_without_fictitious_resistance(self) -> None:
|
|
system = GenericFluidSystem(self.build_network())
|
|
|
|
result = system.simulate(
|
|
SolveIVPConfig(t_stop=0.001, method="BDF", max_step=0.0002),
|
|
sample_step=0.001,
|
|
)
|
|
|
|
self.assertTrue(result.success)
|
|
self.assertAlmostEqual(result.final["pnl0001.p"], 15.3e6, delta=1.0e-4)
|
|
self.assertAlmostEqual(result.final["pnl0003.p1"], 15.3e6, delta=1.0e-4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|