37 lines
993 B
Python
37 lines
993 B
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Literal
|
|
|
|
from app.simulation.core.ports import VariableRole
|
|
|
|
|
|
EquationOwner = Literal["connection", "component"]
|
|
EquationRelation = Literal["equal", "sumToZero", "constitutive", "state"]
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class EquationResidual:
|
|
"""One executable scalar equation in the pressure-flow subsystem."""
|
|
|
|
id: str
|
|
owner: EquationOwner
|
|
owner_id: str
|
|
relation: EquationRelation
|
|
variables: tuple[str, ...]
|
|
value: float
|
|
role: VariableRole | None = None
|
|
|
|
def as_definition_dict(self) -> dict[str, object]:
|
|
return {
|
|
"id": self.id,
|
|
"owner": self.owner,
|
|
"ownerId": self.owner_id,
|
|
"relation": self.relation,
|
|
"variables": list(self.variables),
|
|
"role": self.role,
|
|
}
|
|
|
|
def as_interface_dict(self) -> dict[str, object]:
|
|
return {**self.as_definition_dict(), "residual": self.value}
|