diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/FaultParameters.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/FaultParameters.java index 97cb9463511..f3dd36c0576 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/FaultParameters.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/FaultParameters.java @@ -35,8 +35,9 @@ public class FaultParameters { // VERSION = 1.0 withLimitViolations, withVoltageMap, withFeederResult, studyType and minVoltageDropProportionalThreshold // VERSION = 1.1 withVoltageMap -> withFortescueResult and withVoltageResult // VERSION = 1.2 subTransientCoefficient, withLoads, withShuntCompensators, withVSCConverterStations, withNeutralPosition, - // initialVoltageProfileMode, voltageRanges - public static final String VERSION = "1.2"; + // initialVoltageProfileMode, voltageRange + // VERSION = 1.3 voltage in voltageRange + public static final String VERSION = "1.3"; private final String id; diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/ShortCircuitParameters.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/ShortCircuitParameters.java index 9fc49b8e2a7..83c0b024430 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/ShortCircuitParameters.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/ShortCircuitParameters.java @@ -40,8 +40,8 @@ public class ShortCircuitParameters extends AbstractExtendable withFortescueResult and withVoltageResult // VERSION = 1.2 subTransientCoefficient, withLoads, withShuntCompensators, withVSCConverterStations, withNeutralPosition, - // initialVoltageProfileMode, voltageRanges - // VERSION = 1.3 detailedLog + // initialVoltageProfileMode, voltageRange + // VERSION = 1.3 detailedLog, voltage in voltageRange public static final String VERSION = "1.3"; private boolean withLimitViolations = DEFAULT_WITH_LIMIT_VIOLATIONS; diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/VoltageRange.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/VoltageRange.java index 859839d345a..7072e1a07b3 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/VoltageRange.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/VoltageRange.java @@ -14,17 +14,25 @@ import java.util.Objects; /** - * A class that stores coefficients to be applied to every nominal voltage in a range. This is used to define the configured initial voltage profile - * for short circuit calculation. + * A class that stores coefficients and nominal voltages to be applied to each nominal voltage of the network in a range. + * This is used to define the configured initial voltage profile for short circuit calculation. + * The voltage attribute allows to modify the nominal voltage to be considered for each nominal voltage of the range. + * The coefficient is a coefficient that is applied to each nominal voltage. * @author Coline Piloquet {@literal } */ public class VoltageRange { private final Range range; private final double rangeCoefficient; + private final double voltage; public VoltageRange(double lowVoltage, double highVoltage, double rangeCoefficient) { + this(lowVoltage, highVoltage, rangeCoefficient, Double.NaN); + } + + public VoltageRange(double lowVoltage, double highVoltage, double rangeCoefficient, double voltage) { this.range = Range.of(lowVoltage, highVoltage); this.rangeCoefficient = checkCoefficient(rangeCoefficient); + this.voltage = checkVoltage(voltage, this.range); } /** @@ -55,6 +63,13 @@ public double getMaximumNominalVoltage() { return range.getMaximum(); } + /** + * The nominal voltage to consider for the range. All nominal voltages in the range will be replaced by this value. + */ + public double getVoltage() { + return voltage; + } + static void checkVoltageRange(List voltageRange) { if (voltageRange == null || voltageRange.isEmpty()) { return; @@ -76,6 +91,13 @@ private static double checkCoefficient(double rangeCoefficient) { return rangeCoefficient; } + private static double checkVoltage(double voltage, Range voltageRange) { + if (!Double.isNaN(voltage) && !voltageRange.contains(voltage)) { + throw new PowsyblException("Range voltage should be in voltageRange " + voltageRange + " but it is " + voltage); + } + return voltage; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -85,12 +107,12 @@ public boolean equals(Object o) { return false; } VoltageRange that = (VoltageRange) o; - return range.equals(that.range) && rangeCoefficient == that.rangeCoefficient; + return range.equals(that.range) && rangeCoefficient == that.rangeCoefficient && voltage == that.voltage; } @Override public int hashCode() { - return Objects.hash(range, rangeCoefficient); + return Objects.hash(range, rangeCoefficient, voltage); } } diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/FaultParametersDeserializer.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/FaultParametersDeserializer.java index aec92de2786..986c6795337 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/FaultParametersDeserializer.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/FaultParametersDeserializer.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.util.List; +import static com.powsybl.shortcircuit.json.ParametersDeserializationConstants.*; + /** * @author Thomas Adam {@literal } */ @@ -54,6 +56,8 @@ public FaultParameters deserialize(JsonParser parser, DeserializationContext des case "version" -> { parser.nextToken(); version = parser.getValueAsString(); + JsonUtil.setSourceVersion(deserializationContext, version, SOURCE_VERSION_ATTRIBUTE); + deserializationContext.setAttribute(SOURCE_PARAMETER_TYPE_ATTRIBUTE, ParametersType.FAULT); } case "id" -> { parser.nextToken(); diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ParametersDeserializationConstants.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ParametersDeserializationConstants.java new file mode 100644 index 00000000000..adccca62192 --- /dev/null +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ParametersDeserializationConstants.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.shortcircuit.json; + +/** + * @author Olivier Perrin {@literal } + */ +public final class ParametersDeserializationConstants { + private ParametersDeserializationConstants() { + } + + public static final String SOURCE_VERSION_ATTRIBUTE = "sourceVersionAttribute"; + + public static final String SOURCE_PARAMETER_TYPE_ATTRIBUTE = "sourceParameterTypeAttribute"; + + public enum ParametersType { + FAULT, + SHORT_CIRCUIT + } +} diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ShortCircuitParametersDeserializer.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ShortCircuitParametersDeserializer.java index 46d51965387..f05679e64ec 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ShortCircuitParametersDeserializer.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/ShortCircuitParametersDeserializer.java @@ -19,6 +19,7 @@ import java.util.List; import static com.powsybl.shortcircuit.json.JsonShortCircuitParameters.getExtensionSerializers; +import static com.powsybl.shortcircuit.json.ParametersDeserializationConstants.*; /** * @author Boubakeur Brahimi @@ -46,6 +47,8 @@ public ShortCircuitParameters deserialize(JsonParser parser, DeserializationCont case "version" -> { parser.nextToken(); version = parser.getValueAsString(); + JsonUtil.setSourceVersion(deserializationContext, version, SOURCE_VERSION_ATTRIBUTE); + deserializationContext.setAttribute(SOURCE_PARAMETER_TYPE_ATTRIBUTE, ParametersType.SHORT_CIRCUIT); } case "withLimitViolations" -> { parser.nextToken(); diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeDeserializer.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeDeserializer.java index 784aa8543f2..6af7f6e6eb1 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeDeserializer.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeDeserializer.java @@ -11,15 +11,20 @@ import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.powsybl.commons.json.JsonUtil; import com.powsybl.shortcircuit.VoltageRange; import java.io.IOException; +import static com.powsybl.shortcircuit.json.ParametersDeserializationConstants.SOURCE_VERSION_ATTRIBUTE; + /** * @author Coline Piloquet {@literal } */ public class VoltageRangeDeserializer extends StdDeserializer { + private static final String CONTEXT_NAME = "VoltageRange"; + public VoltageRangeDeserializer() { super(VoltageRange.class); } @@ -28,6 +33,10 @@ public VoltageRange deserialize(JsonParser parser, DeserializationContext contex Double minimumVoltage = Double.NaN; Double maximumVoltage = Double.NaN; Double coefficient = Double.NaN; + Double voltage = Double.NaN; + String version = JsonUtil.getSourceVersion(context, SOURCE_VERSION_ATTRIBUTE); + // If needed, the type of the enclosing Parameters (Fault, Short-circuit, ...) can be retrieved + // from the context with `context.getAttribute(ParametersDeserializationConstants.SOURCE_PARAMETER_TYPE_ATTRIBUTE)` while (parser.nextToken() != JsonToken.END_OBJECT) { switch (parser.getCurrentName()) { @@ -43,10 +52,15 @@ public VoltageRange deserialize(JsonParser parser, DeserializationContext contex parser.nextToken(); coefficient = parser.readValueAs(Double.class); } + case "voltage" -> { + JsonUtil.assertGreaterOrEqualThanReferenceVersion(CONTEXT_NAME, "Tag: " + parser.getCurrentName(), version, "1.3"); + parser.nextToken(); + voltage = parser.readValueAs(Double.class); + } default -> throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); } } - return new VoltageRange(minimumVoltage, maximumVoltage, coefficient); + return new VoltageRange(minimumVoltage, maximumVoltage, coefficient, voltage); } } diff --git a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeSerializer.java b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeSerializer.java index 49962fcd71a..e6fda4dc246 100644 --- a/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeSerializer.java +++ b/shortcircuit-api/src/main/java/com/powsybl/shortcircuit/json/VoltageRangeSerializer.java @@ -26,13 +26,14 @@ public class VoltageRangeSerializer extends StdSerializer { } @Override - public void serialize(VoltageRange coefficient, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException { - Objects.requireNonNull(coefficient); + public void serialize(VoltageRange voltageRange, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException { + Objects.requireNonNull(voltageRange); jsonGenerator.writeStartObject(); - JsonUtil.writeOptionalDoubleField(jsonGenerator, "minimumNominalVoltage", coefficient.getMinimumNominalVoltage()); - JsonUtil.writeOptionalDoubleField(jsonGenerator, "maximumNominalVoltage", coefficient.getMaximumNominalVoltage()); - JsonUtil.writeOptionalDoubleField(jsonGenerator, "voltageRangeCoefficient", coefficient.getRangeCoefficient()); + JsonUtil.writeOptionalDoubleField(jsonGenerator, "minimumNominalVoltage", voltageRange.getMinimumNominalVoltage()); + JsonUtil.writeOptionalDoubleField(jsonGenerator, "maximumNominalVoltage", voltageRange.getMaximumNominalVoltage()); + JsonUtil.writeOptionalDoubleField(jsonGenerator, "voltageRangeCoefficient", voltageRange.getRangeCoefficient()); + JsonUtil.writeOptionalDoubleField(jsonGenerator, "voltage", voltageRange.getVoltage()); jsonGenerator.writeEndObject(); } diff --git a/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/ShortCircuitParametersTest.java b/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/ShortCircuitParametersTest.java index 5f9708ef198..c17ddf16942 100644 --- a/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/ShortCircuitParametersTest.java +++ b/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/ShortCircuitParametersTest.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -120,8 +121,7 @@ public DummyExtension deserialize(JsonParser jsonParser, DeserializationContext public DummyExtension deserializeAndUpdate(JsonParser jsonParser, DeserializationContext deserializationContext, DummyExtension parameters) throws IOException { ObjectMapper objectMapper = createMapper(); ObjectReader objectReader = objectMapper.readerForUpdating(parameters); - DummyExtension updatedParameters = objectReader.readValue(jsonParser, DummyExtension.class); - return updatedParameters; + return objectReader.readValue(jsonParser, DummyExtension.class); } @Override @@ -295,6 +295,13 @@ void readVersion12() { assertEquals(Range.of(230., 375.), voltageRanges.get(2).getRange()); } + @Test + void testInvalidVersion12VoltageNotSupportedInVoltageRange() { + InputStream is = getClass().getResourceAsStream("/ShortCircuitParametersVersion12Invalid.json"); + UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> JsonShortCircuitParameters.read(is)); + assertTrue(e.getMessage().contains("VoltageRange. Tag: voltage is not valid for version 1.2. Version should be >= 1.3")); + } + @Test void readVersion13() { ShortCircuitParameters parameters = JsonShortCircuitParameters @@ -306,8 +313,13 @@ void readVersion13() { assertEquals(StudyType.SUB_TRANSIENT, parameters.getStudyType()); assertEquals(0, parameters.getMinVoltageDropProportionalThreshold(), 0); assertEquals(0.7, parameters.getSubTransientCoefficient(), 0); - assertEquals(InitialVoltageProfileMode.NOMINAL, parameters.getInitialVoltageProfileMode()); assertFalse(parameters.isDetailedReport()); + assertEquals(InitialVoltageProfileMode.CONFIGURED, parameters.getInitialVoltageProfileMode()); + assertEquals(1, parameters.getVoltageRanges().size()); + VoltageRange voltageRange = parameters.getVoltageRanges().get(0); + assertEquals(Range.of(380., 410.), voltageRange.getRange()); + assertEquals(1.05, voltageRange.getRangeCoefficient()); + assertEquals(380., voltageRange.getVoltage()); } @Test @@ -412,4 +424,41 @@ void testReadWithUnsortedRanges() { .read(stream)); assertEquals("Voltage ranges for configured initial voltage profile are overlapping", e0.getMessage()); } + + @Test + void testVoltageRangeWithSpecificVoltage() { + VoltageRange range = new VoltageRange(100, 200, 0.9, 150); + assertEquals(100, range.getMinimumNominalVoltage()); + assertEquals(200, range.getMaximumNominalVoltage()); + assertEquals(0.9, range.getRangeCoefficient()); + assertEquals(150, range.getVoltage()); + } + + @Test + void testVoltageRangeWithSpecificVoltageOutOfBounds() { + PowsyblException e = assertThrows(PowsyblException.class, () -> new VoltageRange(100, 150, 0.9, 200)); + assertEquals("Range voltage should be in voltageRange [100.0..150.0] but it is 200.0", e.getMessage()); + } + + @Test + void roundTripWithVoltageInVoltageRange() throws IOException { + List voltageRanges = new ArrayList<>(); + voltageRanges.add(new VoltageRange(0, 100, 0.95, 100)); + voltageRanges.add(new VoltageRange(101, 150, 1.1, 140)); + ShortCircuitParameters parameters = new ShortCircuitParameters() + .setInitialVoltageProfileMode(InitialVoltageProfileMode.CONFIGURED) + .setVoltageRanges(voltageRanges); + roundTripTest(parameters, JsonShortCircuitParameters::write, JsonShortCircuitParameters::read, + "/ShortCircuitParametersWithRangeVoltage.json"); + } + + @Test + void testVoltageRange() { + VoltageRange voltageRange0 = new VoltageRange(350.0, 400.0, 1.05, 380.0); + VoltageRange voltageRange1 = new VoltageRange(350.0, 400.0, 1.05, 380.0); + assertEquals(voltageRange1, voltageRange0); + assertNotNull(voltageRange0); + assertNotEquals(new VoltageRange(350.0, 400.0, 1.05), voltageRange0); + assertEquals(voltageRange0.hashCode(), voltageRange1.hashCode()); + } } diff --git a/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/json/JsonFaultParametersTest.java b/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/json/JsonFaultParametersTest.java index 8ecdac47a64..fc2ab1aec27 100644 --- a/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/json/JsonFaultParametersTest.java +++ b/shortcircuit-api/src/test/java/com/powsybl/shortcircuit/json/JsonFaultParametersTest.java @@ -11,6 +11,7 @@ import com.powsybl.shortcircuit.InitialVoltageProfileMode; import com.powsybl.shortcircuit.StudyType; import com.powsybl.shortcircuit.VoltageRange; +import org.apache.commons.lang3.Range; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -19,6 +20,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static org.junit.jupiter.api.Assertions.*; @@ -31,7 +33,7 @@ class JsonFaultParametersTest extends AbstractSerDeTest { void roundTrip() throws IOException { List parameters = new ArrayList<>(); parameters.add(new FaultParameters("f00", false, false, true, StudyType.STEADY_STATE, 20, true, Double.NaN, true, true, true, true, InitialVoltageProfileMode.NOMINAL, null)); - List voltageRanges = List.of(new VoltageRange(0, 230, 1), new VoltageRange(235, 400, 1.05)); + List voltageRanges = List.of(new VoltageRange(0, 230, 1), new VoltageRange(231, 250, 1.05, 240)); parameters.add(new FaultParameters("f01", false, true, false, null, Double.NaN, true, Double.NaN, true, true, false, false, InitialVoltageProfileMode.CONFIGURED, voltageRanges)); parameters.add(new FaultParameters("f10", true, false, false, null, Double.NaN, false, Double.NaN, false, true, false, false, InitialVoltageProfileMode.NOMINAL, null)); parameters.add(new FaultParameters("f11", true, true, false, null, Double.NaN, false, Double.NaN, false, false, false, false, null, null)); @@ -46,7 +48,7 @@ void roundTrip() throws IOException { // @Test void readVersion10() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFileVersion10.json"), fileSystem.getPath("/FaultParametersFileVersion10.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileVersion10.json")), fileSystem.getPath("/FaultParametersFileVersion10.json")); List parameters = FaultParameters.read(fileSystem.getPath("/FaultParametersFileVersion10.json")); assertEquals(4, parameters.size()); @@ -85,7 +87,7 @@ void readVersion10() throws IOException { @Test void readVersion11() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFileVersion11.json"), fileSystem.getPath("/FaultParametersFileVersion11.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileVersion11.json")), fileSystem.getPath("/FaultParametersFileVersion11.json")); List parameters = FaultParameters.read(fileSystem.getPath("/FaultParametersFileVersion11.json")); assertEquals(1, parameters.size()); @@ -100,7 +102,7 @@ void readVersion11() throws IOException { @Test void readVersion12() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFileVersion12.json"), fileSystem.getPath("/FaultParametersFileVersion12.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileVersion12.json")), fileSystem.getPath("/FaultParametersFileVersion12.json")); List parameters = FaultParameters.read(fileSystem.getPath("/FaultParametersFileVersion12.json")); assertEquals(1, parameters.size()); @@ -114,9 +116,35 @@ void readVersion12() throws IOException { assertEquals(0.8, firstParam.getSubTransientCoefficient()); } + @Test + void readVersion13() throws IOException { + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileVersion13.json")), fileSystem.getPath("/FaultParametersFileVersion13.json")); + List parameters = FaultParameters.read(fileSystem.getPath("/FaultParametersFileVersion13.json")); + assertEquals(1, parameters.size()); + + FaultParameters param = parameters.get(0); + assertEquals("f00", param.getId()); + assertFalse(param.isWithLimitViolations()); + assertEquals(StudyType.SUB_TRANSIENT, param.getStudyType()); + assertTrue(param.isWithFeederResult()); + assertFalse(param.isWithVoltageResult()); + assertEquals(20, param.getMinVoltageDropProportionalThreshold(), 0); + assertEquals(0.8, param.getSubTransientCoefficient()); + assertEquals(InitialVoltageProfileMode.CONFIGURED, param.getInitialVoltageProfileMode()); + assertEquals(2, param.getVoltageRanges().size()); + VoltageRange voltageRange1 = param.getVoltageRanges().get(0); + assertEquals(Range.of(0., 230.), voltageRange1.getRange()); + assertEquals(1.0, voltageRange1.getRangeCoefficient()); + assertTrue(Double.isNaN(voltageRange1.getVoltage())); + VoltageRange voltageRange2 = param.getVoltageRanges().get(1); + assertEquals(Range.of(231., 250.), voltageRange2.getRange()); + assertEquals(1.05, voltageRange2.getRangeCoefficient()); + assertEquals(240., voltageRange2.getVoltage()); + } + @Test void readUnexpectedField() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFileInvalid.json"), fileSystem.getPath("/FaultParametersFileInvalid.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileInvalid.json")), fileSystem.getPath("/FaultParametersFileInvalid.json")); Path path = fileSystem.getPath("/FaultParametersFileInvalid.json"); UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> FaultParameters.read(path)); @@ -125,7 +153,7 @@ void readUnexpectedField() throws IOException { @Test void readParameters() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFile.json"), fileSystem.getPath("/FaultParametersFile.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFile.json")), fileSystem.getPath("/FaultParametersFile.json")); List parameters = FaultParameters.read(fileSystem.getPath("/FaultParametersFile.json")); assertEquals(5, parameters.size()); @@ -138,7 +166,7 @@ void readParameters() throws IOException { @Test void readParametersMissingVoltageRanges() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFileWithoutVoltageRanges.json"), fileSystem.getPath("/FaultParametersFileWithoutVoltageRanges.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileWithoutVoltageRanges.json")), fileSystem.getPath("/FaultParametersFileWithoutVoltageRanges.json")); Path path = fileSystem.getPath("/FaultParametersFileWithoutVoltageRanges.json"); UncheckedIOException e0 = assertThrows(UncheckedIOException.class, () -> FaultParameters.read(path)); assertEquals("com.fasterxml.jackson.databind.JsonMappingException: Configured initial voltage profile but nominal voltage ranges with associated coefficients are missing. (through reference chain: java.util.ArrayList[0])", e0.getMessage()); @@ -146,7 +174,7 @@ void readParametersMissingVoltageRanges() throws IOException { @Test void readParametersEmptyVoltageRange() throws IOException { - Files.copy(getClass().getResourceAsStream("/FaultParametersFileEmptyVoltageRanges.json"), fileSystem.getPath("/FaultParametersFileEmptyVoltageRanges.json")); + Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/FaultParametersFileEmptyVoltageRanges.json")), fileSystem.getPath("/FaultParametersFileEmptyVoltageRanges.json")); Path path = fileSystem.getPath("/FaultParametersFileEmptyVoltageRanges.json"); UncheckedIOException e0 = assertThrows(UncheckedIOException.class, () -> FaultParameters.read(path)); assertEquals("com.fasterxml.jackson.databind.JsonMappingException: Configured initial voltage profile but nominal voltage ranges with associated coefficients are missing. (through reference chain: java.util.ArrayList[0])", e0.getMessage()); diff --git a/shortcircuit-api/src/test/resources/FaultParametersFile.json b/shortcircuit-api/src/test/resources/FaultParametersFile.json index 99f1bfd7105..b410ba49cab 100644 --- a/shortcircuit-api/src/test/resources/FaultParametersFile.json +++ b/shortcircuit-api/src/test/resources/FaultParametersFile.json @@ -1,5 +1,5 @@ [ { - "version" : "1.2", + "version" : "1.3", "id" : "f00", "withFeederResult" : true, "studyType" : "STEADY_STATE", @@ -11,7 +11,7 @@ "withNeutralPosition" : true, "initialVoltageProfileMode" : "NOMINAL" }, { - "version" : "1.2", + "version" : "1.3", "id" : "f01", "withVoltageResult" : true, "withFortescueResult" : true, @@ -23,23 +23,24 @@ "maximumNominalVoltage" : 230.0, "voltageRangeCoefficient" : 1.0 }, { - "minimumNominalVoltage" : 235.0, - "maximumNominalVoltage" : 400.0, - "voltageRangeCoefficient" : 1.05 + "minimumNominalVoltage" : 231.0, + "maximumNominalVoltage" : 250.0, + "voltageRangeCoefficient" : 1.05, + "voltage" : 240.0 } ] }, { - "version" : "1.2", + "version" : "1.3", "id" : "f10", "withLimitViolations" : true, "withShuntCompensators" : true, "initialVoltageProfileMode" : "NOMINAL" }, { - "version" : "1.2", + "version" : "1.3", "id" : "f11", "withLimitViolations" : true, "withVoltageResult" : true }, { - "version" : "1.2", + "version" : "1.3", "id" : "f12", "withLimitViolations" : true, "studyType" : "SUB_TRANSIENT", diff --git a/shortcircuit-api/src/test/resources/FaultParametersFileVersion13.json b/shortcircuit-api/src/test/resources/FaultParametersFileVersion13.json new file mode 100644 index 00000000000..f42e29b51c8 --- /dev/null +++ b/shortcircuit-api/src/test/resources/FaultParametersFileVersion13.json @@ -0,0 +1,19 @@ +[ { + "version" : "1.3", + "id" : "f00", + "withFeederResult" : true, + "studyType" : "SUB_TRANSIENT", + "minVoltageDropProportionalThreshold" : 20.0, + "subTransientCoefficient": 0.8, + "initialVoltageProfileMode" : "CONFIGURED", + "voltageRanges" : [ { + "minimumNominalVoltage" : 0.0, + "maximumNominalVoltage" : 230.0, + "voltageRangeCoefficient" : 1.0 + }, { + "minimumNominalVoltage" : 231.0, + "maximumNominalVoltage" : 250.0, + "voltageRangeCoefficient" : 1.05, + "voltage" : 240.0 + } ] +} ] \ No newline at end of file diff --git a/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion12Invalid.json b/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion12Invalid.json new file mode 100644 index 00000000000..3bc44ee1806 --- /dev/null +++ b/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion12Invalid.json @@ -0,0 +1,29 @@ +{ + "version" : "1.2", + "withLimitViolations" : false, + "withVoltageResult" : false, + "withFeederResult" : true, + "studyType" : "SUB_TRANSIENT", + "subTransientCoefficient" : 0.7, + "minVoltageDropProportionalThreshold" : 0.0, + "withFortescueResult" : true, + "withLoads" : false, + "withShuntCompensators" : false, + "withVSCConverterStations" : false, + "withNeutralPosition" : true, + "initialVoltageProfileMode" : "CONFIGURED", + "voltageRanges" : [ { + "minimumNominalVoltage" : 380.0, + "maximumNominalVoltage" : 410.0, + "voltageRangeCoefficient" : 1.05, + "voltage" : 400.0 + }, { + "minimumNominalVoltage" : 0.0, + "maximumNominalVoltage" : 225.0, + "voltageRangeCoefficient" : 1.1 + }, { + "minimumNominalVoltage" : 230.0, + "maximumNominalVoltage" : 375.0, + "voltageRangeCoefficient" : 1.09 + } ] +} \ No newline at end of file diff --git a/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion13.json b/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion13.json index 71a770a86a9..54963fe372a 100644 --- a/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion13.json +++ b/shortcircuit-api/src/test/resources/ShortCircuitParametersVersion13.json @@ -11,6 +11,12 @@ "withShuntCompensators" : true, "withVSCConverterStations" : true, "withNeutralPosition" : false, - "initialVoltageProfileMode" : "NOMINAL", - "detailedReport" : false + "initialVoltageProfileMode" : "CONFIGURED", + "detailedReport" : false, + "voltageRanges" : [ { + "minimumNominalVoltage" : 380.0, + "maximumNominalVoltage" : 410.0, + "voltageRangeCoefficient" : 1.05, + "voltage" : 380.0 + } ] } \ No newline at end of file diff --git a/shortcircuit-api/src/test/resources/ShortCircuitParametersWithRangeVoltage.json b/shortcircuit-api/src/test/resources/ShortCircuitParametersWithRangeVoltage.json new file mode 100644 index 00000000000..5f2740a1e03 --- /dev/null +++ b/shortcircuit-api/src/test/resources/ShortCircuitParametersWithRangeVoltage.json @@ -0,0 +1,26 @@ +{ + "version" : "1.3", + "withLimitViolations" : true, + "withVoltageResult" : true, + "withFeederResult" : true, + "studyType" : "TRANSIENT", + "minVoltageDropProportionalThreshold" : 0.0, + "withFortescueResult" : true, + "withLoads" : true, + "withShuntCompensators" : true, + "withVSCConverterStations" : true, + "withNeutralPosition" : false, + "initialVoltageProfileMode" : "CONFIGURED", + "voltageRanges" : [ { + "minimumNominalVoltage" : 0.0, + "maximumNominalVoltage" : 100.0, + "voltageRangeCoefficient" : 0.95, + "voltage" : 100.0 + }, { + "minimumNominalVoltage" : 101.0, + "maximumNominalVoltage" : 150.0, + "voltageRangeCoefficient" : 1.1, + "voltage" : 140.0 + } ], + "detailedReport" : true +} \ No newline at end of file