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
14 changes: 8 additions & 6 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

**In development**

* [PR113](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/113) Raise an error when accessing the results of
disconnected elements.
* [PR112](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/112) Make the geometry serialization optional.
* [PR106](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/106) Improvements for non-euclidean projections.
* [PR104](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/104) Remove `roseau.load_flow.utils.BranchType`
Expand All @@ -14,14 +16,14 @@
* [GH100](https://github.com/RoseauTechnologies/Roseau_Load_Flow/issues/100) Fix the `Yz` transformers
* [PR97](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/97) Add the model section to the documentation
* [PR96](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/96)
* Add single-phase transformer
* Add center-tapped transformer
* Remove the `TransformerType` enumeration
* Add single-phase transformer
* Add center-tapped transformer
* Remove the `TransformerType` enumeration
* [PR93](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/93) Add short circuit computation
* [PR92](https://github.com/RoseauTechnologies/Roseau_Load_Flow/pull/92)
* Add the changelog in the documentation
* Use NodeJs 20 in the Dockerfile
* Correction of a dead link in the README
* Add the changelog in the documentation
* Use NodeJs 20 in the Dockerfile
* Correction of a dead link in the README

## Version 0.4.0

Expand Down
23 changes: 11 additions & 12 deletions roseau/load_flow/models/loads/loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _validate_value(self, value: Sequence[complex]) -> np.ndarray:
return np.asarray(value, dtype=complex)

def _res_potentials_getter(self, warning: bool) -> np.ndarray:
self._raise_disconnected_error()
return self.bus._get_potentials_of(self.phases, warning)

@property
Expand Down Expand Up @@ -159,6 +160,13 @@ def disconnect(self) -> None:
self._disconnect()
self.bus = None

def _raise_disconnected_error(self) -> None:
"""Raise an error if the load is disconnected."""
if self.bus is None:
msg = f"The load {self.id!r} is disconnected and cannot be used anymore."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.DISCONNECTED_ELEMENT)

#
# Json Mixin interface
#
Expand Down Expand Up @@ -309,10 +317,7 @@ def res_flexible_powers(self) -> Q_[np.ndarray]:
# Json Mixin interface
#
def to_dict(self, include_geometry: bool = True) -> JsonDict:
if self.bus is None:
msg = f"The load {self.id!r} is disconnected and cannot be used anymore."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.DISCONNECTED_ELEMENT)
self._raise_disconnected_error()
res = {
"id": self.id,
"bus": self.bus.id,
Expand Down Expand Up @@ -384,10 +389,7 @@ def currents(self, value: Sequence[complex]) -> None:
self._invalidate_network_results()

def to_dict(self, include_geometry: bool = True) -> JsonDict:
if self.bus is None:
msg = f"The load {self.id!r} is disconnected and cannot be used anymore."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.DISCONNECTED_ELEMENT)
self._raise_disconnected_error()
return {
"id": self.id,
"bus": self.bus.id,
Expand Down Expand Up @@ -442,10 +444,7 @@ def impedances(self, impedances: Sequence[complex]) -> None:
self._invalidate_network_results()

def to_dict(self, include_geometry: bool = True) -> JsonDict:
if self.bus is None:
msg = f"The load {self.id!r} is disconnected and cannot be used anymore."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.DISCONNECTED_ELEMENT)
self._raise_disconnected_error()
return {
"id": self.id,
"bus": self.bus.id,
Expand Down
13 changes: 9 additions & 4 deletions roseau/load_flow/models/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def res_currents(self) -> Q_[np.ndarray]:
return self._res_currents_getter(warning=True)

def _res_potentials_getter(self, warning: bool) -> np.ndarray:
self._raise_disconnected_error()
return self.bus._get_potentials_of(self.phases, warning)

@property
Expand Down Expand Up @@ -145,6 +146,13 @@ def disconnect(self) -> None:
self._disconnect()
self.bus = None

def _raise_disconnected_error(self) -> None:
"""Raise an error if the voltage source is disconnected."""
if self.bus is None:
msg = f"The voltage source {self.id!r} is disconnected and cannot be used anymore."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.DISCONNECTED_ELEMENT)

#
# Json Mixin interface
#
Expand All @@ -154,10 +162,7 @@ def from_dict(cls, data: JsonDict) -> Self:
return cls(data["id"], data["bus"], voltages=voltages, phases=data["phases"])

def to_dict(self, include_geometry: bool = True) -> JsonDict:
if self.bus is None:
msg = f"The voltage source {self.id!r} is disconnected and cannot be used anymore."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.DISCONNECTED_ELEMENT)
self._raise_disconnected_error()
return {
"id": self.id,
"bus": self.bus.id,
Expand Down