From ab8c62278988923e3e701083d2aa5a664d8f1e18 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Tue, 27 Aug 2024 16:29:36 +0200 Subject: [PATCH] Error when transformer has null impedance (#262) --- doc/Changelog.md | 1 + roseau/load_flow/exceptions.py | 1 + .../models/tests/test_transformer_parameters.py | 12 ++++++++++++ roseau/load_flow/models/transformers/parameters.py | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/doc/Changelog.md b/doc/Changelog.md index 1bf6dba3..8e59df0d 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -19,6 +19,7 @@ og:description: See what's new in the latest release of Roseau Load Flow ! ## Unreleased +- {gh-pr}`262` Raise a proper error when a transformer is defined with null impedance. - {gh-pr}`259` The cache of the license object was not reset after the activation of a new license key. - {gh-pr}`258` {gh-pr}`261` Add basic plotting functionality in the new `roseau.load_flow.plotting` module. The `plot_interactive_map` function plots an electrical network on an interactive map using diff --git a/roseau/load_flow/exceptions.py b/roseau/load_flow/exceptions.py index b1dcb8c1..a6630295 100644 --- a/roseau/load_flow/exceptions.py +++ b/roseau/load_flow/exceptions.py @@ -47,6 +47,7 @@ class RoseauLoadFlowExceptionCode(StrEnum): BAD_TRANSFORMER_WINDINGS = auto() BAD_TRANSFORMER_TYPE = auto() BAD_TRANSFORMER_VOLTAGES = auto() + BAD_TRANSFORMER_IMPEDANCE = auto() BAD_TRANSFORMER_PARAMETERS = auto() # Switch diff --git a/roseau/load_flow/models/tests/test_transformer_parameters.py b/roseau/load_flow/models/tests/test_transformer_parameters.py index d89bc39b..f00bc881 100644 --- a/roseau/load_flow/models/tests/test_transformer_parameters.py +++ b/roseau/load_flow/models/tests/test_transformer_parameters.py @@ -771,3 +771,15 @@ def test_compute_open_short_circuit_parameters(): psc, vsc = tp._compute_short_circuit_parameters() assert np.isclose(psc.m, tp.psc.m, rtol=0.001) assert np.isclose(vsc.m, tp.vsc.m) + + +def test_ideal_transformer(): + # Ideal transformer not yet supported + with pytest.raises(RoseauLoadFlowException) as e: + TransformerParameters(id="test", type="Dyn11", sn=50e3, uhv=20e3, ulv=400, z2=0.0, ym=0.0) + assert e.value.msg == ( + "Transformer type 'test' has a null series impedance z2. Ideal transformers are not supported." + ) + assert e.value.code == RoseauLoadFlowExceptionCode.BAD_TRANSFORMER_IMPEDANCE + # OK + TransformerParameters(id="test", type="Dyn11", sn=50e3, uhv=20e3, ulv=400, z2=0.0000001, ym=0.0) diff --git a/roseau/load_flow/models/transformers/parameters.py b/roseau/load_flow/models/transformers/parameters.py index 30c8cfcf..95bb88ff 100644 --- a/roseau/load_flow/models/transformers/parameters.py +++ b/roseau/load_flow/models/transformers/parameters.py @@ -98,6 +98,11 @@ def __init__( logger.error(msg) raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_TRANSFORMER_VOLTAGES) + if np.isclose(z2, 0.0): + msg = f"Transformer type {id!r} has a null series impedance z2. Ideal transformers are not supported." + logger.error(msg) + raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_TRANSFORMER_IMPEDANCE) + self._sn: float = sn self._uhv: float = uhv self._ulv: float = ulv