From 318671957705652e3581142d3a5e54399a129a76 Mon Sep 17 00:00:00 2001 From: CHIQUET Benoit Date: Fri, 27 Sep 2024 16:57:34 +0200 Subject: [PATCH] add Tempo extension for OverloadManagementsystem Trippings Signed-off-by: CHIQUET Benoit --- .../network/OverloadManagementSystem.java | 14 +++++- .../network/extensions/TrippingTempo.java | 22 +++++++++ .../extensions/TrippingTempoAdder.java | 16 +++++++ .../extensions/TrippingTempoContainer.java | 22 +++++++++ .../TrippingTempoContainerAdder.java | 15 ++++++ .../OverloadManagementSystemAdderImpl.java | 22 ++++----- .../impl/OverloadManagementSystemImpl.java | 33 ++++++++----- .../extensions/TrippingTempoAdderImpl.java | 37 +++++++++++++++ .../TrippingTempoAdderImplProvider.java | 32 +++++++++++++ .../TrippingTempoContainerAdderImpl.java | 39 ++++++++++++++++ ...ippingTempoContainerAdderImplProvider.java | 32 +++++++++++++ .../TrippingTempoContainerImpl.java | 31 +++++++++++++ .../impl/extensions/TrippingTempoImpl.java | 27 +++++++++++ .../serde/extensions/TrippingTempoSerDe.java | 43 +++++++++++++++++ .../src/main/resources/xsd/trippingTempo.xsd | 19 ++++++++ .../iidm/serde/TrippingTempoSerDeTest.java | 46 +++++++++++++++++++ .../V1_13/trippingTempoRoundtripRef.xml | 36 +++++++++++++++ .../tripping-tempo-base-network.xiidm | 31 +++++++++++++ 18 files changed, 493 insertions(+), 24 deletions(-) create mode 100644 iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempo.java create mode 100644 iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoAdder.java create mode 100644 iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainer.java create mode 100644 iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainerAdder.java create mode 100644 iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImpl.java create mode 100644 iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImplProvider.java create mode 100644 iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImpl.java create mode 100644 iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImplProvider.java create mode 100644 iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerImpl.java create mode 100644 iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoImpl.java create mode 100644 iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/TrippingTempoSerDe.java create mode 100644 iidm/iidm-serde/src/main/resources/xsd/trippingTempo.xsd create mode 100644 iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/TrippingTempoSerDeTest.java create mode 100644 iidm/iidm-serde/src/test/resources/V1_13/trippingTempoRoundtripRef.xml create mode 100644 iidm/iidm-serde/src/test/resources/tripping-tempo-base-network.xiidm diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OverloadManagementSystem.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OverloadManagementSystem.java index 4222a202506..999b3049047 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OverloadManagementSystem.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OverloadManagementSystem.java @@ -7,7 +7,10 @@ */ package com.powsybl.iidm.network; +import com.powsybl.commons.extensions.Extendable; + import java.util.List; +import java.util.Optional; /** * An overload management system. @@ -16,7 +19,16 @@ */ public interface OverloadManagementSystem extends AutomationSystem { - interface Tripping { + default Optional getTripping(String trippingKey) { + return this.getTrippings() + .stream() + .filter(tripping -> tripping.getKey().equals(trippingKey)) + .findFirst(); + } + + interface Tripping extends Extendable { + OverloadManagementSystem getOverloadManagementSystem(); + enum Type { BRANCH_TRIPPING, THREE_WINDINGS_TRANSFORMER_TRIPPING, diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempo.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempo.java new file mode 100644 index 00000000000..394d5b1ec01 --- /dev/null +++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempo.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.extensions; + +import com.powsybl.commons.extensions.Extension; +import com.powsybl.iidm.network.OverloadManagementSystem; + +public interface TrippingTempo extends Extension { + String NAME = "trippingTempo"; + + @Override + default String getName() { + return NAME; + } + + int getTempo(); +} diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoAdder.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoAdder.java new file mode 100644 index 00000000000..58892ad1c90 --- /dev/null +++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoAdder.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.extensions; + +import com.powsybl.commons.extensions.ExtensionAdder; +import com.powsybl.iidm.network.OverloadManagementSystem; + +public interface TrippingTempoAdder + extends ExtensionAdder { + TrippingTempoAdder withTempo(int tempo); +} diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainer.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainer.java new file mode 100644 index 00000000000..67c919835ed --- /dev/null +++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainer.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.extensions; + +import com.powsybl.commons.extensions.Extension; +import com.powsybl.iidm.network.OverloadManagementSystem; + +public interface TrippingTempoContainer extends Extension { + String NAME = "trippingTempo"; + + @Override + default String getName() { + return NAME; + } + + OverloadManagementSystem.Tripping getTripping(); +} diff --git a/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainerAdder.java b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainerAdder.java new file mode 100644 index 00000000000..a38b5455a03 --- /dev/null +++ b/iidm/iidm-extensions/src/main/java/com/powsybl/iidm/network/extensions/TrippingTempoContainerAdder.java @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.extensions; + +import com.powsybl.commons.extensions.ExtensionAdder; +import com.powsybl.iidm.network.OverloadManagementSystem; + +public interface TrippingTempoContainerAdder extends ExtensionAdder { + TrippingTempoContainerAdder withTempo(String tripping, int tempo); +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemAdderImpl.java index bae47923ef3..99b0854ec3b 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemAdderImpl.java @@ -199,7 +199,7 @@ public OverloadManagementSystem add() { // Add the trippings Set knownTrippingKeys = new HashSet<>(); for (AbstractTrippingAdderImpl adder : trippingAdders) { - overloadManagementSystem.addTripping(createTripping(adder, id, knownTrippingKeys)); + overloadManagementSystem.addTripping(createTripping(adder, overloadManagementSystem, knownTrippingKeys)); } getNetwork().getIndex().checkAndAdd(overloadManagementSystem); @@ -208,7 +208,7 @@ public OverloadManagementSystem add() { return overloadManagementSystem; } - private OverloadManagementSystem.Tripping createTripping(AbstractTrippingAdderImpl adder, String overloadManagementSystemId, + private OverloadManagementSystem.Tripping createTripping(AbstractTrippingAdderImpl adder, OverloadManagementSystem overloadManagementSystem, Set knownTrippingKeys) { String key = adder.key; if (!knownTrippingKeys.add(key)) { @@ -216,31 +216,31 @@ private OverloadManagementSystem.Tripping createTripping(AbstractTrippingAdderIm "\" is already used for another tripping in the overload management system."); } return switch (adder.getType()) { - case SWITCH_TRIPPING -> createTripping((SwitchTrippingAdderImpl) adder, overloadManagementSystemId); - case BRANCH_TRIPPING -> createTripping((BranchTrippingAdderImpl) adder, overloadManagementSystemId); + case SWITCH_TRIPPING -> createTripping((SwitchTrippingAdderImpl) adder, overloadManagementSystem); + case BRANCH_TRIPPING -> createTripping((BranchTrippingAdderImpl) adder, overloadManagementSystem); case THREE_WINDINGS_TRANSFORMER_TRIPPING -> createTripping((ThreeWindingsTransformerTrippingAdderImpl) adder, - overloadManagementSystemId); + overloadManagementSystem); }; } - private OverloadManagementSystem.Tripping createTripping(SwitchTrippingAdderImpl adder, String overloadManagementSystemId) { + private OverloadManagementSystem.Tripping createTripping(SwitchTrippingAdderImpl adder, OverloadManagementSystem overloadManagementSystem) { return new OverloadManagementSystemImpl.SwitchTrippingImpl( - overloadManagementSystemId, adder.key, adder.name, + overloadManagementSystem, adder.key, adder.name, adder.currentLimit, adder.openAction, adder.checkSwitchId()); } - private OverloadManagementSystem.Tripping createTripping(BranchTrippingAdderImpl adder, String overloadManagementSystemId) { + private OverloadManagementSystem.Tripping createTripping(BranchTrippingAdderImpl adder, OverloadManagementSystem overloadManagementSystem) { return new OverloadManagementSystemImpl.BranchTrippingImpl( - overloadManagementSystemId, + overloadManagementSystem, adder.key, adder.name, adder.currentLimit, adder.openAction, adder.checkBranchId(), adder.side); } private OverloadManagementSystem.Tripping createTripping(ThreeWindingsTransformerTrippingAdderImpl adder, - String overloadManagementSystemId) { + OverloadManagementSystem overloadManagementSystem) { return new OverloadManagementSystemImpl.ThreeWindingsTransformerTrippingImpl( - overloadManagementSystemId, + overloadManagementSystem, adder.key, adder.name, adder.currentLimit, adder.openAction, adder.checkThreeWindingsTransformerId(), adder.side); } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemImpl.java index 180adfb1c46..eb7163998ad 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/OverloadManagementSystemImpl.java @@ -8,9 +8,13 @@ package com.powsybl.iidm.network.impl; import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.extensions.AbstractExtendable; import com.powsybl.iidm.network.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; /** * Overload management system implementation. @@ -19,16 +23,16 @@ */ class OverloadManagementSystemImpl extends AbstractAutomationSystem implements OverloadManagementSystem { - abstract static class AbstractTrippingImpl implements Tripping, Validable { - private final String overloadManagementSystemId; + abstract static class AbstractTrippingImpl extends AbstractExtendable implements Tripping, Validable { + private final OverloadManagementSystem overloadManagementSystem; private final String key; private String name; private double currentLimit; private boolean openAction; - protected AbstractTrippingImpl(String overloadManagementSystemId, String key, String name, + protected AbstractTrippingImpl(OverloadManagementSystem overloadManagementSystem, String key, String name, double currentLimit, boolean openAction) { - this.overloadManagementSystemId = overloadManagementSystemId; + this.overloadManagementSystem = overloadManagementSystem; this.key = Objects.requireNonNull(key); setName(name); setCurrentLimit(currentLimit); @@ -78,23 +82,28 @@ public Tripping setOpenAction(boolean open) { return this; } + @Override + public OverloadManagementSystem getOverloadManagementSystem() { + return overloadManagementSystem; + } + protected String getTrippingAttribute() { return String.format("tripping '%s'", key); } @Override public String getMessageHeader() { - return String.format("Overload management system '%s' - %s:", overloadManagementSystemId, getTrippingAttribute()); + return String.format("Overload management system '%s' - %s:", getOverloadManagementSystem().getId(), getTrippingAttribute()); } } static class SwitchTrippingImpl extends AbstractTrippingImpl implements SwitchTripping { private String switchToOperateId; - public SwitchTrippingImpl(String overloadManagementSystemId, String key, String name, + public SwitchTrippingImpl(OverloadManagementSystem overloadManagementSystem, String key, String name, double currentLimit, boolean openAction, String switchToOperateId) { - super(overloadManagementSystemId, key, name, currentLimit, openAction); + super(overloadManagementSystem, key, name, currentLimit, openAction); setSwitchToOperateId(switchToOperateId); } @@ -114,10 +123,10 @@ static class BranchTrippingImpl extends AbstractTrippingImpl implements Overload private String branchToOperateId; private TwoSides side; - protected BranchTrippingImpl(String overloadManagementSystemId, String key, String name, + protected BranchTrippingImpl(OverloadManagementSystem overloadManagementSystem, String key, String name, double currentLimit, boolean openAction, String branchToOperateId, TwoSides side) { - super(overloadManagementSystemId, key, name, currentLimit, openAction); + super(overloadManagementSystem, key, name, currentLimit, openAction); setBranchToOperateId(branchToOperateId); setSideToOperate(side); } @@ -151,10 +160,10 @@ static class ThreeWindingsTransformerTrippingImpl extends AbstractTrippingImpl private String threeWindingsTransformerId; private ThreeSides side; - protected ThreeWindingsTransformerTrippingImpl(String overloadManagementSystemId, String key, String name, + protected ThreeWindingsTransformerTrippingImpl(OverloadManagementSystem overloadManagementSystem, String key, String name, double currentLimit, boolean openAction, String threeWindingsTransformerId, ThreeSides side) { - super(overloadManagementSystemId, key, name, currentLimit, openAction); + super(overloadManagementSystem, key, name, currentLimit, openAction); setThreeWindingsTransformerToOperateId(threeWindingsTransformerId); setSideToOperate(side); } diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImpl.java new file mode 100644 index 00000000000..b95b33b6d54 --- /dev/null +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImpl.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.impl.extensions; + +import com.powsybl.commons.extensions.AbstractExtensionAdder; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempo; +import com.powsybl.iidm.network.extensions.TrippingTempoAdder; + +public class TrippingTempoAdderImpl extends AbstractExtensionAdder implements TrippingTempoAdder { + private int tempo; + + protected TrippingTempoAdderImpl(OverloadManagementSystem.Tripping extendable) { + super(extendable); + } + + @Override + protected TrippingTempo createExtension(OverloadManagementSystem.Tripping tripping) { + return new TrippingTempoImpl(tripping, tempo); + } + + @Override + public TrippingTempoAdder withTempo(int tempo) { + this.tempo = tempo; + return this; + } + + @Override + public Class getExtensionClass() { + return TrippingTempo.class; + } +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImplProvider.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImplProvider.java new file mode 100644 index 00000000000..933e6bb9e0a --- /dev/null +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoAdderImplProvider.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.impl.extensions; + +import com.google.auto.service.AutoService; +import com.powsybl.commons.extensions.ExtensionAdderProvider; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempo; + +@AutoService(ExtensionAdderProvider.class) +public class TrippingTempoAdderImplProvider implements + ExtensionAdderProvider { + @Override + public String getImplementationName() { + return "Default"; + } + + @Override + public Class getAdderClass() { + return TrippingTempoAdderImpl.class; + } + + @Override + public TrippingTempoAdderImpl newAdder(OverloadManagementSystem.Tripping tripping) { + return new TrippingTempoAdderImpl(tripping); + } +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImpl.java new file mode 100644 index 00000000000..bc74acd8f6d --- /dev/null +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImpl.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.impl.extensions; + +import com.powsybl.commons.extensions.AbstractExtensionAdder; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempoContainer; +import com.powsybl.iidm.network.extensions.TrippingTempoContainerAdder; + +public class TrippingTempoContainerAdderImpl extends AbstractExtensionAdder implements TrippingTempoContainerAdder { + private int tempo; + private String tripping; + + protected TrippingTempoContainerAdderImpl(OverloadManagementSystem extendable) { + super(extendable); + } + + @Override + protected TrippingTempoContainer createExtension(OverloadManagementSystem oms) { + return new TrippingTempoContainerImpl(oms, tripping, tempo); + } + + @Override + public Class getExtensionClass() { + return TrippingTempoContainer.class; + } + + @Override + public TrippingTempoContainerAdder withTempo(String tripping, int tempo) { + this.tripping = tripping; + this.tempo = tempo; + return this; + } +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImplProvider.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImplProvider.java new file mode 100644 index 00000000000..144ea915ab8 --- /dev/null +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerAdderImplProvider.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.impl.extensions; + +import com.google.auto.service.AutoService; +import com.powsybl.commons.extensions.ExtensionAdderProvider; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempoContainer; + +@AutoService(ExtensionAdderProvider.class) +public class TrippingTempoContainerAdderImplProvider implements + ExtensionAdderProvider { + @Override + public String getImplementationName() { + return "Default"; + } + + @Override + public Class getAdderClass() { + return TrippingTempoContainerAdderImpl.class; + } + + @Override + public TrippingTempoContainerAdderImpl newAdder(OverloadManagementSystem oms) { + return new TrippingTempoContainerAdderImpl(oms); + } +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerImpl.java new file mode 100644 index 00000000000..ade6e37d555 --- /dev/null +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoContainerImpl.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.impl.extensions; + +import com.powsybl.commons.extensions.AbstractExtension; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempoAdder; +import com.powsybl.iidm.network.extensions.TrippingTempoContainer; + +public class TrippingTempoContainerImpl extends AbstractExtension implements TrippingTempoContainer { + private OverloadManagementSystem.Tripping tripping; + + public TrippingTempoContainerImpl(OverloadManagementSystem oms, String trippingKey, int tempo) { + super(oms); + oms.getTripping(trippingKey) + .ifPresent(tripping -> { + this.tripping = tripping; + tripping.newExtension(TrippingTempoAdder.class).withTempo(tempo).add(); + }); + } + + @Override + public OverloadManagementSystem.Tripping getTripping() { + return tripping; + } +} diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoImpl.java new file mode 100644 index 00000000000..cce0e1e2fea --- /dev/null +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/extensions/TrippingTempoImpl.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.network.impl.extensions; + +import com.powsybl.commons.extensions.AbstractExtension; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempo; + +public class TrippingTempoImpl extends + AbstractExtension implements TrippingTempo { + private final int tempo; + + public TrippingTempoImpl(OverloadManagementSystem.Tripping tripping, int tempo) { + super(tripping); + this.tempo = tempo; + } + + @Override + public int getTempo() { + return tempo; + } +} diff --git a/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/TrippingTempoSerDe.java b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/TrippingTempoSerDe.java new file mode 100644 index 00000000000..55bb8d7fdc3 --- /dev/null +++ b/iidm/iidm-serde/src/main/java/com/powsybl/iidm/serde/extensions/TrippingTempoSerDe.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.serde.extensions; + +import com.google.auto.service.AutoService; +import com.powsybl.commons.extensions.AbstractExtensionSerDe; +import com.powsybl.commons.extensions.ExtensionSerDe; +import com.powsybl.commons.io.DeserializerContext; +import com.powsybl.commons.io.SerializerContext; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.extensions.TrippingTempo; +import com.powsybl.iidm.network.extensions.TrippingTempoContainer; +import com.powsybl.iidm.network.extensions.TrippingTempoContainerAdder; + +@AutoService(ExtensionSerDe.class) +public class TrippingTempoSerDe extends AbstractExtensionSerDe { + + public TrippingTempoSerDe() { + super(TrippingTempoContainer.NAME, "network", TrippingTempoContainer.class, "trippingTempo.xsd", + "http://www.powsybl.org/schema/iidm/ext/tripping_tempo/1_0", "tt"); + } + + @Override + public void write(TrippingTempoContainer tempoPointer, SerializerContext context) { + context.getWriter().writeStringAttribute("tripping", tempoPointer.getTripping().getKey()); + context.getWriter().writeIntAttribute("tempo", tempoPointer.getTripping().getExtension(TrippingTempo.class).getTempo()); + } + + @Override + public TrippingTempoContainer read(OverloadManagementSystem oms, DeserializerContext context) { + String tripping = context.getReader().readStringAttribute("tripping"); + Integer tempo = context.getReader().readIntAttribute("tempo"); + context.getReader().readEndNode(); + return oms.newExtension(TrippingTempoContainerAdder.class) + .withTempo(tripping, tempo) + .add(); + } +} diff --git a/iidm/iidm-serde/src/main/resources/xsd/trippingTempo.xsd b/iidm/iidm-serde/src/main/resources/xsd/trippingTempo.xsd new file mode 100644 index 00000000000..ce40bcc1c1c --- /dev/null +++ b/iidm/iidm-serde/src/main/resources/xsd/trippingTempo.xsd @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/TrippingTempoSerDeTest.java b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/TrippingTempoSerDeTest.java new file mode 100644 index 00000000000..5578eab0687 --- /dev/null +++ b/iidm/iidm-serde/src/test/java/com/powsybl/iidm/serde/TrippingTempoSerDeTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.iidm.serde; + +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.OverloadManagementSystem; +import com.powsybl.iidm.network.ThreeSides; +import com.powsybl.iidm.network.extensions.TrippingTempoContainerAdder; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Paths; + +import static com.powsybl.iidm.serde.IidmSerDeConstants.CURRENT_IIDM_VERSION; + +public class TrippingTempoSerDeTest extends AbstractIidmSerDeTest { + + @Test + void roundTripTest() throws IOException { + allFormatsRoundTripTest(createTestNetwork(), "trippingTempoRoundtripRef.xml", CURRENT_IIDM_VERSION); + } + + Network createTestNetwork() { + Network network = NetworkSerDe.read(Paths.get("src/test/resources/tripping-tempo-base-network.xiidm")); + OverloadManagementSystem automaton = network.getSubstation("Substation").newOverloadManagementSystem() + .setId("OMS_1") + .setEnabled(true) + .newSwitchTripping() + .setName("tutu") + .setKey("OMS_1_tripping_1") + .setCurrentLimit(620) + .setSwitchToOperateId("Switch1_ID") + .setOpenAction(false) + .add() + .setMonitoredElementId("Transformer_1") + .setMonitoredElementSide(ThreeSides.TWO) + .add(); + automaton.newExtension(TrippingTempoContainerAdder.class).withTempo("OMS_1_tripping_1", 2).add(); + return network; + } +} diff --git a/iidm/iidm-serde/src/test/resources/V1_13/trippingTempoRoundtripRef.xml b/iidm/iidm-serde/src/test/resources/V1_13/trippingTempoRoundtripRef.xml new file mode 100644 index 00000000000..9520e76e43b --- /dev/null +++ b/iidm/iidm-serde/src/test/resources/V1_13/trippingTempoRoundtripRef.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iidm/iidm-serde/src/test/resources/tripping-tempo-base-network.xiidm b/iidm/iidm-serde/src/test/resources/tripping-tempo-base-network.xiidm new file mode 100644 index 00000000000..c460de5f804 --- /dev/null +++ b/iidm/iidm-serde/src/test/resources/tripping-tempo-base-network.xiidm @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +