Skip to content

Commit

Permalink
WIP: Replace the 3 OperationalLimits Current, ApparentPower and Activ…
Browse files Browse the repository at this point in the history
…ePower by a Group of OperationalLimits in a set of Group indexed by and Id and with a default Group which will act as the 3 OperationalLimits in a retro compatible way

Signed-off-by: Pauline Jean-Marie <pauline.jean-marie@artelys.com>
  • Loading branch information
Pauline Jean-Marie committed Dec 19, 2023
1 parent 3c391da commit 334ab50
Show file tree
Hide file tree
Showing 29 changed files with 894 additions and 258 deletions.
39 changes: 34 additions & 5 deletions iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
Expand Down Expand Up @@ -116,11 +117,15 @@ public interface Branch<I extends Branch<I>> extends Identifiable<I> {

TwoSides getSide(Terminal terminal);

default Collection<OperationalLimits> getOperationalLimits1() {
return getCurrentLimits1()
.map(l -> Collections.singletonList((OperationalLimits) l))
.orElseGet(Collections::emptyList);
}
List<OperationalLimitsGroup> getOperationalLimitsGroups1();

Optional<OperationalLimitsGroup> getOperationalLimitsGroup1(String id);

Optional<OperationalLimitsGroup> getDefaultOperationalLimitsGroup1();

OperationalLimitsGroup newOperationalLimitsGroup1(String id);

void setDefaultOperationalLimitsGroup1To(String id);

Optional<CurrentLimits> getCurrentLimits1();

Expand All @@ -140,6 +145,16 @@ default Collection<OperationalLimits> getOperationalLimits1() {

ApparentPowerLimitsAdder newApparentPowerLimits1();

List<OperationalLimitsGroup> getOperationalLimitsGroups2();

Optional<OperationalLimitsGroup> getOperationalLimitsGroup2(String id);

Optional<OperationalLimitsGroup> getDefaultOperationalLimitsGroup2();

OperationalLimitsGroup newOperationalLimitsGroup2(String id);

void setDefaultOperationalLimitsGroup2To(String id);

default Collection<OperationalLimits> getOperationalLimits2() {
return getCurrentLimits2()
.map(l -> Collections.singletonList((OperationalLimits) l))
Expand Down Expand Up @@ -256,6 +271,20 @@ default LoadingLimits getNullableLimits(LimitType type, TwoSides side) {
}
}

default List<OperationalLimitsGroup> getOperationalLimitsGroups(TwoSides side) {
return switch (side) {
case ONE -> this.getOperationalLimitsGroups1();
case TWO -> this.getOperationalLimitsGroups2();
};
}

default Optional<OperationalLimitsGroup> getDefaultOperationalLimitsGroup(TwoSides side) {
return switch (side) {
case ONE -> this.getDefaultOperationalLimitsGroup1();
case TWO -> this.getDefaultOperationalLimitsGroup2();
};
}

/**
* Only checks overloading for LimitType.Current and permanent limits
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
*/
package com.powsybl.iidm.network;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* @author Miora Ralambotiana {@literal <miora.ralambotiana at rte-france.com>}
*/
public interface FlowsLimitsHolder {

default Collection<OperationalLimits> getOperationalLimits() {
return getCurrentLimits()
.map(l -> Collections.singletonList((OperationalLimits) l))
.orElseGet(Collections::emptyList);
}
List<OperationalLimitsGroup> getOperationalLimitsGroups();

Optional<OperationalLimitsGroup> getOperationalLimitsGroup(String id);

Optional<OperationalLimitsGroup> getDefaultOperationalLimitsGroup();

OperationalLimitsGroup newOperationalLimitsGroup(String id);

void setDefaultOperationalLimitsGroupTo(String id);

Optional<CurrentLimits> getCurrentLimits();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
* @author Thibaut Vermeulen {@literal <thibaut.vermeulen at rte-france.com>}
*/
public interface OperationalLimits {

/**
* Get the operational limits' type (can be APPARENT_POWER, CURRENT or VOLTAGE)
*/
LimitType getLimitType();

default void remove() {
// do nothing
}
void remove();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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
*/

package com.powsybl.iidm.network;
import java.util.Optional;

public interface OperationalLimitsGroup {

String getId();

Optional<CurrentLimits> getCurrentLimits();

Optional<ActivePowerLimits> getActivePowerLimits();

Optional<ApparentPowerLimits> getApparentPowerLimits();

CurrentLimitsAdder newCurrentLimits();

ActivePowerLimitsAdder newActivePowerLimits();

ApparentPowerLimitsAdder newApparentPowerLimits();

void removeCurrentLimits();

void removeActivePowerLimits();

void removeApparentPowerLimits();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
import com.powsybl.iidm.network.impl.util.Ref;
import com.powsybl.iidm.network.util.LimitViolationUtils;

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

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
abstract class AbstractConnectableBranch<I extends Branch<I> & Connectable<I>> extends AbstractConnectable<I> implements Branch<I> {

protected final OperationalLimitsHolderImpl operationalLimitsHolder1;
protected final OperationalLimitsGroupsImpl operationalLimitsHolder1;

protected final OperationalLimitsHolderImpl operationalLimitsHolder2;
protected final OperationalLimitsGroupsImpl operationalLimitsHolder2;

AbstractConnectableBranch(Ref<NetworkImpl> network, String id, String name, boolean fictitious) {
super(network, id, name, fictitious);
operationalLimitsHolder1 = new OperationalLimitsHolderImpl(this, "limits1");
operationalLimitsHolder2 = new OperationalLimitsHolderImpl(this, "limits2");
operationalLimitsHolder1 = new OperationalLimitsGroupsImpl(this, "limits1");
operationalLimitsHolder2 = new OperationalLimitsGroupsImpl(this, "limits2");
}

@Override
Expand Down Expand Up @@ -53,18 +53,38 @@ public TwoSides getSide(Terminal terminal) {
}

@Override
public Collection<OperationalLimits> getOperationalLimits1() {
return operationalLimitsHolder1.getOperationalLimits();
public List<OperationalLimitsGroup> getOperationalLimitsGroups1() {
return operationalLimitsHolder1.getAllOperationalLimitsGroup();
}

@Override
public Optional<OperationalLimitsGroup> getOperationalLimitsGroup1(String id) {
return operationalLimitsHolder1.getOperationalLimitsGroup(id);
}

@Override
public Optional<OperationalLimitsGroup> getDefaultOperationalLimitsGroup1() {
return operationalLimitsHolder1.getDefaultOperationalLimitsGroup();
}

@Override
public OperationalLimitsGroup newOperationalLimitsGroup1(String id) {
return operationalLimitsHolder1.newOperationalLimitsGroup(id);
}

@Override
public void setDefaultOperationalLimitsGroup1To(String id) {
operationalLimitsHolder1.setDefaultTo(id);
}

@Override
public Optional<CurrentLimits> getCurrentLimits1() {
return operationalLimitsHolder1.getOperationalLimits(LimitType.CURRENT, CurrentLimits.class);
return getDefaultOperationalLimitsGroup1().flatMap(OperationalLimitsGroup::getCurrentLimits);
}

@Override
public CurrentLimits getNullableCurrentLimits1() {
return operationalLimitsHolder1.getNullableOperationalLimits(LimitType.CURRENT, CurrentLimits.class);
return getCurrentLimits1().orElse(null);
}

@Override
Expand All @@ -74,47 +94,67 @@ public CurrentLimitsAdder newCurrentLimits1() {

@Override
public Optional<ApparentPowerLimits> getApparentPowerLimits1() {
return operationalLimitsHolder1.getOperationalLimits(LimitType.APPARENT_POWER, ApparentPowerLimits.class);
return getDefaultOperationalLimitsGroup1().flatMap(OperationalLimitsGroup::getApparentPowerLimits);
}

@Override
public ApparentPowerLimits getNullableApparentPowerLimits1() {
return operationalLimitsHolder1.getNullableOperationalLimits(LimitType.APPARENT_POWER, ApparentPowerLimits.class);
return getApparentPowerLimits1().orElse(null);
}

@Override
public ApparentPowerLimitsAdder newApparentPowerLimits1() {
return operationalLimitsHolder1.newApparentPowerLimits();
}

@Override
public Collection<OperationalLimits> getOperationalLimits2() {
return operationalLimitsHolder2.getOperationalLimits();
}

@Override
public Optional<ActivePowerLimits> getActivePowerLimits1() {
return operationalLimitsHolder1.getOperationalLimits(LimitType.ACTIVE_POWER, ActivePowerLimits.class);
return getDefaultOperationalLimitsGroup1().flatMap(OperationalLimitsGroup::getActivePowerLimits);
}

@Override
public ActivePowerLimits getNullableActivePowerLimits1() {
return operationalLimitsHolder1.getNullableOperationalLimits(LimitType.ACTIVE_POWER, ActivePowerLimits.class);
return getActivePowerLimits1().orElse(null);
}

@Override
public ActivePowerLimitsAdder newActivePowerLimits1() {
return operationalLimitsHolder1.newActivePowerLimits();
}

@Override
public List<OperationalLimitsGroup> getOperationalLimitsGroups2() {
return operationalLimitsHolder2.getAllOperationalLimitsGroup();
}

@Override
public Optional<OperationalLimitsGroup> getOperationalLimitsGroup2(String id) {
return operationalLimitsHolder2.getOperationalLimitsGroup(id);
}

@Override
public Optional<OperationalLimitsGroup> getDefaultOperationalLimitsGroup2() {
return operationalLimitsHolder2.getDefaultOperationalLimitsGroup();
}

@Override
public OperationalLimitsGroup newOperationalLimitsGroup2(String id) {
return operationalLimitsHolder2.newOperationalLimitsGroup(id);
}

@Override
public void setDefaultOperationalLimitsGroup2To(String id) {
operationalLimitsHolder2.setDefaultTo(id);
}

@Override
public Optional<CurrentLimits> getCurrentLimits2() {
return operationalLimitsHolder2.getOperationalLimits(LimitType.CURRENT, CurrentLimits.class);
return getDefaultOperationalLimitsGroup2().flatMap(OperationalLimitsGroup::getCurrentLimits);
}

@Override
public CurrentLimits getNullableCurrentLimits2() {
return operationalLimitsHolder2.getNullableOperationalLimits(LimitType.CURRENT, CurrentLimits.class);
return getCurrentLimits2().orElse(null);
}

@Override
Expand All @@ -124,12 +164,12 @@ public CurrentLimitsAdder newCurrentLimits2() {

@Override
public Optional<ApparentPowerLimits> getApparentPowerLimits2() {
return operationalLimitsHolder2.getOperationalLimits(LimitType.APPARENT_POWER, ApparentPowerLimits.class);
return getDefaultOperationalLimitsGroup2().flatMap(OperationalLimitsGroup::getApparentPowerLimits);
}

@Override
public ApparentPowerLimits getNullableApparentPowerLimits2() {
return operationalLimitsHolder2.getNullableOperationalLimits(LimitType.APPARENT_POWER, ApparentPowerLimits.class);
return getApparentPowerLimits2().orElse(null);
}

@Override
Expand All @@ -139,12 +179,12 @@ public ApparentPowerLimitsAdder newApparentPowerLimits2() {

@Override
public Optional<ActivePowerLimits> getActivePowerLimits2() {
return operationalLimitsHolder2.getOperationalLimits(LimitType.ACTIVE_POWER, ActivePowerLimits.class);
return getDefaultOperationalLimitsGroup2().flatMap(OperationalLimitsGroup::getActivePowerLimits);
}

@Override
public ActivePowerLimits getNullableActivePowerLimits2() {
return operationalLimitsHolder2.getNullableOperationalLimits(LimitType.ACTIVE_POWER, ActivePowerLimits.class);
return getActivePowerLimits2().orElse(null);
}

@Override
Expand All @@ -167,11 +207,11 @@ public Optional<ApparentPowerLimits> getApparentPowerLimits(TwoSides side) {
return BranchUtil.getFromSide(side, this::getApparentPowerLimits1, this::getApparentPowerLimits2);
}

OperationalLimitsHolderImpl getLimitsHolder1() {
OperationalLimitsGroupsImpl getLimitsHolder1() {
return operationalLimitsHolder1;
}

OperationalLimitsHolderImpl getLimitsHolder2() {
OperationalLimitsGroupsImpl getLimitsHolder2() {
return operationalLimitsHolder2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
package com.powsybl.iidm.network.impl;

import com.powsybl.iidm.network.LoadingLimits;
import com.powsybl.iidm.network.ValidationUtil;
import com.powsybl.iidm.network.*;

import java.util.Collection;
import java.util.Objects;
Expand All @@ -17,9 +16,7 @@
* @author Miora Ralambotiana {@literal <miora.ralambotiana at rte-france.com>}
*/
abstract class AbstractLoadingLimits<L extends AbstractLoadingLimits<L>> extends AbstractOperationalLimits implements LoadingLimits {

private double permanentLimit;

private final TreeMap<Integer, TemporaryLimit> temporaryLimits;

static class TemporaryLimitImpl implements TemporaryLimit {
Expand Down Expand Up @@ -60,7 +57,7 @@ public boolean isFictitious() {
}
}

AbstractLoadingLimits(OperationalLimitsOwner owner, double permanentLimit, TreeMap<Integer, TemporaryLimit> temporaryLimits) {
AbstractLoadingLimits(OperationalLimitsGroupImpl owner, double permanentLimit, TreeMap<Integer, TemporaryLimit> temporaryLimits) {
super(owner);
this.permanentLimit = permanentLimit;
this.temporaryLimits = Objects.requireNonNull(temporaryLimits);
Expand All @@ -73,10 +70,10 @@ public double getPermanentLimit() {

@Override
public L setPermanentLimit(double permanentLimit) {
ValidationUtil.checkPermanentLimit(owner, permanentLimit);
ValidationUtil.checkPermanentLimit(group.getValidable(), permanentLimit);
double oldValue = this.permanentLimit;
this.permanentLimit = permanentLimit;
owner.notifyUpdate(getLimitType(), "permanentLimit", oldValue, this.permanentLimit);
group.notifyUpdateIfDefaultLimits(getLimitType(), "permanentLimit", oldValue, this.permanentLimit);
return (L) this;
}

Expand Down
Loading

0 comments on commit 334ab50

Please sign in to comment.