验收四路模型并优化拓扑求解性能
This commit is contained in:
1 parent
caca32a513
commit
456c29b3b6
20 files changed
+1085
-137
No files matched your search
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import lru_cache
|
||||
from collections.abc import Mapping
|
||||
from math import isclose, log, sqrt, tanh
|
||||
|
||||
@@ -277,6 +278,7 @@ class AmesimPnor001(AlgebraicComponent):
|
||||
)
|
||||
)
|
||||
|
||||
@lru_cache(maxsize=32768)
|
||||
def _one_way_flow_characteristics(
|
||||
self,
|
||||
*,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from functools import lru_cache
|
||||
from math import isclose, log, log10, pi, sqrt, tanh
|
||||
|
||||
from app.simulation.components.amesim.gases import (
|
||||
@@ -47,7 +48,7 @@ class AmesimPnl00r(AlgebraicComponent):
|
||||
"""
|
||||
|
||||
MODEL_TYPE = "amesim_pnl00r"
|
||||
MODEL_VERSION = "0.2.0"
|
||||
MODEL_VERSION = "0.3.0"
|
||||
PORTS = (
|
||||
PortDefinition.pneumatic("port_1", nominal_role="bidirectional"),
|
||||
PortDefinition.pneumatic("port_2", nominal_role="bidirectional"),
|
||||
@@ -217,8 +218,12 @@ class AmesimPnl00r(AlgebraicComponent):
|
||||
if self.rr <= 0.0:
|
||||
turbulent = smooth_turbulent
|
||||
else:
|
||||
# Nikuradse's fully rough asymptote is the Re-independent limit
|
||||
# of Colebrook. Haaland's rounded all-regime approximation is
|
||||
# about 0.2003% high at the test_mql roughness values, enough to
|
||||
# bias its long high-Re PNL0001 filling transient.
|
||||
fully_rough = 1.0 / (
|
||||
-1.8 * log10((self.rr / 3.7) ** 1.11)
|
||||
-2.0 * log10(self.rr / 3.7)
|
||||
) ** 2
|
||||
roughness_reynolds = reynolds_number * self.rr
|
||||
roughness_weight = roughness_reynolds * roughness_reynolds / (
|
||||
@@ -351,7 +356,7 @@ class AmesimPnl0001(ThermodynamicVolumeComponent):
|
||||
"""AMESim PNL0001 C-R pneumatic pipe with compressibility and friction."""
|
||||
|
||||
MODEL_TYPE = "amesim_pnl0001"
|
||||
MODEL_VERSION = "0.3.0"
|
||||
MODEL_VERSION = "0.4.0"
|
||||
PORTS = (
|
||||
PortDefinition.pneumatic("port_1", nominal_role="bidirectional"),
|
||||
PortDefinition.pneumatic("port_2", nominal_role="bidirectional"),
|
||||
@@ -685,6 +690,7 @@ class AmesimPnl0001(ThermodynamicVolumeComponent):
|
||||
upper = middle
|
||||
return 0.5 * (lower + upper)
|
||||
|
||||
@lru_cache(maxsize=32768)
|
||||
def _one_way_pn2pipefr_mass_flow(
|
||||
self,
|
||||
*,
|
||||
@@ -890,7 +896,7 @@ class AmesimPnl0002(AmesimPnl0001):
|
||||
"""AMESim PNL0002 R-C-R pneumatic pipe with one center compliance."""
|
||||
|
||||
MODEL_TYPE = "amesim_pnl0002"
|
||||
MODEL_VERSION = "0.5.0"
|
||||
MODEL_VERSION = "0.6.0"
|
||||
PORTS = (
|
||||
PortDefinition.pneumatic("port_1", nominal_role="bidirectional"),
|
||||
PortDefinition.pneumatic("port_2", nominal_role="bidirectional"),
|
||||
@@ -1123,7 +1129,7 @@ class AmesimPnl0003(DynamicComponent):
|
||||
|
||||
state_size = 4
|
||||
MODEL_TYPE = "amesim_pnl0003"
|
||||
MODEL_VERSION = "0.3.0"
|
||||
MODEL_VERSION = "0.4.0"
|
||||
PORTS = (
|
||||
PortDefinition.pneumatic("port_1", nominal_role="bidirectional"),
|
||||
PortDefinition.pneumatic("port_2", nominal_role="bidirectional"),
|
||||
|
||||
@@ -1082,7 +1082,14 @@ class AmesimLmechn1(AlgebraicComponent):
|
||||
|
||||
@property
|
||||
def total_force(self) -> float:
|
||||
return sum(self.get_port(port_name).f for port_name in self.active_ports)
|
||||
# AMESim's ``tforce`` is the force transmitted by the summed branch
|
||||
# ports (1..v1). Port 9 is the balancing/common port and is excluded
|
||||
# from that reported value.
|
||||
return sum(self.get_port(port_name).f for port_name in self.active_ports[:-1])
|
||||
|
||||
@property
|
||||
def force_balance(self) -> float:
|
||||
return self.total_force + self.port_9.f
|
||||
|
||||
def pressure_flow_equation_residuals(self) -> tuple[EquationResidual, ...]:
|
||||
reference = self.port_9
|
||||
@@ -1119,7 +1126,7 @@ class AmesimLmechn1(AlgebraicComponent):
|
||||
relation="sumToZero",
|
||||
variables=tuple(f"{self.name}.{port_name}.f" for port_name in self.active_ports),
|
||||
role="flow",
|
||||
value=self.total_force,
|
||||
value=self.force_balance,
|
||||
)
|
||||
)
|
||||
return tuple(residuals)
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from functools import lru_cache
|
||||
from typing import ClassVar
|
||||
|
||||
from app.simulation.core.errors import RecoverableTrialStateError
|
||||
@@ -197,6 +198,7 @@ class AmesimHeliumPengRobinsonMedium(IdealGasMedium):
|
||||
h / self.R_gas - self.nasa_enthalpy_constant_K
|
||||
) / self.nasa_cp_over_R
|
||||
|
||||
@lru_cache(maxsize=8192)
|
||||
def temperature_from_pressure_enthalpy(self, p: float, h: float) -> float:
|
||||
temperature = max(self.temperature_from_enthalpy(h), 2.2)
|
||||
for _iteration in range(16):
|
||||
@@ -220,12 +222,21 @@ class AmesimHeliumPengRobinsonMedium(IdealGasMedium):
|
||||
)
|
||||
return self.temperature_from_internal_energy(U / m)
|
||||
|
||||
@lru_cache(maxsize=8192)
|
||||
def properties_from_mU(
|
||||
self,
|
||||
m: float,
|
||||
U: float,
|
||||
V: float,
|
||||
) -> ThermodynamicProperties:
|
||||
"""Recover a real-gas state, reusing exact repeated evaluations.
|
||||
|
||||
Implicit integration asks several component interfaces for the same
|
||||
``(m, U, V)`` state while closing one RHS evaluation and while building
|
||||
finite-difference Jacobians. The calculation is pure and its result is
|
||||
immutable, so an exact-key bounded cache avoids repeating the
|
||||
Peng-Robinson temperature iteration without changing model semantics.
|
||||
"""
|
||||
if m <= 0.0:
|
||||
raise RecoverableTrialStateError(
|
||||
"Mass must stay positive when recovering temperature."
|
||||
|
||||
Reference in new issue
Block a user