From eb16f983b7c1bdbe2d25229ac74e5dda13d58e78 Mon Sep 17 00:00:00 2001 From: VEDELAGO MIORA Date: Tue, 21 Mar 2023 12:59:25 +0100 Subject: [PATCH 1/3] Add scaling parameters to BalanceComputationParameters and adapt to core 5.3.0-SNAPSHOT (prepare to 5.2.0) Signed-off-by: VEDELAGO MIORA --- .../BalanceComputationImpl.java | 7 +-- .../BalanceComputationParameters.java | 59 ++++++++++++++----- ...anceComputationParametersDeserializer.java | 16 ++++- ...alanceComputationParametersSerializer.java | 4 ++ .../BalanceComputationImplDcTest.java | 2 +- .../balanceComputationParameters.json | 13 +++- ...nceComputationParametersWithExtension.json | 13 +++- .../java/com/powsybl/emf/IGMmergeTests.java | 3 +- .../GlskPointScalableConverter.java | 4 +- pom.xml | 2 +- 10 files changed, 91 insertions(+), 32 deletions(-) diff --git a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImpl.java b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImpl.java index 7da31bb6..c3411c63 100644 --- a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImpl.java +++ b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImpl.java @@ -81,12 +81,7 @@ public CompletableFuture run(Network network, String w double asked = entry.getValue(); Scalable scalable = area.getScalable(); - double done = 0; - if (parameters.isLoadPowerFactorConstant()) { - done = scalable.scaleWithConstantPowerFactor(network, balanceOffsets.get(area)); - } else { - done = scalable.scale(network, balanceOffsets.get(area)); - } + double done = scalable.scale(network, balanceOffsets.get(area), parameters.getScalingParameters()); LOGGER.info("Scaling for area {}: asked={}, done={}", area.getName(), asked, done); } diff --git a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java index 28409bfd..2cd4003a 100644 --- a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java +++ b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java @@ -6,13 +6,17 @@ */ package com.powsybl.balances_adjustment.balance_computation; -import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.powsybl.commons.config.PlatformConfig; -import com.powsybl.commons.extensions.*; +import com.powsybl.commons.extensions.AbstractExtendable; +import com.powsybl.commons.extensions.Extension; +import com.powsybl.commons.extensions.ExtensionConfigLoader; +import com.powsybl.commons.extensions.ExtensionProviders; +import com.powsybl.iidm.modification.scalable.ScalingParameters; import com.powsybl.loadflow.LoadFlowParameters; import java.util.Objects; +import java.util.function.Supplier; /** * parameters for balance computation. @@ -22,9 +26,10 @@ */ public class BalanceComputationParameters extends AbstractExtendable { + public static final String VERSION = "1.1"; + public static final double DEFAULT_THRESHOLD_NET_POSITION = 1; public static final int DEFAULT_MAX_NUMBER_ITERATIONS = 5; - public static final boolean DEFAULT_LOAD_POWER_FACTOR_CONSTANT = false; /** * Threshold for comparing net positions (given in MW). @@ -37,13 +42,11 @@ public class BalanceComputationParameters extends AbstractExtendable parameters.setMaxNumberIterations(config.getIntProperty("maxNumberIterations", DEFAULT_MAX_NUMBER_ITERATIONS)) + .setThresholdNetPosition(config.getDoubleProperty("thresholdNetPosition", DEFAULT_THRESHOLD_NET_POSITION))); parameters.readExtensions(platformConfig); parameters.setLoadFlowParameters(LoadFlowParameters.load(platformConfig)); + parameters.setScalingParameters(ScalingParameters.load(platformConfig)); return parameters; } private void readExtensions(PlatformConfig platformConfig) { - for (ExtensionConfigLoader provider : SUPPLIER.get().getProviders()) { + for (ConfigLoader provider : SUPPLIER.get().getProviders()) { addExtension(provider.getExtensionClass(), provider.load(platformConfig)); } } diff --git a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersDeserializer.java b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersDeserializer.java index 6d344179..77cbe6ef 100644 --- a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersDeserializer.java +++ b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersDeserializer.java @@ -13,6 +13,7 @@ import com.powsybl.balances_adjustment.balance_computation.BalanceComputationParameters; import com.powsybl.commons.extensions.Extension; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.iidm.modification.scalable.json.JsonScalingParameters; import com.powsybl.loadflow.json.JsonLoadFlowParameters; import java.io.IOException; @@ -24,6 +25,8 @@ */ public class BalanceComputationParametersDeserializer extends StdDeserializer { + private static final String CONTEXT_NAME = "BalanceComputationParameters"; + BalanceComputationParametersDeserializer() { super(BalanceComputationParameters.class); } @@ -35,10 +38,15 @@ public BalanceComputationParameters deserialize(JsonParser parser, Deserializati @Override public BalanceComputationParameters deserialize(JsonParser parser, DeserializationContext deserializationContext, BalanceComputationParameters parameters) throws IOException { - + String version = "1.0"; // when no version specified, considered 1.0 (version was not serialized in 1.0) List> extensions = Collections.emptyList(); while (parser.nextToken() != JsonToken.END_OBJECT) { switch (parser.getCurrentName()) { + case "version": + parser.nextToken(); + version = parser.getValueAsString(); + break; + case "maxNumberIterations": parser.nextToken(); parameters.setMaxNumberIterations(parser.readValueAs(int.class)); @@ -54,6 +62,12 @@ public BalanceComputationParameters deserialize(JsonParser parser, Deserializati JsonLoadFlowParameters.deserialize(parser, deserializationContext, parameters.getLoadFlowParameters()); break; + case "scaling-parameters": + JsonUtil.assertGreaterOrEqualThanReferenceVersion(CONTEXT_NAME, "Tag: scaling-parameters", version, "1.1"); + parser.nextToken(); + JsonScalingParameters.deserialize(parser, deserializationContext, parameters.getScalingParameters()); + break; + case "extensions": parser.nextToken(); extensions = JsonUtil.readExtensions(parser, deserializationContext, JsonBalanceComputationParameters.getExtensionSerializers()); diff --git a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersSerializer.java b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersSerializer.java index 8f2d96de..9873555f 100644 --- a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersSerializer.java +++ b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/json_parameters/BalanceComputationParametersSerializer.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.powsybl.balances_adjustment.balance_computation.BalanceComputationParameters; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.iidm.modification.scalable.json.JsonScalingParameters; import com.powsybl.loadflow.json.JsonLoadFlowParameters; import java.io.IOException; @@ -28,10 +29,13 @@ public void serialize(BalanceComputationParameters parameters, JsonGenerator jso jsonGenerator.writeStartObject(); + jsonGenerator.writeStringField("version", BalanceComputationParameters.VERSION); jsonGenerator.writeNumberField("maxNumberIterations", parameters.getMaxNumberIterations()); jsonGenerator.writeNumberField("thresholdNetPosition", parameters.getThresholdNetPosition()); jsonGenerator.writeFieldName("load-flow-parameters"); JsonLoadFlowParameters.serialize(parameters.getLoadFlowParameters(), jsonGenerator, serializerProvider); + jsonGenerator.writeFieldName("scaling-parameters"); + JsonScalingParameters.serialize(parameters.getScalingParameters(), jsonGenerator, serializerProvider); JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonBalanceComputationParameters.getExtensionSerializers()); diff --git a/balances-adjustment/src/test/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImplDcTest.java b/balances-adjustment/src/test/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImplDcTest.java index b2893f4a..6b533998 100644 --- a/balances-adjustment/src/test/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImplDcTest.java +++ b/balances-adjustment/src/test/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationImplDcTest.java @@ -137,7 +137,7 @@ void testUnBalancedNetwork() { @Test void testConstantPowerFactor() { - parameters.setLoadPowerFactorConstant(true); + parameters.getScalingParameters().setConstantPowerFactor(true); List areas = new ArrayList<>(); areas.add(new BalanceComputationArea("FR", countryAreaFR, scalableFR, 1200.)); areas.add(new BalanceComputationArea("BE", countryAreaBE, scalableBE, 1300.)); diff --git a/balances-adjustment/src/test/resources/balanceComputationParameters.json b/balances-adjustment/src/test/resources/balanceComputationParameters.json index 9e886efc..5800ceb7 100644 --- a/balances-adjustment/src/test/resources/balanceComputationParameters.json +++ b/balances-adjustment/src/test/resources/balanceComputationParameters.json @@ -1,8 +1,9 @@ { + "version" : "1.1", "maxNumberIterations" : 11, "thresholdNetPosition" : 2.0, "load-flow-parameters" : { - "version" : "1.8", + "version" : "1.9", "voltageInitMode" : "DC_VALUES", "transformerVoltageControlOn" : true, "phaseShifterRegulationOn" : true, @@ -17,6 +18,14 @@ "dcUseTransformerRatio" : true, "countriesToBalance" : [ ], "connectedComponentMode" : "MAIN", - "hvdcAcEmulation" : true + "hvdcAcEmulation" : true, + "dcPowerFactor" : 1.0 + }, + "scaling-parameters" : { + "version" : "1.0", + "scalingConvention" : "GENERATOR", + "constantPowerFactor" : false, + "reconnect" : false, + "iterative" : false } } \ No newline at end of file diff --git a/balances-adjustment/src/test/resources/balanceComputationParametersWithExtension.json b/balances-adjustment/src/test/resources/balanceComputationParametersWithExtension.json index ecc439f3..ba2cb142 100755 --- a/balances-adjustment/src/test/resources/balanceComputationParametersWithExtension.json +++ b/balances-adjustment/src/test/resources/balanceComputationParametersWithExtension.json @@ -1,8 +1,9 @@ { + "version" : "1.1", "maxNumberIterations" : 5, "thresholdNetPosition" : 1.0, "load-flow-parameters" : { - "version" : "1.8", + "version" : "1.9", "voltageInitMode" : "UNIFORM_VALUES", "transformerVoltageControlOn" : false, "phaseShifterRegulationOn" : false, @@ -17,7 +18,15 @@ "dcUseTransformerRatio" : true, "countriesToBalance" : [ ], "connectedComponentMode" : "MAIN", - "hvdcAcEmulation" : true + "hvdcAcEmulation" : true, + "dcPowerFactor" : 1.0 + }, + "scaling-parameters" : { + "version" : "1.0", + "scalingConvention" : "GENERATOR", + "constantPowerFactor" : false, + "reconnect" : false, + "iterative" : false }, "extensions" : { "dummy-extension" : { } diff --git a/emf/src/test/java/com/powsybl/emf/IGMmergeTests.java b/emf/src/test/java/com/powsybl/emf/IGMmergeTests.java index 8b00956c..0a485ae5 100644 --- a/emf/src/test/java/com/powsybl/emf/IGMmergeTests.java +++ b/emf/src/test/java/com/powsybl/emf/IGMmergeTests.java @@ -162,8 +162,7 @@ void cgmToCgmes() throws IOException { Set generatorsId = new HashSet<>(); Set voltageLevelIds = new HashSet<>(); - //networkBENL.getBranches().forEach(b -> branchIds.add(b.getId())); - networkBENL.getBranches().forEach(b -> branchIds.add(b.getId().replace(" ", "%20"))); // FIXME workaround before fixing CGMES export/import + networkBENL.getBranches().forEach(b -> branchIds.add(b.getId())); networkBENL.getGenerators().forEach(g -> generatorsId.add(g.getId())); networkBENL.getVoltageLevels().forEach(v -> voltageLevelIds.add(v.getId())); diff --git a/glsk/glsk-document-api/src/main/java/com/powsybl/glsk/api/util/converters/GlskPointScalableConverter.java b/glsk/glsk-document-api/src/main/java/com/powsybl/glsk/api/util/converters/GlskPointScalableConverter.java index a4ffb853..23af8408 100644 --- a/glsk/glsk-document-api/src/main/java/com/powsybl/glsk/api/util/converters/GlskPointScalableConverter.java +++ b/glsk/glsk-document-api/src/main/java/com/powsybl/glsk/api/util/converters/GlskPointScalableConverter.java @@ -68,7 +68,7 @@ public static Scalable convert(Network network, List shiftKeys) { throw new GlskException("In convert glskShiftKey business type not supported"); } } - return Scalable.proportional(percentages, scalables, true); + return Scalable.proportional(percentages, scalables); // iterative must be set in scalingParameters during scale } private static void convertRemainingCapacity(Network network, GlskShiftKey glskShiftKey, List percentages, List scalables) { @@ -97,7 +97,7 @@ private static Scalable createRemainingCapacityScalable(Network network, GlskShi scalables.add(getGeneratorScalableWithLimits(network, generatorResource)); } }); - return Scalable.proportional(percentages, scalables, true); + return Scalable.proportional(percentages, scalables); // iterative must be set in scalingParameters during scale } private static double getRemainingCapacityUp(GlskRegisteredResource resource, Network network) { diff --git a/pom.xml b/pom.xml index 53c94532..3f6994ef 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 11 - 5.2.0-alpha-1 + 5.3.0-SNAPSHOT 1.0.0 ../distribution-entsoe/target/site/jacoco-aggregate/jacoco.xml, From 8639a6a0154aea11b6488ecd5e32f8d08ac96a4c Mon Sep 17 00:00:00 2001 From: VEDELAGO MIORA Date: Tue, 21 Mar 2023 13:24:26 +0100 Subject: [PATCH 2/3] Add tag "since" to deprecated methods and constructor Signed-off-by: VEDELAGO MIORA --- .../balance_computation/BalanceComputationParameters.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java index 2cd4003a..c5bfe250 100644 --- a/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java +++ b/balances-adjustment/src/main/java/com/powsybl/balances_adjustment/balance_computation/BalanceComputationParameters.java @@ -62,7 +62,7 @@ public BalanceComputationParameters(double threshold, int maxNumberIterations) { /** * @deprecated Use {@link #BalanceComputationParameters()} or {@link #BalanceComputationParameters(double, int)} instead. */ - @Deprecated + @Deprecated(since = "2.3.0") public BalanceComputationParameters(double threshold, int maxNumberIterations, boolean loadPowerFactorConstant) { this(threshold, maxNumberIterations); scalingParameters.setConstantPowerFactor(loadPowerFactorConstant); @@ -94,7 +94,7 @@ public BalanceComputationParameters setScalingParameters(ScalingParameters scali /** * @deprecated Use {@link #getScalingParameters()} and {@link ScalingParameters#isConstantPowerFactor()} instead. */ - @Deprecated + @Deprecated(since = "2.3.0") public boolean isLoadPowerFactorConstant() { return scalingParameters.isConstantPowerFactor(); } @@ -102,7 +102,7 @@ public boolean isLoadPowerFactorConstant() { /** * @deprecated Use {@link #getScalingParameters()} and {@link ScalingParameters#setConstantPowerFactor(boolean)} instead. */ - @Deprecated + @Deprecated(since = "2.3.0") public void setLoadPowerFactorConstant(boolean loadPowerFactorConstant) { this.scalingParameters.setConstantPowerFactor(loadPowerFactorConstant); } From 9adc55f11543c0bc5e1e6b6f7e353a69e0f7a17e Mon Sep 17 00:00:00 2001 From: VEDELAGO MIORA Date: Fri, 31 Mar 2023 10:57:32 +0200 Subject: [PATCH 3/3] Bump core to 5.2.0 Signed-off-by: VEDELAGO MIORA --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3f6994ef..041ae492 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 11 - 5.3.0-SNAPSHOT + 5.2.0 1.0.0 ../distribution-entsoe/target/site/jacoco-aggregate/jacoco.xml,