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

Fix secondary voltage control notifications #2859

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -12,6 +12,9 @@
*/
public interface ControlUnit {

record ParticipateEvent(String controlZoneName, String controlUnitId, boolean value) {
}

String getId();

boolean isParticipate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
public interface PilotPoint {

record TargetVoltageEvent(String controlZoneName, double value) {
}

/**
* Get pilot point busbar section ID or bus ID of the bus/breaker view.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.iidm.network.Network;

import java.util.List;
import java.util.Optional;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
Expand All @@ -21,6 +22,8 @@ public interface SecondaryVoltageControl extends Extension<Network> {

List<ControlZone> getControlZones();

Optional<ControlZone> getControlZone(String name);

@Override
default String getName() {
return NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void setParticipate(boolean participate) {
this.participate = participate;
SecondaryVoltageControlImpl secondaryVoltageControl = controlZone.getSecondaryVoltageControl();
NetworkImpl network = (NetworkImpl) secondaryVoltageControl.getExtendable();
network.getListeners().notifyExtensionUpdate(secondaryVoltageControl, "controlUnitParticipate", !this.participate, this.participate);
network.getListeners().notifyExtensionUpdate(secondaryVoltageControl, "controlUnitParticipate",
new ParticipateEvent(controlZone.getName(), id, !this.participate), new ParticipateEvent(controlZone.getName(), id, this.participate));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void setTargetV(double targetV) {
this.targetV = targetV;
SecondaryVoltageControlImpl secondaryVoltageControl = controlZone.getSecondaryVoltageControl();
NetworkImpl network = (NetworkImpl) secondaryVoltageControl.getExtendable();
network.getListeners().notifyExtensionUpdate(secondaryVoltageControl, "pilotPointTargetV", oldTargetV, targetV);
network.getListeners().notifyExtensionUpdate(secondaryVoltageControl, "pilotPointTargetV",
new TargetVoltageEvent(controlZone.getName(), oldTargetV), new TargetVoltageEvent(controlZone.getName(), targetV));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
Expand All @@ -32,4 +33,10 @@ public class SecondaryVoltageControlImpl extends AbstractExtension<Network> impl
public List<ControlZone> getControlZones() {
return Collections.unmodifiableList(controlZones);
}

@Override
public Optional<ControlZone> getControlZone(String name) {
Objects.requireNonNull(name);
return controlZones.stream().filter(z -> z.getName().equals(name)).findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import com.powsybl.iidm.network.DefaultNetworkListener;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.extensions.ControlUnit;
import com.powsybl.iidm.network.extensions.ControlZone;
import com.powsybl.iidm.network.extensions.SecondaryVoltageControl;
import com.powsybl.iidm.network.extensions.SecondaryVoltageControlAdder;
import com.powsybl.iidm.network.extensions.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -57,6 +54,7 @@ public void setUp() {
@Test
void test() throws IOException {
assertEquals(1, control.getControlZones().size());
assertTrue(control.getControlZone("z1").isPresent());
ControlZone z1 = control.getControlZones().get(0);
assertEquals("z1", z1.getName());
assertNotNull(z1.getPilotPoint());
Expand All @@ -79,8 +77,8 @@ void pilotPointTargetVoltageNotificationTest() {
public void onExtensionUpdate(Extension<?> extendable, String attribute, Object oldValue, Object newValue) {
assertInstanceOf(SecondaryVoltageControl.class, extendable);
assertEquals("pilotPointTargetV", attribute);
assertEquals(15d, (double) oldValue, 0d);
assertEquals(16d, (double) newValue, 0d);
assertEquals(new PilotPoint.TargetVoltageEvent("z1", 15d), oldValue);
assertEquals(new PilotPoint.TargetVoltageEvent("z1", 16d), newValue);
updated[0] = true;
}
});
Expand All @@ -98,8 +96,8 @@ void controlUnitParticipateNotificationTest() {
public void onExtensionUpdate(Extension<?> extendable, String attribute, Object oldValue, Object newValue) {
assertInstanceOf(SecondaryVoltageControl.class, extendable);
assertEquals("controlUnitParticipate", attribute);
assertFalse((boolean) oldValue);
assertTrue((boolean) newValue);
assertEquals(new ControlUnit.ParticipateEvent("z1", "GEN", false), oldValue);
assertEquals(new ControlUnit.ParticipateEvent("z1", "GEN", true), newValue);
updated[0] = true;
}
});
Expand Down