Skip to content

Commit

Permalink
Secondary voltage control notifications (#2852)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Jan 16, 2024
1 parent 9ffb6ab commit 15eec73
Show file tree
Hide file tree
Showing 28 changed files with 848 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ public <E extends Extension<T>> E getExtensionByName(String name) {
return (E) extensionsByName.get(name);
}

protected <E extends Extension<T>> void removeExtension(Class<E> type, E extension) {
extensions.remove(type);
extensionsByName.remove(extension.getName());
extension.setExtendable(null);
}

@Override
public <E extends Extension<T>> boolean removeExtension(Class<E> type) {
boolean removed = false;

E extension = getExtension(type);
if (extension != null) {
extensions.remove(type);
extensionsByName.remove(extension.getName());
extension.setExtendable(null);
removeExtension(type, extension);
removed = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public abstract class AbstractExtensionAdder<T extends Extendable<T>, E extends Extension<T>>
implements ExtensionAdder<T, E> {

private final T extendable;
protected final T extendable;

protected AbstractExtensionAdder(T extendable) {
this.extendable = Objects.requireNonNull(extendable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
*/
package com.powsybl.iidm.network;

import com.powsybl.commons.extensions.Extension;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public class DefaultNetworkListener implements NetworkListener {
@Override
public void onCreation(Identifiable identifiable) {
public void onCreation(Identifiable<?> identifiable) {
// empty default implementation
}

@Override
public void beforeRemoval(Identifiable identifiable) {
public void beforeRemoval(Identifiable<?> identifiable) {
// empty default implementation
}

Expand All @@ -26,7 +28,32 @@ public void afterRemoval(String identifiable) {
}

@Override
public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
public void onUpdate(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue) {
// empty default implementation
}

@Override
public void onUpdate(Identifiable<?> identifiable, String attribute, String variantId, Object oldValue, Object newValue) {
// empty default implementation
}

@Override
public void onExtensionCreation(Extension<?> extension) {
// empty default implementation
}

@Override
public void onExtensionUpdate(Extension<?> extension, String attribute, Object oldValue, Object newValue) {
// empty default implementation
}

@Override
public void onExtensionBeforeRemoval(Extension<?> extension) {
// empty default implementation
}

@Override
public void onExtensionAfterRemoval(Identifiable<?> identifiable, String extensionName) {
// empty default implementation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,40 @@
*/
package com.powsybl.iidm.network;

import com.powsybl.commons.extensions.Extension;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface NetworkListener {

void onCreation(Identifiable identifiable);
void onCreation(Identifiable<?> identifiable);

void beforeRemoval(Identifiable identifiable);
void beforeRemoval(Identifiable<?> identifiable);

void afterRemoval(String id);

void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue);
void onUpdate(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue);

default void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue,
Object newValue) {
// empty default implementation
}
void onUpdate(Identifiable<?> identifiable, String attribute, String variantId, Object oldValue, Object newValue);

void onExtensionCreation(Extension<?> extension);

void onExtensionAfterRemoval(Identifiable<?> identifiable, String extensionName);

void onExtensionBeforeRemoval(Extension<?> extension);

void onExtensionUpdate(Extension<?> extendable, String attribute, Object oldValue, Object newValue);

default void onElementAdded(Identifiable identifiable, String attribute, Object newValue) {
default void onElementAdded(Identifiable<?> identifiable, String attribute, Object newValue) {
// empty default implementation
}

default void onElementReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
default void onElementReplaced(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue) {
// empty default implementation
}

default void onElementRemoved(Identifiable identifiable, String attribute, Object oldValue) {
default void onElementRemoved(Identifiable<?> identifiable, String attribute, Object oldValue) {
// empty default implementation
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.extensions;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface ControlUnit {

String getId();

boolean isParticipate();

void setParticipate(boolean participate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.extensions;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface ControlUnitAdder {

ControlUnitAdder withId(String id);

ControlUnitAdder withParticipate(boolean participate);

ControlZoneAdder add();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.extensions;

import java.util.List;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface ControlZone {

String getName();

PilotPoint getPilotPoint();

List<ControlUnit> getControlUnits();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.extensions;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface ControlZoneAdder {

ControlZoneAdder withName(String name);

PilotPointAdder newPilotPoint();

ControlUnitAdder newControlUnit();

SecondaryVoltageControlAdder add();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.extensions;

import java.util.List;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface PilotPoint {

/**
* Get pilot point busbar section ID or bus ID of the bus/breaker view.
*/
List<String> getBusbarSectionsOrBusesIds();

double getTargetV();

void setTargetV(double targetV);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.extensions;

import java.util.List;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
public interface PilotPointAdder {

PilotPointAdder withBusbarSectionsOrBusesIds(List<String> busbarSectionsOrBusesIds);

PilotPointAdder withTargetV(double targetV);

ControlZoneAdder add();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
*/
package com.powsybl.iidm.network.extensions;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.extensions.Extension;
import com.powsybl.iidm.network.Network;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

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

String NAME = "secondaryVoltageControl";

class PilotPoint {

private final List<String> busbarSectionsOrBusesIds = new ArrayList<>();

private double targetV;

public PilotPoint(List<String> busbarSectionsOrBusesIds, double targetV) {
Objects.requireNonNull(busbarSectionsOrBusesIds).forEach(Objects::requireNonNull);
if (busbarSectionsOrBusesIds.isEmpty()) {
throw new PowsyblException("Empty busbar section of bus ID list");
}
this.busbarSectionsOrBusesIds.addAll(busbarSectionsOrBusesIds);
if (Double.isNaN(targetV)) {
throw new PowsyblException("Invalid target voltage");
}
this.targetV = targetV;
}

/**
* Get pilot point busbar section ID or bus ID of the bus/breaker view.
*/
public List<String> getBusbarSectionsOrBusesIds() {
return Collections.unmodifiableList(busbarSectionsOrBusesIds);
}

public double getTargetV() {
return targetV;
}

public void setTargetV(double targetV) {
this.targetV = targetV;
}
}

class ControlUnit {

private final String id;

private boolean participate;

public ControlUnit(String id) {
this(id, true);
}

public ControlUnit(String id, boolean participate) {
this.id = Objects.requireNonNull(id);
this.participate = participate;
}

public String getId() {
return id;
}

public boolean isParticipate() {
return participate;
}

public void setParticipate(boolean participate) {
this.participate = participate;
}
}

class ControlZone {

private final String name;

private final PilotPoint pilotPoint;

private final List<ControlUnit> controlUnits = new ArrayList<>();

public ControlZone(String name, PilotPoint pilotPoint, List<ControlUnit> controlUnits) {
this.name = Objects.requireNonNull(name);
this.pilotPoint = Objects.requireNonNull(pilotPoint);
Objects.requireNonNull(controlUnits).forEach(Objects::requireNonNull);
if (controlUnits.isEmpty()) {
throw new PowsyblException("Empty control unit list");
}
this.controlUnits.addAll(controlUnits);
}

public String getName() {
return name;
}

public PilotPoint getPilotPoint() {
return pilotPoint;
}

public List<ControlUnit> getControlUnits() {
return Collections.unmodifiableList(controlUnits);
}
}

List<ControlZone> getControlZones();

@Override
Expand Down
Loading

0 comments on commit 15eec73

Please sign in to comment.