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

Custom connection/disconnection of terminals #2754

Merged
merged 35 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ca699e0
new methods disconnect with Predicate<Switch> isSwitchOpenable parameter
rolnico Oct 23, 2023
3f37b2e
add condition
rolnico Oct 23, 2023
89bda0f
add static predicates
rolnico Oct 24, 2023
9cdfc52
changed default predicate in order not to get a breaking change
rolnico Oct 24, 2023
c0de505
add predicate to exclude load break switches
rolnico Oct 24, 2023
97ff059
modify stopping condition in path detection
rolnico Oct 25, 2023
5adc462
new class SwitchPredicates
rolnico Oct 27, 2023
4f62dd2
allow path filtering before sizing
rolnico Oct 27, 2023
84d377f
default predicate correction
rolnico Oct 30, 2023
fa87677
stop path on open switches during disconnect
rolnico Oct 31, 2023
7d16299
sort paths by size according to the given predicate then by actual size
rolnico Oct 31, 2023
d01adbb
update comment
rolnico Oct 31, 2023
b4ceb33
stop added when terminal is disconnected
rolnico Oct 31, 2023
d529823
add check on connect + comments
rolnico Oct 31, 2023
29d41f3
changed SwitchPredicates type to Predicate<Switch> + moved to iidm.ne…
rolnico Oct 31, 2023
7ca9573
create list of switch to open then open if all paths
rolnico Nov 2, 2023
62e639c
add isTypeSwitchToOperate parameter to connect method + coverage tests
rolnico Nov 2, 2023
4127413
add connect method with parameter in interface
rolnico Nov 2, 2023
cb65c8d
add test for coverage + typo
rolnico Nov 2, 2023
c56e25e
Merge branch 'main' into nro/custom_disconnection_of_connectables
rolnico Nov 2, 2023
e69dde7
add disconnection test cases + author mentions
rolnico Nov 3, 2023
c686e6a
author mentions
rolnico Nov 3, 2023
b1be0ff
add setup method in AbstractSwitchPredicatesTest + swap ComparisonCha…
rolnico Nov 6, 2023
dd4cd15
comment correction
rolnico Nov 6, 2023
3b3276a
comment correction
rolnico Nov 6, 2023
e6f401e
Added comment for checkNonClosableSwitches + renamed this method + si…
rolnico Nov 6, 2023
af91e07
typo in comment
rolnico Nov 7, 2023
560a480
Merge branch 'main' into nro/custom_disconnection_of_connectables
olperr1 Nov 7, 2023
63c1cf2
authors reinstated + blank lines deleted + changed parameter from fil…
rolnico Nov 8, 2023
9a05515
Merge remote-tracking branch 'origin/nro/custom_disconnection_of_conn…
rolnico Nov 8, 2023
9b96fb6
unused import
rolnico Nov 8, 2023
8e9d4af
unused import
rolnico Nov 8, 2023
e02a0b8
changed Function to Predicate to solve code smell
rolnico Nov 9, 2023
9bc9270
typos and improvements thanks to reviewer
rolnico Nov 9, 2023
bd651d3
Merge branch 'main' into nro/custom_disconnection_of_connectables
flo-dup Nov 9, 2023
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
42 changes: 28 additions & 14 deletions iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.math.graph.TraverseResult;

import java.util.Optional;
import java.util.function.Predicate;

/**
* An equipment connection point in a substation topology.
Expand Down Expand Up @@ -112,60 +113,73 @@ public static interface BusView {
Connectable getConnectable();

/**
* Get the active power in MW injected at the terminal.
* <p>
* Get the active power in MW injected at the terminal.<br/>
* Depends on the working variant.
* @see VariantManager
*/
double getP();

/**
* Set the active power in MW injected at the terminal.
* <p>
* Set the active power in MW injected at the terminal.<br/>
* Depends on the working variant.
* @see VariantManager
*/
Terminal setP(double p);

/**
* Get the reactive power in MVAR injected at the terminal.
* <p>
* Get the reactive power in MVAR injected at the terminal.<br/>
* Depends on the working variant.
* @see VariantManager
*/
double getQ();

/**
* Set the reactive power in MVAR injected at the terminal.
* <p>
* Set the reactive power in MVAR injected at the terminal.<br/>
* Depends on the working variant.
* @see VariantManager
*/
Terminal setQ(double q);

/**
* Get the current in A at the terminal.
* <p>Depends on the working variant.
* Get the current in A at the terminal.<br/>
* Depends on the working variant.
* @see VariantManager
*/
double getI();

/**
* Try to connect the terminal.
* <p>Depends on the working variant.
* Try to connect the terminal.<br/>
* Depends on the working variant.
* @return true if terminal has been connected, false otherwise
* @see VariantManager
*/
boolean connect();

/**
* Disconnect the terminal.
* <p>Depends on the working variant.
* Try to connect the terminal.<br/>
* Depends on the working variant.
* @return true if terminal has been connected, false otherwise
* @see VariantManager
*/
boolean connect(Predicate<Switch> isTypeSwitchToOperate);

