Skip to content

Commit

Permalink
add a new enum type for regulating ratio/phase tap changer
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Dec 3, 2024
1 parent cc7737e commit a7c9927
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/
@Setter
@Getter
public abstract class AbstractRegulatingEquipment<I extends Injection<I>, D extends InjectionAttributes> extends AbstractInjectionImpl<I, D> implements Injection<I> {
public abstract class AbstractRegulatingInjection<I extends Injection<I>, D extends InjectionAttributes> extends AbstractInjectionImpl<I, D> implements Injection<I> {

protected final InjectionRegulatingPoint<I, D> regulatingPoint;

protected AbstractRegulatingEquipment(NetworkObjectIndex index, Resource<D> resource) {
protected AbstractRegulatingInjection(NetworkObjectIndex index, Resource<D> resource) {
super(index, resource);
regulatingPoint = new InjectionRegulatingPoint<>(index, this, AbstractRegulatingEquipmentAttributes.class::cast);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.network.store.model.AbstractRegulatingEquipmentAttributes;
import com.powsybl.network.store.model.Attributes;
import com.powsybl.network.store.model.RegulatingPointAttributes;
import com.powsybl.network.store.model.ResourceType;
import com.powsybl.network.store.model.*;

import java.util.function.Function;

Expand All @@ -36,6 +33,10 @@ public ResourceType getRegulatingEquipmentType() {
return getAttributes().getRegulatingResourceType();
}

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

public abstract RegulatingPointAttributes getAttributes();

public Terminal getRegulatingTerminal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -37,4 +43,19 @@ public AbstractTapChangerAdder(NetworkObjectIndex index, int lowTapPosition, Int
this.regulating = regulating;
this.targetDeadband = targetDeadband;
}

protected RegulatingPointAttributes createRegulationPointAttributes(TapChangerParent tapChangerParent, RegulatingTapChangerType regulatingTapChangerType,
String regulationMode) {
// for three windings transformer the local side will be the leg number
// for two windings transformer the ratio is regulating on side 2
ThreeSides side = ThreeSides.TWO;
RegulatingTapChangerType finalRegulatingTapChangerType = regulatingTapChangerType;
if (tapChangerParent instanceof ThreeWindingsTransformerImpl.LegImpl leg) {
side = leg.getSide();
finalRegulatingTapChangerType = RegulatingTapChangerType.getThreeWindingType(side, regulatingTapChangerType);
}
TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);
return new RegulatingPointAttributes(tapChangerParent.getTransformer().getId(), ResourceType.TWO_WINDINGS_TRANSFORMER, finalRegulatingTapChangerType,
new TerminalRefAttributes(tapChangerParent.getTransformer().getId(), side.toString()), terminalRefAttributes, regulationMode, ResourceType.TWO_WINDINGS_TRANSFORMER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.network.store.model.*;
import org.apache.commons.lang3.mutable.MutableInt;
Expand Down Expand Up @@ -1120,7 +1119,6 @@ private NetworkCollectionIndex<? extends CollectionCache<?>> getCache(ResourceTy
case CONFIGURED_BUS -> configuredBusesCache;
case TIE_LINE -> tieLinesCache;
case GROUND -> groundsCache;
case RATIO_TAP_CHANGER, PHASE_TAP_CHANGER -> throw new PowsyblException("no cache for ratio orphase tap changers");
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public Generator add() {

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

Resource<GeneratorAttributes> resource = Resource.generatorBuilder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Etienne Homer <etienne.homer at rte-france.com>
*/
public class GeneratorImpl extends AbstractRegulatingEquipment<Generator, GeneratorAttributes> implements Generator, ReactiveLimitsOwner {
public class GeneratorImpl extends AbstractRegulatingInjection<Generator, GeneratorAttributes> implements Generator, ReactiveLimitsOwner {

public GeneratorImpl(NetworkObjectIndex index, Resource<GeneratorAttributes> resource) {
super(index, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public final class InjectionRegulatingPoint<I extends Injection<I>, D extends InjectionAttributes> extends AbstractRegulatingPoint {
private final AbstractRegulatingEquipment<I, D> identifiable;
private final AbstractRegulatingInjection<I, D> injection;

public InjectionRegulatingPoint(NetworkObjectIndex index, AbstractRegulatingEquipment<I, D> identifiable, Function<Attributes, AbstractRegulatingEquipmentAttributes> attributesGetter) {
public InjectionRegulatingPoint(NetworkObjectIndex index, AbstractRegulatingInjection<I, D> injection, Function<Attributes, AbstractRegulatingEquipmentAttributes> attributesGetter) {
super(index, attributesGetter);
this.identifiable = identifiable;
this.injection = injection;
}

private Resource<D> getResource() {
return identifiable.getResource();
return injection.getResource();
}

@Override
Expand All @@ -44,21 +44,21 @@ public void setRegulatingTerminal(TerminalImpl<?> regulatingTerminal) {
oldRegulatingTerminal.removeRegulatingPoint(this);
}
regulatingTerminal.setAsRegulatingPoint(this);
identifiable.updateResource(res -> getAttributes(res)
injection.updateResource(res -> getAttributes(res)
.setRegulatingTerminal(TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal)));
identifiable.updateResource(res -> getAttributes(res)
injection.updateResource(res -> getAttributes(res)
.setRegulatedResourceType(ResourceType.convert(regulatingTerminal.getConnectable().getType())));
}

@Override
public void resetRegulationToLocalTerminal() {
identifiable.updateResource(res -> getAttributes(res).setRegulatingTerminal(getAttributes().getLocalTerminal()));
identifiable.updateResource(res -> getAttributes(res).setRegulatedResourceType(getAttributes().getRegulatingResourceType()));
injection.updateResource(res -> getAttributes(res).setRegulatingTerminal(getAttributes().getLocalTerminal()));
injection.updateResource(res -> getAttributes(res).setRegulatedResourceType(getAttributes().getRegulatingResourceType()));
}

@Override
public void setRegulationMode(String regulationMode) {
identifiable.updateResource(res -> getAttributes(res).setRegulationMode(regulationMode));
injection.updateResource(res -> getAttributes(res).setRegulationMode(regulationMode));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,7 @@ public PhaseTapChanger add() {
tapChangers.remove(tapChangerParent.getPhaseTapChanger());
ValidationUtil.checkOnlyOneTapChangerRegulatingEnabled(tapChangerParent, tapChangers, regulating, ValidationLevel.STEADY_STATE_HYPOTHESIS, tapChangerParent.getNetwork().getReportNodeContext().getReportNode());

// for three windings transformer the local side will be the leg number
// for two windings transformer the ratio is regulating on side 2
ThreeSides side = ThreeSides.TWO;
if (tapChangerParent instanceof ThreeWindingsTransformerImpl.LegImpl leg) {
side = leg.getSide();
}
TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(tapChangerParent.getTransformer().getId(), ResourceType.PHASE_TAP_CHANGER,
new TerminalRefAttributes(tapChangerParent.getTransformer().getId(), side.toString()), terminalRefAttributes, regulationMode.toString(), ResourceType.PHASE_TAP_CHANGER);
RegulatingPointAttributes regulatingPointAttributes = createRegulationPointAttributes(tapChangerParent, RegulatingTapChangerType.PHASE_TAP_CHANGER, regulationMode.toString());

PhaseTapChangerAttributes phaseTapChangerAttributes = PhaseTapChangerAttributes.builder()
.lowTapPosition(lowTapPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,7 @@ public RatioTapChanger add() {
ValidationUtil.checkOnlyOneTapChangerRegulatingEnabled(tapChangerParent, tapChangers, regulating, ValidationLevel.STEADY_STATE_HYPOTHESIS, tapChangerParent.getNetwork().getReportNodeContext().getReportNode());

String regulationModeStr = regulationMode == null ? null : regulationMode.toString();

TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);

// for three windings transformer the local side will be the leg number
// for two windings transformer the ratio is regulating on side 2
ThreeSides side = ThreeSides.TWO;
if (tapChangerParent instanceof ThreeWindingsTransformerImpl.LegImpl leg) {
side = leg.getSide();
}
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(tapChangerParent.getTransformer().getId(), ResourceType.RATIO_TAP_CHANGER,
new TerminalRefAttributes(tapChangerParent.getTransformer().getId(), side.toString()), terminalRefAttributes, regulationModeStr, ResourceType.RATIO_TAP_CHANGER);
RegulatingPointAttributes regulatingPointAttributes = createRegulationPointAttributes(tapChangerParent, RegulatingTapChangerType.RATIO_TAP_CHANGER, regulationModeStr);

RatioTapChangerAttributes ratioTapChangerAttributes = RatioTapChangerAttributes.builder()
.loadTapChangingCapabilities(loadTapChangingCapabilities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public ShuntCompensator add() {
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,
new TerminalRefAttributes(getId(), null), terminalRefAttributes, null, ResourceType.SHUNT_COMPENSATOR);
null, new TerminalRefAttributes(getId(), null), terminalRefAttributes,
null, ResourceType.SHUNT_COMPENSATOR);

Resource<ShuntCompensatorAttributes> resource = Resource.shuntCompensatorBuilder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Etienne Homer <etienne.homer at rte-france.com>
*/
public class ShuntCompensatorImpl extends AbstractRegulatingEquipment<ShuntCompensator, ShuntCompensatorAttributes> implements ShuntCompensator {
public class ShuntCompensatorImpl extends AbstractRegulatingInjection<ShuntCompensator, ShuntCompensatorAttributes> implements ShuntCompensator {

public ShuntCompensatorImpl(NetworkObjectIndex index, Resource<ShuntCompensatorAttributes> resource) {
super(index, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public StaticVarCompensator add() {
ValidationUtil.checkRegulatingTerminal(this, regulatingTerminal, getNetwork());

TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal);
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.STATIC_VAR_COMPENSATOR,
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.STATIC_VAR_COMPENSATOR, null,
new TerminalRefAttributes(getId(), null), terminalRefAttributes, String.valueOf(regulationMode), ResourceType.STATIC_VAR_COMPENSATOR);
Resource<StaticVarCompensatorAttributes> resource = Resource.staticVarCompensatorBuilder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Etienne Homer <etienne.homer at rte-france.com>
*/
public class StaticVarCompensatorImpl extends AbstractRegulatingEquipment<StaticVarCompensator, StaticVarCompensatorAttributes> implements StaticVarCompensator {
public class StaticVarCompensatorImpl extends AbstractRegulatingInjection<StaticVarCompensator, StaticVarCompensatorAttributes> implements StaticVarCompensator {

public StaticVarCompensatorImpl(NetworkObjectIndex index, Resource<StaticVarCompensatorAttributes> resource) {
super(index, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ protected void resetRegulationMode(Terminal regulatingTerminal, Terminal localTe
// 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 PHASE_TAP_CHANGER ->
switch (getAttributes().getRegulatingResourceSubType()) {
// 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 -> {
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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,23 +591,27 @@ public ThreeSides getSide() {

public void setAsRegulatingPoint(AbstractRegulatingPoint regulatingPoint) {
getAttributes().getRegulatingEquipments()
.add(new RegulatingEquipmentIdentifier(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType()));
.add(new RegulatingEquipmentIdentifier(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType(),
regulatingPoint.getRegulatingResourceSubType()));
}

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

public void removeAsRegulatingPoint() {
getAttributes().getRegulatingEquipments().forEach(regulatingEquipmentIdentifier -> {
Identifiable<?> identifiable = index.getIdentifiable(regulatingEquipmentIdentifier.getEquipmentId());
if (identifiable instanceof AbstractRegulatingEquipment<?, ?> regulatingEquipment) {
if (identifiable instanceof AbstractRegulatingInjection<?, ?> regulatingEquipment) {
regulatingEquipment.getRegulatingPoint().removeRegulation();
} else if (identifiable instanceof TapChangerParent tapChangerParent) {
AbstractTapChanger abstractTapChanger;
if (regulatingEquipmentIdentifier.getResourceType() == ResourceType.RATIO_TAP_CHANGER) {
if (regulatingEquipmentIdentifier.getRegulatingTapChangerType() == RegulatingTapChangerType.RATIO_TAP_CHANGER ||
regulatingEquipmentIdentifier.getRegulatingTapChangerType() == RegulatingTapChangerType.RATIO_TAP_CHANGER_SIDE_ONE ||
regulatingEquipmentIdentifier.getRegulatingTapChangerType() == RegulatingTapChangerType.RATIO_TAP_CHANGER_SIDE_TWO ||
regulatingEquipmentIdentifier.getRegulatingTapChangerType() == RegulatingTapChangerType.RATIO_TAP_CHANGER_SIDE_THREE) {
abstractTapChanger = (RatioTapChangerImpl) tapChangerParent.getRatioTapChanger();
} else {
abstractTapChanger = (PhaseTapChangerImpl) tapChangerParent.getPhaseTapChanger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public VscConverterStation add() {

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

Resource<VscConverterStationAttributes> resource = Resource.vscConverterStationBuilder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Etienne Homer <etienne.homer at rte-france.com>
*/
public class VscConverterStationImpl extends AbstractRegulatingEquipment<VscConverterStation, VscConverterStationAttributes> implements VscConverterStation, ReactiveLimitsOwner {
public class VscConverterStationImpl extends AbstractRegulatingInjection<VscConverterStation, VscConverterStationAttributes> implements VscConverterStation, ReactiveLimitsOwner {

public VscConverterStationImpl(NetworkObjectIndex index, Resource<VscConverterStationAttributes> resource) {
super(index, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@
*/
package com.powsybl.network.store.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@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;
}

public RegulatingEquipmentIdentifier() {

this.regulatingTapChangerType = null;
}
}
Loading

0 comments on commit a7c9927

Please sign in to comment.