FlowsValidation { public boolean checkFlows(BranchData branch, ValidationConfig config, Writer writer) { Objects.requireNonNull(branch); Objects.requireNonNull(branch.getId()); Objects.requireNonNull(config); Objects.requireNonNull(writer); try (ValidationWriter flowsWriter = ValidationUtils.createValidationWriter(branch.getId(), config, writer, ValidationType.FLOWS)) { return checkFlows(branch, config, flowsWriter); } catch (IOException e) { throw new UncheckedIOException(e); } } private  FlowsValidation(); boolean checkFlows(BranchData branch, ValidationConfig config, Writer writer); boolean checkFlows(BranchData branch, ValidationConfig config, ValidationWriter flowsWriter); boolean checkFlows(Line l, ValidationConfig config, Writer writer); boolean checkFlows(Line l, ValidationConfig config, ValidationWriter flowsWriter); boolean checkFlows(TwoWindingsTransformer twt, ValidationConfig config, Writer writer); boolean checkFlows(TwoWindingsTransformer twt, ValidationConfig config, ValidationWriter flowsWriter); boolean checkFlows(Network network, ValidationConfig config, Writer writer); boolean checkFlows(Network network, ValidationConfig config, Path file); boolean checkFlows(Network network, ValidationConfig config, ValidationWriter flowsWriter); static final FlowsValidation INSTANCE; }
@Test public void checkFlows() { double p1 = 40.0744; double q1 = 2.3124743; double p2 = -40.073254; double q2 = -2.3003194; assertTrue(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, u1, u2, theta1, theta2, alpha1, alpha2, g1, g2, b1, b2, p1, q1, p2, q2, connected1, connected2, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, u1, u2, theta1, theta2, alpha1, alpha2, g1, g2, b1, b2, p1, q1, p2, q2, connected1, connected2, mainComponent1, mainComponent2, strictConfig.getEpsilonX(), strictConfig.applyReactanceCorrection()), strictConfig, NullWriter.NULL_WRITER)); double r = 0.04 / (rho2 * rho2); double x = 0.423 / (rho2 * rho2); double rho1 = 1 / rho2; double rho2 = 1; assertTrue(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, u1, u2, theta1, theta2, alpha1, alpha2, g1, g2, b1, b2, p1, q1, p2, q2, connected1, connected2, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, u1, u2, theta1, theta2, alpha1, alpha2, g1, g2, b1, b2, p1, q1, p2, q2, connected1, connected2, mainComponent1, mainComponent2, strictConfig.getEpsilonX(), strictConfig.applyReactanceCorrection()), strictConfig, NullWriter.NULL_WRITER)); assertTrue(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, Double.NaN, u2, Double.NaN, theta2, alpha1, alpha2, g1, g2, b1, b2, Double.NaN, Double.NaN, 0f, 0f, false, connected2, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, new PrintWriter(System.err))); assertFalse(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, Double.NaN, u2, Double.NaN, theta2, alpha1, alpha2, g1, g2, b1, b2, Double.NaN, Double.NaN, 0.2f, 0f, false, connected2, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); assertTrue(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, Double.NaN, Double.NaN, Double.NaN, Double.NaN, alpha1, alpha2, g1, g2, b1, b2, Float.NaN, Float.NaN, Float.NaN, Float.NaN, false, false, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, Double.NaN, Double.NaN, Double.NaN, Double.NaN, alpha1, alpha2, g1, g2, b1, b2, p1, q2, Double.NaN, Double.NaN, false, false, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, rho1, rho2, Double.NaN, Double.NaN, Double.NaN, Double.NaN, alpha1, alpha2, g1, g2, b1, b2, Double.NaN, Double.NaN, p2, q2, false, false, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, Double.NaN, rho2, u1, u2, theta1, theta2, alpha1, alpha2, g1, g2, b1, b2, p1, q1, p2, q2, connected1, connected2, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(true); assertTrue(FlowsValidation.INSTANCE.checkFlows(new BranchData("test", r, x, Double.NaN, rho2, u1, u2, theta1, theta2, alpha1, alpha2, g1, g2, b1, b2, p1, q1, p2, q2, connected1, connected2, mainComponent1, mainComponent2, looseConfig.getEpsilonX(), looseConfig.applyReactanceCorrection()), looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(false); }
@Test public void checkLineFlows() { assertTrue(FlowsValidation.INSTANCE.checkFlows(line1, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(line1, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus1.isInMainConnectedComponent()).thenReturn(false); Mockito.when(bus2.isInMainConnectedComponent()).thenReturn(false); assertTrue(FlowsValidation.INSTANCE.checkFlows(line1, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkTransformerFlows() { assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer1, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(transformer1, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus1.isInMainConnectedComponent()).thenReturn(false); Mockito.when(bus2.isInMainConnectedComponent()).thenReturn(false); assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer1, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkTransformerFlowsSpecificCompatibility() { assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer1, looseConfigSpecificCompatibility, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(transformer1, strictConfigSpecificCompatibility, NullWriter.NULL_WRITER)); }
@Test public void checkNetworkFlows() throws IOException { Line line2 = Mockito.mock(Line.class); Mockito.when(line2.getId()).thenReturn("line2"); Mockito.when(line2.getTerminal1()).thenReturn(terminal1); Mockito.when(line2.getTerminal2()).thenReturn(terminal2); Mockito.when(line2.getR()).thenReturn(r); Mockito.when(line2.getX()).thenReturn(x); Mockito.when(line2.getG1()).thenReturn(g1); Mockito.when(line2.getG2()).thenReturn(g2); Mockito.when(line2.getB1()).thenReturn(b1); Mockito.when(line2.getB2()).thenReturn(b2); TwoWindingsTransformer transformer2 = Mockito.mock(TwoWindingsTransformer.class); Mockito.when(transformer2.getId()).thenReturn("transformer2"); Mockito.when(transformer2.getTerminal1()).thenReturn(terminal1); Mockito.when(transformer2.getTerminal2()).thenReturn(terminal2); Mockito.when(transformer2.getR()).thenReturn(r * (1 - r / 100)); Mockito.when(transformer2.getX()).thenReturn(x * (1 - x / 100)); Mockito.when(transformer2.getG()).thenReturn(g1 * (1 - g1 / 100)); Mockito.when(transformer2.getB()).thenReturn(b1 * 2 * (1 - b1 / 100)); Mockito.when(transformer2.getRatioTapChanger()).thenReturn(ratioTapChanger); Mockito.when(transformer2.getOptionalRatioTapChanger()).thenReturn(Optional.ofNullable(ratioTapChanger)); Mockito.when(transformer2.hasRatioTapChanger()).thenReturn(true); Mockito.when(transformer2.getRatedU1()).thenReturn(ratedU1); Mockito.when(transformer2.getRatedU2()).thenReturn(ratedU2); assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer2, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(transformer2, strictConfig, NullWriter.NULL_WRITER)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getLineStream()).thenAnswer(dummy -> Stream.of(line2, line1)); Mockito.when(network.getTwoWindingsTransformerStream()).thenAnswer(dummy -> Stream.of(transformer2, transformer1)); assertTrue(FlowsValidation.INSTANCE.checkFlows(network, looseConfig, data)); assertFalse(FlowsValidation.INSTANCE.checkFlows(network, strictConfig, data)); assertTrue(ValidationType.FLOWS.check(network, looseConfig, tmpDir)); assertFalse(ValidationType.FLOWS.check(network, strictConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), looseConfig, NullWriter.NULL_WRITER, ValidationType.FLOWS); assertTrue(ValidationType.FLOWS.check(network, looseConfig, validationWriter)); }