/**
* Disconnect the terminal.<br/>
* Depends on the working variant.
* @return true if terminal has been disconnected, false otherwise
* @see VariantManager
*/
boolean disconnect();

/**
* Disconnect the terminal.<br/>
* Depends on the working variant.
* @param isSwitchOpenable function telling if a switch is openable according to conditions
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
* @return true if terminal has been disconnected, false otherwise
* @see VariantManager
*/
boolean disconnect(Predicate<Switch> isSwitchOpenable);

/**
* Test if the terminal is connected.
* @return true if the terminal is connected, false otherwise
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023. , 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
*/

flo-dup marked this conversation as resolved.
Show resolved Hide resolved
package com.powsybl.iidm.network.util;

import com.powsybl.iidm.network.Switch;
import com.powsybl.iidm.network.SwitchKind;

import java.util.Objects;
import java.util.function.Predicate;

/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
*/
public final class SwitchPredicates {

private SwitchPredicates() { }

public static final Predicate<Switch> IS_NONFICTIONAL_CLOSED_BREAKER = switchObject -> switchObject != null && switchObject.getKind() == SwitchKind.BREAKER && !switchObject.isOpen() && !switchObject.isFictitious();
public static final Predicate<Switch> IS_NONFICTIONAL_BREAKER = switchObject -> switchObject != null && switchObject.getKind() == SwitchKind.BREAKER && !switchObject.isFictitious();
public static final Predicate<Switch> IS_CLOSED_BREAKER = switchObject -> switchObject != null && switchObject.getKind() == SwitchKind.BREAKER && !switchObject.isOpen();
public static final Predicate<Switch> IS_BREAKER_OR_DISCONNECTOR = switchObject -> switchObject != null && (switchObject.getKind() == SwitchKind.BREAKER || switchObject.getKind() == SwitchKind.DISCONNECTOR);
public static final Predicate<Switch> IS_OPEN_DISCONNECTOR = switchObject -> switchObject != null && switchObject.getKind() == SwitchKind.DISCONNECTOR && switchObject.isOpen();
public static final Predicate<Switch> IS_OPEN = switchObject -> switchObject != null && switchObject.isOpen();
public static final Predicate<Switch> IS_NON_NULL = Objects::nonNull;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
package com.powsybl.iidm.network.impl;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.ValidationException;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.impl.util.Ref;
import com.powsybl.iidm.network.util.SwitchPredicates;
import gnu.trove.list.array.TDoubleArrayList;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
*
Expand Down Expand Up @@ -158,18 +158,44 @@ public double getI() {

@Override
public boolean connect() {
return connect(SwitchPredicates.IS_NONFICTIONAL_BREAKER);
}


flo-dup marked this conversation as resolved.
Show resolved Hide resolved
/**
* Try to connect the terminal.<br/>
* Depends on the working variant.
* @param isTypeSwitchToOperate Predicate telling if a switch is operable according to conditions. Examples of predicates are available in the class {@link SwitchPredicates}
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
* @return true if terminal has been connected, false otherwise
* @see VariantManager
*/
@Override
public boolean connect(Predicate<Switch> isTypeSwitchToOperate) {
if (removed) {
throw new PowsyblException(UNMODIFIABLE_REMOVED_EQUIPMENT + connectable.id);
}
return voltageLevel.connect(this);
return voltageLevel.connect(this, isTypeSwitchToOperate);
}

@Override
public boolean disconnect() {
return disconnect(SwitchPredicates.IS_CLOSED_BREAKER);
}


flo-dup marked this conversation as resolved.
Show resolved Hide resolved
/**
* Disconnect the terminal.<br/>
* Depends on the working variant.
* @param isSwitchOpenable Predicate telling if a switch is openable according to conditions. Examples of predicates are available in the class {@link SwitchPredicates}
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
* @return true if terminal has been disconnected, false otherwise
* @see VariantManager
*/
@Override
public boolean disconnect(Predicate<Switch> isSwitchOpenable) {
if (removed) {
throw new PowsyblException(UNMODIFIABLE_REMOVED_EQUIPMENT + connectable.id);
}
return voltageLevel.disconnect(this);
return voltageLevel.disconnect(this, isSwitchOpenable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.security.SecureRandom;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -926,6 +927,11 @@ public boolean connect(TerminalExt terminal) {
return true;
}

@Override
public boolean connect(TerminalExt terminal, Predicate<? super SwitchImpl> isTypeSwitchToOperate) {
return connect(terminal);
}

@Override
public boolean disconnect(TerminalExt terminal) {
if (!(terminal instanceof BusTerminal)) {
Expand All @@ -942,7 +948,11 @@ public boolean disconnect(TerminalExt terminal) {
invalidateCache();

return true;
}

@Override
public boolean disconnect(TerminalExt terminal, Predicate<? super SwitchImpl> isSwitchOpenable) {
return disconnect(terminal);
}

void traverse(BusTerminal terminal, Terminal.TopologyTraverser traverser, TraversalType traversalType) {
Expand Down
Loading