diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingEquipment.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingInjection.java similarity index 72% rename from network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingEquipment.java rename to network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingInjection.java index a08cc5af3..579eed4d1 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingEquipment.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingInjection.java @@ -20,23 +20,19 @@ */ @Setter @Getter -public abstract class AbstractRegulatingEquipment, D extends InjectionAttributes> extends AbstractInjectionImpl implements Injection { +public abstract class AbstractRegulatingInjection, D extends InjectionAttributes> extends AbstractInjectionImpl implements Injection { - protected final RegulatingPoint regulatingPoint; + protected final InjectionRegulatingPoint regulatingPoint; - protected AbstractRegulatingEquipment(NetworkObjectIndex index, Resource resource) { + protected AbstractRegulatingInjection(NetworkObjectIndex index, Resource resource) { super(index, resource); - regulatingPoint = new RegulatingPoint<>(index, this, AbstractRegulatingEquipmentAttributes.class::cast); + regulatingPoint = new InjectionRegulatingPoint<>(index, this, AbstractRegulatingEquipmentAttributes.class::cast); } // should be setRegulatingTerminal but there is already a method with the same name in the regulating equipments protected void setRegTerminal(Terminal regulatingTerminal) { ValidationUtil.checkRegulatingTerminal(this, regulatingTerminal, getNetwork()); - if (regulatingTerminal instanceof TerminalImpl) { - regulatingPoint.setRegulatingTerminal((TerminalImpl) regulatingTerminal); - } else { - regulatingPoint.setRegulatingTerminalAsLocalTerminalAndRemoveRegulation(); - } + regulatingPoint.setRegulatingTerminal(regulatingTerminal); } public Terminal getRegulatingTerminal() { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingPoint.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingPoint.java new file mode 100644 index 000000000..7d67f8fa3 --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractRegulatingPoint.java @@ -0,0 +1,107 @@ +/** + * 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/. + */ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.Identifiable; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.network.store.model.*; + +import java.util.function.Function; + +/** + * @author Etienne Lesot + */ +public abstract class AbstractRegulatingPoint { + + protected final NetworkObjectIndex index; + protected final Function attributesGetter; + + protected AbstractRegulatingPoint(NetworkObjectIndex index, Function attributesGetter) { + this.index = index; + this.attributesGetter = attributesGetter; + } + + public String getRegulatingEquipmentId() { + return getAttributes().getRegulatingEquipmentId(); + } + + public ResourceType getRegulatingEquipmentType() { + return getAttributes().getRegulatingResourceType(); + } + + public RegulatingTapChangerType getRegulatingTapChangerType() { + return getAttributes().getRegulatingTapChangerType(); + } + + public abstract RegulatingPointAttributes getAttributes(); + + public Terminal getRegulatingTerminal() { + Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); + Terminal localTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getLocalTerminal()); + return regulatingTerminal != null ? regulatingTerminal : localTerminal; + } + + public void resetRegulationToLocalTerminal() { + getIdentifiable().updateResource(res -> getAttributes().setRegulatingTerminal(getAttributes().getLocalTerminal())); + getIdentifiable().updateResource(res -> getAttributes().setRegulatedResourceType(getAttributes().getRegulatingResourceType())); + } + + protected abstract , D extends IdentifiableAttributes> AbstractIdentifiableImpl getIdentifiable(); + + public void setRegulationMode(String regulationMode) { + getIdentifiable().updateResource(res -> getAttributes().setRegulationMode(regulationMode)); + } + + public void setRegulatingTerminal(Terminal regulatingTerminal) { + TerminalImpl oldRegulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, + getAttributes().getRegulatingTerminal()); + if (oldRegulatingTerminal != null) { + oldRegulatingTerminal.removeRegulatingPoint(this); + } + if (regulatingTerminal != null) { + TerminalImpl regulatingTerminal1 = (TerminalImpl) regulatingTerminal; + regulatingTerminal1.setAsRegulatingPoint(this); + getIdentifiable().updateResource(res -> getAttributes() + .setRegulatingTerminal(TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal1))); + getIdentifiable().updateResource(res -> getAttributes() + .setRegulatedResourceType(ResourceType.convert(regulatingTerminal1.getConnectable().getType()))); + } else { + // if we set regulating terminal to null when getting the regulating Terminal it will return the local terminal + // thus the regulatedResourceType is itself type + getIdentifiable().updateResource(res -> getAttributes().setRegulatingTerminal(null)); + getIdentifiable().updateResource(res -> getAttributes().setRegulatedResourceType(getRegulatingEquipmentType())); + } + } + + protected abstract void resetRegulationMode(Terminal regulatingTerminal, Terminal localTerminal); + + void remove() { + TerminalImpl regulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); + // if regulating Terminal is null dont need to reset the regulation on the terminal because the terminal will be deleted + if (regulatingTerminal != null) { + regulatingTerminal.removeRegulatingPoint(this); + } + } + + public void removeRegulation() { + Terminal localTerminal = TerminalRefUtils.getTerminal(index, + getAttributes().getLocalTerminal()); + Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); + // set local terminal as regulating terminal + resetRegulationToLocalTerminal(); + // rest regulation mode for equipment having one + resetRegulationMode(regulatingTerminal, localTerminal); + } + + public Boolean isRegulating() { + return getAttributes().getRegulating(); + } + + public void setRegulating(boolean regulating) { + getIdentifiable().updateResource(res -> getAttributes().setRegulating(regulating)); + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChanger.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChanger.java index eaff0eb58..d4442de11 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChanger.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChanger.java @@ -6,14 +6,12 @@ */ package com.powsybl.network.store.iidm.impl; -import com.powsybl.iidm.network.Terminal; -import com.powsybl.iidm.network.ValidationException; -import com.powsybl.iidm.network.ValidationLevel; -import com.powsybl.iidm.network.ValidationUtil; +import com.powsybl.iidm.network.*; +import com.powsybl.network.store.model.AbstractRegulatingEquipmentAttributes; import com.powsybl.network.store.model.Resource; import com.powsybl.network.store.model.TapChangerAttributes; import com.powsybl.network.store.model.TapChangerStepAttributes; -import com.powsybl.network.store.model.TerminalRefAttributes; +import lombok.Getter; import java.util.List; import java.util.Objects; @@ -23,18 +21,21 @@ /** * @author Nicolas Noir */ -abstract class AbstractTapChanger, A extends TapChangerAttributes> { +abstract class AbstractTapChanger, A extends TapChangerAttributes> implements Validable { protected final H parent; protected final NetworkObjectIndex index; private final String type; + @Getter + protected final TapChangerRegulatingPoint regulatingPoint; AbstractTapChanger(H parent, NetworkObjectIndex index, String type) { this.parent = parent; this.index = index; this.type = Objects.requireNonNull(type); + regulatingPoint = new TapChangerRegulatingPoint(index, this, AbstractRegulatingEquipmentAttributes.class::cast); } AbstractIdentifiableImpl getTransformer() { @@ -90,34 +91,29 @@ public C setTapPosition(int tapPosition) { } public boolean isRegulating() { - return getAttributes().isRegulating(); + return regulatingPoint.isRegulating(); } public C setRegulating(boolean regulating) { ValidationUtil.checkTargetDeadband(parent, type, regulating, getTargetDeadband(), ValidationLevel.STEADY_STATE_HYPOTHESIS, parent.getNetwork().getReportNodeContext().getReportNode()); - boolean oldValue = getAttributes().isRegulating(); + boolean oldValue = isRegulating(); if (regulating != oldValue) { - getTransformer().updateResource(res -> getAttributes(res).setRegulating(regulating)); + regulatingPoint.setRegulating(regulating); notifyUpdate(() -> getTapChangerAttribute() + ".regulating", index.getNetwork().getVariantManager().getWorkingVariantId(), oldValue, regulating); } return (C) this; } - public Terminal getRegulationTerminal() { - TerminalRefAttributes terminalRefAttributes = getAttributes().getRegulatingTerminal(); - return TerminalRefUtils.getTerminal(index, terminalRefAttributes); - } - public C setRegulationTerminal(Terminal regulatingTerminal) { - if (regulatingTerminal != null && regulatingTerminal.getVoltageLevel().getNetwork() != parent.getNetwork()) { - throw new ValidationException(parent, "regulation terminal is not part of the network"); - } - TerminalRefAttributes oldValue = getAttributes().getRegulatingTerminal(); - getTransformer().updateResource(res -> getAttributes(res).setRegulatingTerminal(TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal))); - notifyUpdate(() -> getTapChangerAttribute() + ".regulationTerminal", index.getNetwork().getVariantManager().getWorkingVariantId(), oldValue, TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal)); + ValidationUtil.checkRegulatingTerminal(parent, regulatingTerminal, parent.getNetwork()); + regulatingPoint.setRegulatingTerminal(regulatingTerminal); return (C) this; } + public Terminal getRegulationTerminal() { + return regulatingPoint.getRegulatingTerminal(); + } + public double getTargetDeadband() { return getAttributes().getTargetDeadband(); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChangerAdder.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChangerAdder.java index f012d3b81..d7eaf73f0 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChangerAdder.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractTapChangerAdder.java @@ -7,6 +7,12 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.iidm.network.Terminal; +import com.powsybl.iidm.network.ThreeSides; +import com.powsybl.network.store.model.RegulatingPointAttributes; +import com.powsybl.network.store.model.RegulatingTapChangerType; +import com.powsybl.network.store.model.ResourceType; +import com.powsybl.network.store.model.TerminalRefAttributes; + import java.util.Objects; /** @@ -26,15 +32,30 @@ public abstract class AbstractTapChangerAdder { protected Terminal regulatingTerminal; - public AbstractTapChangerAdder(NetworkObjectIndex index) { + protected AbstractTapChangerAdder(NetworkObjectIndex index) { this.index = Objects.requireNonNull(index); } - public AbstractTapChangerAdder(NetworkObjectIndex index, int lowTapPosition, Integer tapPosition, boolean regulating, double targetDeadband) { + protected AbstractTapChangerAdder(NetworkObjectIndex index, int lowTapPosition, Integer tapPosition, boolean regulating, double targetDeadband) { this.index = Objects.requireNonNull(index); this.lowTapPosition = lowTapPosition; this.tapPosition = tapPosition; this.regulating = regulating; this.targetDeadband = targetDeadband; } + + protected RegulatingPointAttributes createRegulationPointAttributes(TapChangerParent tapChangerParent, RegulatingTapChangerType regulatingTapChangerType, + String regulationMode) { + RegulatingTapChangerType finalRegulatingTapChangerType = regulatingTapChangerType; + ResourceType resourceType = ResourceType.TWO_WINDINGS_TRANSFORMER; + if (tapChangerParent instanceof ThreeWindingsTransformerImpl.LegImpl leg) { + ThreeSides side = leg.getSide(); + finalRegulatingTapChangerType = RegulatingTapChangerType.getThreeWindingsTransformerTapChangerType(side, regulatingTapChangerType); + resourceType = ResourceType.THREE_WINDINGS_TRANSFORMER; + } + TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); + // local terminal is null for tapChanger because it has more than one + return new RegulatingPointAttributes(tapChangerParent.getTransformer().getId(), resourceType, finalRegulatingTapChangerType, + null, terminalRefAttributes, regulationMode, resourceType, regulating); + } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java index 7205b39ec..cfb8fdafd 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BranchToInjectionAttributesAdapter.java @@ -9,10 +9,10 @@ import com.powsybl.iidm.network.Branch; import com.powsybl.network.store.model.BranchAttributes; import com.powsybl.network.store.model.ConnectablePositionAttributes; -import com.powsybl.network.store.model.ResourceType; +import com.powsybl.network.store.model.RegulatingEquipmentIdentifier; -import java.util.Map; import java.util.Objects; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -136,12 +136,12 @@ public void setPosition(ConnectablePositionAttributes position) { } @Override - public Map getRegulatingEquipments() { + public Set getRegulatingEquipments() { return attributes.getRegulatingEquipments(); } @Override - public void setRegulatingEquipments(Map regulatingEquipments) { + public void setRegulatingEquipments(Set regulatingEquipments) { attributes.setRegulatingEquipments(regulatingEquipments); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java index 99bbe4711..0449cf4bb 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionToInjectionAdapter.java @@ -8,9 +8,9 @@ import com.powsybl.network.store.model.BusbarSectionAttributes; import com.powsybl.network.store.model.ConnectablePositionAttributes; -import com.powsybl.network.store.model.ResourceType; +import com.powsybl.network.store.model.RegulatingEquipmentIdentifier; -import java.util.Map; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -92,12 +92,12 @@ public void setPosition(ConnectablePositionAttributes position) { } @Override - public Map getRegulatingEquipments() { + public Set getRegulatingEquipments() { return attributes.getRegulatingEquipments(); } @Override - public void setRegulatingEquipments(Map regulatingEquipments) { + public void setRegulatingEquipments(Set regulatingEquipments) { attributes.setRegulatingEquipments(regulatingEquipments); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java index 316de009e..42f9777ed 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorAdderImpl.java @@ -130,7 +130,7 @@ public Generator add() { .build(); TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); - RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.GENERATOR, + RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.GENERATOR, RegulatingTapChangerType.NONE, new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.GENERATOR, voltageRegulatorOn); Resource resource = Resource.generatorBuilder() diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorImpl.java index 7b87d5e41..fe646a8c2 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/GeneratorImpl.java @@ -25,7 +25,7 @@ * @author Geoffroy Jamgotchian * @author Etienne Homer */ -public class GeneratorImpl extends AbstractRegulatingEquipment implements Generator, ReactiveLimitsOwner { +public class GeneratorImpl extends AbstractRegulatingInjection implements Generator, ReactiveLimitsOwner { public GeneratorImpl(NetworkObjectIndex index, Resource resource) { super(index, resource); @@ -102,6 +102,7 @@ public void remove() { ((TerminalImpl) terminal).removeAsRegulatingPoint(); ((TerminalImpl) terminal).getReferrerManager().notifyOfRemoval(); } + regulatingPoint.remove(); // invalidate calculated buses before removal otherwise voltage levels won't be accessible anymore for topology invalidation! invalidateCalculatedBuses(getTerminals()); index.removeGenerator(resource.getId()); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/InjectionRegulatingPoint.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/InjectionRegulatingPoint.java new file mode 100644 index 000000000..019728ce2 --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/InjectionRegulatingPoint.java @@ -0,0 +1,59 @@ +/** + * 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/. + */ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.commons.PowsyblException; +import com.powsybl.iidm.network.*; +import com.powsybl.network.store.model.*; + +import java.util.function.Function; + +/** + * @author Etienne Lesot + */ +public final class InjectionRegulatingPoint, D extends InjectionAttributes> extends AbstractRegulatingPoint { + private final AbstractRegulatingInjection injection; + + public InjectionRegulatingPoint(NetworkObjectIndex index, AbstractRegulatingInjection injection, Function attributesGetter) { + super(index, attributesGetter); + this.injection = injection; + } + + private Resource getResource() { + return injection.getResource(); + } + + @Override + public RegulatingPointAttributes getAttributes() { + return attributesGetter.apply(getResource().getAttributes()).getRegulatingPoint(); + } + + @Override + protected void resetRegulationMode(Terminal regulatingTerminal, Terminal localTerminal) { + // if localTerminal or regulatingTerminal is not connected then the bus is null + if (regulatingTerminal != null && localTerminal.isConnected() && regulatingTerminal.isConnected() && + !localTerminal.getBusView().getBus().equals(regulatingTerminal.getBusView().getBus())) { + switch (getAttributes().getRegulatingResourceType()) { + // for svc we set the regulation mode to Off if the regulation was not on the same bus than the svc. If the svc is on the same bus were the equipment was remove we keep the regulation + case STATIC_VAR_COMPENSATOR -> + setRegulationMode(String.valueOf(StaticVarCompensator.RegulationMode.OFF)); + case GENERATOR, SHUNT_COMPENSATOR, VSC_CONVERTER_STATION -> { + } + default -> throw new PowsyblException("No regulation for this kind of equipment"); + } + // the target can be inappropriated if it was a remote regulation + setRegulating(false); + } + // if the regulating equipment was already regulating on his bus but on another element + // we reallocate the regulating point and we keep the regulation on + } + + @Override + protected AbstractRegulatingInjection getIdentifiable() { + return injection; + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerAdderImpl.java index d35615f8d..1938f4eec 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerAdderImpl.java @@ -178,17 +178,15 @@ public PhaseTapChanger add() { tapChangers.remove(tapChangerParent.getPhaseTapChanger()); ValidationUtil.checkOnlyOneTapChangerRegulatingEnabled(tapChangerParent, tapChangers, regulating, ValidationLevel.STEADY_STATE_HYPOTHESIS, tapChangerParent.getNetwork().getReportNodeContext().getReportNode()); - TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); + RegulatingPointAttributes regulatingPointAttributes = createRegulationPointAttributes(tapChangerParent, RegulatingTapChangerType.PHASE_TAP_CHANGER, regulationMode.toString()); PhaseTapChangerAttributes phaseTapChangerAttributes = PhaseTapChangerAttributes.builder() .lowTapPosition(lowTapPosition) - .regulating(regulating) - .regulationMode(regulationMode) .regulationValue(regulationValue) .steps(steps) .tapPosition(tapPosition) .targetDeadband(targetDeadband) - .regulatingTerminal(terminalRefAttributes) + .regulatingPoint(regulatingPointAttributes) .build(); TapChangerParentAttributes tapChangerParentAttributes = attributesGetter.apply(tapChangerParent.getTransformer().getResource().getAttributes()); if (tapChangerParentAttributes.getRatioTapChangerAttributes() != null) { @@ -196,7 +194,8 @@ public PhaseTapChanger add() { } tapChangerParent.setPhaseTapChanger(phaseTapChangerAttributes); - - return new PhaseTapChangerImpl(tapChangerParent, index, attributesGetter); + PhaseTapChangerImpl tapChanger = new PhaseTapChangerImpl(tapChangerParent, index, attributesGetter); + tapChanger.setRegulationTerminal(regulatingTerminal); + return tapChanger; } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerImpl.java index 68e33a4e1..4e8d42a0a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerImpl.java @@ -35,15 +35,17 @@ protected PhaseTapChangerAttributes getAttributes(Resource resource) { @Override public RegulationMode getRegulationMode() { - return getAttributes().getRegulationMode(); + return PhaseTapChanger.RegulationMode.valueOf(getAttributes().getRegulatingPoint().getRegulationMode()); } @Override public PhaseTapChanger setRegulationMode(RegulationMode regulationMode) { ValidationUtil.checkPhaseTapChangerRegulation(parent, regulationMode, getRegulationValue(), isRegulating(), getRegulationTerminal(), parent.getNetwork(), ValidationLevel.STEADY_STATE_HYPOTHESIS, parent.getNetwork().getReportNodeContext().getReportNode()); - RegulationMode oldValue = getAttributes().getRegulationMode(); - parent.getTransformer().updateResource(res -> getAttributes(res).setRegulationMode(regulationMode)); - notifyUpdate(() -> getTapChangerAttribute() + ".regulationMode", index.getNetwork().getVariantManager().getWorkingVariantId(), oldValue, regulationMode); + PhaseTapChanger.RegulationMode oldValue = getRegulationMode(); + if (regulationMode != oldValue) { + regulatingPoint.setRegulationMode(String.valueOf(regulationMode)); + notifyUpdate(() -> getTapChangerAttribute() + ".regulationMode", index.getNetwork().getVariantManager().getWorkingVariantId(), oldValue, regulationMode); + } return this; } @@ -128,6 +130,7 @@ public Optional getNeutralStep() { @Override public void remove() { + regulatingPoint.remove(); parent.setPhaseTapChanger(null); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerAdderImpl.java index 81bfd9d4f..a6e2189ca 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerAdderImpl.java @@ -163,18 +163,17 @@ public RatioTapChanger add() { tapChangers.remove(tapChangerParent.getRatioTapChanger()); ValidationUtil.checkOnlyOneTapChangerRegulatingEnabled(tapChangerParent, tapChangers, regulating, ValidationLevel.STEADY_STATE_HYPOTHESIS, tapChangerParent.getNetwork().getReportNodeContext().getReportNode()); - TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); + String regulationModeStr = regulationMode == null ? null : regulationMode.toString(); + RegulatingPointAttributes regulatingPointAttributes = createRegulationPointAttributes(tapChangerParent, RegulatingTapChangerType.RATIO_TAP_CHANGER, regulationModeStr); RatioTapChangerAttributes ratioTapChangerAttributes = RatioTapChangerAttributes.builder() .loadTapChangingCapabilities(loadTapChangingCapabilities) .lowTapPosition(lowTapPosition) .tapPosition(tapPosition) - .regulating(regulating) .targetDeadband(targetDeadband) - .regulationMode(regulationMode) .regulationValue(regulationValue) .steps(steps) - .regulatingTerminal(terminalRefAttributes) + .regulatingPoint(regulatingPointAttributes) .build(); TapChangerParentAttributes tapChangerParentAttributes = attributesGetter.apply(tapChangerParent.getTransformer().getResource().getAttributes()); if (tapChangerParentAttributes.getPhaseTapChangerAttributes() != null) { diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerImpl.java index 34f794ee5..568cafde3 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerImpl.java @@ -132,6 +132,7 @@ protected Integer getRelativeNeutralPosition() { @Override public void remove() { + regulatingPoint.remove(); parent.setRatioTapChanger(null); } @@ -146,15 +147,16 @@ public String getMessageHeader() { @Override public RegulationMode getRegulationMode() { - return getAttributes().getRegulationMode(); + String regulationMode = getAttributes().getRegulatingPoint().getRegulationMode(); + return regulationMode != null ? RegulationMode.valueOf(regulationMode) : null; } @Override public RatioTapChanger setRegulationMode(RegulationMode regulationMode) { ValidationUtil.checkRatioTapChangerRegulation(parent, isRegulating(), hasLoadTapChangingCapabilities(), getRegulationTerminal(), regulationMode, getTargetV(), parent.getNetwork(), ValidationLevel.STEADY_STATE_HYPOTHESIS, parent.getNetwork().getReportNodeContext().getReportNode()); - RegulationMode oldValue = getAttributes().getRegulationMode(); + RegulationMode oldValue = getRegulationMode(); if (regulationMode != oldValue) { - getTransformer().updateResource(res -> getAttributes(res).setRegulationMode(regulationMode)); + regulatingPoint.setRegulationMode(String.valueOf(regulationMode)); notifyUpdate(() -> getTapChangerAttribute() + ".regulationMode", index.getNetwork().getVariantManager().getWorkingVariantId(), oldValue, regulationMode); } return this; diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java deleted file mode 100644 index 2f0890a64..000000000 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RegulatingPoint.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * 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/. - */ -package com.powsybl.network.store.iidm.impl; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.iidm.network.*; -import com.powsybl.network.store.model.*; - -import java.util.*; -import java.util.function.Function; - -/** - * @author Etienne Lesot - */ -public final class RegulatingPoint , D extends InjectionAttributes> { - private final NetworkObjectIndex index; - private final AbstractRegulatingEquipment identifiable; - private final Function attributesGetter; - - public RegulatingPoint(NetworkObjectIndex index, AbstractRegulatingEquipment identifiable, Function attributesGetter) { - this.index = index; - this.attributesGetter = Objects.requireNonNull(attributesGetter); - this.identifiable = identifiable; - } - - private Resource getResource() { - return identifiable.getResource(); - } - - public RegulatingPointAttributes getAttributes() { - return attributesGetter.apply(getResource().getAttributes()).getRegulatingPoint(); - } - - private RegulatingPointAttributes getAttributes(Resource resource) { - return attributesGetter.apply(resource.getAttributes()).getRegulatingPoint(); - } - - public Terminal getRegulatingTerminal() { - Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); - Terminal localTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getLocalTerminal()); - return regulatingTerminal != null ? regulatingTerminal : localTerminal; - } - - public void setRegulatingTerminal(TerminalImpl regulatingTerminal) { - TerminalImpl oldRegulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, - getAttributes().getRegulatingTerminal()); - if (oldRegulatingTerminal != null) { - oldRegulatingTerminal.removeRegulatingPoint(this); - } - regulatingTerminal.setAsRegulatingPoint(this); - identifiable.updateResource(res -> getAttributes(res) - .setRegulatingTerminal(TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal))); - identifiable.updateResource(res -> getAttributes(res) - .setRegulatedResourceType(ResourceType.convert(regulatingTerminal.getConnectable().getType()))); - } - - public void setRegulatingTerminalAsLocalTerminalAndRemoveRegulation() { - TerminalImpl oldRegulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, - getAttributes().getRegulatingTerminal()); - if (oldRegulatingTerminal != null) { - oldRegulatingTerminal.removeRegulatingPoint(this); - } - resetRegulationToLocalTerminal(); - } - - public void resetRegulationToLocalTerminal() { - identifiable.updateResource(res -> getAttributes(res).setRegulatingTerminal(getAttributes().getLocalTerminal())); - identifiable.updateResource(res -> getAttributes(res).setRegulatedResourceType(getAttributes().getRegulatingResourceType())); - } - - public void setRegulationMode(String regulationMode) { - identifiable.updateResource(res -> getAttributes(res).setRegulationMode(regulationMode)); - } - - public void removeRegulation() { - Terminal terminal = TerminalRefUtils.getTerminal(index, - getAttributes().getLocalTerminal()); - if (terminal instanceof TerminalImpl localTerminal) { - Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); - // set local terminal as regulating terminal - resetRegulationToLocalTerminal(); - // rest regulation mode for equipment having one - resetRegulationMode(regulatingTerminal, localTerminal); - } else { - throw new PowsyblException("Cannot remove regulation because the local terminal is null"); - } - } - - private void resetRegulationMode(Terminal regulatingTerminal, Terminal localTerminal) { - // if localTerminal or regulatingTerminal is not connected then the bus is null - if (regulatingTerminal != null && localTerminal.isConnected() && regulatingTerminal.isConnected() && - !localTerminal.getBusView().getBus().equals(regulatingTerminal.getBusView().getBus())) { - switch (getAttributes().getRegulatingResourceType()) { - // for svc we set the regulation mode to Off if the regulation was not on the same bus than the svc. If the svc is on the same bus were the equipment was remove we keep the regulation - case STATIC_VAR_COMPENSATOR -> - setRegulationMode(String.valueOf(StaticVarCompensator.RegulationMode.OFF)); - case GENERATOR, SHUNT_COMPENSATOR, VSC_CONVERTER_STATION -> { - } - default -> throw new PowsyblException("No regulation for this kind of equipment"); - } - // the target can be inappropriated if it was a remote regulation - setRegulating(false); - } - // if the regulating equipment was already regulating on his bus we reallocate the regulating point and we keep the regulation on - } - - void remove() { - TerminalImpl regulatingTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal()); - regulatingTerminal.removeRegulatingPoint(this); - } - - public String getRegulatingEquipmentId() { - return getAttributes().getRegulatingEquipmentId(); - } - - public ResourceType getRegulatingEquipmentType() { - return getAttributes().getRegulatingResourceType(); - } - - public Boolean isRegulating() { - return getAttributes().getRegulating(); - } - - public void setRegulating(boolean regulating) { - identifiable.updateResource(res -> getAttributes(res).setRegulating(regulating)); - } -} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java index 1dd7739cb..685851d8a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorAdderImpl.java @@ -209,7 +209,7 @@ public ShuntCompensator add() { TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); ValidationUtil.checkVoltageControl(this, voltageRegulatorOn, targetV, ValidationLevel.STEADY_STATE_HYPOTHESIS, getNetwork().getReportNodeContext().getReportNode()); ValidationUtil.checkTargetDeadband(this, "shunt compensator", voltageRegulatorOn, targetDeadband, ValidationLevel.STEADY_STATE_HYPOTHESIS, getNetwork().getReportNodeContext().getReportNode()); - RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.SHUNT_COMPENSATOR, + RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.SHUNT_COMPENSATOR, RegulatingTapChangerType.NONE, new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.SHUNT_COMPENSATOR, voltageRegulatorOn); Resource resource = Resource.shuntCompensatorBuilder() diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorImpl.java index ee0abe674..3bd2ed9c5 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ShuntCompensatorImpl.java @@ -16,7 +16,7 @@ * @author Geoffroy Jamgotchian * @author Etienne Homer */ -public class ShuntCompensatorImpl extends AbstractRegulatingEquipment implements ShuntCompensator { +public class ShuntCompensatorImpl extends AbstractRegulatingInjection implements ShuntCompensator { public ShuntCompensatorImpl(NetworkObjectIndex index, Resource resource) { super(index, resource); @@ -181,6 +181,7 @@ public void remove() { ((TerminalImpl) terminal).removeAsRegulatingPoint(); ((TerminalImpl) terminal).getReferrerManager().notifyOfRemoval(); } + regulatingPoint.remove(); // invalidate calculated buses before removal otherwise voltage levels won't be accessible anymore for topology invalidation! invalidateCalculatedBuses(getTerminals()); index.removeShuntCompensator(resource.getId()); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java index 178079701..28a089126 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java @@ -77,7 +77,7 @@ public StaticVarCompensator add() { TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); Boolean isRegulating = regulationMode == StaticVarCompensator.RegulationMode.VOLTAGE; - RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.STATIC_VAR_COMPENSATOR, + RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.STATIC_VAR_COMPENSATOR, RegulatingTapChangerType.NONE, new TerminalRefAttributes(getId(), null), terminalRefAttributes, String.valueOf(regulationMode), ResourceType.STATIC_VAR_COMPENSATOR, isRegulating); Resource resource = Resource.staticVarCompensatorBuilder() .id(id) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorImpl.java index 99aa1582f..a61e28882 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorImpl.java @@ -20,7 +20,7 @@ * @author Geoffroy Jamgotchian * @author Etienne Homer */ -public class StaticVarCompensatorImpl extends AbstractRegulatingEquipment implements StaticVarCompensator { +public class StaticVarCompensatorImpl extends AbstractRegulatingInjection implements StaticVarCompensator { public StaticVarCompensatorImpl(NetworkObjectIndex index, Resource resource) { super(index, resource); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TapChangerRegulatingPoint.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TapChangerRegulatingPoint.java new file mode 100644 index 000000000..7660ff429 --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TapChangerRegulatingPoint.java @@ -0,0 +1,44 @@ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.commons.PowsyblException; +import com.powsybl.iidm.network.PhaseTapChanger; +import com.powsybl.iidm.network.Terminal; +import com.powsybl.network.store.model.*; + +import java.util.function.Function; + +public final class TapChangerRegulatingPoint extends AbstractRegulatingPoint { + private final AbstractTapChanger tapChanger; + + public TapChangerRegulatingPoint(NetworkObjectIndex index, AbstractTapChanger tapChanger, + Function attributesGetter) { + super(index, attributesGetter); + this.tapChanger = tapChanger; + } + + @Override + public RegulatingPointAttributes getAttributes() { + return attributesGetter.apply(tapChanger.getAttributes()).getRegulatingPoint(); + } + + @Override + protected AbstractIdentifiableImpl getIdentifiable() { + return tapChanger.getTransformer(); + } + + @Override + protected void resetRegulationMode(Terminal regulatingTerminal, Terminal localTerminal) { + // for tap changer the local terminal is null so we deactivate the regulation and reset the regulation mode + // the target can be inappropriated if it was a remote regulation + setRegulating(false); + switch (getAttributes().getRegulatingTapChangerType()) { + // for phase tap changer we reset the regulation mode to Fixed Tap + case PHASE_TAP_CHANGER, PHASE_TAP_CHANGER_SIDE_ONE, PHASE_TAP_CHANGER_SIDE_TWO, PHASE_TAP_CHANGER_SIDE_THREE -> + setRegulationMode(String.valueOf(PhaseTapChanger.RegulationMode.FIXED_TAP)); + case RATIO_TAP_CHANGER, RATIO_TAP_CHANGER_SIDE_ONE, RATIO_TAP_CHANGER_SIDE_TWO, RATIO_TAP_CHANGER_SIDE_THREE -> + setRegulationMode(null); + default -> throw new PowsyblException("No tap changer regulation for " + getAttributes().getRegulatingResourceType() + " resource type"); + } + // if the regulating equipment was already regulating on his local bus we reallocate the regulating point and we keep the regulation on + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java index 3a6c86fae..c5e78c76f 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java @@ -656,21 +656,48 @@ public ThreeSides getSide() { return ThreeSides.valueOf(terminalIndex + 1); } - public void setAsRegulatingPoint(RegulatingPoint regulatingPoint) { + public void setAsRegulatingPoint(AbstractRegulatingPoint regulatingPoint) { getAttributes().getRegulatingEquipments() - .put(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType()); + .add(new RegulatingEquipmentIdentifier(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType(), + regulatingPoint.getRegulatingTapChangerType())); } - public void removeRegulatingPoint(RegulatingPoint regulatingPoint) { + public void removeRegulatingPoint(AbstractRegulatingPoint regulatingPoint) { getAttributes().getRegulatingEquipments() - .remove(regulatingPoint.getRegulatingEquipmentId()); + .remove(new RegulatingEquipmentIdentifier(regulatingPoint.getRegulatingEquipmentId(), + regulatingPoint.getRegulatingEquipmentType(), regulatingPoint.getRegulatingTapChangerType())); } public void removeAsRegulatingPoint() { - getAttributes().getRegulatingEquipments().forEach((regulatingEquipmentId, resourceType) -> { - Identifiable identifiable = index.getIdentifiable(regulatingEquipmentId); - if (identifiable instanceof AbstractRegulatingEquipment regulatingEquipment) { + getAttributes().getRegulatingEquipments().forEach(regulatingEquipmentIdentifier -> { + Identifiable identifiable = index.getIdentifiable(regulatingEquipmentIdentifier.getEquipmentId()); + if (identifiable instanceof AbstractRegulatingInjection regulatingEquipment) { regulatingEquipment.getRegulatingPoint().removeRegulation(); + } else if (identifiable instanceof TwoWindingsTransformerImpl twoWindingsTransformer) { + AbstractTapChanger abstractTapChanger; + if (regulatingEquipmentIdentifier.getRegulatingTapChangerType() == RegulatingTapChangerType.RATIO_TAP_CHANGER) { + abstractTapChanger = (RatioTapChangerImpl) twoWindingsTransformer.getRatioTapChanger(); + } else { + abstractTapChanger = (PhaseTapChangerImpl) twoWindingsTransformer.getPhaseTapChanger(); + } + abstractTapChanger.getRegulatingPoint().removeRegulation(); + } else if (identifiable instanceof ThreeWindingsTransformerImpl threeWindingsTransformer) { + AbstractTapChanger abstractTapChanger = switch (regulatingEquipmentIdentifier.getRegulatingTapChangerType()) { + case RATIO_TAP_CHANGER_SIDE_ONE -> + (RatioTapChangerImpl) threeWindingsTransformer.getLeg1().getRatioTapChanger(); + case RATIO_TAP_CHANGER_SIDE_TWO -> + (RatioTapChangerImpl) threeWindingsTransformer.getLeg2().getRatioTapChanger(); + case RATIO_TAP_CHANGER_SIDE_THREE -> + (RatioTapChangerImpl) threeWindingsTransformer.getLeg3().getRatioTapChanger(); + case PHASE_TAP_CHANGER_SIDE_ONE -> + (PhaseTapChangerImpl) threeWindingsTransformer.getLeg1().getPhaseTapChanger(); + case PHASE_TAP_CHANGER_SIDE_TWO -> + (PhaseTapChangerImpl) threeWindingsTransformer.getLeg2().getPhaseTapChanger(); + case PHASE_TAP_CHANGER_SIDE_THREE -> + (PhaseTapChangerImpl) threeWindingsTransformer.getLeg3().getPhaseTapChanger(); + default -> throw new PowsyblException("tap changer not found when removing regulation"); + }; + abstractTapChanger.getRegulatingPoint().removeRegulation(); } }); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java index d52479ce4..d7265497c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerToInjectionAttributesAdapter.java @@ -7,12 +7,9 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.iidm.network.ThreeSides; -import com.powsybl.network.store.model.ConnectablePositionAttributes; -import com.powsybl.network.store.model.LegAttributes; -import com.powsybl.network.store.model.ResourceType; -import com.powsybl.network.store.model.ThreeWindingsTransformerAttributes; +import com.powsybl.network.store.model.*; -import java.util.Map; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -136,12 +133,12 @@ public void setPosition(ConnectablePositionAttributes position) { } @Override - public Map getRegulatingEquipments() { + public Set getRegulatingEquipments() { return attributes.getRegulatingEquipments(); } @Override - public void setRegulatingEquipments(Map regulatingEquipments) { + public void setRegulatingEquipments(Set regulatingEquipments) { attributes.setRegulatingEquipments(regulatingEquipments); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java index 1860e6d07..451aaf2e2 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationAdderImpl.java @@ -57,7 +57,7 @@ public VscConverterStation add() { validate(); TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal); - RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.VSC_CONVERTER_STATION, + RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.VSC_CONVERTER_STATION, RegulatingTapChangerType.NONE, new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.VSC_CONVERTER_STATION, voltageRegulatorOn); Resource resource = Resource.vscConverterStationBuilder() diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationImpl.java index 422e36ea8..602f0acad 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/VscConverterStationImpl.java @@ -13,7 +13,7 @@ * @author Geoffroy Jamgotchian * @author Etienne Homer */ -public class VscConverterStationImpl extends AbstractRegulatingEquipment implements VscConverterStation, ReactiveLimitsOwner { +public class VscConverterStationImpl extends AbstractRegulatingInjection implements VscConverterStation, ReactiveLimitsOwner { public VscConverterStationImpl(NetworkObjectIndex index, Resource resource) { super(index, resource); @@ -150,6 +150,7 @@ public void remove() { ((TerminalImpl) terminal).removeAsRegulatingPoint(); ((TerminalImpl) terminal).getReferrerManager().notifyOfRemoval(); } + regulatingPoint.remove(); HvdcLine hvdcLine = getHvdcLine(); // For optimization if (hvdcLine != null) { throw new ValidationException(this, "Impossible to remove this converter station (still attached to '" + hvdcLine.getId() + "')"); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ThreeWindingTransformerTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ThreeWindingTransformerTest.java new file mode 100644 index 000000000..7283c51dd --- /dev/null +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/ThreeWindingTransformerTest.java @@ -0,0 +1,65 @@ +/** + * 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/. + */ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.Load; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.PhaseTapChanger; +import com.powsybl.iidm.network.RatioTapChanger; +import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author Etienne Lesot + */ +class ThreeWindingTransformerTest { + @Test + void testTapChangerRegulation() { + String twtId = "3WT"; + String load1Id = "LOAD_33"; + String load2Id = "LOAD_11"; + Network network = createNetwork(); + + RatioTapChanger ratioTapChanger = network.getThreeWindingsTransformer(twtId).getLeg2().getRatioTapChanger(); + assertEquals(load1Id, ratioTapChanger.getRegulationTerminal().getConnectable().getId()); + Load load = network.getLoad(load2Id); + ratioTapChanger.setRegulationTerminal(load.getTerminal()); + assertEquals(load2Id, ratioTapChanger.getRegulationTerminal().getConnectable().getId()); + + PhaseTapChanger phaseTapChanger = network.getThreeWindingsTransformer(twtId).getLeg2().getPhaseTapChanger(); + phaseTapChanger.setRegulationTerminal(load.getTerminal()); + assertEquals(load2Id, phaseTapChanger.getRegulationTerminal().getConnectable().getId()); + phaseTapChanger.setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL); + phaseTapChanger.setRegulationValue(225); + load.remove(); + assertEquals(PhaseTapChanger.RegulationMode.FIXED_TAP, phaseTapChanger.getRegulationMode()); + assertNull(phaseTapChanger.getRegulationTerminal()); + assertNull(ratioTapChanger.getRegulationMode()); + assertNull(ratioTapChanger.getRegulationTerminal()); + } + + private Network createNetwork() { + Network network = ThreeWindingsTransformerNetworkFactory.create(); + network.getThreeWindingsTransformer("3WT").getLeg2() + .newPhaseTapChanger() + .setTargetDeadband(2) + .setRegulating(false) + .setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP) + .setTapPosition(0) + .beginStep() + .setR(1) + .setAlpha(12) + .setRho(13) + .endStep() + .setTapPosition(0) + .add(); + return network; + } +} diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerTest.java index 0de1b4c84..953843e06 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/TwoWindingsTransformerTest.java @@ -290,6 +290,28 @@ void testTerminals() { assertEquals(Collections.emptyList(), ((TwoWindingsTransformerImpl) twt).getTerminals(ThreeSides.THREE)); } + @Test + void testTapChangerRegulation() { + String loadId = "69add5b4-70bd-4360-8a93-286256c0d38b"; + String twtId1 = "b94318f6-6d24-4f56-96b9-df2531ad6543"; + String twtId2 = "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0"; + Network network = createNetwork(); + RatioTapChanger ratioTapChanger = network.getTwoWindingsTransformer(twtId1).getRatioTapChanger(); + assertEquals(twtId1, ratioTapChanger.getRegulationTerminal().getConnectable().getId()); + Load load = network.getLoad(loadId); + ratioTapChanger.setRegulationTerminal(load.getTerminal()); + assertEquals(loadId, ratioTapChanger.getRegulationTerminal().getConnectable().getId()); + PhaseTapChanger phaseTapChanger = network.getTwoWindingsTransformer(twtId2).getPhaseTapChanger(); + phaseTapChanger.setRegulationTerminal(load.getTerminal()); + assertEquals(loadId, phaseTapChanger.getRegulationTerminal().getConnectable().getId()); + phaseTapChanger.setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL); + load.remove(); + assertEquals(PhaseTapChanger.RegulationMode.FIXED_TAP, phaseTapChanger.getRegulationMode()); + assertNull(phaseTapChanger.getRegulationTerminal()); + assertNull(ratioTapChanger.getRegulationMode()); + assertNull(ratioTapChanger.getRegulationTerminal()); + } + @Test void settersTest() { Network network = createNetwork(); diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/GeneratorTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/GeneratorTest.java index c046beee3..a6e164ab7 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/GeneratorTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/GeneratorTest.java @@ -11,7 +11,7 @@ /** * @author Geoffroy Jamgotchian */ -public class GeneratorTest extends AbstractGeneratorTest { +class GeneratorTest extends AbstractGeneratorTest { @Override public void testRemove() { diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/TapChangerTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/TapChangerTest.java index 19f35adf8..ebab68b2c 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/TapChangerTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/TapChangerTest.java @@ -18,10 +18,4 @@ public class TapChangerTest extends AbstractTapChangerTest { // and isRegulating is not updated either @Override public void baseTestsPhaseTapChanger() { } - - // TODO remove this test when regulation are handled properly : - // regulating terminal are not deleted from TapChangers when linked terminals are deleted - // and isRegulating is not updated either - @Override - public void undefinedRegulationValueOnlyWarning() { } } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java index 2070a4275..3fd69dfcc 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/BatteryAttributes.java @@ -10,8 +10,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Nicolas Noir @@ -64,5 +64,5 @@ public class BatteryAttributes extends AbstractIdentifiableAttributes implements @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/BusbarSectionAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/BusbarSectionAttributes.java index 9f0f99355..860452f49 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/BusbarSectionAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/BusbarSectionAttributes.java @@ -14,10 +14,7 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author Geoffroy Jamgotchian @@ -46,5 +43,5 @@ public Set getContainerIds() { @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java index 3a1ecedc5..7981eeb59 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/DanglingLineAttributes.java @@ -11,9 +11,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Nicolas Noir @@ -86,7 +84,7 @@ public class DanglingLineAttributes extends AbstractIdentifiableAttributes imple @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); @Override @JsonIgnore diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java index ca1440be6..2fe071547 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/GeneratorAttributes.java @@ -11,8 +11,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -89,5 +89,5 @@ public class GeneratorAttributes extends AbstractRegulatingEquipmentAttributes i @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java index 7c4a89ace..91f0f564b 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/GroundAttributes.java @@ -10,8 +10,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Ayoub LABIDI @@ -49,5 +49,5 @@ public class GroundAttributes extends AbstractIdentifiableAttributes implements @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java index 8e90696f5..63b7cb98d 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LccConverterStationAttributes.java @@ -10,8 +10,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Nicolas Noir @@ -56,5 +56,5 @@ public class LccConverterStationAttributes extends AbstractIdentifiableAttribute @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java index 0b8878e16..70d5f2799 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LineAttributes.java @@ -10,8 +10,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * @author Geoffroy Jamgotchian @@ -107,5 +106,5 @@ public class LineAttributes extends AbstractIdentifiableAttributes implements Br @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java index 967f13393..2e0dcd731 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/LoadAttributes.java @@ -11,8 +11,9 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; + /** * @author Geoffroy Jamgotchian @@ -62,5 +63,5 @@ public class LoadAttributes extends AbstractIdentifiableAttributes implements In @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/PhaseTapChangerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/PhaseTapChangerAttributes.java index 1103f408f..2b2301b5e 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/PhaseTapChangerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/PhaseTapChangerAttributes.java @@ -6,7 +6,6 @@ */ package com.powsybl.network.store.model; -import com.powsybl.iidm.network.PhaseTapChanger; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; @@ -23,9 +22,6 @@ @Schema(description = "PhaseTapChanger attributes") public class PhaseTapChangerAttributes extends TapChangerAttributes { - @Schema(description = "regulationMode") - private PhaseTapChanger.RegulationMode regulationMode; - @Schema(description = "regulationValue") private double regulationValue; } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/RatioTapChangerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/RatioTapChangerAttributes.java index 53497ba7a..dd10f8ea3 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/RatioTapChangerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/RatioTapChangerAttributes.java @@ -6,8 +6,6 @@ */ package com.powsybl.network.store.model; -import com.powsybl.iidm.network.RatioTapChanger; - import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; @@ -29,7 +27,4 @@ public class RatioTapChangerAttributes extends TapChangerAttributes { @Schema(description = "regulationValue") private double regulationValue; - - @Schema(description = "regulationMode") - private RatioTapChanger.RegulationMode regulationMode; } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatedEquipmentAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatedEquipmentAttributes.java index e9ad9b2ab..c5e33c7b5 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatedEquipmentAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatedEquipmentAttributes.java @@ -6,15 +6,15 @@ */ package com.powsybl.network.store.model; -import java.util.Map; +import java.util.Set; /** * @author Etienne Lesot */ public interface RegulatedEquipmentAttributes extends Attributes { - Map getRegulatingEquipments(); + Set getRegulatingEquipments(); - void setRegulatingEquipments(Map regulatingEquipments); + void setRegulatingEquipments(Set regulatingEquipments); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingEquipmentIdentifier.java b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingEquipmentIdentifier.java new file mode 100644 index 000000000..64bf1e2c7 --- /dev/null +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingEquipmentIdentifier.java @@ -0,0 +1,29 @@ +/** + * 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/. + */ +package com.powsybl.network.store.model; + +import lombok.*; + +/** + * @author Etienne Lesot + */ +@EqualsAndHashCode +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class RegulatingEquipmentIdentifier { + private String equipmentId; + private ResourceType resourceType; + private RegulatingTapChangerType regulatingTapChangerType; + + public RegulatingEquipmentIdentifier(String equipmentId, ResourceType resourceType) { + this.equipmentId = equipmentId; + this.resourceType = resourceType; + this.regulatingTapChangerType = RegulatingTapChangerType.NONE; + } +} diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingPointAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingPointAttributes.java index b4af0f53f..76761e676 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingPointAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingPointAttributes.java @@ -28,6 +28,9 @@ public class RegulatingPointAttributes extends AbstractAttributes implements Att @Schema(description = "Resource type of the regulating equipment") private ResourceType regulatingResourceType; + @Schema(description = "tap changer type of the regulating equipment (for tap changer of transformer)") + private RegulatingTapChangerType regulatingTapChangerType; + @Schema(description = "Local terminal") private TerminalRefAttributes localTerminal; diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingTapChangerType.java b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingTapChangerType.java new file mode 100644 index 000000000..bb80866e5 --- /dev/null +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/RegulatingTapChangerType.java @@ -0,0 +1,45 @@ +/** + * 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/. + */ +package com.powsybl.network.store.model; + +import com.powsybl.commons.PowsyblException; +import com.powsybl.iidm.network.ThreeSides; + +/** + * @author Etienne Lesot + */ +public enum RegulatingTapChangerType { + RATIO_TAP_CHANGER, + RATIO_TAP_CHANGER_SIDE_ONE, + RATIO_TAP_CHANGER_SIDE_TWO, + RATIO_TAP_CHANGER_SIDE_THREE, + PHASE_TAP_CHANGER, + PHASE_TAP_CHANGER_SIDE_ONE, + PHASE_TAP_CHANGER_SIDE_TWO, + PHASE_TAP_CHANGER_SIDE_THREE, + NONE; + + public static RegulatingTapChangerType getThreeWindingsTransformerTapChangerType(ThreeSides side, RegulatingTapChangerType type) { + return switch (type) { + case PHASE_TAP_CHANGER -> + getSideType(side, PHASE_TAP_CHANGER_SIDE_ONE, PHASE_TAP_CHANGER_SIDE_TWO, PHASE_TAP_CHANGER_SIDE_THREE); + case RATIO_TAP_CHANGER -> + getSideType(side, RATIO_TAP_CHANGER_SIDE_ONE, RATIO_TAP_CHANGER_SIDE_TWO, RATIO_TAP_CHANGER_SIDE_THREE); + default -> throw new PowsyblException("type to select a three winding tap changer type " + + "must be RATIO_TAP_CHANGER or PHASE_TAP_CHANGER"); + }; + } + + private static RegulatingTapChangerType getSideType(ThreeSides side, RegulatingTapChangerType tapChangerSideOne, + RegulatingTapChangerType tapChangerSideTwo, RegulatingTapChangerType tapChangerSideThree) { + return switch (side) { + case ONE -> tapChangerSideOne; + case TWO -> tapChangerSideTwo; + case THREE -> tapChangerSideThree; + }; + } +} diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java index 8235ba563..ccd2ee368 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ShuntCompensatorAttributes.java @@ -10,8 +10,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -61,5 +61,5 @@ public class ShuntCompensatorAttributes extends AbstractRegulatingEquipmentAttri @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java index a1effd513..2873fb0b0 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/StaticVarCompensatorAttributes.java @@ -10,8 +10,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -67,5 +67,5 @@ public class StaticVarCompensatorAttributes extends AbstractRegulatingEquipmentA @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerAttributes.java index fe8b0d76c..f58082b82 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerAttributes.java @@ -23,7 +23,7 @@ @AllArgsConstructor @SuperBuilder @JsonInclude(JsonInclude.Include.NON_NULL) -public class TapChangerAttributes { +public class TapChangerAttributes extends AbstractRegulatingEquipmentAttributes { @Schema(description = "lowTapPosition") private int lowTapPosition; @@ -31,15 +31,9 @@ public class TapChangerAttributes { @Schema(description = "tapPosition") private int tapPosition; - @Schema(description = "regulating") - private boolean regulating; - @Schema(description = "targetDeadband") private double targetDeadband; - @Schema(description = "regulatingTerminal") - private TerminalRefAttributes regulatingTerminal; - @Schema(description = "steps") private List steps; } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerType.java b/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerType.java index 25b54b890..fa39d0db8 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerType.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/TapChangerType.java @@ -8,7 +8,7 @@ import java.util.Objects; /** - * @author Symvain Bouzols + * @author Sylvain Bouzols */ public enum TapChangerType { RATIO("RATIO"), diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java index 6474ecaed..f7b0eba79 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/ThreeWindingsTransformerAttributes.java @@ -13,10 +13,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author Nicolas Noir @@ -82,7 +79,7 @@ public class ThreeWindingsTransformerAttributes extends AbstractIdentifiableAttr @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); @Override @JsonIgnore diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java index f380cfa41..4fb60ade1 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/TwoWindingsTransformerAttributes.java @@ -10,9 +10,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Geoffroy Jamgotchian @@ -120,5 +118,5 @@ public class TwoWindingsTransformerAttributes extends AbstractIdentifiableAttrib @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java b/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java index fb0b4b882..8d7f29949 100644 --- a/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java +++ b/network-store-model/src/main/java/com/powsybl/network/store/model/VscConverterStationAttributes.java @@ -10,8 +10,8 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; /** * @author Geoffroy Jamgotchian @@ -62,5 +62,5 @@ public class VscConverterStationAttributes extends AbstractRegulatingEquipmentAt @Builder.Default @Schema(description = "regulatingEquipments") - private Map regulatingEquipments = new HashMap<>(); + private Set regulatingEquipments = new HashSet<>(); } diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java index 0831e2717..5a5b2bcf7 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/ResourceTest.java @@ -155,7 +155,7 @@ public void lineTest() { .b1(1) .g2(1) .b2(1) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build()) .build(); @@ -169,7 +169,7 @@ public void lineTest() { resourceLine.getAttributes().setP1(100.0); assertEquals(100.0, resourceLine.getAttributes().getP1(), 0); assertFalse(resourceLine.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceLine.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceLine.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -190,7 +190,7 @@ public void twoWindingsTransformer() { .g(1) .ratedU1(1.) .ratedU2(1.) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build()) .build(); @@ -204,7 +204,7 @@ public void twoWindingsTransformer() { resourceTransformer.getAttributes().setP1(100.0); assertEquals(100.0, resourceTransformer.getAttributes().getP1(), 0); assertFalse(resourceTransformer.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceTransformer.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceTransformer.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -214,7 +214,7 @@ public void threeWindingsTransformer() { .attributes(ThreeWindingsTransformerAttributes.builder() .name("id3WT") .ratedU0(1) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build()) .build(); @@ -235,7 +235,7 @@ public void threeWindingsTransformer() { assertEquals(500., resourceTransformer.getAttributes().getQ2(), 0); assertEquals(700., resourceTransformer.getAttributes().getP3(), 0); assertFalse(resourceTransformer.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceTransformer.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceTransformer.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -247,7 +247,7 @@ public void load() { .bus("bus1") .fictitious(false) .node(1) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build(); Resource resourceLoad = Resource.loadBuilder() @@ -261,7 +261,7 @@ public void load() { assertTrue(Double.isNaN(resourceLoad.getAttributes().getP())); assertTrue(Double.isNaN(resourceLoad.getAttributes().getQ())); assertFalse(resourceLoad.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceLoad.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceLoad.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -286,7 +286,7 @@ public void generator() { .targetP(3) .targetV(4) .regulatingPoint(regulatingPointAttributes) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build(); Resource resourceGenerator = Resource.generatorBuilder() @@ -309,7 +309,7 @@ public void generator() { assertEquals("gen", resourceGenerator.getAttributes().getRegulatingPoint().getLocalTerminal().getConnectableId()); assertNull(resourceGenerator.getAttributes().getRegulatingPoint().getLocalTerminal().getSide()); assertFalse(resourceGenerator.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceGenerator.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceGenerator.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -325,7 +325,7 @@ public void battery() { .targetQ(100) .fictitious(false) .node(1) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build(); Resource resourceBattery = Resource.batteryBuilder() @@ -343,7 +343,7 @@ public void battery() { assertTrue(Double.isNaN(resourceBattery.getAttributes().getP())); assertTrue(Double.isNaN(resourceBattery.getAttributes().getQ())); assertFalse(resourceBattery.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceBattery.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceBattery.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -356,7 +356,7 @@ public void ground() { .p(250) .q(100) .fictitious(false) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .node(1) .build(); @@ -370,7 +370,7 @@ public void ground() { assertEquals(100, resourceGround.getAttributes().getQ(), 0); assertEquals(1, resourceGround.getAttributes().getNode(), 0); assertFalse(resourceGround.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceGround.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceGround.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -409,7 +409,7 @@ public void shuntCompensator() { .model(linearModelAttributes) .sectionCount(2) .regulatingPoint(regulatingPointAttributes) - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build(); Resource resourceShunt = Resource.shuntCompensatorBuilder() @@ -430,7 +430,7 @@ public void shuntCompensator() { assertEquals(2, ((ShuntCompensatorLinearModelAttributes) resourceShunt.getAttributes().getModel()).getGPerSection(), 0.001); assertEquals(3, resourceShunt.getAttributes().getModel().getMaximumSectionCount(), 0.001); assertFalse(resourceShunt.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceShunt.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceShunt.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test @@ -462,7 +462,7 @@ public void danglingLine() throws JsonProcessingException { .pairingKey("XN1") .bus("bus1") .tieLineId("idTieLineParent") - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build(); Resource resourceDanglingLine = Resource.danglingLineBuilder() @@ -496,7 +496,7 @@ public void danglingLine() throws JsonProcessingException { assertTrue(Double.isNaN(resourceDanglingLine.getAttributes().getP())); assertTrue(Double.isNaN(resourceDanglingLine.getAttributes().getQ())); assertFalse(resourceDanglingLine.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceDanglingLine.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceDanglingLine.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); @@ -564,7 +564,7 @@ public void busBarSection() { .attributes(BusbarSectionAttributes.builder() .voltageLevelId("vl1") .name("bbs") - .regulatingEquipments(Collections.singletonMap("gen1", ResourceType.GENERATOR)) + .regulatingEquipments(Collections.singleton(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))) .build()) .build(); @@ -572,7 +572,7 @@ public void busBarSection() { assertEquals("vl1", resourceTransformer.getAttributes().getVoltageLevelId()); assertEquals("bbs", resourceTransformer.getAttributes().getName()); assertFalse(resourceTransformer.getAttributes().getRegulatingEquipments().isEmpty()); - assertEquals(ResourceType.GENERATOR, resourceTransformer.getAttributes().getRegulatingEquipments().get("gen1")); + assertTrue(resourceTransformer.getAttributes().getRegulatingEquipments().contains(new RegulatingEquipmentIdentifier("gen1", ResourceType.GENERATOR))); } @Test diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java index 8cd9e4671..461e65020 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/TapChangerParentTest.java @@ -88,6 +88,28 @@ public void setUp() { @Test public void twoWindingsTransformertapChangerAttributesTest() { + RegulatingPointAttributes phaseTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder() + .regulatingEquipmentId("id2WT") + .regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER) + .regulatingTapChangerType(RegulatingTapChangerType.PHASE_TAP_CHANGER) + .regulationMode(RegulationMode.ACTIVE_POWER_CONTROL.toString()) + .regulatingTerminal(TerminalRefAttributes.builder() + .connectableId("connectableId") + .side("this side").build()) + .regulatedResourceType(ResourceType.LOAD) + .regulating(true) + .build(); + + RegulatingPointAttributes ratioTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder() + .regulatingEquipmentId("id2WT") + .regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER) + .regulatingTapChangerType(RegulatingTapChangerType.RATIO_TAP_CHANGER) + .regulatingTerminal(TerminalRefAttributes.builder() + .connectableId("connectableId") + .side("this side").build()) + .regulatedResourceType(ResourceType.LOAD) + .regulating(true) + .build(); Resource resourceTransformer = Resource.twoWindingsTransformerBuilder() .id("id2WT") .attributes(TwoWindingsTransformerAttributes.builder() @@ -106,25 +128,14 @@ public void twoWindingsTransformertapChangerAttributesTest() { .ratedU2(1.) .phaseTapChangerAttributes(PhaseTapChangerAttributes.builder() .lowTapPosition(1) - .regulating(true) - .regulatingTerminal(TerminalRefAttributes.builder() - .connectableId("connectableId") - .side("this side") - .build() - ) - .regulationMode(RegulationMode.ACTIVE_POWER_CONTROL) + .regulatingPoint(ratioTapChangerRegulatingPointAttributes) .regulationValue(10.) .steps(tapChangerStepsA) .build() ) .ratioTapChangerAttributes(RatioTapChangerAttributes.builder() .lowTapPosition(1) - .regulating(true) - .regulatingTerminal(TerminalRefAttributes.builder() - .connectableId("connectableId") - .side("this side") - .build() - ) + .regulatingPoint(phaseTapChangerRegulatingPointAttributes) .loadTapChangingCapabilities(true) .targetDeadband(1.) .regulationValue(10.) @@ -164,6 +175,41 @@ public void twoWindingsTransformertapChangerAttributesTest() { @Test public void threeWindingsTransformertapChangerAttributesTest() { + RegulatingPointAttributes phaseTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder() + .regulatingEquipmentId("id2WT") + .regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER) + .regulatingTapChangerType(RegulatingTapChangerType.PHASE_TAP_CHANGER) + .regulationMode(RegulationMode.ACTIVE_POWER_CONTROL.toString()) + .regulatingTerminal(TerminalRefAttributes.builder() + .connectableId("connectableId") + .side("this side").build()) + .regulatedResourceType(ResourceType.LOAD) + .regulating(true) + .build(); + + RegulatingPointAttributes phaseTapChangerRegulatingPointAttributes2 = RegulatingPointAttributes.builder() + .regulatingEquipmentId("id2WT") + .regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER) + .regulatingTapChangerType(RegulatingTapChangerType.PHASE_TAP_CHANGER) + .regulationMode(RegulationMode.CURRENT_LIMITER.toString()) + .regulatingTerminal(TerminalRefAttributes.builder() + .connectableId("connectableId") + .side("this side").build()) + .regulatedResourceType(ResourceType.LOAD) + .regulating(true) + .build(); + + RegulatingPointAttributes ratioTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder() + .regulatingEquipmentId("id2WT") + .regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER) + .regulatingTapChangerType(RegulatingTapChangerType.RATIO_TAP_CHANGER) + .regulatingTerminal(TerminalRefAttributes.builder() + .connectableId("connectableId") + .side("this side").build()) + .regulatedResourceType(ResourceType.LOAD) + .regulating(true) + .build(); + Resource resourceTransformer = Resource.threeWindingsTransformerBuilder() .id("id3WT") .attributes(ThreeWindingsTransformerAttributes.builder() @@ -172,13 +218,7 @@ public void threeWindingsTransformertapChangerAttributesTest() { .leg1(LegAttributes.builder() .phaseTapChangerAttributes(PhaseTapChangerAttributes.builder() .lowTapPosition(1) - .regulating(true) - .regulatingTerminal(TerminalRefAttributes.builder() - .connectableId("connectableId") - .side("this side") - .build() - ) - .regulationMode(RegulationMode.ACTIVE_POWER_CONTROL) + .regulatingPoint(phaseTapChangerRegulatingPointAttributes) .regulationValue(10.) .steps(tapChangerStepsA) .build() @@ -188,12 +228,7 @@ public void threeWindingsTransformertapChangerAttributesTest() { .leg2(LegAttributes.builder() .ratioTapChangerAttributes(RatioTapChangerAttributes.builder() .lowTapPosition(1) - .regulating(true) - .regulatingTerminal(TerminalRefAttributes.builder() - .connectableId("connectableId") - .side("this side") - .build() - ) + .regulatingPoint(ratioTapChangerRegulatingPointAttributes) .loadTapChangingCapabilities(true) .targetDeadband(1.) .regulationValue(10.) @@ -205,13 +240,7 @@ public void threeWindingsTransformertapChangerAttributesTest() { .leg3(LegAttributes.builder() .phaseTapChangerAttributes(PhaseTapChangerAttributes.builder() .lowTapPosition(1) - .regulating(true) - .regulatingTerminal(TerminalRefAttributes.builder() - .connectableId("connectableId") - .side("this side") - .build() - ) - .regulationMode(RegulationMode.CURRENT_LIMITER) + .regulatingPoint(phaseTapChangerRegulatingPointAttributes2) .regulationValue(20.) .steps(tapChangerStepsC) .build() diff --git a/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java b/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java index 88ee9194e..f8a0a384f 100644 --- a/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java +++ b/network-store-model/src/test/java/com/powsybl/network/store/model/TopLevelDocumentTest.java @@ -15,8 +15,7 @@ import org.junit.Test; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import static com.powsybl.network.store.model.ResourceType.*; import static org.junit.Assert.assertEquals; @@ -94,11 +93,11 @@ public void testMeta() throws IOException { public void testGenerator() throws IOException { TerminalRefAttributes regulatedTerminalAttributes = TerminalRefAttributes.builder().side("ONE").connectableId("idEq").build(); - RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes("gen1", GENERATOR, + RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes("gen1", GENERATOR, RegulatingTapChangerType.NONE, new TerminalRefAttributes("gen1", null), regulatedTerminalAttributes, null, GENERATOR, true); - Map regEquipments = new HashMap<>(); - regEquipments.put("gen1", GENERATOR); - regEquipments.put("gen2", GENERATOR); + Set regEquipments = new HashSet<>(); + regEquipments.add(new RegulatingEquipmentIdentifier("gen1", GENERATOR)); + regEquipments.add(new RegulatingEquipmentIdentifier("gen2", GENERATOR)); GeneratorAttributes generatorAttributes = GeneratorAttributes .builder() .voltageLevelId("vl1") @@ -123,7 +122,7 @@ public void testGenerator() throws IOException { TopLevelDocument document = TopLevelDocument.of(resourceGenerator); ObjectMapper objectMapper = JsonUtil.createObjectMapper(); String json = objectMapper.writeValueAsString(document); - String jsonRef = "{\"data\":[{\"type\":\"GENERATOR\",\"id\":\"gen1\",\"variantNum\":0,\"attributes\":{\"name\":\"name\",\"fictitious\":false,\"extensionAttributes\":{},\"regulatingPoint\":{\"regulatingEquipmentId\":\"gen1\",\"regulatingResourceType\":\"GENERATOR\",\"localTerminal\":{\"connectableId\":\"gen1\"},\"regulatingTerminal\":{\"connectableId\":\"idEq\",\"side\":\"ONE\"},\"regulationMode\":null,\"regulatedResourceType\":\"GENERATOR\",\"regulating\":true},\"voltageLevelId\":\"vl1\",\"node\":1,\"bus\":\"bus1\",\"energySource\":\"HYDRO\",\"minP\":2.0,\"maxP\":1.0,\"targetP\":3.0,\"targetQ\":0.0,\"targetV\":4.0,\"ratedS\":0.0,\"p\":NaN,\"q\":NaN,\"condenser\":false,\"regulatingEquipments\":{\"gen1\":\"GENERATOR\",\"gen2\":\"GENERATOR\"}}}],\"meta\":{}}"; + String jsonRef = "{\"data\":[{\"type\":\"GENERATOR\",\"id\":\"gen1\",\"variantNum\":0,\"attributes\":{\"name\":\"name\",\"fictitious\":false,\"extensionAttributes\":{},\"regulatingPoint\":{\"regulatingEquipmentId\":\"gen1\",\"regulatingResourceType\":\"GENERATOR\",\"regulatingTapChangerType\":\"NONE\",\"localTerminal\":{\"connectableId\":\"gen1\"},\"regulatingTerminal\":{\"connectableId\":\"idEq\",\"side\":\"ONE\"},\"regulationMode\":null,\"regulatedResourceType\":\"GENERATOR\",\"regulating\":true},\"voltageLevelId\":\"vl1\",\"node\":1,\"bus\":\"bus1\",\"energySource\":\"HYDRO\",\"minP\":2.0,\"maxP\":1.0,\"targetP\":3.0,\"targetQ\":0.0,\"targetV\":4.0,\"ratedS\":0.0,\"p\":NaN,\"q\":NaN,\"condenser\":false,\"regulatingEquipments\":[{\"equipmentId\":\"gen2\",\"resourceType\":\"GENERATOR\",\"regulatingTapChangerType\":\"NONE\"},{\"equipmentId\":\"gen1\",\"resourceType\":\"GENERATOR\",\"regulatingTapChangerType\":\"NONE\"}]}}],\"meta\":{}}"; assertEquals(jsonRef, json); TopLevelDocument document2 = objectMapper.readValue(json, TopLevelDocument.class); assertEquals(resourceGenerator, document2.getData().get(0));