diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java index a9f8b0f9e..d96b6b0d8 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java @@ -17,6 +17,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import java.util.Collections; import java.util.List; import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.DOUBLE; @@ -80,7 +81,9 @@ private List getVarConnectionsWithOmegaRefGenerator(OmegaRefGener } private List getVarConnectionsWithBus(BusModel connected) { - return List.of(new VarConnection("numcc_node_@INDEX@", connected.getNumCCVarName())); + return connected.getNumCCVarName() + .map(numCCVarName -> List.of(new VarConnection("numcc_node_@INDEX@", numCCVarName))) + .orElse(Collections.emptyList()); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java index b51a5baa5..3ee0506f8 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java @@ -24,4 +24,8 @@ public enum Side { public String getSideSuffix() { return sideSuffix; } + + public int getSideNumber() { + return ordinal() + 1; + } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/BusModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/BusModel.java index 1d59eb92f..f0be85562 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/BusModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/BusModel.java @@ -8,13 +8,15 @@ import com.powsybl.dynawaltz.models.Model; +import java.util.Optional; + /** * @author Florian Dupuy */ public interface BusModel extends Model { String getTerminalVarName(); - String getSwitchOffSignalVarName(); + Optional getSwitchOffSignalVarName(); - String getNumCCVarName(); + Optional getNumCCVarName(); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultBusModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultBusModel.java index 7d1bd3752..091031f3d 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultBusModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultBusModel.java @@ -8,6 +8,8 @@ import com.powsybl.dynawaltz.models.AbstractNetworkModel; +import java.util.Optional; + /** * @author Florian Dupuy */ @@ -27,12 +29,12 @@ public String getTerminalVarName() { } @Override - public String getSwitchOffSignalVarName() { - return "@NAME@_switchOff"; + public Optional getSwitchOffSignalVarName() { + return Optional.of("@NAME@_switchOff"); } @Override - public String getNumCCVarName() { - return "@NAME@_numcc"; + public Optional getNumCCVarName() { + return Optional.of("@NAME@_numcc"); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/StandardBus.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/StandardBus.java index 716cb207e..410a4f169 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/StandardBus.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/StandardBus.java @@ -18,6 +18,7 @@ import javax.xml.stream.XMLStreamWriter; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Stream; /** @@ -82,12 +83,12 @@ public String getTerminalVarName() { } @Override - public String getSwitchOffSignalVarName() { - return "bus_switchOff"; + public Optional getSwitchOffSignalVarName() { + return Optional.empty(); } @Override - public String getNumCCVarName() { - return "@NAME@_numcc"; + public Optional getNumCCVarName() { + return Optional.empty(); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/AbstractGeneratorModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/AbstractGeneratorModel.java index 4c123aa01..aa72045bd 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/AbstractGeneratorModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/AbstractGeneratorModel.java @@ -15,6 +15,7 @@ import com.powsybl.dynawaltz.models.utils.BusUtils; import com.powsybl.iidm.network.Generator; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -64,10 +65,12 @@ public void createMacroConnections(DynaWaltzContext context) { } private List getVarConnectionsWithBus(BusModel connected) { - return Arrays.asList( - new VarConnection(getTerminalVarName(), connected.getTerminalVarName()), - new VarConnection(getSwitchOffSignalNodeVarName(), connected.getSwitchOffSignalVarName()) - ); + List varConnections = new ArrayList<>(2); + varConnections.add(new VarConnection(getTerminalVarName(), connected.getTerminalVarName())); + connected.getSwitchOffSignalVarName() + .map(switchOff -> new VarConnection(getSwitchOffSignalNodeVarName(), switchOff)) + .ifPresent(varConnections::add); + return varConnections; } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorFictitious.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorFictitious.java index 44e482dca..1711bc48f 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorFictitious.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorFictitious.java @@ -17,7 +17,7 @@ public GeneratorFictitious(String dynamicModelId, String staticId, String parame "generator_switchOffSignal1", "generator_switchOffSignal2", "generator_switchOffSignal3", - "generator_fictitious"); + "generator_running"); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java index 5b31c7738..40f8be865 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java @@ -17,7 +17,6 @@ import com.powsybl.dynawaltz.models.utils.SideConverter; import com.powsybl.iidm.network.Line; -import java.util.Arrays; import java.util.List; /** @@ -35,10 +34,11 @@ public String getLib() { } private List getVarConnectionsWithBus(BusModel connected, Side side) { - return Arrays.asList( - new VarConnection(getIVarName(side), connected.getNumCCVarName()), - new VarConnection(getStateVarName(), connected.getTerminalVarName()) - ); + return List.of(new VarConnection(getTerminalVarName(side), connected.getTerminalVarName())); + } + + private String getTerminalVarName(Side side) { + return "line_terminal" + side.getSideNumber(); } @Override @@ -60,22 +60,22 @@ public String getName() { } @Override - public String getIVarName(Side side) { - return getDynamicModelId() + side.getSideSuffix(); + public String getStateVarName() { + return "line_state"; } @Override - public String getStateVarName() { - return getDynamicModelId() + "_state"; + public String getStateValueVarName() { + return "line_state_value"; } @Override - public String getDesactivateCurrentLimitsVarName() { - return getDynamicModelId() + "_desactivate_currentLimits"; + public String getIVarName(Side side) { + throw new UnsupportedOperationException("i variable not implemented in StandardLine dynawo's model"); } @Override - public String getStateValueVarName() { - return getDynamicModelId() + "_state_value"; + public String getDesactivateCurrentLimitsVarName() { + throw new UnsupportedOperationException("deactivateCurrentLimits variable not implemented in StandardLine dynawo's model"); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadAlphaBeta.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadAlphaBeta.java index cd137e7f8..18bee1c2f 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadAlphaBeta.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadAlphaBeta.java @@ -10,6 +10,7 @@ import com.powsybl.dynawaltz.models.VarMapping; import com.powsybl.dynawaltz.models.buses.BusModel; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -38,11 +39,17 @@ public List getVarsMapping() { return VAR_MAPPING; } + private String getTerminalVarName() { + return "load_terminal"; + } + @Override protected List getVarConnectionsWithBus(BusModel connected) { - return Arrays.asList( - new VarConnection("load_terminal", connected.getTerminalVarName()), - new VarConnection("load_switchOffSignal1", connected.getSwitchOffSignalVarName()) - ); + List varConnections = new ArrayList<>(2); + varConnections.add(new VarConnection(getTerminalVarName(), connected.getTerminalVarName())); + connected.getSwitchOffSignalVarName() + .map(switchOff -> new VarConnection("load_switchOffSignal1", switchOff)) + .ifPresent(varConnections::add); + return varConnections; } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadOneTransformer.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadOneTransformer.java index 901b72479..39dedec1a 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadOneTransformer.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadOneTransformer.java @@ -10,6 +10,7 @@ import com.powsybl.dynawaltz.models.VarMapping; import com.powsybl.dynawaltz.models.buses.BusModel; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -38,12 +39,20 @@ public List getVarsMapping() { return VAR_MAPPING; } + private String getTerminalVarName() { + return "transformer_terminal"; + } + @Override protected List getVarConnectionsWithBus(BusModel connected) { - return Arrays.asList( - new VarConnection("transformer_terminal", connected.getTerminalVarName()), - new VarConnection("transformer_switchOffSignal1", connected.getSwitchOffSignalVarName()), - new VarConnection("load_switchOffSignal1", connected.getSwitchOffSignalVarName()) - ); + List varConnections = new ArrayList<>(3); + varConnections.add(new VarConnection(getTerminalVarName(), connected.getTerminalVarName())); + connected.getSwitchOffSignalVarName() + .map(switchOff -> new VarConnection("transformer_switchOffSignal1", switchOff)) + .ifPresent(varConnections::add); + connected.getSwitchOffSignalVarName() + .map(switchOff -> new VarConnection("load_switchOffSignal1", switchOff)) + .ifPresent(varConnections::add); + return varConnections; } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java new file mode 100644 index 000000000..4ab1baf9d --- /dev/null +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java @@ -0,0 +1,55 @@ +/* + * 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.dynawaltz.models.lines; + +import com.powsybl.dynamicsimulation.Curve; +import com.powsybl.dynamicsimulation.DynamicSimulationParameters; +import com.powsybl.dynawaltz.DynaWaltzContext; +import com.powsybl.dynawaltz.DynaWaltzParameters; +import com.powsybl.dynawaltz.models.BlackBoxModel; +import com.powsybl.dynawaltz.models.Side; +import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton; +import com.powsybl.iidm.network.*; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Florian Dupuy + */ +class StandardLineTest { + + @Test + void connectionToCurrentLimitAutomatonException() { + Network network = Network.create("test", "test"); + Substation s = network.newSubstation().setId("s").add(); + VoltageLevel vl1 = s.newVoltageLevel().setId("vl1").setNominalV(400).setTopologyKind(TopologyKind.BUS_BREAKER).add(); + VoltageLevel vl2 = s.newVoltageLevel().setId("vl2").setNominalV(400).setTopologyKind(TopologyKind.BUS_BREAKER).add(); + Bus b1 = vl1.getBusBreakerView().newBus().setId("bus1").add(); + Bus b2 = vl2.getBusBreakerView().newBus().setId("bus2").add(); + Line l = network.newLine().setId("l").setVoltageLevel1(vl1.getId()).setBus1(b1.getId()).setVoltageLevel2(vl2.getId()).setBus2(b2.getId()) + .setR(1).setX(3).setG1(0).setG2(0).setB1(0).setB2(0).add(); + + List dynamicModels = new ArrayList<>(); + dynamicModels.add(new StandardLine("BBM_l", l.getId(), "SL")); + dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA", l.getId(), "CLA", Side.ONE)); + DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); + DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(); + String workingVariantId = network.getVariantManager().getWorkingVariantId(); + List events = Collections.emptyList(); + List curves = Collections.emptyList(); + UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, + () -> new DynaWaltzContext(network, workingVariantId, dynamicModels, events, curves, parameters, dynawoParameters)); + assertEquals("i variable not implemented in StandardLine dynawo's model", e.getMessage()); + } +} diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java index 19181ce3b..c01987fea 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java @@ -21,10 +21,7 @@ import com.powsybl.dynawaltz.models.lines.StandardLine; import com.powsybl.dynawaltz.models.loads.LoadAlphaBeta; import com.powsybl.dynawaltz.models.loads.LoadOneTransformer; -import com.powsybl.iidm.network.Bus; -import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.NetworkFactory; -import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import org.junit.jupiter.api.BeforeEach; import org.xml.sax.SAXException; @@ -61,6 +58,7 @@ void setup() { curves = new ArrayList<>(); network.getBusBreakerView().getBusStream().forEach(b -> curves.add(new DynaWaltzCurve("NETWORK", b.getId() + "_Upu_value"))); + // A curve is made up of the id of the dynamic model and the variable to plot. // The static id of the generator is used as the id of the dynamic model (dynamicModelId). network.getGeneratorStream().forEach(g -> { @@ -95,14 +93,12 @@ void setup() { dynamicModels.add(new GeneratorSynchronous("BBM_" + g.getId(), g.getId(), "GSTWPR", "GeneratorSynchronousThreeWindingsProportionalRegulations")); } }); - network.getBusBreakerView().getBuses().forEach(b -> { - if (b.getId().equals("NHV2") || b.getId().equals("NHV1")) { - dynamicModels.add(new StandardBus("BBM_" + b.getId(), b.getId(), "SB")); - } - }); - network.getLineStream().forEach(l -> - dynamicModels.add(new StandardLine("Line_" + l.getId(), l.getId(), "SL")) - ); + + Bus standardBus = network.getBusBreakerView().getBus("NLOAD"); + dynamicModels.add(new StandardBus("BBM_" + standardBus.getId(), standardBus.getId(), "SB")); + + Line standardLine = network.getLine("NHV1_NHV2_1"); + dynamicModels.add(new StandardLine("Line_" + standardLine.getId(), standardLine.getId(), "SL")); // Events eventModels = new ArrayList<>(); @@ -114,7 +110,8 @@ void setup() { }); // Automatons - network.getLineStream().forEach(l -> dynamicModels.add(new CurrentLimitAutomaton("BBM_" + l.getId(), l.getId(), "CLA", Side.ONE))); + network.getLineStream().filter(line -> line != standardLine) + .forEach(l -> dynamicModels.add(new CurrentLimitAutomaton("BBM_" + l.getId(), l.getId(), "CLA", Side.ONE))); } public void validate(String schemaDefinition, String expectedResourceName, Path xmlFile) throws SAXException, IOException { diff --git a/dynawaltz/src/test/resources/dyd.xml b/dynawaltz/src/test/resources/dyd.xml index b5b045ca4..cccdd2371 100644 --- a/dynawaltz/src/test/resources/dyd.xml +++ b/dynawaltz/src/test/resources/dyd.xml @@ -30,21 +30,15 @@ - - + - - - - - + + - - - - + + @@ -70,35 +64,16 @@ - - - + + - - - + + - - - - - - - - - - - - - - - - - - - - - + + + + @@ -127,9 +102,6 @@ - - - @@ -170,8 +142,8 @@ - - + + @@ -179,13 +151,10 @@ - - - - - - - + + + + @@ -199,5 +168,5 @@ - +