Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**In development**

* [PR104](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/104) Remove `roseau.load_flow.utils.BranchType`
* [GH99](https://github.com/RoseauTechnologies/Roseau_Load_Flow/issues/99) Add `Line.res_series_currents`
and `Line.res_shunt_currents` properties to get the currents in the series and shunt components
of lines. Also added `ElectricalNetwork.res_lines` that contains the series losses and currents
Expand Down
5 changes: 2 additions & 3 deletions roseau/load_flow/models/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from roseau.load_flow.models.core import Element
from roseau.load_flow.typing import Id, JsonDict
from roseau.load_flow.units import Q_, ureg_wraps
from roseau.load_flow.utils import BranchType

logger = logging.getLogger(__name__)

Expand All @@ -24,7 +23,7 @@ class AbstractBranch(Element):
:doc:`Switch model documentation </models/Switch>`
"""

branch_type: BranchType
branch_type: str

def __init__(
self,
Expand Down Expand Up @@ -130,7 +129,7 @@ def from_dict(cls, data: JsonDict) -> Self:
def to_dict(self) -> JsonDict:
res = {
"id": self.id,
"type": str(self.branch_type),
"type": self.branch_type,
"phases1": self.phases1,
"phases2": self.phases2,
"bus1": self.bus1.id,
Expand Down
5 changes: 2 additions & 3 deletions roseau/load_flow/models/lines/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from roseau.load_flow.models.sources import VoltageSource
from roseau.load_flow.typing import Id, JsonDict
from roseau.load_flow.units import Q_, ureg_wraps
from roseau.load_flow.utils import BranchType

logger = logging.getLogger(__name__)

Expand All @@ -26,7 +25,7 @@ class Switch(AbstractBranch):
:doc:`Switch model documentation </models/Switch>`
"""

branch_type = BranchType.SWITCH
branch_type = "switch"

allowed_phases = frozenset(Bus.allowed_phases | {"a", "b", "c", "n"})
"""The allowed phases for a switch are:
Expand Down Expand Up @@ -135,7 +134,7 @@ class Line(AbstractBranch):
:doc:`Line documentation </models/Line/index>`
"""

branch_type = BranchType.LINE
branch_type = "line"

allowed_phases = frozenset(Bus.allowed_phases | {"a", "b", "c", "n"})
"""The allowed phases for a line are:
Expand Down
3 changes: 1 addition & 2 deletions roseau/load_flow/models/transformers/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from roseau.load_flow.models.buses import Bus
from roseau.load_flow.models.transformers.parameters import TransformerParameters
from roseau.load_flow.typing import Id, JsonDict
from roseau.load_flow.utils import BranchType

logger = logging.getLogger(__name__)

Expand All @@ -22,7 +21,7 @@ class Transformer(AbstractBranch):
:doc:`Transformer models documentation </models/Transformer/index>`
"""

branch_type = BranchType.TRANSFORMER
branch_type = "transformer"

allowed_phases = Bus.allowed_phases
"""The allowed phases for a transformer are:
Expand Down
3 changes: 1 addition & 2 deletions roseau/load_flow/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from roseau.load_flow.utils.constants import CX, DELTA_P, EPSILON_0, EPSILON_R, MU_0, MU_R, OMEGA, PI, RHO, TAN_D, F
from roseau.load_flow.utils.mixins import Identifiable, JsonMixin
from roseau.load_flow.utils.types import BranchType, ConductorType, InsulationType, LineModel, LineType
from roseau.load_flow.utils.types import ConductorType, InsulationType, LineModel, LineType

__all__ = [
# Constants
Expand All @@ -26,5 +26,4 @@
"LineModel",
"ConductorType",
"InsulationType",
"BranchType",
]
42 changes: 0 additions & 42 deletions roseau/load_flow/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,45 +300,3 @@ def without_shunt(cls) -> tuple["LineModel", ...]:
The tuple of line models which do not support the shunt.
"""
return cls.Z_NEUTRAL, cls.Z


@unique
class BranchType(Enum):
"""The type of 'line' in a network."""

LINE = auto()
"""The branch is a regular line."""
TRANSFORMER = auto()
"""The branch is a regular transformer."""
SWITCH = auto()
"""The branch is a regular switch."""

def __str__(self) -> str:
"""Print a `BranchType`.

Returns:
A printable string of the connection type.
"""
return self.name.lower()

@classmethod
def from_string(cls, string: str) -> Self:
"""Convert a string into a ConnectionType

Args:
string:
The string to convert

Returns:
The corresponding ConnectionType.
"""
if string == "line":
return cls.LINE
elif string == "transformer":
return cls.TRANSFORMER
elif string == "switch":
return cls.SWITCH
else:
msg = f"The string {string!r} cannot be converted into a BranchType."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_BRANCH_TYPE)