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

Monitoring bug fix #1188

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading