接入test_mql P4节点局部闭合
This commit is contained in:
1 parent
a071896834
commit
fafce0af87
3 files changed
+647
No files matched your search
@@ -3963,6 +3963,48 @@ class TestMqlSystem:
|
||||
def typed_node4_count(self) -> int:
|
||||
return len(self.node4_assembly)
|
||||
|
||||
def _pnl0001_spec_for_node_port(self, node_alias: str, port_name: str):
|
||||
for spec in self.pnl0001_assembly.specs:
|
||||
if spec.source_component == node_alias and spec.source_port == port_name:
|
||||
return spec
|
||||
if spec.target_component == node_alias and spec.target_port == port_name:
|
||||
return spec
|
||||
raise KeyError(f"No PNL0001 line attached to {node_alias}.{port_name}")
|
||||
|
||||
def _pnl0001_line_for_node_port(self, node_alias: str, port_name: str):
|
||||
spec = self._pnl0001_spec_for_node_port(node_alias, port_name)
|
||||
return self.pnl0001_assembly.lines[spec.alias]
|
||||
|
||||
def _pnl0002_spec_for_node_port(self, node_alias: str, port_name: str):
|
||||
for spec in self.pnl0002_assembly.specs:
|
||||
if spec.source_component == node_alias and spec.source_port == port_name:
|
||||
return spec
|
||||
if spec.target_component == node_alias and spec.target_port == port_name:
|
||||
return spec
|
||||
raise KeyError(f"No PNL0002 line attached to {node_alias}.{port_name}")
|
||||
|
||||
def _pnl0002_line_for_node_port(self, node_alias: str, port_name: str):
|
||||
spec = self._pnl0002_spec_for_node_port(node_alias, port_name)
|
||||
return self.pnl0002_assembly.lines[spec.alias]
|
||||
|
||||
def _p4_node_alias_for_orifice_port_2(self, orifice_alias: str) -> str:
|
||||
for spec in CONNECTION_SPECS:
|
||||
if spec["submodel"] != "DIRECT":
|
||||
continue
|
||||
if (
|
||||
spec["source_component"] == orifice_alias
|
||||
and spec["source_port"] == "port_2"
|
||||
and str(spec["target_component"]) in self.node4_assembly
|
||||
):
|
||||
return str(spec["target_component"])
|
||||
if (
|
||||
spec["target_component"] == orifice_alias
|
||||
and spec["target_port"] == "port_2"
|
||||
and str(spec["source_component"]) in self.node4_assembly
|
||||
):
|
||||
return str(spec["source_component"])
|
||||
raise KeyError(f"No P4 node attached to {orifice_alias}.port_2")
|
||||
|
||||
def _pnl0003_spec_for_node_port(self, node_alias: str, port_name: str):
|
||||
for spec in self.pnl0003_assembly.specs:
|
||||
if spec.source_component == node_alias and spec.source_port == port_name:
|
||||
@@ -4430,6 +4472,150 @@ class TestMqlSystem:
|
||||
t_eval=t_eval,
|
||||
)
|
||||
|
||||
def pn3_p4_node_chamber_segment_closure_from_spec(
|
||||
self,
|
||||
spec,
|
||||
*,
|
||||
inlet_node_pressure_pa: float,
|
||||
resistance_boundary_pressure_pa: float,
|
||||
inlet_node_temperature_k: float = 293.15,
|
||||
resistance_boundary_temperature_k: float = 293.15,
|
||||
p4_primary_boundary_pressure_pa: float = 100_000.0,
|
||||
p4_primary_boundary_temperature_k: float = 293.15,
|
||||
p4_port1_boundary_pressure_pa: float = 100_000.0,
|
||||
p4_port1_boundary_temperature_k: float = 293.15,
|
||||
p4_port3_boundary_pressure_pa: float = 100_000.0,
|
||||
p4_port3_boundary_temperature_k: float = 293.15,
|
||||
):
|
||||
"""Close a PN3 chamber segment through the adjacent real P4 node.
|
||||
|
||||
The P4 primary pressure/temperature is supplied by the PNL0001 line on
|
||||
P4 port 2. Ports 1 and 3 use the adjacent PNL0002 center compliances;
|
||||
their far P4 nodes remain prescribed boundaries in this local closure.
|
||||
"""
|
||||
from PythonModels.components.amesim_pneumatic import (
|
||||
AmesimPneumaticOrifice,
|
||||
AmesimPneumaticVolume,
|
||||
)
|
||||
from PythonModels.systems.test_mql_closure import (
|
||||
TestMqlPneumaticBoundaryCondition,
|
||||
TestMqlPn3P4NodeChamberSegmentClosure,
|
||||
TestMqlPn3P4NodeChamberSegmentComponents,
|
||||
)
|
||||
|
||||
inlet_line = self.pnl0001_assembly.lines[spec.inlet_line_alias]
|
||||
outlet_line = self.pnl0001_assembly.lines[spec.outlet_line_alias]
|
||||
node_line_spec = self._pnl0003_spec_for_node_port(
|
||||
spec.outlet_node_alias,
|
||||
"port_2",
|
||||
)
|
||||
node_line = self.pnl0003_assembly.lines[node_line_spec.alias]
|
||||
node_orifice_alias = (
|
||||
node_line_spec.target_component
|
||||
if node_line_spec.source_component == spec.outlet_node_alias
|
||||
else node_line_spec.source_component
|
||||
)
|
||||
p4_node_alias = self._p4_node_alias_for_orifice_port_2(node_orifice_alias)
|
||||
node_orifice = self.pneumatic_assembly.variable_orifices[node_orifice_alias]
|
||||
node_resistance = self._pnl00r_line_for_node_port(
|
||||
spec.outlet_node_alias,
|
||||
"port_1",
|
||||
)
|
||||
node = self.node3_assembly[spec.outlet_node_alias]
|
||||
p4_node = self.node4_assembly[p4_node_alias]
|
||||
p4_primary_line = self._pnl0001_line_for_node_port(p4_node_alias, "port_2")
|
||||
p4_port1_line = self._pnl0002_line_for_node_port(p4_node_alias, "port_1")
|
||||
p4_port3_line = self._pnl0002_line_for_node_port(p4_node_alias, "port_3")
|
||||
volume = self.network.components[spec.volume_alias]
|
||||
inlet_orifice = self.network.components[spec.inlet_orifice_alias]
|
||||
outlet_orifice = self.network.components[spec.outlet_orifice_alias]
|
||||
if not isinstance(volume, AmesimPneumaticVolume):
|
||||
raise TypeError(f"{spec.volume_alias} is not an AMESim pneumatic volume")
|
||||
if not isinstance(inlet_orifice, AmesimPneumaticOrifice):
|
||||
raise TypeError(
|
||||
f"{spec.inlet_orifice_alias} is not an AMESim pneumatic orifice"
|
||||
)
|
||||
if not isinstance(outlet_orifice, AmesimPneumaticOrifice):
|
||||
raise TypeError(
|
||||
f"{spec.outlet_orifice_alias} is not an AMESim pneumatic orifice"
|
||||
)
|
||||
return TestMqlPn3P4NodeChamberSegmentClosure(
|
||||
components=TestMqlPn3P4NodeChamberSegmentComponents(
|
||||
inlet_line=inlet_line,
|
||||
outlet_line=outlet_line,
|
||||
node_line=node_line,
|
||||
node_resistance=node_resistance,
|
||||
node_orifice=node_orifice,
|
||||
node=node,
|
||||
p4_node=p4_node,
|
||||
p4_primary_line=p4_primary_line,
|
||||
p4_port1_line=p4_port1_line,
|
||||
p4_port3_line=p4_port3_line,
|
||||
volume=volume,
|
||||
inlet_orifice=inlet_orifice,
|
||||
outlet_orifice=outlet_orifice,
|
||||
spec=spec,
|
||||
),
|
||||
inlet_node=TestMqlPneumaticBoundaryCondition(
|
||||
pressure_pa=inlet_node_pressure_pa,
|
||||
temperature_k=inlet_node_temperature_k,
|
||||
),
|
||||
resistance_boundary=TestMqlPneumaticBoundaryCondition(
|
||||
pressure_pa=resistance_boundary_pressure_pa,
|
||||
temperature_k=resistance_boundary_temperature_k,
|
||||
),
|
||||
p4_primary_boundary=TestMqlPneumaticBoundaryCondition(
|
||||
pressure_pa=p4_primary_boundary_pressure_pa,
|
||||
temperature_k=p4_primary_boundary_temperature_k,
|
||||
),
|
||||
p4_port1_boundary=TestMqlPneumaticBoundaryCondition(
|
||||
pressure_pa=p4_port1_boundary_pressure_pa,
|
||||
temperature_k=p4_port1_boundary_temperature_k,
|
||||
),
|
||||
p4_port3_boundary=TestMqlPneumaticBoundaryCondition(
|
||||
pressure_pa=p4_port3_boundary_pressure_pa,
|
||||
temperature_k=p4_port3_boundary_temperature_k,
|
||||
),
|
||||
)
|
||||
|
||||
def simulate_pn3_p4_node_chamber_segment_from_spec(
|
||||
self,
|
||||
spec,
|
||||
*,
|
||||
inlet_node_pressure_pa: float,
|
||||
resistance_boundary_pressure_pa: float,
|
||||
inlet_node_temperature_k: float = 293.15,
|
||||
resistance_boundary_temperature_k: float = 293.15,
|
||||
p4_primary_boundary_pressure_pa: float = 100_000.0,
|
||||
p4_primary_boundary_temperature_k: float = 293.15,
|
||||
p4_port1_boundary_pressure_pa: float = 100_000.0,
|
||||
p4_port1_boundary_temperature_k: float = 293.15,
|
||||
p4_port3_boundary_pressure_pa: float = 100_000.0,
|
||||
p4_port3_boundary_temperature_k: float = 293.15,
|
||||
config: SolveIVPConfig | None = None,
|
||||
t_eval: list[float] | None = None,
|
||||
):
|
||||
closure = self.pn3_p4_node_chamber_segment_closure_from_spec(
|
||||
spec,
|
||||
inlet_node_pressure_pa=inlet_node_pressure_pa,
|
||||
resistance_boundary_pressure_pa=resistance_boundary_pressure_pa,
|
||||
inlet_node_temperature_k=inlet_node_temperature_k,
|
||||
resistance_boundary_temperature_k=resistance_boundary_temperature_k,
|
||||
p4_primary_boundary_pressure_pa=p4_primary_boundary_pressure_pa,
|
||||
p4_primary_boundary_temperature_k=p4_primary_boundary_temperature_k,
|
||||
p4_port1_boundary_pressure_pa=p4_port1_boundary_pressure_pa,
|
||||
p4_port1_boundary_temperature_k=p4_port1_boundary_temperature_k,
|
||||
p4_port3_boundary_pressure_pa=p4_port3_boundary_pressure_pa,
|
||||
p4_port3_boundary_temperature_k=p4_port3_boundary_temperature_k,
|
||||
)
|
||||
run_config = config or SolveIVPConfig(t_stop=1.0e-4, max_step=1.0e-5)
|
||||
return integrate_ode(
|
||||
rhs=lambda t, state: closure.rhs(state),
|
||||
initial_state=closure.initial_state_vector(),
|
||||
config=run_config,
|
||||
t_eval=t_eval,
|
||||
)
|
||||
|
||||
def pneumatic_branch_closure_from_spec(self, spec):
|
||||
return self.pneumatic_branch_closure(
|
||||
name=spec.name,
|
||||
|
||||
Reference in new issue
Block a user