Skip to content

Commit

Permalink
review and fix
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
  • Loading branch information
EtienneLt committed Dec 11, 2024
1 parent 7aa8d22 commit bcf2460
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.network.store.iidm.impl;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.network.store.model.*;

Expand All @@ -33,8 +34,8 @@ public ResourceType getRegulatingEquipmentType() {
return getAttributes().getRegulatingResourceType();
}

public RegulatingTapChangerType getRegulatingResourceSubType() {
return getAttributes().getRegulatingResourceSubType();
public RegulatingTapChangerType getRegulatingTapChangerType() {
return getAttributes().getRegulatingTapChangerType();
}

public abstract RegulatingPointAttributes getAttributes();
Expand All @@ -59,7 +60,7 @@ public void resetRegulationToLocalTerminal() {
getIdentifiable().updateResource(res -> getAttributes().setRegulatedResourceType(getAttributes().getRegulatingResourceType()));
}

protected abstract AbstractIdentifiableImpl getIdentifiable();
protected abstract <I extends Identifiable<I>, D extends IdentifiableAttributes> AbstractIdentifiableImpl<I, D> getIdentifiable();

public void setRegulationMode(String regulationMode) {
getIdentifiable().updateResource(res -> getAttributes().setRegulationMode(regulationMode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected RegulatingPointAttributes createRegulationPointAttributes(TapChangerPa
RegulatingTapChangerType finalRegulatingTapChangerType = regulatingTapChangerType;
if (tapChangerParent instanceof ThreeWindingsTransformerImpl.LegImpl leg) {
side = leg.getSide();
finalRegulatingTapChangerType = RegulatingTapChangerType.getThreeWindingType(side, regulatingTapChangerType);
finalRegulatingTapChangerType = RegulatingTapChangerType.getThreeWindingsTransformerTapChangerType(side, regulatingTapChangerType);
}
TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);
return new RegulatingPointAttributes(tapChangerParent.getTransformer().getId(), ResourceType.TWO_WINDINGS_TRANSFORMER, finalRegulatingTapChangerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Generator add() {
.build();

TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.GENERATOR, null,
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.GENERATOR, RegulatingTapChangerType.NO_TAP_CHANGER,
new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.GENERATOR, voltageRegulatorOn);

Resource<GeneratorAttributes> resource = Resource.generatorBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void remove() {
for (Terminal terminal : getTerminals()) {
((TerminalImpl<?>) terminal).removeAsRegulatingPoint();
}
regulatingPoint.remove();
// invalidate calculated buses before removal otherwise voltage levels won't be accessible anymore for topology invalidation!
invalidateCalculatedBuses(getTerminals());
index.removeGenerator(resource.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void resetRegulationMode(Terminal regulatingTerminal, Terminal localTe
}

@Override
protected AbstractIdentifiableImpl getIdentifiable() {
protected AbstractRegulatingInjection<I, D> getIdentifiable() {
return injection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public Optional<PhaseTapChangerStep> getNeutralStep() {

@Override
public void remove() {
regulatingPoint.remove();
parent.setPhaseTapChanger(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected Integer getRelativeNeutralPosition() {

@Override
public void remove() {
regulatingPoint.remove();
parent.setRatioTapChanger(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, null,
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.SHUNT_COMPENSATOR, RegulatingTapChangerType.NO_TAP_CHANGER,
new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.SHUNT_COMPENSATOR, voltageRegulatorOn);

Resource<ShuntCompensatorAttributes> resource = Resource.shuntCompensatorBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void remove() {
for (Terminal terminal : getTerminals()) {
((TerminalImpl<?>) terminal).removeAsRegulatingPoint();
}
regulatingPoint.remove();
// invalidate calculated buses before removal otherwise voltage levels won't be accessible anymore for topology invalidation!
invalidateCalculatedBuses(getTerminals());
index.removeShuntCompensator(resource.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, null,
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.STATIC_VAR_COMPENSATOR, RegulatingTapChangerType.NO_TAP_CHANGER,
new TerminalRefAttributes(getId(), null), terminalRefAttributes, String.valueOf(regulationMode), ResourceType.STATIC_VAR_COMPENSATOR, isRegulating);
Resource<StaticVarCompensatorAttributes> resource = Resource.staticVarCompensatorBuilder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public RegulatingPointAttributes getAttributes() {
}

@Override
protected AbstractIdentifiableImpl getIdentifiable() {
protected AbstractIdentifiableImpl<?, ?> getIdentifiable() {
return tapChanger.getTransformer();
}

Expand All @@ -33,13 +33,13 @@ protected void resetRegulationMode(Terminal regulatingTerminal, Terminal localTe
!localTerminal.getBusView().getBus().equals(regulatingTerminal.getBusView().getBus())) {
// the target can be inappropriated if it was a remote regulation
tapChanger.setRegulating(false);
switch (getAttributes().getRegulatingResourceSubType()) {
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() + " this kind of equipment");
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,13 @@ public ThreeSides getSide() {
public void setAsRegulatingPoint(AbstractRegulatingPoint regulatingPoint) {
getAttributes().getRegulatingEquipments()
.add(new RegulatingEquipmentIdentifier(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType(),
regulatingPoint.getRegulatingResourceSubType()));
regulatingPoint.getRegulatingTapChangerType()));
}

public void removeRegulatingPoint(AbstractRegulatingPoint regulatingPoint) {
getAttributes().getRegulatingEquipments()
.remove(new RegulatingEquipmentIdentifier(regulatingPoint.getRegulatingEquipmentId(),
regulatingPoint.getRegulatingEquipmentType(), regulatingPoint.getRegulatingResourceSubType()));
regulatingPoint.getRegulatingEquipmentType(), regulatingPoint.getRegulatingTapChangerType()));
}

public void removeAsRegulatingPoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public VscConverterStation add() {
validate();

TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.VSC_CONVERTER_STATION, null,
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.VSC_CONVERTER_STATION, RegulatingTapChangerType.NO_TAP_CHANGER,
new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.VSC_CONVERTER_STATION, voltageRegulatorOn);

Resource<VscConverterStationAttributes> resource = Resource.vscConverterStationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void remove() {
for (Terminal terminal : getTerminals()) {
((TerminalImpl<?>) terminal).removeAsRegulatingPoint();
}
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() + "')");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
*/
package com.powsybl.network.store.iidm.impl.tck;

import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.tck.AbstractGeneratorTest;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -23,49 +17,4 @@ class GeneratorTest extends AbstractGeneratorTest {
public void testRemove() {
// FIXME remove this test when exception msg are homogenized with the powsybl-core
}

@Test
void testRegulationWhenRegulatedElementIsRemoved() {
Network network = FourSubstationsNodeBreakerFactory.create();

// initialization
Generator generator = network.getGenerator("GH3");
Load load = network.getLoad("LD1");
Assertions.assertTrue(generator.isVoltageRegulatorOn());
Assertions.assertEquals(generator.getTerminal(), generator.getRegulatingTerminal());
Assertions.assertEquals(400, generator.getTargetV());

// set the generator's regulation on the load terminal (both equipments are not on the same voltage level/bus)
generator.setRegulatingTerminal(load.getTerminal());
generator.setTargetV(225);
Assertions.assertTrue(generator.isVoltageRegulatorOn());
Assertions.assertEquals(load.getTerminal(), generator.getRegulatingTerminal());
Assertions.assertEquals(225, generator.getTargetV());

// remove the load
network.getLoad("LD1").remove();
Assertions.assertEquals(generator.getTerminal(), generator.getRegulatingTerminal());
Assertions.assertFalse(generator.isVoltageRegulatorOn());
}

@Test
void testRegulationWhenRegulatedElementOnSameBusIsRemoved() {
Network network = FourSubstationsNodeBreakerFactory.create();

// initialization
Generator generator = network.getGenerator("GH3");
Load load = network.getLoad("LD2");
Assertions.assertTrue(generator.isVoltageRegulatorOn());
Assertions.assertEquals(generator.getTerminal(), generator.getRegulatingTerminal());

// set the generator's regulation on the load terminal (both equipments are on the same voltage level/bus)
generator.setRegulatingTerminal(load.getTerminal());
Assertions.assertTrue(generator.isVoltageRegulatorOn());
Assertions.assertEquals(load.getTerminal(), generator.getRegulatingTerminal());

// remove the load
network.getLoad("LD2").remove();
Assertions.assertEquals(generator.getTerminal(), generator.getRegulatingTerminal());
Assertions.assertTrue(generator.isVoltageRegulatorOn());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class RegulatingPointAttributes extends AbstractAttributes implements Att
@Schema(description = "Resource type of the regulating equipment")
private ResourceType regulatingResourceType;

@Schema(description = "Resource sub type of the regulating equipment (for tap changer of transformer)")
private RegulatingTapChangerType regulatingResourceSubType;
@Schema(description = "tap changer type of the regulating equipment (for tap changer of transformer)")
private RegulatingTapChangerType regulatingTapChangerType;

@Schema(description = "Local terminal")
private TerminalRefAttributes localTerminal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public enum RegulatingTapChangerType {
PHASE_TAP_CHANGER,
PHASE_TAP_CHANGER_SIDE_ONE,
PHASE_TAP_CHANGER_SIDE_TWO,
PHASE_TAP_CHANGER_SIDE_THREE;
PHASE_TAP_CHANGER_SIDE_THREE,
NO_TAP_CHANGER;

public static RegulatingTapChangerType getThreeWindingType(ThreeSides side, RegulatingTapChangerType type) {
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);
Expand All @@ -33,11 +34,12 @@ public static RegulatingTapChangerType getThreeWindingType(ThreeSides side, Regu
};
}

private static RegulatingTapChangerType getSideType(ThreeSides side, RegulatingTapChangerType enum1, RegulatingTapChangerType enum2, RegulatingTapChangerType enum3) {
private static RegulatingTapChangerType getSideType(ThreeSides side, RegulatingTapChangerType tapChangerSideOne,
RegulatingTapChangerType tapChangerSideTwo, RegulatingTapChangerType tapChangerSideThree) {
return switch (side) {
case ONE -> enum1;
case TWO -> enum2;
case THREE -> enum3;
case ONE -> tapChangerSideOne;
case TWO -> tapChangerSideTwo;
case THREE -> tapChangerSideThree;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void twoWindingsTransformertapChangerAttributesTest() {
RegulatingPointAttributes phaseTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder()
.regulatingEquipmentId("id2WT")
.regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER)
.regulatingResourceSubType(RegulatingTapChangerType.PHASE_TAP_CHANGER)
.regulatingTapChangerType(RegulatingTapChangerType.PHASE_TAP_CHANGER)
.regulationMode(RegulationMode.ACTIVE_POWER_CONTROL.toString())
.regulatingTerminal(TerminalRefAttributes.builder()
.connectableId("connectableId")
Expand All @@ -103,7 +103,7 @@ public void twoWindingsTransformertapChangerAttributesTest() {
RegulatingPointAttributes ratioTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder()
.regulatingEquipmentId("id2WT")
.regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER)
.regulatingResourceSubType(RegulatingTapChangerType.RATIO_TAP_CHANGER)
.regulatingTapChangerType(RegulatingTapChangerType.RATIO_TAP_CHANGER)
.regulatingTerminal(TerminalRefAttributes.builder()
.connectableId("connectableId")
.side("this side").build())
Expand Down Expand Up @@ -178,7 +178,7 @@ public void threeWindingsTransformertapChangerAttributesTest() {
RegulatingPointAttributes phaseTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder()
.regulatingEquipmentId("id2WT")
.regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER)
.regulatingResourceSubType(RegulatingTapChangerType.PHASE_TAP_CHANGER)
.regulatingTapChangerType(RegulatingTapChangerType.PHASE_TAP_CHANGER)
.regulationMode(RegulationMode.ACTIVE_POWER_CONTROL.toString())
.regulatingTerminal(TerminalRefAttributes.builder()
.connectableId("connectableId")
Expand All @@ -190,7 +190,7 @@ public void threeWindingsTransformertapChangerAttributesTest() {
RegulatingPointAttributes phaseTapChangerRegulatingPointAttributes2 = RegulatingPointAttributes.builder()
.regulatingEquipmentId("id2WT")
.regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER)
.regulatingResourceSubType(RegulatingTapChangerType.PHASE_TAP_CHANGER)
.regulatingTapChangerType(RegulatingTapChangerType.PHASE_TAP_CHANGER)
.regulationMode(RegulationMode.CURRENT_LIMITER.toString())
.regulatingTerminal(TerminalRefAttributes.builder()
.connectableId("connectableId")
Expand All @@ -202,7 +202,7 @@ public void threeWindingsTransformertapChangerAttributesTest() {
RegulatingPointAttributes ratioTapChangerRegulatingPointAttributes = RegulatingPointAttributes.builder()
.regulatingEquipmentId("id2WT")
.regulatingResourceType(ResourceType.TWO_WINDINGS_TRANSFORMER)
.regulatingResourceSubType(RegulatingTapChangerType.RATIO_TAP_CHANGER)
.regulatingTapChangerType(RegulatingTapChangerType.RATIO_TAP_CHANGER)
.regulatingTerminal(TerminalRefAttributes.builder()
.connectableId("connectableId")
.side("this side").build())
Expand Down
Loading

0 comments on commit bcf2460

Please sign in to comment.