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

Create setters for temporary limits #3113

Merged
merged 17 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -44,6 +44,8 @@ interface TemporaryLimit {
* @return false if it is a real limit, false otherwise
*/
boolean isFictitious();

void setValue(double temporaryLimitValue);
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -80,4 +82,12 @@ interface TemporaryLimit {
* @return the temporary limit value or NaN if there is no temporary limit for this acceptable duration
*/
double getTemporaryLimitValue(int acceptableDuration);

/**
* Set the temporary limit value
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
* @param acceptableDuration the acceptable duration
* @param temporaryLimitValue the temporary limit value
* @return itself for method chaining
*/
LoadingLimits setTemporaryLimitValue(int acceptableDuration, double temporaryLimitValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@

import com.powsybl.iidm.network.LoadingLimits;
import com.powsybl.iidm.network.ValidationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Objects;
import java.util.TreeMap;
import java.util.*;

/**
* @author Miora Ralambotiana {@literal <miora.ralambotiana at rte-france.com>}
*/
abstract class AbstractLoadingLimits<L extends AbstractLoadingLimits<L>> implements LoadingLimits {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractLoadingLimits.class);
protected final OperationalLimitsGroupImpl group;
private double permanentLimit;
private final TreeMap<Integer, TemporaryLimit> temporaryLimits;
Expand All @@ -27,7 +28,7 @@ static class TemporaryLimitImpl implements TemporaryLimit {

private final String name;

private final double value;
private double value;

private final int acceptableDuration;

Expand Down Expand Up @@ -59,6 +60,11 @@ public int getAcceptableDuration() {
public boolean isFictitious() {
return fictitious;
}

@Override
public void setValue(double temporaryLimitValue) {
this.value = temporaryLimitValue;
}
}

AbstractLoadingLimits(OperationalLimitsGroupImpl owner, double permanentLimit, TreeMap<Integer, TemporaryLimit> temporaryLimits) {
Expand All @@ -85,6 +91,66 @@ public L setPermanentLimit(double permanentLimit) {
return (L) this;
}

@Override
public L setTemporaryLimitValue(int acceptableDuration, double temporaryLimitValue) {
olperr1 marked this conversation as resolved.
Show resolved Hide resolved

// Checks
NetworkImpl network = group.getNetwork();
ValidationUtil.checkLoadingLimits(
group.getValidable(),
getPermanentLimit(),
getTemporaryLimits(),
network.getMinValidationLevel(),
network.getReportNodeContext().getReportNode()
);
olperr1 marked this conversation as resolved.
Show resolved Hide resolved

TreeMap<Integer, TemporaryLimit> temporaryLimitTreeMap = new TreeMap<>(this.temporaryLimits);
// Creation of index markers
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
Map.Entry<Integer, TemporaryLimit> lowerEntry = temporaryLimitTreeMap.lowerEntry(acceptableDuration);
Map.Entry<Integer, TemporaryLimit> higherEntry = temporaryLimitTreeMap.higherEntry(acceptableDuration);
olperr1 marked this conversation as resolved.
Show resolved Hide resolved

// Identify the limit that needs to be modified
TemporaryLimit identifiedLimit = getTemporaryLimit(acceptableDuration);
if (identifiedLimit == null) {
LOGGER.warn("No temporary limit found for the given acceptable duration");
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
return (L) this;
}

double oldValue = identifiedLimit.getValue();

if (isTemporaryLimitVaLueValid(lowerEntry, higherEntry, acceptableDuration, temporaryLimitValue)) {
identifiedLimit.setValue(temporaryLimitValue);
network.invalidateValidationLevel();
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
group.notifyTemporaryLimitValueUpdate(getLimitType(), oldValue, temporaryLimitValue);
LOGGER.info("Temporary limit value changed from {} to {}", oldValue, temporaryLimitValue);
} else {
LOGGER.warn("Temporary limit value couldn't be changed because it is not valid");
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
return (L) this;
}

return (L) this;
}

protected boolean isTemporaryLimitVaLueValid(Map.Entry<Integer, TemporaryLimit> lowerEntry,
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
Map.Entry<Integer, TemporaryLimit> higherEntry,
int acceptableDuration,
double temporaryLimitValue) {

if (lowerEntry != null && higherEntry != null) {
return lowerEntry.getValue().getAcceptableDuration() > acceptableDuration
&& higherEntry.getValue().getAcceptableDuration() < acceptableDuration
&& lowerEntry.getValue().getValue() < temporaryLimitValue
&& higherEntry.getValue().getValue() > temporaryLimitValue;
} else if (lowerEntry == null && higherEntry != null) {
return temporaryLimitValue > this.permanentLimit &&
higherEntry.getValue().getValue() > temporaryLimitValue;
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
} else if (lowerEntry != null && higherEntry == null) {
return lowerEntry.getValue().getAcceptableDuration() > acceptableDuration
&& lowerEntry.getValue().getValue() < temporaryLimitValue;
}
return temporaryLimitValue > this.permanentLimit;
}

@Override
public Collection<TemporaryLimit> getTemporaryLimits() {
return temporaryLimits.values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.LoggerFactory;

import java.util.*;

import static java.lang.Integer.MAX_VALUE;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ public ActivePowerLimits add() {
group.setActivePowerLimits(limits);
return limits;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ public ApparentPowerLimits add() {
group.setApparentPowerLimits(limits);
return limits;
}

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

import com.powsybl.iidm.network.ApparentPowerLimits;

import java.util.TreeMap;

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

import com.powsybl.iidm.network.CurrentLimits;

import java.util.TreeMap;

/**
Expand All @@ -25,4 +24,5 @@ public class CurrentLimitsImpl extends AbstractLoadingLimits<CurrentLimitsImpl>
public void remove() {
group.removeCurrentLimits();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ private void notifyUpdate(LimitType limitType, OperationalLimits oldValue, Opera
doNotify(attributeName + "_" + limitType, oldOperationalLimitsInfo, newOperationalLimitsInfo);
}

public void notifyTemporaryLimitValueUpdate(LimitType limitType, double oldValue, double newValue) {
TemporaryLimitInfo oldTemporaryLimitInfo = new TemporaryLimitInfo(oldValue, id, id.equals(selectedGroupId));
TemporaryLimitInfo newTemporaryLimitInfo = new TemporaryLimitInfo(newValue, id, id.equals(selectedGroupId));
doNotify(attributeName + "_" + limitType + ".temporaryLimit.value", oldTemporaryLimitInfo, newTemporaryLimitInfo);
}

private void doNotify(String attribute, Object oldValue, Object newValue) {
if (listeners != null) {
listeners.notifyUpdate(identifiable, attribute, oldValue, newValue);
Expand All @@ -155,4 +161,7 @@ public record PermanentLimitInfo(double value, String groupId, boolean inSelecte

public record OperationalLimitsInfo(OperationalLimits value, String groupId, boolean inSelectedGroup) {
}

public record TemporaryLimitInfo(double value, String groupId, boolean inSelectedGroup) {
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,46 @@ public void testAdderWithValueZero() {
assertEquals(0, limits.getPermanentLimit());
assertEquals(0, limits.getTemporaryLimit(Integer.MAX_VALUE).getValue());
}

@Test
public void testSetTemporaryLimitValue() {
colinepiloquet marked this conversation as resolved.
Show resolved Hide resolved
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
Line line = createNetwork().getLine("L");
CurrentLimitsAdder adder = line.newCurrentLimits1()
.setPermanentLimit(1000.)
.beginTemporaryLimit()
.setName("TL1")
.setAcceptableDuration(20 * 60)
.setValue(1200.0)
.endTemporaryLimit()
.beginTemporaryLimit()
.setName("TL2")
.setAcceptableDuration(10 * 60)
.setValue(1400.0)
.endTemporaryLimit()
.beginTemporaryLimit()
.setName("TL3")
.setAcceptableDuration(5 * 60)
.setValue(1600.0)
.endTemporaryLimit();
adder.add();

Optional<CurrentLimits> optionalLimits = line.getCurrentLimits(TwoSides.ONE);
assertTrue(optionalLimits.isPresent());
CurrentLimits limits = optionalLimits.get();

limits.setTemporaryLimitValue(20 * 60, 1050.0);
assertEquals(1050.0, limits.getTemporaryLimit(20 * 60).getValue());

limits.setTemporaryLimitValue(10 * 60, 1450.0);
assertEquals(1450.0, limits.getTemporaryLimit(10 * 60).getValue());

limits.setTemporaryLimitValue(5 * 60, 1750.0);
assertEquals(1750.0, limits.getTemporaryLimit(5 * 60).getValue());

// Test with an invalid value
limits.setTemporaryLimitValue(5 * 60, 1250.0);
assertEquals(1750.0, limits.getTemporaryLimit(5 * 60).getValue());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public boolean isFictitious() {
return fictitious();
}

@Override
public void setValue(double temporaryLimitValue) {
}

public double getOriginalValue() {
return originalValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.security.limitreduction.result;

import com.powsybl.iidm.network.ActivePowerLimits;
import com.powsybl.iidm.network.LoadingLimits;

/**
* <p>Simple implementation of {@link ActivePowerLimits} not linked to a network element, used to provide
Expand All @@ -19,4 +20,9 @@ public ReducedActivePowerLimits(double permanentLimit, double originalPermanentL
double permanentLimitReduction) {
super(permanentLimit, originalPermanentLimit, permanentLimitReduction);
}

@Override
public LoadingLimits setTemporaryLimitValue(int acceptableDuration, double temporaryLimitValue) {
return null;
}
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.security.limitreduction.result;

import com.powsybl.iidm.network.ApparentPowerLimits;
import com.powsybl.iidm.network.LoadingLimits;

/**
* <p>Simple implementation of {@link ApparentPowerLimits} not linked to a network element, used to provide
Expand All @@ -19,4 +20,9 @@ public ReducedApparentPowerLimits(double permanentLimit, double originalPermanen
double permanentLimitReduction) {
super(permanentLimit, originalPermanentLimit, permanentLimitReduction);
}

@Override
public LoadingLimits setTemporaryLimitValue(int acceptableDuration, double temporaryLimitValue) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.security.limitreduction.result;

import com.powsybl.iidm.network.CurrentLimits;
import com.powsybl.iidm.network.LoadingLimits;

/**
* <p>Simple implementation of {@link CurrentLimits} not linked to a network element, used to provide
Expand All @@ -19,4 +20,9 @@ public ReducedCurrentLimits(double permanentLimit, double originalPermanentLimit
double permanentLimitReduction) {
super(permanentLimit, originalPermanentLimit, permanentLimitReduction);
}

@Override
public LoadingLimits setTemporaryLimitValue(int acceptableDuration, double temporaryLimitValue) {
return null;
}
}