From e129426591081de0a3fd0220918a51d0a45af84f Mon Sep 17 00:00:00 2001 From: Lisrte Date: Thu, 12 Dec 2024 12:47:09 +0100 Subject: [PATCH] Add disconnection event for bus (#408) * Add disconnection event for bus * Add DSA integration test with divergence * Allow divergent ScenarioResult to have failed criteria Signed-off-by: lisrte --- docs/dynamic_simulation/event-models-dsl.md | 2 +- .../powsybl/dynaflow/results/ResultsUtil.java | 6 +- .../dynawo/dsl/EventModelsSupplierTest.java | 4 +- .../missingDisconnectionEquipment.groovy | 2 +- .../dynawo/it/DynawoSecurityAnalysisTest.java | 12 ++- .../divergence/criteria.crt | 34 +++++++ .../divergence/results.json | 57 ++++++++++++ .../dynawo/DynawoSimulationReports.java | 11 +++ .../dynawo/models/buses/AbstractBus.java | 5 + .../models/buses/ActionConnectionPoint.java | 2 + .../buses/DefaultActionConnectionPoint.java | 5 + .../AbstractDynamicLibEventDisconnection.java | 6 +- .../models/events/EventBusDisconnection.java | 93 +++++++++++++++++++ .../events/EventDisconnectionBuilder.java | 25 +++-- .../dynawo/xml/DisconnectBusEventXmlTest.java | 43 +++++++++ .../xml/DisconnectDynamicBusEventXmlTest.java | 61 ++++++++++++ .../src/test/resources/disconnect_bus_dyd.xml | 8 ++ .../src/test/resources/disconnect_bus_par.xml | 7 ++ .../resources/disconnect_dynamic_bus_dyd.xml | 40 ++++++++ .../resources/disconnect_dynamic_bus_par.xml | 2 + .../src/test/resources/parameters.xsd | 28 ++++-- 21 files changed, 422 insertions(+), 31 deletions(-) create mode 100644 dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/criteria.crt create mode 100644 dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/results.json create mode 100644 dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventBusDisconnection.java create mode 100644 dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectBusEventXmlTest.java create mode 100644 dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectDynamicBusEventXmlTest.java create mode 100644 dynawo-simulation/src/test/resources/disconnect_bus_dyd.xml create mode 100644 dynawo-simulation/src/test/resources/disconnect_bus_par.xml create mode 100644 dynawo-simulation/src/test/resources/disconnect_dynamic_bus_dyd.xml create mode 100644 dynawo-simulation/src/test/resources/disconnect_dynamic_bus_par.xml diff --git a/docs/dynamic_simulation/event-models-dsl.md b/docs/dynamic_simulation/event-models-dsl.md index d0b8b2a95..cf4ec7557 100644 --- a/docs/dynamic_simulation/event-models-dsl.md +++ b/docs/dynamic_simulation/event-models-dsl.md @@ -9,7 +9,7 @@ The Event Models DSL is a domain specific language written in groovy for the sim - `startTime` defines when the event starts. ## Disconnect -Use this event to disconnect a branch, injection or an HVDC line. +Use this event to disconnect a bus, branch, injection or an HVDC line. **Example** ```groovy diff --git a/dynaflow/src/main/java/com/powsybl/dynaflow/results/ResultsUtil.java b/dynaflow/src/main/java/com/powsybl/dynaflow/results/ResultsUtil.java index 8840f8e8d..5cb8fe3b5 100644 --- a/dynaflow/src/main/java/com/powsybl/dynaflow/results/ResultsUtil.java +++ b/dynaflow/src/main/java/com/powsybl/dynaflow/results/ResultsUtil.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Optional; +import static com.powsybl.dynaflow.results.Status.CONVERGENCE; import static com.powsybl.dynaflow.results.Status.CRITERIA_NON_RESPECTED; import static com.powsybl.security.PostContingencyComputationStatus.*; @@ -41,11 +42,10 @@ static Optional createScenarioResult(String id, String status, L } else { try { Status statusE = Status.valueOf(status); - boolean isCriterionError = CRITERIA_NON_RESPECTED == statusE; - if (isCriterionError && failedCriteria.isEmpty()) { + if (CRITERIA_NON_RESPECTED == statusE && failedCriteria.isEmpty()) { LOGGER.warn("ScenarioResult with {} status should have failed criteria", status); return Optional.empty(); - } else if (!isCriterionError && !failedCriteria.isEmpty()) { + } else if (CONVERGENCE == statusE && !failedCriteria.isEmpty()) { LOGGER.warn("ScenarioResult with {} status should not have failed criteria", status); return Optional.empty(); } diff --git a/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/EventModelsSupplierTest.java b/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/EventModelsSupplierTest.java index 0f8a742ec..867e96493 100644 --- a/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/EventModelsSupplierTest.java +++ b/dynawo-dsl/src/test/java/com/powsybl/dynawo/dsl/EventModelsSupplierTest.java @@ -125,8 +125,8 @@ faultTime should be strictly positive (0.0) + DSL tests + Groovy Event Models Supplier + DSL model builder for Disconnect - 'staticId' field value 'NGEN' not found for equipment type(s) Disconnectable equipment - Model Disconnect_NGEN cannot be instantiated + 'staticId' field value 'WRONG_ID' not found for equipment type(s) Disconnectable equipment + Model Disconnect_WRONG_ID cannot be instantiated """), Arguments.of("/eventWarnings/missingDisconnectionSide.groovy", EurostagTutorialExample1Factory.create(), """ diff --git a/dynawo-dsl/src/test/resources/eventWarnings/missingDisconnectionEquipment.groovy b/dynawo-dsl/src/test/resources/eventWarnings/missingDisconnectionEquipment.groovy index 855b9cda9..c0fe7b68e 100644 --- a/dynawo-dsl/src/test/resources/eventWarnings/missingDisconnectionEquipment.groovy +++ b/dynawo-dsl/src/test/resources/eventWarnings/missingDisconnectionEquipment.groovy @@ -9,6 +9,6 @@ package eventWarnings Disconnect { - staticId "NGEN" + staticId "WRONG_ID" startTime 1 } diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSecurityAnalysisTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSecurityAnalysisTest.java index 7d65e480c..48d24286a 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSecurityAnalysisTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynawoSecurityAnalysisTest.java @@ -107,11 +107,19 @@ void testIeee14DSA(String criteriaPath, List contingencies, String private static Stream provideSimulationParameter() { return Stream.of( Arguments.of("/ieee14/dynamic-security-analysis/convergence/criteria.crt", - List.of(Contingency.line("_BUS____1-BUS____5-1_AC"), Contingency.generator("_GEN____2_SM")), + List.of(Contingency.line("_BUS____1-BUS____5-1_AC"), + Contingency.generator("_GEN____2_SM")), "/ieee14/dynamic-security-analysis/convergence/results.json"), Arguments.of("/ieee14/dynamic-security-analysis/failed-criteria/criteria.crt", List.of(Contingency.line("_BUS____1-BUS____5-1_AC")), - "/ieee14/dynamic-security-analysis/failed-criteria/results.json") + "/ieee14/dynamic-security-analysis/failed-criteria/results.json"), + Arguments.of("/ieee14/dynamic-security-analysis/divergence/criteria.crt", + List.of(Contingency.builder("Disconnect") + .addLine("_BUS____1-BUS____5-1_AC") + .addGenerator("_GEN____2_SM") + .addBus("_BUS____1_TN") + .build()), + "/ieee14/dynamic-security-analysis/divergence/results.json") ); } } diff --git a/dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/criteria.crt b/dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/criteria.crt new file mode 100644 index 000000000..763421ea2 --- /dev/null +++ b/dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/criteria.crt @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/results.json b/dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/results.json new file mode 100644 index 000000000..973d7cc56 --- /dev/null +++ b/dynawo-integration-tests/src/test/resources/ieee14/dynamic-security-analysis/divergence/results.json @@ -0,0 +1,57 @@ +{ + "version" : "1.7", + "preContingencyResult" : { + "status" : "CONVERGED", + "limitViolationsResult" : { + "limitViolations" : [ { + "subjectId" : "_BUS____1-BUS____2-1_AC", + "subjectName" : "BUS 1-BUS 2-1", + "limitType" : "CURRENT", + "limitName" : "permanent", + "limit" : 836.74, + "limitReduction" : 1.0, + "value" : 1248.0773003764798, + "side" : "ONE" + } ], + "actionsTaken" : [ ] + }, + "networkResult" : { + "branchResults" : [ ], + "busResults" : [ ], + "threeWindingsTransformerResults" : [ ] + } + }, + "postContingencyResults" : [ { + "contingency" : { + "id" : "Disconnect", + "elements" : [ { + "id" : "_BUS____1-BUS____5-1_AC", + "type" : "LINE" + }, { + "id" : "_GEN____2_SM", + "type" : "GENERATOR" + }, { + "id" : "_BUS____1_TN", + "type" : "BUS" + } ] + }, + "status" : "SOLVER_FAILED", + "limitViolationsResult" : { + "limitViolations" : [ ], + "actionsTaken" : [ ] + }, + "networkResult" : { + "branchResults" : [ ], + "busResults" : [ ], + "threeWindingsTransformerResults" : [ ] + }, + "connectivityResult" : { + "createdSynchronousComponentCount" : 0, + "createdConnectedComponentCount" : 0, + "disconnectedLoadActivePower" : 0.0, + "disconnectedGenerationActivePower" : 0.0, + "disconnectedElements" : [ ] + } + } ], + "operatorStrategyResults" : [ ] +} \ No newline at end of file diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationReports.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationReports.java index fa37b83c9..8b4d749ab 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationReports.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/DynawoSimulationReports.java @@ -102,6 +102,17 @@ public static void reportEmptyListAutomaton(ReportNode reportNode, String automa .add(); } + public static void reportFailedDynamicModelHandling(ReportNode reportNode, String modelName, String dynamicId, String equipmentType) { + reportNode.newReportNode() + .withMessageTemplate("emptyListAutomaton", + "${modelName} ${dynamicId} cannot handle ${equipmentType} dynamic model, the model will be skipped") + .withUntypedValue(MODEL_NAME_FIELD, modelName) + .withUntypedValue(DYNAMIC_ID_FIELD, dynamicId) + .withUntypedValue("equipmentType", equipmentType) + .withSeverity(TypedValue.WARN_SEVERITY) + .add(); + } + public static ReportNode createDynawoSpecificLogReportNode(ReportNode reportNode, DynawoSimulationParameters.SpecificLog logType) { String logTypeName = StringUtils.capitalize(logType.toString().toLowerCase()); return reportNode.newReportNode() diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/AbstractBus.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/AbstractBus.java index e182bdbb6..fca44e487 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/AbstractBus.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/AbstractBus.java @@ -63,4 +63,9 @@ public Optional getUImpinVarName() { public Optional getUpuImpinVarName() { return Optional.empty(); } + + @Override + public Optional getStateValueVarName() { + return Optional.empty(); + } } diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/ActionConnectionPoint.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/ActionConnectionPoint.java index e4da98012..9c2f3504b 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/ActionConnectionPoint.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/ActionConnectionPoint.java @@ -22,4 +22,6 @@ public interface ActionConnectionPoint extends Model { Optional getUImpinVarName(); Optional getUpuImpinVarName(); + + Optional getStateValueVarName(); } diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/DefaultActionConnectionPoint.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/DefaultActionConnectionPoint.java index e3af4ef04..20918a945 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/DefaultActionConnectionPoint.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/buses/DefaultActionConnectionPoint.java @@ -40,4 +40,9 @@ public Optional getUImpinVarName() { public Optional getUpuImpinVarName() { return Optional.of("@NAME@_Upu"); } + + @Override + public Optional getStateValueVarName() { + return Optional.of("@NAME@_state_value"); + } } diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/AbstractDynamicLibEventDisconnection.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/AbstractDynamicLibEventDisconnection.java index 5d54db2b9..a7e0ea6ce 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/AbstractDynamicLibEventDisconnection.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/AbstractDynamicLibEventDisconnection.java @@ -22,11 +22,11 @@ */ public abstract class AbstractDynamicLibEventDisconnection extends AbstractEvent implements ContextDependentEvent { - private static final String DYNAMIC_MODEL_LIB = "EventSetPointBoolean"; - private static final String DEFAULT_MODEL_LIB = "EventConnectedStatus"; + protected static final String DYNAMIC_MODEL_LIB = "EventSetPointBoolean"; + protected static final String DEFAULT_MODEL_LIB = "EventConnectedStatus"; protected static final String DISCONNECTION_VAR_CONNECT = "event_state1"; - private final boolean disconnect; + protected final boolean disconnect; private final ImmutableLateInit equipmentHasDynamicModel = new ImmutableLateInit<>(); protected AbstractDynamicLibEventDisconnection(String eventId, Identifiable equipment, EventModelInfo eventModelInfo, double startTime, boolean disconnect) { diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventBusDisconnection.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventBusDisconnection.java new file mode 100644 index 000000000..3b0a8621f --- /dev/null +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventBusDisconnection.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2024, 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.dynawo.models.events; + +import com.powsybl.dynawo.DynawoSimulationContext; +import com.powsybl.dynawo.DynawoSimulationReports; +import com.powsybl.dynawo.builders.EventModelInfo; +import com.powsybl.dynawo.models.VarConnection; +import com.powsybl.dynawo.models.buses.ActionConnectionPoint; +import com.powsybl.dynawo.models.macroconnections.MacroConnectionsAdder; +import com.powsybl.dynawo.parameters.ParametersSet; +import com.powsybl.iidm.network.Bus; +import com.powsybl.iidm.network.IdentifiableType; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +import static com.powsybl.dynawo.parameters.ParameterType.BOOL; +import static com.powsybl.dynawo.parameters.ParameterType.DOUBLE; + +/** + * @author Laurent Issertial {@literal } + */ +public class EventBusDisconnection extends AbstractEvent implements ContextDependentEvent { + + private final boolean disconnect; + private boolean hasDefaultModel; + + protected EventBusDisconnection(String eventId, Bus equipment, EventModelInfo eventModelInfo, double startTime, boolean disconnect) { + super(eventId, equipment, eventModelInfo, startTime); + this.disconnect = disconnect; + } + + private List getVarConnectionsWith(ActionConnectionPoint connected) { + return connected.getStateValueVarName() + .map(sv -> List.of(new VarConnection("event_state1_value", sv))) + .orElse(Collections.emptyList()); + } + + @Override + public void createMacroConnections(MacroConnectionsAdder adder) { + if (hasDefaultModel) { + adder.createMacroConnections(this, getEquipment(), ActionConnectionPoint.class, this::getVarConnectionsWith); + } else { + DynawoSimulationReports.reportFailedDynamicModelHandling(adder.getReportNode(), getName(), getDynamicModelId(), IdentifiableType.BUS.toString()); + } + } + + @Override + public String getLib() { + return "EventConnectedStatus"; + } + + @Override + public String getName() { + return getClass().getSimpleName(); + } + + @Override + public void createDynamicModelParameters(DynawoSimulationContext context, Consumer parametersAdder) { + if (hasDefaultModel) { + ParametersSet paramSet = new ParametersSet(getParameterSetId()); + createEventSpecificParameters(paramSet); + parametersAdder.accept(paramSet); + } + } + + @Override + protected void createEventSpecificParameters(ParametersSet paramSet) { + paramSet.addParameter("event_tEvent", DOUBLE, Double.toString(getStartTime())); + paramSet.addParameter("event_open", BOOL, Boolean.toString(disconnect)); + } + + @Override + public final void setEquipmentHasDynamicModel(DynawoSimulationContext context) { + hasDefaultModel = !hasDynamicModel(context); + } + + @Override + public void write(XMLStreamWriter writer, String parFileName) throws XMLStreamException { + if (hasDefaultModel) { + super.write(writer, parFileName); + } + } +} diff --git a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventDisconnectionBuilder.java b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventDisconnectionBuilder.java index 88e88cbbe..590243efe 100644 --- a/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventDisconnectionBuilder.java +++ b/dynawo-simulation/src/main/java/com/powsybl/dynawo/models/events/EventDisconnectionBuilder.java @@ -15,18 +15,15 @@ import com.powsybl.dynawo.commons.DynawoVersion; import com.powsybl.iidm.network.*; -import java.util.EnumSet; - /** * @author Laurent Issertial {@literal } */ public class EventDisconnectionBuilder extends AbstractEventModelBuilder, EventDisconnectionBuilder> { - private static final EventModelInfo MODEL_INFO = new EventModelInfo("Disconnect", "Disconnect network equipment (injection, branch or hvdc)"); - private static final EnumSet CONNECTABLE_INJECTIONS = EnumSet.of(IdentifiableType.GENERATOR, IdentifiableType.LOAD, IdentifiableType.STATIC_VAR_COMPENSATOR, IdentifiableType.SHUNT_COMPENSATOR); - private static final EnumSet CONNECTABLE_BRANCHES = EnumSet.of(IdentifiableType.LINE, IdentifiableType.TWO_WINDINGS_TRANSFORMER); + private static final EventModelInfo MODEL_INFO = new EventModelInfo("Disconnect", "Disconnect network equipment (bus, injection, branch or hvdc)"); private enum DisconnectionType { + BUS, INJECTION, BRANCH, HVDC, @@ -65,13 +62,13 @@ public EventDisconnectionBuilder disconnectOnly(TwoSides side) { } private void setDisconnectionType(IdentifiableType type) { - if (CONNECTABLE_INJECTIONS.contains(type)) { - disconnectionType = DisconnectionType.INJECTION; - } else if (CONNECTABLE_BRANCHES.contains(type)) { - disconnectionType = DisconnectionType.BRANCH; - } else if (IdentifiableType.HVDC_LINE == type) { - disconnectionType = DisconnectionType.HVDC; - } + disconnectionType = switch (type) { + case BUS -> DisconnectionType.BUS; + case HVDC_LINE -> DisconnectionType.HVDC; + case GENERATOR, LOAD, STATIC_VAR_COMPENSATOR, SHUNT_COMPENSATOR -> DisconnectionType.INJECTION; + case LINE, TWO_WINDINGS_TRANSFORMER -> DisconnectionType.BRANCH; + default -> DisconnectionType.NONE; + }; } @Override @@ -93,7 +90,7 @@ protected void checkData() { BuilderReports.reportStaticIdUnknown(reportNode, "staticId", builderEquipment.getStaticId(), "Disconnectable equipment"); isInstantiable = false; } - if (DisconnectionType.INJECTION == disconnectionType && disconnectSide != null) { + if ((DisconnectionType.INJECTION == disconnectionType || DisconnectionType.BUS == disconnectionType) && disconnectSide != null) { BuilderReports.reportFieldSetWithWrongEquipment(reportNode, "disconnectOnly", builderEquipment.getEquipment().getType(), builderEquipment.getStaticId()); isInstantiable = false; } @@ -109,6 +106,8 @@ public AbstractEvent build() { new EventBranchDisconnection(eventId, (Branch) builderEquipment.getEquipment(), MODEL_INFO, startTime, disconnectSide); case HVDC -> new EventHvdcDisconnection(eventId, (HvdcLine) builderEquipment.getEquipment(), MODEL_INFO, startTime, disconnectSide); + case BUS -> + new EventBusDisconnection(eventId, (Bus) builderEquipment.getEquipment(), MODEL_INFO, startTime, true); default -> null; }; } diff --git a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectBusEventXmlTest.java b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectBusEventXmlTest.java new file mode 100644 index 000000000..4e1f58768 --- /dev/null +++ b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectBusEventXmlTest.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2024, 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.dynawo.xml; + +import com.powsybl.dynawo.DynawoSimulationConstants; +import com.powsybl.dynawo.models.events.EventDisconnectionBuilder; +import com.powsybl.iidm.network.test.SvcTestCaseFactory; +import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; + +import java.io.IOException; + +/** + * @author Laurent Issertial {@literal } + */ +class DisconnectBusEventXmlTest extends AbstractDynamicModelXmlTest { + + @Override + protected void setupNetwork() { + network = SvcTestCaseFactory.create(); + } + + @Override + protected void addDynamicModels() { + eventModels.add(EventDisconnectionBuilder.of(network) + .staticId("B1") + .startTime(1) + .build()); + } + + @Test + void writeDisconnectModel() throws SAXException, IOException { + DydXml.write(tmpDir, context); + ParametersXml.write(tmpDir, context); + validate("dyd.xsd", "disconnect_bus_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME)); + validate("parameters.xsd", "disconnect_bus_par.xml", tmpDir.resolve(context.getSimulationParFile())); + } +} diff --git a/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectDynamicBusEventXmlTest.java b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectDynamicBusEventXmlTest.java new file mode 100644 index 000000000..b25c3d013 --- /dev/null +++ b/dynawo-simulation/src/test/java/com/powsybl/dynawo/xml/DisconnectDynamicBusEventXmlTest.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2024, 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.dynawo.xml; + +import com.powsybl.dynawo.DynawoSimulationConstants; +import com.powsybl.dynawo.models.buses.StandardBusBuilder; +import com.powsybl.dynawo.models.events.EventDisconnectionBuilder; +import com.powsybl.dynawo.models.generators.BaseGeneratorBuilder; +import com.powsybl.dynawo.models.lines.LineBuilder; +import com.powsybl.iidm.network.test.SvcTestCaseFactory; +import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; + +import java.io.IOException; + +/** + * @author Laurent Issertial {@literal } + */ +class DisconnectDynamicBusEventXmlTest extends AbstractDynamicModelXmlTest { + + @Override + protected void setupNetwork() { + network = SvcTestCaseFactory.create(); + } + + @Override + protected void addDynamicModels() { + dynamicModels.add(BaseGeneratorBuilder.of(network) + .dynamicModelId("BBM_GEN") + .staticId("G1") + .parameterSetId("gen") + .build()); + dynamicModels.add(StandardBusBuilder.of(network) + .dynamicModelId("BBM_B1") + .staticId("B1") + .parameterSetId("bus") + .build()); + dynamicModels.add(LineBuilder.of(network) + .dynamicModelId("BBM_L1") + .staticId("L1") + .parameterSetId("line") + .build()); + eventModels.add(EventDisconnectionBuilder.of(network) + .staticId("B1") + .startTime(1) + .build()); + } + + @Test + void testEmptyEvent() throws IOException, SAXException { + DydXml.write(tmpDir, context); + ParametersXml.write(tmpDir, context); + validate("dyd.xsd", "disconnect_dynamic_bus_dyd.xml", tmpDir.resolve(DynawoSimulationConstants.DYD_FILENAME)); + validate("parameters.xsd", "disconnect_dynamic_bus_par.xml", tmpDir.resolve(context.getSimulationParFile())); + } +} diff --git a/dynawo-simulation/src/test/resources/disconnect_bus_dyd.xml b/dynawo-simulation/src/test/resources/disconnect_bus_dyd.xml new file mode 100644 index 000000000..b572bd196 --- /dev/null +++ b/dynawo-simulation/src/test/resources/disconnect_bus_dyd.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/dynawo-simulation/src/test/resources/disconnect_bus_par.xml b/dynawo-simulation/src/test/resources/disconnect_bus_par.xml new file mode 100644 index 000000000..44261da97 --- /dev/null +++ b/dynawo-simulation/src/test/resources/disconnect_bus_par.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dynawo-simulation/src/test/resources/disconnect_dynamic_bus_dyd.xml b/dynawo-simulation/src/test/resources/disconnect_dynamic_bus_dyd.xml new file mode 100644 index 000000000..efde07fe5 --- /dev/null +++ b/dynawo-simulation/src/test/resources/disconnect_dynamic_bus_dyd.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawo-simulation/src/test/resources/disconnect_dynamic_bus_par.xml b/dynawo-simulation/src/test/resources/disconnect_dynamic_bus_par.xml new file mode 100644 index 000000000..cdf881fd3 --- /dev/null +++ b/dynawo-simulation/src/test/resources/disconnect_dynamic_bus_par.xml @@ -0,0 +1,2 @@ + + diff --git a/dynawo-simulation/src/test/resources/parameters.xsd b/dynawo-simulation/src/test/resources/parameters.xsd index 80963021c..3f50e07b8 100644 --- a/dynawo-simulation/src/test/resources/parameters.xsd +++ b/dynawo-simulation/src/test/resources/parameters.xsd @@ -7,6 +7,7 @@ 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 + This file is part of Dynawo, an hybrid C++/Modelica open source time domain simulation tool for power systems. --> @@ -18,14 +19,15 @@ - + - + - + + @@ -38,6 +40,7 @@ + @@ -69,11 +72,14 @@ + + + @@ -87,9 +93,19 @@ - - - + + + + + + + + + + + + +