fix: align mechanical dynamic port validation
This commit is contained in:
1 parent
6a064892e2
commit
4e0b9fd8cc
7 files changed
+105
-7
No files matched your search
@@ -96,8 +96,8 @@ class SimulationNetwork:
|
||||
f"Cannot connect component {endpoint_a.component} to itself."
|
||||
)
|
||||
|
||||
first_port = self._port_for(endpoint_a)
|
||||
second_port = self._port_for(endpoint_b)
|
||||
first_port = self._active_port_for(endpoint_a)
|
||||
second_port = self._active_port_for(endpoint_b)
|
||||
first_definition = first_port.definition
|
||||
second_definition = second_port.definition
|
||||
if first_definition is None or second_definition is None:
|
||||
@@ -168,6 +168,20 @@ class SimulationNetwork:
|
||||
raise ValueError(f"Unknown component: {endpoint.component}.") from exc
|
||||
return component.get_port(endpoint.port)
|
||||
|
||||
def _active_port_for(self, endpoint: Endpoint) -> PortState:
|
||||
try:
|
||||
component = self.components[endpoint.component]
|
||||
except KeyError as exc:
|
||||
raise ValueError(f"Unknown component: {endpoint.component}.") from exc
|
||||
active_names = {
|
||||
definition.name for definition in component.active_port_definitions
|
||||
}
|
||||
if endpoint.port not in active_names:
|
||||
raise ValueError(
|
||||
f"Port {endpoint} is not active for the component's current parameters."
|
||||
)
|
||||
return component.get_port(endpoint.port)
|
||||
|
||||
def connection_equation_residuals(self) -> tuple[EquationResidual, ...]:
|
||||
"""Evaluate connector equations that have a direct scalar residual.
|
||||
|
||||
|
||||
Reference in new issue
Block a user