Skip to content

Commit

Permalink
fix all
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Oct 18, 2024
1 parent 1fb4e77 commit 51ff55e
Show file tree
Hide file tree
Showing 22 changed files with 219 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void setRegTerminal(Terminal regulatingTerminal) {
if (regulatingTerminal instanceof TerminalImpl<?>) {
regulatingPoint.setRegulatingTerminal((TerminalImpl<?>) regulatingTerminal);
} else {
regulatingPoint.setRegulatingTerminalAsLocalTerminal();
regulatingPoint.setRegulatingTerminalAsLocalTerminalAndRemoveRegulation();
}
}

Expand Down Expand Up @@ -107,4 +107,8 @@ public <E extends Extension<I>> Collection<E> getExtensions() {
public List<Terminal> getTerminals(ThreeSides side) {
return (side == null || side.equals(ThreeSides.ONE)) ? Collections.singletonList(terminal) : Collections.emptyList();
}

public RegulatingPoint getRegulatingPoint() {
return regulatingPoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +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 java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -18,7 +21,7 @@
public class BranchToInjectionAttributesAdapter extends AbstractIdentifiableToInjectionAttributesAdapter<BranchAttributes> {

private final AbstractBranchImpl<? extends Branch<?>, ? extends BranchAttributes> branch;

private Map<String, ResourceType> regulatingEquipments = new HashMap<>();
private final boolean side1;

public BranchToInjectionAttributesAdapter(AbstractBranchImpl<? extends Branch<?>, ? extends BranchAttributes> branch, BranchAttributes attributes, boolean side1) {
Expand Down Expand Up @@ -132,4 +135,14 @@ public void setPosition(ConnectablePositionAttributes position) {
attributes.setPosition2(position);
}
}

@Override
public Map<String, ResourceType> getRegulatingEquipments() {
return regulatingEquipments;
}

@Override
public void setRegulatingEquipments(Map<String, ResourceType> regulatingEquipments) {
this.regulatingEquipments = regulatingEquipments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

import com.powsybl.network.store.model.BusbarSectionAttributes;
import com.powsybl.network.store.model.ConnectablePositionAttributes;
import com.powsybl.network.store.model.ResourceType;

import java.util.HashMap;
import java.util.Map;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class BusbarSectionToInjectionAdapter extends AbstractIdentifiableToInjectionAttributesAdapter<BusbarSectionAttributes> {

private Map<String, ResourceType> regulatingEquipments = new HashMap<>();

public BusbarSectionToInjectionAdapter(BusbarSectionAttributes attributes) {
super(attributes);
}
Expand Down Expand Up @@ -87,4 +93,14 @@ public ConnectablePositionAttributes getPosition() {
public void setPosition(ConnectablePositionAttributes position) {
throw new AssertionError();
}

@Override
public Map<String, ResourceType> getRegulatingEquipments() {
return regulatingEquipments;
}

@Override
public void setRegulatingEquipments(Map<String, ResourceType> regulatingEquipments) {
this.regulatingEquipments = regulatingEquipments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,41 @@ public Identifiable<?> getIdentifiable(String id) {
return null;
}

public AbstractInjectionImpl getRegulatingEquipment(String id, ResourceType resourceType) {
return switch (resourceType) {
case STATIC_VAR_COMPENSATOR -> getStaticVarCompensator(id).orElse(null);
case GENERATOR -> getGenerator(id).orElse(null);
case VSC_CONVERTER_STATION -> getVscConverterStation(id).orElse(null);
case SHUNT_COMPENSATOR -> getShuntCompensator(id).orElse(null);
default -> throw new PowsyblException(String.format("equipement : %s of type %s does not regulate", id, resourceType));
};
}

public AbstractIdentifiableImpl getIdentifiable(String id, ResourceType resourceType) {
return switch (resourceType) {
case LOAD -> getLoad(id).orElse(null);
case STATIC_VAR_COMPENSATOR -> getStaticVarCompensator(id).orElse(null);
case LINE -> getLine(id).orElse(null);
case BATTERY -> getBattery(id).orElse(null);
case GENERATOR -> getGenerator(id).orElse(null);
case BUSBAR_SECTION -> getBusbarSection(id).orElse(null);
case TWO_WINDINGS_TRANSFORMER -> getTwoWindingsTransformer(id).orElse(null);
case THREE_WINDINGS_TRANSFORMER -> getThreeWindingsTransformer(id).orElse(null);
case VSC_CONVERTER_STATION -> getVscConverterStation(id).orElse(null);
case SHUNT_COMPENSATOR -> getShuntCompensator(id).orElse(null);
case VOLTAGE_LEVEL -> getVoltageLevel(id).orElse(null);
case DANGLING_LINE -> getDanglingLine(id).orElse(null);
case SUBSTATION -> getSubstation(id).orElse(null);
case LCC_CONVERTER_STATION -> getLccConverterStation(id).orElse(null);
case SWITCH -> getSwitch(id).orElse(null);
case HVDC_LINE -> getHvdcLine(id).orElse(null);
case GROUND -> getGround(id).orElse(null);
case CONFIGURED_BUS -> getConfiguredBus(id).orElse(null);
case TIE_LINE -> getTieLine(id).orElse(null);
case NETWORK -> throw new PowsyblException("the identifiable asked can not be the network");
};
}

public void removeDanglingLine(String danglingLineId) {
danglingLineCache.remove(danglingLineId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,27 @@ public Terminal getRegulatingTerminal() {
}

public void setRegulatingTerminal(TerminalImpl<?> regulatingTerminal) {
TerminalImpl<?> oldRegulatingTerminal = (TerminalImpl<?>) TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal());
oldRegulatingTerminal.removeRegulatingPoint(this);
TerminalImpl<?> oldRegulatingTerminal = (TerminalImpl<?>) TerminalRefUtils.getTerminal(index,
getAttributes().getRegulatingTerminal(), getAttributes().getRegulatingResourceType());
if (oldRegulatingTerminal != null) {
oldRegulatingTerminal.removeRegulatingPoint(this);
}
regulatingTerminal.addNewRegulatingPoint(this);
identifiable.updateResource(res -> getAttributes((Resource<?>) res)
.setRegulatingTerminal(TerminalRefUtils.getTerminalRefAttributes(regulatingTerminal)));
identifiable.updateResource(res -> getAttributes((Resource<?>) res)
.setRegulatingResourceType(ResourceType.convert(regulatingTerminal.getConnectable().getType())));
}

public void setRegulatingTerminalAsLocalTerminalAndRemoveRegulation() {
TerminalImpl<?> oldRegulatingTerminal = (TerminalImpl<?>) TerminalRefUtils.getTerminal(index,
getAttributes().getRegulatingTerminal(), getAttributes().getRegulatingResourceType());
if (oldRegulatingTerminal != null) {
oldRegulatingTerminal.removeRegulatingPoint(this);
}
setRegulatingTerminalAsLocalTerminal();
}

public void setRegulatingTerminalAsLocalTerminal() {
identifiable.updateResource(res -> getAttributes((Resource<?>) res).setRegulatingTerminal(getAttributes().getLocalTerminal()));
identifiable.updateResource(res -> getAttributes((Resource<?>) res).setRegulatingResourceType(getAttributes().getResourceType()));
Expand All @@ -63,8 +75,11 @@ public void setRegulationMode(String regulationModeOrdinal) {
}

public void removeRegulation() {
Terminal localTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getLocalTerminal());
Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal());
TerminalImpl localTerminal = (TerminalImpl) TerminalRefUtils.getTerminal(index,
getAttributes().getLocalTerminal(), getAttributes().getResourceType());
Terminal regulatingTerminal = TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal(),
getAttributes().getRegulatingResourceType());
// set local terminal as regulating terminal
setRegulatingTerminalAsLocalTerminal();
// if localTerminal or regulatingTerminal is not connected then the bus is null
if (localTerminal.isConnected() && regulatingTerminal.isConnected() && !localTerminal.getBusView().getBus().equals(regulatingTerminal.getBusView().getBus())) {
Expand All @@ -82,4 +97,12 @@ void remove() {
TerminalImpl<?> regulatingTerminal = (TerminalImpl<?>) TerminalRefUtils.getTerminal(index, getAttributes().getRegulatingTerminal());
regulatingTerminal.removeRegulatingPoint(this);
}

public String getRegulatingEquipmentId() {
return getAttributes().getRegulatedEquipmentId();
}

public ResourceType getRegulatingEquipmentType() {
return getAttributes().getResourceType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,13 @@ public class TerminalImpl<U extends IdentifiableAttributes> implements Terminal,

private final TerminalBusViewImpl<U> busView;

private final List<RegulatingPoint> regulated = new ArrayList<>();

public TerminalImpl(NetworkObjectIndex index, Connectable<?> connectable, Function<Resource<U>, InjectionAttributes> attributesGetter) {
this.index = index;
this.connectable = connectable;
this.attributesGetter = attributesGetter;
nodeBreakerView = new TerminalNodeBreakerViewImpl<>(index, connectable, attributesGetter);
busBreakerView = new TerminalBusBreakerViewImpl<>(index, connectable, attributesGetter);
busView = new TerminalBusViewImpl<>(index, connectable, attributesGetter);
setRegulated();
}

private void setRegulated() {
if (getAttributes().getRegulatingEquipments() != null) {
getAttributes().getRegulatingEquipments()
.forEach(regulatingEquipment -> {
// get identifiable create stack overflow error
regulated.add(new RegulatingPoint(index, (AbstractIdentifiableImpl) index.getIdentifiable(regulatingEquipment),
AbstractIdentifiableAttributes.class::cast));
});
}
}

private TopologyKind getTopologyKind() {
Expand Down Expand Up @@ -587,15 +573,19 @@ public ThreeSides getSide() {
}

public void addNewRegulatingPoint(RegulatingPoint regulatingPoint) {
regulated.add(regulatingPoint);
getAttributes().getRegulatingEquipments()
.put(regulatingPoint.getRegulatingEquipmentId(), regulatingPoint.getRegulatingEquipmentType());
}

public void removeRegulatingPoint(RegulatingPoint regulatingPoint) {
regulated.remove(regulatingPoint);
getAttributes().getRegulatingEquipments()
.remove(regulatingPoint.getRegulatingEquipmentId());
}

public void removeAsRegulatingPoint() {
regulated.forEach(RegulatingPoint::removeRegulation);
regulated.clear();
getAttributes().getRegulatingEquipments().forEach((regulatingEquipmentId, resourceType) ->
index.getRegulatingEquipment(regulatingEquipmentId, resourceType)
.getRegulatingPoint().removeRegulation());
getAttributes().getRegulatingEquipments().clear();
}
}
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.iidm.network.*;
import com.powsybl.network.store.model.ResourceType;
import com.powsybl.network.store.model.TerminalRefAttributes;

/**
Expand All @@ -18,18 +19,30 @@ private TerminalRefUtils() {
}

public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttributes terminalRefAttributes) {
return getTerminal(index, terminalRefAttributes, null);
}

public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttributes terminalRefAttributes, ResourceType resourceType) {
if (terminalRefAttributes == null) {
return null;
}
Identifiable<?> identifiable = index.getIdentifiable(terminalRefAttributes.getConnectableId());
Identifiable<?> identifiable;
if (resourceType == null) {
identifiable = index.getIdentifiable(terminalRefAttributes.getConnectableId());
} else {
identifiable = index.getIdentifiable(terminalRefAttributes.getConnectableId(), resourceType);
}
if (identifiable == null) {
return null;
}

String side = terminalRefAttributes.getSide();

if (identifiable instanceof Injection) {
return ((Injection<?>) identifiable).getTerminal();
} else if (identifiable instanceof Branch) {
return ((Branch<?>) identifiable).getTerminal(TwoSides.valueOf(side));
} else if (identifiable instanceof ThreeWindingsTransformer) {
ThreeWindingsTransformer twt = (ThreeWindingsTransformer) identifiable;
if (identifiable instanceof Injection<?> injection) {
return injection.getTerminal();
} else if (identifiable instanceof Branch<?> branch) {
return branch.getTerminal(TwoSides.valueOf(side));
} else if (identifiable instanceof ThreeWindingsTransformer twt) {
return twt.getTerminal(ThreeSides.valueOf(side));
} else {
throw new AssertionError("Unexpected Identifiable instance: " + identifiable.getClass());
Expand All @@ -39,11 +52,9 @@ public static Terminal getTerminal(NetworkObjectIndex index, TerminalRefAttribut
private static String getSide(Terminal terminal) {
String side = null;
if (terminal.getConnectable().getTerminals().size() > 1) {
if (terminal.getConnectable() instanceof Branch) {
Branch<?> branch = (Branch<?>) terminal.getConnectable();
if (terminal.getConnectable() instanceof Branch<?> branch) {
side = branch.getSide(terminal).name();
} else if (terminal.getConnectable() instanceof ThreeWindingsTransformer) {
ThreeWindingsTransformer twt = (ThreeWindingsTransformer) terminal.getConnectable();
} else if (terminal.getConnectable() instanceof ThreeWindingsTransformer twt) {
side = twt.getSide(terminal).name();
} else {
throw new AssertionError("Unexpected connectable instance: " + terminal.getConnectable().getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
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 java.util.HashMap;
import java.util.Map;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class ThreeWindingsTransformerToInjectionAttributesAdapter extends AbstractIdentifiableToInjectionAttributesAdapter<ThreeWindingsTransformerAttributes> {

private final ThreeSides side;
private Map<String, ResourceType> regulatingEquipments = new HashMap<>();

public ThreeWindingsTransformerToInjectionAttributesAdapter(ThreeWindingsTransformerAttributes attributes, ThreeSides side) {
super(attributes);
Expand Down Expand Up @@ -131,4 +136,14 @@ public void setPosition(ConnectablePositionAttributes position) {
default -> throw createUnknownSideException();
}
}

@Override
public Map<String, ResourceType> getRegulatingEquipments() {
return regulatingEquipments;
}

@Override
public void setRegulatingEquipments(Map<String, ResourceType> regulatingEquipments) {
this.regulatingEquipments = regulatingEquipments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import lombok.experimental.SuperBuilder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -43,13 +42,10 @@ public abstract class AbstractIdentifiableAttributes extends AbstractAttributes
@Schema(description = "Alias by type")
private Map<String, String> aliasByType;

@Schema(description = "Extension attributes")
@Builder.Default
@Schema(description = "Extension attributes")
private Map<String, ExtensionAttributes> extensionAttributes = new HashMap<>();

@Schema(description = "regulation info")
private RegulationPointAttributes regulationPoint;

@Schema(description = "regulatingEquipments")
private List<String> regulatingEquipments;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.HashMap;
import java.util.Map;

/**
* @author Nicolas Noir <nicolas.noir at rte-france.com>
*/
Expand Down Expand Up @@ -58,4 +61,8 @@ public class BatteryAttributes extends AbstractIdentifiableAttributes implements

@Schema(description = "reactiveLimits")
private ReactiveLimitsAttributes reactiveLimits;

@Builder.Default
@Schema(description = "regulatingEquipments")
private Map<String, ResourceType> regulatingEquipments = new HashMap<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public class DanglingLineAttributes extends AbstractIdentifiableAttributes imple
@Schema(description = "Tie line ID in case of a paired dangling line")
private String tieLineId;

@Builder.Default
@Schema(description = "regulatingEquipments")
private Map<String, ResourceType> regulatingEquipments = new HashMap<>();

@Override
@JsonIgnore
public List<Integer> getSideList() {
Expand Down
Loading

0 comments on commit 51ff55e

Please sign in to comment.