Skip to content

Commit

Permalink
Monitoring bug fix (#1188)
Browse files Browse the repository at this point in the history
* bug fix

Signed-off-by: Godelaine de Montmorillon <godelaine.demontmorillon@rte-france.com>

* Update data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecImpl.java

Co-authored-by: Peter Mitri <peter.mitri@rte-france.com>
Signed-off-by: Godelaine <87479798+Godelaine@users.noreply.github.com>

---------

Signed-off-by: Godelaine de Montmorillon <godelaine.demontmorillon@rte-france.com>
Signed-off-by: Godelaine <87479798+Godelaine@users.noreply.github.com>
Co-authored-by: Peter Mitri <peter.mitri@rte-france.com>
  • Loading branch information
2 people authored and phiedw committed Nov 5, 2024
1 parent 5110f2d commit 82e3e97
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ public FlowCnecValue computeValue(Network network, Unit unit) {
}
Branch branch = network.getBranch(getNetworkElement().getId());
if (getMonitoredSides().size() == 2) {
double power1;
double power2;
power1 = getFlow(branch, TwoSides.ONE, unit);
power2 = getFlow(branch, TwoSides.TWO, unit);
return new FlowCnecValue(power1, power2);
return new FlowCnecValue(getFlow(branch, TwoSides.ONE, unit), getFlow(branch, TwoSides.TWO, unit));
} else {
TwoSides monitoredSide = getMonitoredSides().iterator().next();
double power = getFlow(branch, monitoredSide, unit);
Expand All @@ -176,14 +172,15 @@ public FlowCnecValue computeValue(Network network, Unit unit) {
}

private double getFlow(Branch branch, TwoSides side, Unit unit) {
double power = branch.getTerminal(side).getP();
double activeFlow = branch.getTerminal(side).getP();
double intensity = branch.getTerminal(side).getI();
if (unit.equals(Unit.AMPERE)) {
power = branch.getTerminal(side).getI();
return Double.isNaN(power) ? branch.getTerminal(side).getP() * getFlowUnitMultiplierMegawattToAmpere(side) : power;
// In case flows are negative, we shall replace this value by its opposite
return Double.isNaN(intensity) ? activeFlow * getFlowUnitMultiplierMegawattToAmpere(side) : Math.signum(activeFlow) * intensity;
} else if (!unit.equals(Unit.MEGAWATT)) {
throw new OpenRaoException("FlowCnec can only be requested in AMPERE or MEGAWATT");
}
return Double.isNaN(power) ? branch.getTerminal(side).getP() * getFlowUnitMultiplierMegawattToAmpere(side) : power;
return activeFlow;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ void testComputeValue() {
assertEquals(Double.NaN, ((FlowCnecValue) cnecWithOneSide.computeValue(network, MEGAWATT)).side2Value());
}

@Test
void testComputeValueAmpere() {
Network network = Mockito.mock(Network.class);
Branch branch3 = Mockito.mock(Branch.class);
Terminal terminal31 = Mockito.mock(Terminal.class);
Terminal terminal32 = Mockito.mock(Terminal.class);

Mockito.when(network.getBranch("AAE2AA1 AAE3AA1 1")).thenReturn(branch3);
Mockito.when(terminal31.getP()).thenReturn(-66.);
Mockito.when(terminal31.getI()).thenReturn(55.);
Mockito.when(terminal32.getP()).thenReturn(22.);
Mockito.when(terminal32.getI()).thenReturn(Double.NaN);
Mockito.when(branch3.getTerminal(ONE)).thenReturn(terminal31);
Mockito.when(branch3.getTerminal(TWO)).thenReturn(terminal32);

FlowCnec cnecA = crac.newFlowCnec().withId("cnec-A-id").withNetworkElement("AAE2AA1 AAE3AA1 1").withInstant(PREVENTIVE_INSTANT_ID)
.withNominalVoltage(222.)
.newThreshold().withUnit(AMPERE).withMin(5.).withMax(10.).withSide(TwoSides.ONE).add()
.newThreshold().withUnit(AMPERE).withMin(20.).withMax(300.).withSide(TwoSides.TWO).add()
.add();

assertEquals(-55., ((FlowCnecValue) cnecA.computeValue(network, AMPERE)).side1Value());
assertEquals(57.2, ((FlowCnecValue) cnecA.computeValue(network, AMPERE)).side2Value(), 0.1);
}

@Test
void testComputeWorstMargin() {
Network network = Mockito.mock(Network.class, Mockito.RETURNS_DEEP_STUBS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void applyOptimalRemedialActionsOnContingencyState(State state, Network
if (state.getInstant().isCurative()) {
Optional<Contingency> contingency = state.getContingency();
crac.getStates(contingency.orElseThrow()).forEach(contingencyState ->
applyOptimalRemedialActions(state, network, raoResult));
applyOptimalRemedialActions(contingencyState, network, raoResult));
} else {
applyOptimalRemedialActions(state, network, raoResult);
}
Expand Down

0 comments on commit 82e3e97

Please sign in to comment.