Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add regulating point for transformers #479

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@
*/
@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 RegulatingPoint<I, D> regulatingPoint;
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 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <etienne.lesot at rte-france.com>
*/
public abstract class AbstractRegulatingPoint {

protected final NetworkObjectIndex index;
protected final Function<Attributes, AbstractRegulatingEquipmentAttributes> attributesGetter;

protected AbstractRegulatingPoint(NetworkObjectIndex index, Function<Attributes, AbstractRegulatingEquipmentAttributes> 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 <I extends Identifiable<I>, D extends IdentifiableAttributes> AbstractIdentifiableImpl<I, D> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,18 +21,21 @@
/**
* @author Nicolas Noir <nicolas.noir at rte-france.com>
*/
abstract class AbstractTapChanger<H extends TapChangerParent, C extends AbstractTapChanger<H, C, A>, A extends TapChangerAttributes> {
abstract class AbstractTapChanger<H extends TapChangerParent, C extends AbstractTapChanger<H, C, A>, 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() {
Expand Down Expand Up @@ -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) {
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
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() {
antoinebhs marked this conversation as resolved.
Show resolved Hide resolved
return regulatingPoint.getRegulatingTerminal();
}

public double getTargetDeadband() {
return getAttributes().getTargetDeadband();
}
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 All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -136,12 +136,12 @@ public void setPosition(ConnectablePositionAttributes position) {
}

@Override
public Map<String, ResourceType> getRegulatingEquipments() {
public Set<RegulatingEquipmentIdentifier> getRegulatingEquipments() {
return attributes.getRegulatingEquipments();
}

@Override
public void setRegulatingEquipments(Map<String, ResourceType> regulatingEquipments) {
public void setRegulatingEquipments(Set<RegulatingEquipmentIdentifier> regulatingEquipments) {
attributes.setRegulatingEquipments(regulatingEquipments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -92,12 +92,12 @@ public void setPosition(ConnectablePositionAttributes position) {
}

@Override
public Map<String, ResourceType> getRegulatingEquipments() {
public Set<RegulatingEquipmentIdentifier> getRegulatingEquipments() {
return attributes.getRegulatingEquipments();
}

@Override
public void setRegulatingEquipments(Map<String, ResourceType> regulatingEquipments) {
public void setRegulatingEquipments(Set<RegulatingEquipmentIdentifier> regulatingEquipments) {
attributes.setRegulatingEquipments(regulatingEquipments);
}
}
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,
RegulatingPointAttributes regulatingPointAttributes = new RegulatingPointAttributes(getId(), ResourceType.GENERATOR, RegulatingTapChangerType.NONE,
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 @@ -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 Expand Up @@ -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());
Expand Down
Loading
Loading