From 911623d649e8cdba680d886c5e58e7f747121714 Mon Sep 17 00:00:00 2001 From: lisrte Date: Mon, 7 Oct 2024 15:34:46 +0200 Subject: [PATCH] Use default side TwoSides.TWO for dangling hvdc model Nullify dangling side setting in HVDC builder Signed-off-by: lisrte --- .../dynawo/dsl/DynamicModelsSupplierTest.java | 8 ---- .../resources/warnings/missingDangling.groovy | 15 ------- .../dynawo/builders/BuilderReports.java | 9 ++++ .../models/hvdc/AbstractHvdcBuilder.java | 9 ++-- .../com/powsybl/dynawo/models/HvdcTest.java | 42 ++++++++++++++----- .../xml/DisconnectHvdcEventXmlTest.java | 4 +- .../xml/DisconnectionExceptionXmlTest.java | 4 +- .../com/powsybl/dynawo/xml/HvdcXmlTest.java | 3 -- .../disconnect_hvdc_vsc_dangling_dyd.xml | 16 +++---- .../test/resources/hvdc_p_dangling_dyd.xml | 10 ++--- 10 files changed, 62 insertions(+), 58 deletions(-) delete mode 100644 dynawo-dsl/src/test/resources/warnings/missingDangling.groovy diff --git a/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/DynamicModelsSupplierTest.java b/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/DynamicModelsSupplierTest.java index 3086f7de0..7b81ccb65 100644 --- a/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/DynamicModelsSupplierTest.java +++ b/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/DynamicModelsSupplierTest.java @@ -183,14 +183,6 @@ private static Stream provideWarningsModel() { 'dynamicModelId' field is not set, staticId GEN will be used instead Model GEN cannot be instantiated """), - Arguments.of("/warnings/missingDangling.groovy", HvdcTestNetwork.createVsc(), - """ - + DSL tests - + Groovy Dynamic Models Supplier - + DSL model builder for HvdcPVDangling - 'dangling' field is not set - Model BBM_HVDC_L cannot be instantiated - """), Arguments.of("/warnings/missingDanglingProperty.groovy", HvdcTestNetwork.createVsc(), """ + DSL tests diff --git a/dynawo-dsl/src/test/resources/warnings/missingDangling.groovy b/dynawo-dsl/src/test/resources/warnings/missingDangling.groovy deleted file mode 100644 index c020950cf..000000000 --- a/dynawo-dsl/src/test/resources/warnings/missingDangling.groovy +++ /dev/null @@ -1,15 +0,0 @@ -/** - * 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 warnings - -HvdcPVDangling { - staticId "L" - dynamicModelId "BBM_HVDC_L" - parameterSetId "HVDC" -} diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/builders/BuilderReports.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/builders/BuilderReports.java index e3a408961..196edbeed 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/builders/BuilderReports.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/builders/BuilderReports.java @@ -138,6 +138,15 @@ public static void reportFieldSetWithWrongEquipment(ReportNode reportNode, Strin .add(); } + public static void reportFieldOptionNotImplemented(ReportNode reportNode, String fieldName, String defaultValue) { + reportNode.newReportNode() + .withMessageTemplate("fieldOptionNotImplemented", "'${fieldName}' field is set but this option is not implemented yet, default value ${defaultValue} will be used") + .withUntypedValue(FIELD_NAME, fieldName) + .withUntypedValue("defaultValue", defaultValue) + .withSeverity(TypedValue.WARN_SEVERITY) + .add(); + } + public static void reportFieldConflict(ReportNode reportNode, String firstFieldName, String secondFieldName) { reportNode.newReportNode() .withMessageTemplate("fieldConflict", "Both '${firstFieldName}' and '${secondFieldName}' are defined, '${firstFieldName}' will be used") diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/hvdc/AbstractHvdcBuilder.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/hvdc/AbstractHvdcBuilder.java index c69818ced..e7f962d9f 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/hvdc/AbstractHvdcBuilder.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/hvdc/AbstractHvdcBuilder.java @@ -20,6 +20,8 @@ */ public abstract class AbstractHvdcBuilder> extends AbstractEquipmentModelBuilder { + private static final TwoSides DEFAULT_DANGLING_SIDE = TwoSides.TWO; + protected TwoSides danglingSide; private final Function eventVarNameSupplier; @@ -44,9 +46,8 @@ public R dangling(TwoSides danglingSide) { protected void checkData() { super.checkData(); boolean isDangling = modelConfig.isDangling(); - if (isDangling && danglingSide == null) { - BuilderReports.reportFieldNotSet(reportNode, "dangling"); - isInstantiable = false; + if (isDangling && danglingSide != null) { + BuilderReports.reportFieldOptionNotImplemented(reportNode, "dangling", DEFAULT_DANGLING_SIDE.toString()); } else if (!isDangling && danglingSide != null) { BuilderReports.reportFieldSetWithWrongEquipment(reportNode, "dangling", modelConfig.lib()); isInstantiable = false; @@ -57,7 +58,7 @@ protected void checkData() { public BaseHvdc build() { if (isInstantiable()) { if (modelConfig.isDangling()) { - return new HvdcDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), eventVarNameSupplier, danglingSide); + return new HvdcDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), eventVarNameSupplier, DEFAULT_DANGLING_SIDE); } else { return new BaseHvdc(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), eventVarNameSupplier); } diff --git a/dynawo-simulation/src/test/java/com/powsybl/dynawo/models/HvdcTest.java b/dynawo-simulation/src/test/java/com/powsybl/dynawo/models/HvdcTest.java index 16c097248..96434ec4b 100644 --- a/dynawo-simulation/src/test/java/com/powsybl/dynawo/models/HvdcTest.java +++ b/dynawo-simulation/src/test/java/com/powsybl/dynawo/models/HvdcTest.java @@ -7,6 +7,7 @@ */ package com.powsybl.dynawo.models; +import com.powsybl.commons.report.ReportNode; import com.powsybl.dynawo.models.hvdc.HvdcPBuilder; import com.powsybl.dynawo.models.hvdc.HvdcVscBuilder; import com.powsybl.dynawo.models.hvdc.BaseHvdc; @@ -16,6 +17,9 @@ import com.powsybl.iidm.network.test.HvdcTestNetwork; import org.junit.jupiter.api.Test; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -39,21 +43,10 @@ void testConnectedStation() { void testDanglingConnectedStation() { Network network = HvdcTestNetwork.createVsc(); HvdcLine line = network.getHvdcLine("L"); - - BaseHvdc hvdcPDangling = HvdcPBuilder.of(network, "HvdcPVDangling") - .dynamicModelId("hvdc") - .staticId("L") - .parameterSetId("HVDC") - .dangling(TwoSides.ONE) - .build(); - assertEquals(1, hvdcPDangling.getConnectedStations().size()); - assertEquals(line.getConverterStation2(), hvdcPDangling.getConnectedStations().get(0)); - BaseHvdc hvdcVscDangling = HvdcVscBuilder.of(network, "HvdcVSCDanglingP") .dynamicModelId("hvdc") .staticId("L") .parameterSetId("HVDC") - .dangling(TwoSides.TWO) .build(); assertEquals(1, hvdcVscDangling.getConnectedStations().size()); assertEquals(line.getConverterStation1(), hvdcVscDangling.getConnectedStations().get(0)); @@ -68,4 +61,31 @@ void vscDynamicModelOnLCC() { .parameterSetId("HVDC") .build()); } + + @Test + void testDefaultDanglingSide() { + ReportNode reportNode = ReportNode.newRootReportNode() + .withMessageTemplate("hvdcBuilder", "HVDC builder") + .build(); + Network network = HvdcTestNetwork.createVsc(); + HvdcLine line = network.getHvdcLine("L"); + + // dangling side ONE replaced by side TWO + BaseHvdc hvdcPDangling = Objects.requireNonNull( + HvdcPBuilder.of(network, "HvdcPVDangling", reportNode)) + .dynamicModelId("hvdc") + .staticId("L") + .parameterSetId("HVDC") + .dangling(TwoSides.ONE) + .build(); + assertEquals(1, hvdcPDangling.getConnectedStations().size()); + assertEquals(line.getConverterStation1(), hvdcPDangling.getConnectedStations().get(0)); + assertThat(reportNode.getChildren().stream() + .filter(r -> r.getMessageKey().equalsIgnoreCase("fieldOptionNotImplemented")) + .findFirst()) + .isNotEmpty() + .get() + .hasFieldOrPropertyWithValue("message", + "'dangling' field is set but this option is not implemented yet, default value TWO will be used"); + } } diff --git a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectHvdcEventXmlTest.java b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectHvdcEventXmlTest.java index 5b5a0f22d..fd1cf22ea 100644 --- a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectHvdcEventXmlTest.java +++ b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectHvdcEventXmlTest.java @@ -109,12 +109,12 @@ private static Stream provideModels() { .dynamicModelId(DYN_HVDC_NAME) .staticId(HVDC_NAME) .parameterSetId("hvdc") - .dangling(TwoSides.ONE) + .dangling(TwoSides.TWO) .build(), (Function) n -> EventDisconnectionBuilder.of(n) .staticId(HVDC_NAME) .startTime(1) - .disconnectOnly(TwoSides.TWO) + .disconnectOnly(TwoSides.ONE) .build()) ); } diff --git a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectionExceptionXmlTest.java b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectionExceptionXmlTest.java index a61baa03a..605ca2ce7 100644 --- a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectionExceptionXmlTest.java +++ b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectionExceptionXmlTest.java @@ -61,8 +61,8 @@ void disconnectionOnDanglingSide(String exception, TwoSides side, BiFunction provideModels() { return Stream.of( - Arguments.of("Equipment HvdcPVDangling side 1 is dangling and can't be disconnected with an event", - TwoSides.ONE, + Arguments.of("Equipment HvdcPVDangling side 2 is dangling and can't be disconnected with an event", + TwoSides.TWO, (BiFunction) (network, side) -> HvdcPBuilder.of(network, "HvdcPVDangling") .dynamicModelId("BBM_L") .staticId("L") diff --git a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/HvdcXmlTest.java b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/HvdcXmlTest.java index 96624d6cf..23f3214a4 100644 --- a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/HvdcXmlTest.java +++ b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/HvdcXmlTest.java @@ -11,7 +11,6 @@ import com.powsybl.dynawo.models.hvdc.HvdcVscBuilder; import com.powsybl.dynawo.models.BlackBoxModel; import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.test.HvdcTestNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -71,13 +70,11 @@ private static Stream provideHvdc() { .dynamicModelId(DYN_NAME) .staticId(HVDC_NAME) .parameterSetId("hv") - .dangling(TwoSides.ONE) .build()), Arguments.of("hvdc_vsc_dangling_dyd.xml", (Function) n -> HvdcVscBuilder.of(n, "HvdcVSCDanglingP") .dynamicModelId(DYN_NAME) .staticId(HVDC_NAME) .parameterSetId("hv") - .dangling(TwoSides.TWO) .build()) ); } diff --git a/dynawo-simulation/src/test/resources/disconnect_hvdc_vsc_dangling_dyd.xml b/dynawo-simulation/src/test/resources/disconnect_hvdc_vsc_dangling_dyd.xml index 54440fb29..0051da1f7 100644 --- a/dynawo-simulation/src/test/resources/disconnect_hvdc_vsc_dangling_dyd.xml +++ b/dynawo-simulation/src/test/resources/disconnect_hvdc_vsc_dangling_dyd.xml @@ -4,15 +4,15 @@ - - - - - - + + + + + + @@ -22,7 +22,7 @@ - - + + diff --git a/dynawo-simulation/src/test/resources/hvdc_p_dangling_dyd.xml b/dynawo-simulation/src/test/resources/hvdc_p_dangling_dyd.xml index 339f38446..40e685e5c 100644 --- a/dynawo-simulation/src/test/resources/hvdc_p_dangling_dyd.xml +++ b/dynawo-simulation/src/test/resources/hvdc_p_dangling_dyd.xml @@ -3,12 +3,12 @@ - - - - + + + + @@ -18,6 +18,6 @@ - +