diff --git a/docs/dynamic_simulation/dynamic-models-dsl.md b/docs/dynamic_simulation/dynamic-models-dsl.md index 1b4a0ba8a..672e81065 100644 --- a/docs/dynamic_simulation/dynamic-models-dsl.md +++ b/docs/dynamic_simulation/dynamic-models-dsl.md @@ -93,3 +93,4 @@ Ultimately, all groovy scripts call dedicated builders that can be used directly * DynamicTwoLevelsOverloadManagementSystemBuilder * PhaseShifterPAutomationSystemBuilder * PhaseShifterIAutomationSystemBuilder +* PhaseShifterBlockingIAutomationSystemBuilder diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java index 8abd02178..b5d1c3128 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java @@ -52,12 +52,13 @@ public static void reportDuplicateDynamicId(ReportNode reportNode, String duplic .add(); } - public static void reportEmptyAutomaton(ReportNode reportNode, String automatonName, String dynamicId, String expectedModels) { + public static void reportEmptyAutomaton(ReportNode reportNode, String automatonName, String dynamicId, String equipmentId, String expectedModels) { reportNode.newReportNode() .withMessageTemplate("emptyAutomaton", - "${automatonName} ${dynamicId} equipment is not a ${expectedModels}, the automation system will be skipped") + "${automatonName} ${dynamicId} equipment ${equipmentId} is not a ${expectedModels}, the automation system will be skipped") .withUntypedValue("automatonName", automatonName) .withUntypedValue("dynamicId", dynamicId) + .withUntypedValue("equipmentId", equipmentId) .withUntypedValue("expectedModels", expectedModels) .withSeverity(TypedValue.WARN_SEVERITY) .add(); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderImpl.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderImpl.java index 3a88b4eb9..d47c2a1cb 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderImpl.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderImpl.java @@ -13,6 +13,7 @@ import com.powsybl.dynawaltz.models.automationsystems.UnderVoltageAutomationSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.overloadmanagments.DynamicOverloadManagementSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.overloadmanagments.DynamicTwoLevelsOverloadManagementSystemBuilder; +import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterBlockingIAutomationSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterIAutomationSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterPAutomationSystemBuilder; import com.powsybl.dynawaltz.models.buses.InfiniteBusBuilder; @@ -44,6 +45,7 @@ public final class ModelConfigLoaderImpl implements ModelConfigLoader { new BuilderConfig(UnderVoltageAutomationSystemBuilder.CATEGORY, UnderVoltageAutomationSystemBuilder::of, UnderVoltageAutomationSystemBuilder::getSupportedLibs), new BuilderConfig(PhaseShifterPAutomationSystemBuilder.CATEGORY, PhaseShifterPAutomationSystemBuilder::of, PhaseShifterPAutomationSystemBuilder::getSupportedLibs), new BuilderConfig(PhaseShifterIAutomationSystemBuilder.CATEGORY, PhaseShifterIAutomationSystemBuilder::of, PhaseShifterIAutomationSystemBuilder::getSupportedLibs), + new BuilderConfig(PhaseShifterBlockingIAutomationSystemBuilder.CATEGORY, PhaseShifterBlockingIAutomationSystemBuilder::of, PhaseShifterBlockingIAutomationSystemBuilder::getSupportedLibs), new BuilderConfig(StandardBusBuilder.CATEGORY, StandardBusBuilder::of, StandardBusBuilder::getSupportedLibs), new BuilderConfig(InfiniteBusBuilder.CATEGORY, InfiniteBusBuilder::of, InfiniteBusBuilder::getSupportedLibs), new BuilderConfig(TransformerFixedRatioBuilder.CATEGORY, TransformerFixedRatioBuilder::of, TransformerFixedRatioBuilder::getSupportedLibs), diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/ConnectionStatefulModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/ConnectionStatefulModel.java new file mode 100644 index 000000000..3e62b21d9 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/ConnectionStatefulModel.java @@ -0,0 +1,39 @@ +/** + * 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.dynawaltz.models.automationsystems; + +import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder; + +/** + * Indicates the connection state of a dynamic model + * Used when dynamic model try to connect to a pure dynamic model + * @author Laurent Issertial {@literal } + */ +public interface ConnectionStatefulModel { + + /** + * Dynamic model connection state + */ + enum ConnectionState { + /** + * Connected to specified equipments + */ + CONNECTED, + /** + * Can not be connected + */ + CANNOT_CONNECT + } + + ConnectionState getConnectionState(); + + /** + * Verifies if the model is connected, if null try to createMacroConnections + */ + boolean connect(MacroConnectionsAdder adder); +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerAutomationSystem.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerAutomationSystem.java index b7fa0c237..06a8cdbc0 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerAutomationSystem.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerAutomationSystem.java @@ -24,18 +24,11 @@ /** * @author Laurent Issertial {@literal } */ -public class TapChangerAutomationSystem extends AbstractPureDynamicBlackBoxModel implements TapChangerModel { +public class TapChangerAutomationSystem extends AbstractPureDynamicBlackBoxModel implements TapChangerModel, ConnectionStatefulModel { private final Load load; private final TransformerSide side; - - private ConnectionState connection = ConnectionState.NOT_SET; - - private enum ConnectionState { - CONNECTED, - NOT_CONNECTED, - NOT_SET - } + private ConnectionState connection = null; protected TapChangerAutomationSystem(String dynamicModelId, String parameterSetId, Load load, TransformerSide side, String lib) { super(dynamicModelId, parameterSetId, lib); @@ -55,11 +48,11 @@ public String getLib() { @Override public void createMacroConnections(MacroConnectionsAdder adder) { - if (ConnectionState.NOT_SET == connection) { + if (connection == null) { boolean isSkipped = adder.createMacroConnectionsOrSkip(this, load, LoadWithTransformers.class, this::getVarConnectionsWith); if (isSkipped) { - connection = ConnectionState.NOT_CONNECTED; - DynawaltzReports.reportEmptyAutomaton(adder.getReportNode(), this.getName(), getDynamicModelId(), LoadWithTransformers.class.getSimpleName()); + connection = ConnectionState.CANNOT_CONNECT; + DynawaltzReports.reportEmptyAutomaton(adder.getReportNode(), getName(), getDynamicModelId(), load.getId(), LoadWithTransformers.class.getSimpleName()); } else { connection = ConnectionState.CONNECTED; } @@ -82,10 +75,14 @@ public void write(XMLStreamWriter writer, String parFileName) throws XMLStreamEx } } - public boolean isConnected(MacroConnectionsAdder adder) { - if (ConnectionState.NOT_SET == connection) { - createMacroConnections(adder); - } - return ConnectionState.CONNECTED == connection; + @Override + public ConnectionState getConnectionState() { + return connection; + } + + @Override + public boolean connect(MacroConnectionsAdder adder) { + createMacroConnections(adder); + return ConnectionState.CONNECTED == getConnectionState(); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerBlockingAutomationSystem.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerBlockingAutomationSystem.java index c6db675c3..a78f8a06c 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerBlockingAutomationSystem.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/TapChangerBlockingAutomationSystem.java @@ -74,7 +74,7 @@ public void createMacroConnections(MacroConnectionsAdder adder) { } } for (String id : tapChangerAutomatonIds) { - if (adder.createTcaMacroConnectionsOrSkip(this, id, this::getVarConnectionsWith)) { + if (adder.createMacroConnectionsOrSkip(this, id, TapChangerAutomationSystem.class, this::getVarConnectionsWith)) { skippedTapChangers++; } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterBlockingIAutomationSystem.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterBlockingIAutomationSystem.java new file mode 100644 index 000000000..c55d4a412 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterBlockingIAutomationSystem.java @@ -0,0 +1,62 @@ +/** + * 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.dynawaltz.models.automationsystems.phaseshifters; + +import com.powsybl.dynawaltz.DynaWaltzContext; +import com.powsybl.dynawaltz.DynawaltzReports; +import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel; +import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder; +import com.powsybl.dynawaltz.models.transformers.TransformerModel; +import com.powsybl.dynawaltz.models.utils.ImmutableLateInit; +import com.powsybl.iidm.network.TwoWindingsTransformer; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.util.List; + +/** + * @author Laurent Issertial {@literal } + */ +public class PhaseShifterBlockingIAutomationSystem extends AbstractPureDynamicBlackBoxModel { + + private final String phaseShifterIDynamicId; + private final ImmutableLateInit transformer = new ImmutableLateInit<>(); + private boolean isConnected = true; + + protected PhaseShifterBlockingIAutomationSystem(String dynamicModelId, String phaseShifterIDynamicId, String parameterSetId, String lib) { + super(dynamicModelId, parameterSetId, lib); + this.phaseShifterIDynamicId = phaseShifterIDynamicId; + } + + @Override + public void createMacroConnections(MacroConnectionsAdder adder) { + isConnected = !adder.createMacroConnectionsOrSkip(this, phaseShifterIDynamicId, PhaseShifterIAutomationSystem.class, this::getVarConnectionsWith); + if (isConnected) { + adder.createMacroConnections(this, transformer.getValue(), TransformerModel.class, this::getVarConnectionsWith); + } else { + DynawaltzReports.reportEmptyAutomaton(adder.getReportNode(), getName(), getDynamicModelId(), phaseShifterIDynamicId, PhaseShifterIModel.class.getSimpleName()); + } + } + + protected List getVarConnectionsWith(PhaseShifterIModel connected) { + transformer.setValue(connected.getConnectedTransformer()); + return List.of(new VarConnection("phaseShifterBlockingI_locked", connected.getLockedVarName())); + } + + protected List getVarConnectionsWith(TransformerModel connected) { + return List.of(new VarConnection("phaseShifterBlockingI_IMonitored", connected.getIMonitoredVarName())); + } + + @Override + public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { + if (isConnected) { + super.write(writer, context); + } + } +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterBlockingIAutomationSystemBuilder.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterBlockingIAutomationSystemBuilder.java new file mode 100644 index 000000000..bd94c7d86 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterBlockingIAutomationSystemBuilder.java @@ -0,0 +1,82 @@ +/** + * 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.dynawaltz.models.automationsystems.phaseshifters; + +import com.powsybl.commons.report.ReportNode; +import com.powsybl.dynawaltz.builders.BuilderReports; +import com.powsybl.dynawaltz.builders.ModelConfig; +import com.powsybl.dynawaltz.builders.ModelConfigs; +import com.powsybl.dynawaltz.builders.ModelConfigsHandler; +import com.powsybl.dynawaltz.models.automationsystems.AbstractAutomationSystemModelBuilder; +import com.powsybl.iidm.network.Network; + +import java.util.Set; + +/** + * @author Laurent Issertial {@literal } + */ +public class PhaseShifterBlockingIAutomationSystemBuilder extends AbstractAutomationSystemModelBuilder { + + public static final String CATEGORY = "PHASE_SHIFTER_BLOCKING_I"; + private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY); + + public static PhaseShifterBlockingIAutomationSystemBuilder of(Network network) { + return of(network, ReportNode.NO_OP); + } + + public static PhaseShifterBlockingIAutomationSystemBuilder of(Network network, ReportNode reportNode) { + return new PhaseShifterBlockingIAutomationSystemBuilder(network, MODEL_CONFIGS.getDefaultModelConfig(), reportNode); + } + + public static PhaseShifterBlockingIAutomationSystemBuilder of(Network network, String lib) { + return of(network, lib, ReportNode.NO_OP); + } + + public static PhaseShifterBlockingIAutomationSystemBuilder of(Network network, String lib, ReportNode reportNode) { + ModelConfig modelConfig = MODEL_CONFIGS.getModelConfig(lib); + if (modelConfig == null) { + BuilderReports.reportLibNotFound(reportNode, PhaseShifterBlockingIAutomationSystemBuilder.class.getSimpleName(), lib); + return null; + } + return new PhaseShifterBlockingIAutomationSystemBuilder(network, modelConfig, reportNode); + } + + public static Set getSupportedLibs() { + return MODEL_CONFIGS.getSupportedLibs(); + } + + private String phaseShifterIDynamicId; + + protected PhaseShifterBlockingIAutomationSystemBuilder(Network network, ModelConfig modelConfig, ReportNode reportNode) { + super(network, modelConfig, reportNode); + } + + public PhaseShifterBlockingIAutomationSystemBuilder phaseShifterId(String phaseShifterIDynamicId) { + this.phaseShifterIDynamicId = phaseShifterIDynamicId; + return self(); + } + + @Override + protected void checkData() { + super.checkData(); + if (phaseShifterIDynamicId == null) { + BuilderReports.reportFieldNotSet(reportNode, "phaseShifterId"); + isInstantiable = false; + } + } + + @Override + public PhaseShifterBlockingIAutomationSystem build() { + return isInstantiable() ? new PhaseShifterBlockingIAutomationSystem(dynamicModelId, phaseShifterIDynamicId, parameterSetId, getLib()) : null; + } + + @Override + protected PhaseShifterBlockingIAutomationSystemBuilder self() { + return this; + } +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIAutomationSystem.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIAutomationSystem.java index 39acdbac1..a91a590ab 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIAutomationSystem.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIAutomationSystem.java @@ -8,6 +8,8 @@ package com.powsybl.dynawaltz.models.automationsystems.phaseshifters; import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.automationsystems.ConnectionStatefulModel; +import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder; import com.powsybl.dynawaltz.models.transformers.TransformerModel; import com.powsybl.iidm.network.TwoWindingsTransformer; @@ -17,12 +19,22 @@ /** * @author Laurent Issertial {@literal } */ -public class PhaseShifterIAutomationSystem extends AbstractPhaseShifterAutomationSystem { +public class PhaseShifterIAutomationSystem extends AbstractPhaseShifterAutomationSystem implements PhaseShifterIModel, ConnectionStatefulModel { + + private ConnectionState connection = null; protected PhaseShifterIAutomationSystem(String dynamicModelId, TwoWindingsTransformer transformer, String parameterSetId, String lib) { super(dynamicModelId, transformer, parameterSetId, lib); } + @Override + public void createMacroConnections(MacroConnectionsAdder adder) { + if (connection == null) { + super.createMacroConnections(adder); + connection = ConnectionState.CONNECTED; + } + } + protected List getVarConnectionsWith(TransformerModel connected) { return Arrays.asList( new VarConnection("phaseShifter_tap", connected.getStepVarName()), @@ -31,4 +43,25 @@ protected List getVarConnectionsWith(TransformerModel connected) new VarConnection("phaseShifter_AutomatonExists", connected.getDisableInternalTapChangerVarName()) ); } + + @Override + public ConnectionState getConnectionState() { + return connection; + } + + @Override + public boolean connect(MacroConnectionsAdder adder) { + createMacroConnections(adder); + return ConnectionState.CONNECTED == getConnectionState(); + } + + @Override + public TwoWindingsTransformer getConnectedTransformer() { + return transformer; + } + + @Override + public String getLockedVarName() { + return "phaseShifter_locked"; + } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIModel.java new file mode 100644 index 000000000..ae03d14da --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automationsystems/phaseshifters/PhaseShifterIModel.java @@ -0,0 +1,21 @@ +/** + * 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.dynawaltz.models.automationsystems.phaseshifters; + +import com.powsybl.dynawaltz.models.Model; +import com.powsybl.iidm.network.TwoWindingsTransformer; + +/** + * @author Laurent Issertial {@literal } + */ +public interface PhaseShifterIModel extends Model { + + TwoWindingsTransformer getConnectedTransformer(); + + String getLockedVarName(); +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnectionsAdder.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnectionsAdder.java index 3d34b18bb..dc20c5a81 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnectionsAdder.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnectionsAdder.java @@ -11,7 +11,7 @@ import com.powsybl.dynawaltz.models.BlackBoxModel; import com.powsybl.dynawaltz.models.Model; import com.powsybl.dynawaltz.models.VarConnection; -import com.powsybl.dynawaltz.models.automationsystems.TapChangerAutomationSystem; +import com.powsybl.dynawaltz.models.automationsystems.ConnectionStatefulModel; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; import com.powsybl.dynawaltz.models.utils.BusUtils; import com.powsybl.iidm.network.*; @@ -187,11 +187,11 @@ public void createTerminalMacroConnections(BlackBoxModel originModel, HvdcLine h } /** - * Creates macro connection with TapChangerAutomaton from dynamic id + * Creates macro connection with pure dynamic model from dynamic id */ - public boolean createTcaMacroConnectionsOrSkip(BlackBoxModel originModel, String tapChangerId, Function> varConnectionsSupplier) { - TapChangerAutomationSystem connectedModel = pureDynamicModelGetter.getPureDynamicModel(tapChangerId, TapChangerAutomationSystem.class, false); - if (connectedModel != null && connectedModel.isConnected(this)) { + public boolean createMacroConnectionsOrSkip(BlackBoxModel originModel, String dynamicModelId, Class modelClass, Function> varConnectionsSupplier) { + T connectedModel = pureDynamicModelGetter.getPureDynamicModel(dynamicModelId, modelClass, false); + if (connectedModel != null && connectedModel.connect(this)) { String macroConnectorId = MacroConnector.createMacroConnectorId(originModel.getName(), connectedModel.getName()); MacroConnect mc = new MacroConnect(macroConnectorId, originModel.getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes()); macroConnectAdder.accept(mc); diff --git a/dynawaltz/src/main/resources/models.json b/dynawaltz/src/main/resources/models.json index 07c8e26fd..e49936b17 100644 --- a/dynawaltz/src/main/resources/models.json +++ b/dynawaltz/src/main/resources/models.json @@ -576,6 +576,14 @@ } ] }, + "PHASE_SHIFTER_BLOCKING_I": { + "defaultLib": "PhaseShifterBlockingI", + "libs": [ + { + "lib": "PhaseShifterBlockingI" + } + ] + }, "TAP_CHANGER": { "defaultLib": "TapChangerAutomaton", "libs": [ diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/DefaultLibBuilderTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/DefaultLibBuilderTest.java index 5294978c8..1bab6e406 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/DefaultLibBuilderTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/DefaultLibBuilderTest.java @@ -12,6 +12,7 @@ import com.powsybl.dynawaltz.models.automationsystems.UnderVoltageAutomationSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.overloadmanagments.DynamicOverloadManagementSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.overloadmanagments.DynamicTwoLevelsOverloadManagementSystemBuilder; +import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterBlockingIAutomationSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterIAutomationSystemBuilder; import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterPAutomationSystemBuilder; import com.powsybl.dynawaltz.models.buses.InfiniteBusBuilder; @@ -47,6 +48,7 @@ void testDefaultLibAutomatons() { assertNotNull(DynamicOverloadManagementSystemBuilder.of(NETWORK)); assertNotNull(DynamicTwoLevelsOverloadManagementSystemBuilder.of(NETWORK)); assertNotNull(PhaseShifterIAutomationSystemBuilder.of(NETWORK)); + assertNotNull(PhaseShifterBlockingIAutomationSystemBuilder.of(NETWORK)); assertNotNull(PhaseShifterPAutomationSystemBuilder.of(NETWORK)); } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java index 390cd2d87..edeefd6eb 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java @@ -86,6 +86,14 @@ void setupDynawaltzContext() { protected abstract void addDynamicModels(); + protected void addModelIfNotNull(BlackBoxModel... models) { + for (BlackBoxModel model : models) { + if (model != null) { + dynamicModels.add(model); + } + } + } + protected void checkReport(String report) throws IOException { StringWriter sw = new StringWriter(); reportNode.print(sw); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyPhaseShifterBlockingIXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyPhaseShifterBlockingIXmlTest.java new file mode 100644 index 000000000..8b66568b6 --- /dev/null +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyPhaseShifterBlockingIXmlTest.java @@ -0,0 +1,62 @@ +/** + * 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.dynawaltz.xml; + +import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterBlockingIAutomationSystemBuilder; +import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterIAutomationSystemBuilder; +import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; + +import java.io.IOException; + +/** + * @author Laurent Issertial {@literal } + */ +class EmptyPhaseShifterBlockingIXmlTest extends AbstractDynamicModelXmlTest { + + @Override + protected void setupNetwork() { + network = EurostagTutorialExample1Factory.createWithLFResults(); + } + + @Override + protected void addDynamicModels() { + addModelIfNotNull( + PhaseShifterIAutomationSystemBuilder.of(network, reportNode) + .dynamicModelId("BBM_PS") + .parameterSetId("ps") + .transformer("NGEN_NHV1") + .build(), + PhaseShifterBlockingIAutomationSystemBuilder.of(network, reportNode) + .dynamicModelId("BBM_PSB") + .parameterSetId("psb") + .phaseShifterId("WRONG_ID") + .build(), + PhaseShifterBlockingIAutomationSystemBuilder.of(network, reportNode) + .dynamicModelId("BBM_PSB2") + .parameterSetId("psb") + .build()); + } + + @Test + void writeModel() throws SAXException, IOException { + DydXml.write(tmpDir, context); + ParametersXml.write(tmpDir, context); + validate("dyd.xsd", "empty_phase_shifter_blocking_i_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME)); + checkReport(""" + + Test DYD + Model BBM_PS instantiation successful + Model BBM_PSB instantiation successful + 'phaseShifterId' field is not set + Model BBM_PSB2 cannot be instantiated + + Dynawaltz models processing + PhaseShifterBlockingI BBM_PSB equipment WRONG_ID is not a PhaseShifterIModel, the automation system will be skipped + """); + } +} diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomationSystemXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomationSystemXmlTest.java index e167ba9bc..b95c16968 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomationSystemXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerAutomationSystemXmlTest.java @@ -48,7 +48,7 @@ void writeModel() throws SAXException, IOException, XMLStreamException { checkReport(""" + Test DYD + Dynawaltz models processing - TapChangerAutomaton BBM_TC equipment is not a LoadWithTransformers, the automation system will be skipped + TapChangerAutomaton BBM_TC equipment LOAD is not a LoadWithTransformers, the automation system will be skipped """); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomationSystemXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomationSystemXmlTest.java index 6b1073c6f..9848ed88e 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomationSystemXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/EmptyTapChangerBlockingAutomationSystemXmlTest.java @@ -62,7 +62,7 @@ void writeModel() throws SAXException, IOException, XMLStreamException { checkReport(""" + Test DYD + Dynawaltz models processing - TapChangerAutomaton BBM_TC equipment is not a LoadWithTransformers, the automation system will be skipped + TapChangerAutomaton BBM_TC equipment LOAD2 is not a LoadWithTransformers, the automation system will be skipped None of TapChangerBlockingAutomaton BBM_TapChangerBlocking equipments are TapChangerModel, the automation system will be skipped """); } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/PhaseShifterBlockingIXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/PhaseShifterBlockingIXmlTest.java new file mode 100644 index 000000000..e7ce94a6a --- /dev/null +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/PhaseShifterBlockingIXmlTest.java @@ -0,0 +1,48 @@ +/** + * 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.dynawaltz.xml; + +import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterBlockingIAutomationSystemBuilder; +import com.powsybl.dynawaltz.models.automationsystems.phaseshifters.PhaseShifterIAutomationSystemBuilder; +import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; + +import java.io.IOException; + +/** + * @author Laurent Issertial {@literal } + */ +class PhaseShifterBlockingIXmlTest extends AbstractDynamicModelXmlTest { + + @Override + protected void setupNetwork() { + network = EurostagTutorialExample1Factory.createWithLFResults(); + } + + @Override + protected void addDynamicModels() { + dynamicModels.add(PhaseShifterIAutomationSystemBuilder.of(network) + .dynamicModelId("BBM_PS") + .parameterSetId("ps") + .transformer("NGEN_NHV1") + .build()); + dynamicModels.add(PhaseShifterBlockingIAutomationSystemBuilder.of(network) + .dynamicModelId("BBM_PSB") + .parameterSetId("psb") + .phaseShifterId("BBM_PS") + .build()); + } + + @Test + void writeModel() throws SAXException, IOException { + DydXml.write(tmpDir, context); + ParametersXml.write(tmpDir, context); + validate("dyd.xsd", "phase_shifter_blocking_i_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME)); + } +} diff --git a/dynawaltz/src/test/resources/empty_phase_shifter_blocking_i_dyd.xml b/dynawaltz/src/test/resources/empty_phase_shifter_blocking_i_dyd.xml new file mode 100644 index 000000000..ce13730c9 --- /dev/null +++ b/dynawaltz/src/test/resources/empty_phase_shifter_blocking_i_dyd.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/dynawaltz/src/test/resources/phase_shifter_blocking_i_dyd.xml b/dynawaltz/src/test/resources/phase_shifter_blocking_i_dyd.xml new file mode 100644 index 000000000..efd3f9708 --- /dev/null +++ b/dynawaltz/src/test/resources/phase_shifter_blocking_i_dyd.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + +