Skip to content

Commit

Permalink
SWE CNE: Do not export angle "additional constraints" if angle result…
Browse files Browse the repository at this point in the history
…s do not exist (#957)
  • Loading branch information
schwitzguebel authored Apr 4, 2024
1 parent 464b3c0 commit 01f7ff7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ private AdditionalConstraintSeries generateAdditionalConstraintSeries(AngleCnecC
BUSINESS_WARNS.warn("{} angle cnec {} will not be added to CNE file", angleCnec.getState().getInstant(), angleCnecCreationContext.getNativeId());
return null;
}
AdditionalConstraintSeries additionalConstraintSeries = new AdditionalConstraintSeries();
additionalConstraintSeries.setMRID(angleCnecCreationContext.getCreatedCnecId());
additionalConstraintSeries.setBusinessType(ANGLE_CNEC_BUSINESS_TYPE);
additionalConstraintSeries.setName(angleCnec.getName());
RaoResult raoResult = sweCneHelper.getRaoResult();
// only export if angle check ran
if (!raoResult.getComputationStatus().equals(ComputationStatus.FAILURE) && !Double.isNaN(raoResult.getAngle(crac.getInstant(InstantKind.CURATIVE), angleCnec, Unit.DEGREE))) {
AdditionalConstraintSeries additionalConstraintSeries = new AdditionalConstraintSeries();
additionalConstraintSeries.setMRID(angleCnecCreationContext.getCreatedCnecId());
additionalConstraintSeries.setBusinessType(ANGLE_CNEC_BUSINESS_TYPE);
additionalConstraintSeries.setName(angleCnec.getName());
additionalConstraintSeries.setQuantityQuantity(BigDecimal.valueOf(raoResult.getAngle(crac.getInstant(InstantKind.CURATIVE), angleCnec, Unit.DEGREE)).setScale(1, RoundingMode.HALF_UP));
return additionalConstraintSeries;
}
return additionalConstraintSeries;
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* @author Godelaine de Montmorillon {@literal <godelaine.demontmorillon at rte-france.com>}
Expand Down Expand Up @@ -80,6 +79,25 @@ private SweAdditionalConstraintSeriesCreator setUpAngleCnecs(Contingency conting
return new SweAdditionalConstraintSeriesCreator(sweCneHelper, cracCreationContext);
}

private void setUpNanAngleCnecs(Contingency contingency) {
Mockito.when(contingency.getId()).thenReturn("contingency");
AngleCnecCreationContext acc1 = createAdcs("AngleCnecId1", "contingency");
AngleCnecCreationContext acc2 = createAdcs("AngleCnecId2", "contingency");
AngleCnec angleCnec1 = Mockito.mock(AngleCnec.class);
AngleCnec angleCnec2 = Mockito.mock(AngleCnec.class);
Mockito.when(crac.getAngleCnec(acc1.getCreatedCnecId())).thenReturn(angleCnec1);
Mockito.when(crac.getAngleCnec(acc2.getCreatedCnecId())).thenReturn(angleCnec2);
Mockito.when(angleCnec1.getName()).thenReturn("AngleCnecName1");
Mockito.when(angleCnec2.getName()).thenReturn("AngleCnecName2");
Mockito.when(raoResult.getAngle(curativeInstant, angleCnec1, Unit.DEGREE)).thenReturn(Double.NaN);
Mockito.when(raoResult.getAngle(curativeInstant, angleCnec2, Unit.DEGREE)).thenReturn(Double.NaN);
Mockito.when(cracCreationContext.getAngleCnecCreationContexts()).thenReturn(Set.of(acc1, acc2));
State curativeState = Mockito.mock(State.class);
Mockito.when(curativeState.getInstant()).thenReturn(curativeInstant);
Mockito.when(angleCnec1.getState()).thenReturn(curativeState);
Mockito.when(angleCnec2.getState()).thenReturn(curativeState);
}

@Test
void generatePreventiveAdditionalConstraintSeriesTest() {
AngleCnecCreationContext accPrev = createAdcs("AngleCnecIdPrev", null);
Expand Down Expand Up @@ -136,21 +154,23 @@ void generateContingencyAdditionalConstraintSeriesTest() {
}

@Test
void generateContingencyAdditionalConstraintSeriesWithDivergentAngleMonitoringTest() {
void noGenerateContingencyAdditionalConstraintSeriesWithDivergentAngleMonitoringIfFailureTest() {
Contingency contingency = Mockito.mock(Contingency.class);
Mockito.when(raoResult.getComputationStatus()).thenReturn(ComputationStatus.FAILURE);
setUpAngleCnecs(contingency);
SweAdditionalConstraintSeriesCreator additionalConstraintSeriesCreator = new SweAdditionalConstraintSeriesCreator(sweCneHelper, cracCreationContext);
List<AdditionalConstraintSeries> contingencyAngleSeries = additionalConstraintSeriesCreator.generateAdditionalConstraintSeries(contingency);
assertEquals(2, contingencyAngleSeries.size());
assertEquals("AngleCnecId1", contingencyAngleSeries.get(0).getMRID());
assertEquals("AngleCnecName1", contingencyAngleSeries.get(0).getName());
assertEquals("B87", contingencyAngleSeries.get(0).getBusinessType());
assertNull(contingencyAngleSeries.get(0).getQuantityQuantity());
assertEquals("AngleCnecId2", contingencyAngleSeries.get(1).getMRID());
assertEquals("AngleCnecName2", contingencyAngleSeries.get(1).getName());
assertEquals("B87", contingencyAngleSeries.get(1).getBusinessType());
assertNull(contingencyAngleSeries.get(1).getQuantityQuantity());
assertEquals(0, contingencyAngleSeries.size());
}

@Test
void noGenerateContingencyAdditionalConstraintSeriesWithDivergentAngleMonitoringIfNoAngleTest() {
Contingency contingency = Mockito.mock(Contingency.class);
Mockito.when(raoResult.getComputationStatus()).thenReturn(ComputationStatus.DEFAULT);
setUpNanAngleCnecs(contingency);
SweAdditionalConstraintSeriesCreator additionalConstraintSeriesCreator = new SweAdditionalConstraintSeriesCreator(sweCneHelper, cracCreationContext);
List<AdditionalConstraintSeries> contingencyAngleSeries = additionalConstraintSeriesCreator.generateAdditionalConstraintSeries(contingency);
assertEquals(0, contingencyAngleSeries.size());
}

private AngleCnecCreationContext createAdcs(String nativeId, String contingencyId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@
<Constraint_Series>
<mRID>53c404b-8a90-4830-8f92-78956ce4469f</mRID>
<businessType>B57</businessType>
<AdditionalConstraint_Series>
<mRID>ac1</mRID>
<businessType>B87</businessType>
<name>ac1-name</name>
</AdditionalConstraint_Series>
<Contingency_Series>
<mRID>Co-1</mRID>
<name>Contingency 1 name</name>
Expand Down

0 comments on commit 01f7ff7

Please sign in to comment.