实现test_mql PNL0002管路动态
This commit is contained in:
1 parent
7569917924
commit
a071896834
6 files changed
+492
No files matched your search
@@ -3860,6 +3860,7 @@ class TestMqlSystem:
|
||||
self.archive_path = archive_path or Path(__file__).resolve().parents[2] / AMESIM_ARCHIVE_RELATIVE_PATH
|
||||
self.network = SimulationNetwork(name=MODEL_NAME)
|
||||
self.pnl0001_assembly = self._build_pnl0001_assembly()
|
||||
self.pnl0002_assembly = self._build_pnl0002_assembly()
|
||||
self.pnl0003_assembly = self._build_pnl0003_assembly()
|
||||
self.pnl00r_assembly = self._build_pnl00r_assembly()
|
||||
self.node3_assembly = self._build_node3_assembly()
|
||||
@@ -3893,6 +3894,13 @@ class TestMqlSystem:
|
||||
|
||||
return build_test_mql_pnl0001_assembly(self.archive_path)
|
||||
|
||||
def _build_pnl0002_assembly(self):
|
||||
from PythonModels.systems.test_mql_pneumatic_lines import (
|
||||
build_test_mql_pnl0002_assembly,
|
||||
)
|
||||
|
||||
return build_test_mql_pnl0002_assembly(self.archive_path)
|
||||
|
||||
def _build_pnl0003_assembly(self):
|
||||
from PythonModels.systems.test_mql_pneumatic_lines import (
|
||||
build_test_mql_pnl0003_assembly,
|
||||
@@ -3935,6 +3943,10 @@ class TestMqlSystem:
|
||||
def typed_pnl0001_line_count(self) -> int:
|
||||
return len(self.pnl0001_assembly.lines)
|
||||
|
||||
@property
|
||||
def typed_pnl0002_line_count(self) -> int:
|
||||
return len(self.pnl0002_assembly.lines)
|
||||
|
||||
@property
|
||||
def typed_pnl0003_line_count(self) -> int:
|
||||
return len(self.pnl0003_assembly.lines)
|
||||
|
||||
@@ -35,6 +35,29 @@ class TestMqlPnl0001Spec:
|
||||
return self.initial_gauge_pressure_pa + AMESIM_REFERENCE_PRESSURE_PA
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPnl0002Spec:
|
||||
alias: str
|
||||
source_component: str
|
||||
source_port: str
|
||||
target_component: str
|
||||
target_port: str
|
||||
diameter_mm: float
|
||||
length_m: float
|
||||
relative_roughness: float
|
||||
polytropic_constant: float
|
||||
heat_transfer_coefficient: float
|
||||
external_temperature_k: float
|
||||
gas_type_index: int
|
||||
mode: int
|
||||
initial_center_temperature_k: float
|
||||
initial_center_gauge_pressure_pa: float
|
||||
|
||||
@property
|
||||
def initial_center_absolute_pressure_pa(self) -> float:
|
||||
return self.initial_center_gauge_pressure_pa + AMESIM_REFERENCE_PRESSURE_PA
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPnl0003Spec:
|
||||
alias: str
|
||||
@@ -153,6 +176,82 @@ def load_test_mql_pnl0001_specs(
|
||||
return tuple(specs)
|
||||
|
||||
|
||||
def load_test_mql_pnl0002_specs(
|
||||
archive_path: str | Path,
|
||||
*,
|
||||
cir_member: str = "test_mql_.cir",
|
||||
) -> tuple[TestMqlPnl0002Spec, ...]:
|
||||
"""Load resolved PNL0002 geometry and center compliance initial state."""
|
||||
with tarfile.open(archive_path) as archive:
|
||||
cir_file = archive.extractfile(cir_member)
|
||||
if cir_file is None:
|
||||
raise ValueError(f"Missing AMESim circuit member: {cir_member}")
|
||||
cir_text = cir_file.read().decode("latin1")
|
||||
|
||||
numeric_globals = {
|
||||
name: value
|
||||
for name, expression in GLOBAL_PARAMETERS.items()
|
||||
if (value := resolve_numeric_expression(expression, {})) is not None
|
||||
}
|
||||
connections = {
|
||||
str(connection["alias"]): connection
|
||||
for connection in CONNECTION_SPECS
|
||||
if connection["submodel"] == "PNL0002"
|
||||
}
|
||||
specs = []
|
||||
for block in re.findall(r"<LINE>.*?</LINE>", cir_text, flags=re.DOTALL):
|
||||
if _optional_text(block, "SUB_NAME") != "PNL0002":
|
||||
continue
|
||||
alias = _required_text(block, "ALIAS")
|
||||
connection = connections.get(alias)
|
||||
if connection is None:
|
||||
raise ValueError(f"PNL0002 line {alias!r} is absent from CONNECTION_SPECS")
|
||||
real_parameters = _parameter_expressions(block, "RPARAM")
|
||||
integer_parameters = _parameter_expressions(block, "IPARAM")
|
||||
state_values = _ivar_values(block)
|
||||
specs.append(
|
||||
TestMqlPnl0002Spec(
|
||||
alias=alias,
|
||||
source_component=str(connection["source_component"]),
|
||||
source_port=str(connection["source_port"]),
|
||||
target_component=str(connection["target_component"]),
|
||||
target_port=str(connection["target_port"]),
|
||||
diameter_mm=_required_numeric(
|
||||
alias, "diam", real_parameters, numeric_globals
|
||||
),
|
||||
length_m=_required_numeric(alias, "le", real_parameters, numeric_globals),
|
||||
relative_roughness=_required_numeric(
|
||||
alias, "rr", real_parameters, numeric_globals
|
||||
),
|
||||
polytropic_constant=_required_numeric(
|
||||
alias, "k", real_parameters, numeric_globals
|
||||
),
|
||||
heat_transfer_coefficient=_required_numeric(
|
||||
alias, "kth", real_parameters, numeric_globals
|
||||
),
|
||||
external_temperature_k=_required_numeric(
|
||||
alias, "extemp", real_parameters, numeric_globals
|
||||
),
|
||||
gas_type_index=int(
|
||||
_required_numeric(alias, "gi", integer_parameters, numeric_globals)
|
||||
),
|
||||
mode=int(
|
||||
_required_numeric(alias, "mode", integer_parameters, numeric_globals)
|
||||
),
|
||||
initial_center_temperature_k=_required_numeric(
|
||||
alias, "tctr", state_values, numeric_globals
|
||||
),
|
||||
initial_center_gauge_pressure_pa=_required_numeric(
|
||||
alias, "pctr", state_values, numeric_globals
|
||||
),
|
||||
)
|
||||
)
|
||||
if set(connections) != {spec.alias for spec in specs}:
|
||||
missing = sorted(set(connections) - {spec.alias for spec in specs})
|
||||
raise ValueError(f"Missing PNL0002 parameter blocks: {missing}")
|
||||
return tuple(specs)
|
||||
|
||||
|
||||
def load_test_mql_pnl0003_specs(
|
||||
archive_path: str | Path,
|
||||
*,
|
||||
@@ -306,6 +405,15 @@ def _parameter_expressions(block: str, tag_name: str) -> dict[str, str]:
|
||||
return parameters
|
||||
|
||||
|
||||
def _ivar_values(block: str) -> dict[str, str]:
|
||||
values = {}
|
||||
for variable_block in re.findall(r"<IVAR>.*?</IVAR>", block, flags=re.DOTALL):
|
||||
value = _optional_text(variable_block, "VALUE")
|
||||
if value:
|
||||
values[_required_text(variable_block, "VARNAME")] = value
|
||||
return values
|
||||
|
||||
|
||||
def _evar_values(block: str) -> dict[str, str]:
|
||||
values = {}
|
||||
for variable_block in re.findall(r"<EVAR>.*?</EVAR>", block, flags=re.DOTALL):
|
||||
|
||||
@@ -9,14 +9,17 @@ from PythonModels.components.amesim_pneumatic import (
|
||||
)
|
||||
from PythonModels.components.amesim_pneumatic_line import (
|
||||
AmesimPnl0001Pipe,
|
||||
AmesimPnl0002Pipe,
|
||||
AmesimPnl0003Pipe,
|
||||
AmesimPnl00rPipe,
|
||||
)
|
||||
from PythonModels.systems.test_mql_line_parameters import (
|
||||
TestMqlPnl0001Spec,
|
||||
TestMqlPnl0002Spec,
|
||||
TestMqlPnl0003Spec,
|
||||
TestMqlPnl00rSpec,
|
||||
load_test_mql_pnl0001_specs,
|
||||
load_test_mql_pnl0002_specs,
|
||||
load_test_mql_pnl0003_specs,
|
||||
load_test_mql_pnl00r_specs,
|
||||
)
|
||||
@@ -34,6 +37,18 @@ class TestMqlPnl0001Assembly:
|
||||
raise KeyError(alias)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPnl0002Assembly:
|
||||
specs: tuple[TestMqlPnl0002Spec, ...]
|
||||
lines: dict[str, AmesimPnl0002Pipe]
|
||||
|
||||
def spec(self, alias: str) -> TestMqlPnl0002Spec:
|
||||
for spec in self.specs:
|
||||
if spec.alias == alias:
|
||||
return spec
|
||||
raise KeyError(alias)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPnl0003Assembly:
|
||||
specs: tuple[TestMqlPnl0003Spec, ...]
|
||||
@@ -82,6 +97,30 @@ def build_test_mql_pnl0001_assembly(
|
||||
return TestMqlPnl0001Assembly(specs=specs, lines=lines)
|
||||
|
||||
|
||||
def build_test_mql_pnl0002_assembly(
|
||||
archive_path: str | Path,
|
||||
*,
|
||||
gas: AmesimPneumaticGas = HELIUM_PNEUMATIC_GAS,
|
||||
) -> TestMqlPnl0002Assembly:
|
||||
specs = load_test_mql_pnl0002_specs(archive_path)
|
||||
lines = {
|
||||
spec.alias: AmesimPnl0002Pipe(
|
||||
name=spec.alias,
|
||||
diameter_mm=spec.diameter_mm,
|
||||
length_m=spec.length_m,
|
||||
relative_roughness=spec.relative_roughness,
|
||||
polytropic_constant=spec.polytropic_constant,
|
||||
heat_transfer_coefficient=spec.heat_transfer_coefficient,
|
||||
external_temperature_k=spec.external_temperature_k,
|
||||
gas=gas,
|
||||
pctr_0=spec.initial_center_absolute_pressure_pa,
|
||||
Tctr_0=spec.initial_center_temperature_k,
|
||||
)
|
||||
for spec in specs
|
||||
}
|
||||
return TestMqlPnl0002Assembly(specs=specs, lines=lines)
|
||||
|
||||
|
||||
def build_test_mql_pnl0003_assembly(
|
||||
archive_path: str | Path,
|
||||
*,
|
||||
|
||||
Reference in new issue
Block a user