diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/builders/AbstractPureDynamicModelBuilder.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/builders/AbstractPureDynamicModelBuilder.groovy index 6cd51bbdd..bbd61964a 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/builders/AbstractPureDynamicModelBuilder.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/builders/AbstractPureDynamicModelBuilder.groovy @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. * SPDX-License-Identifier: MPL-2.0 */ - package com.powsybl.dynawaltz.dsl.models.builders import com.powsybl.dsl.DslException diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/AbstractBusBuilder.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/AbstractBusBuilder.groovy new file mode 100644 index 000000000..f49d85282 --- /dev/null +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/AbstractBusBuilder.groovy @@ -0,0 +1,33 @@ +/** + * 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.dsl.models.buses + +import com.powsybl.dsl.DslException +import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder +import com.powsybl.iidm.network.Bus +import com.powsybl.iidm.network.Network + +/** + * @author Laurent Issertial + */ +abstract class AbstractBusBuilder extends AbstractDynamicModelBuilder { + + Bus bus + + AbstractBusBuilder(Network network) { + super(network) + } + + void checkData() { + super.checkData() + bus = network.getBusBreakerView().getBus(staticId) + if (bus == null) { + throw new DslException("Bus static id unknown: " + staticId) + } + } +} \ No newline at end of file diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/BusGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/BusGroovyExtension.groovy index b0d965960..fe377b438 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/BusGroovyExtension.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/BusGroovyExtension.groovy @@ -8,13 +8,10 @@ package com.powsybl.dynawaltz.dsl.models.buses import com.google.auto.service.AutoService -import com.powsybl.dsl.DslException import com.powsybl.dynamicsimulation.DynamicModel import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension -import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder import com.powsybl.dynawaltz.models.buses.StandardBus -import com.powsybl.iidm.network.Bus import com.powsybl.iidm.network.Network /** @@ -34,22 +31,12 @@ class BusGroovyExtension extends AbstractEquipmentGroovyExtension new BusBuilder(network) } - static class BusBuilder extends AbstractDynamicModelBuilder { - - Bus bus + static class BusBuilder extends AbstractBusBuilder { BusBuilder(Network network) { super(network) } - void checkData() { - super.checkData() - bus = network.getBusBreakerView().getBus(staticId) - if (bus == null) { - throw new DslException("Bus static id unknown: " + staticId) - } - } - @Override StandardBus build() { checkData() diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/InfiniteBusGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/InfiniteBusGroovyExtension.groovy new file mode 100644 index 000000000..b6580f9bd --- /dev/null +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/buses/InfiniteBusGroovyExtension.groovy @@ -0,0 +1,50 @@ +/** + * 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.dsl.models.buses + +import com.google.auto.service.AutoService +import com.powsybl.dynamicsimulation.DynamicModel +import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension +import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension +import com.powsybl.dynawaltz.models.buses.InfiniteBus +import com.powsybl.iidm.network.Network + +/** + * @author Laurent Issertial + */ +@AutoService(DynamicModelGroovyExtension.class) +class InfiniteBusGroovyExtension extends AbstractEquipmentGroovyExtension implements DynamicModelGroovyExtension { + + protected static final String BUSES = "infiniteBuses" + + InfiniteBusGroovyExtension() { + ConfigSlurper config = new ConfigSlurper() + modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(BUSES).keySet() as List + } + + @Override + protected BusBuilder createBuilder(Network network, String currentTag) { + new BusBuilder(network, currentTag) + } + + static class BusBuilder extends AbstractBusBuilder { + + String tag + + BusBuilder(Network network, String tag) { + super(network) + this.tag = tag + } + + @Override + InfiniteBus build() { + checkData() + new InfiniteBus(dynamicModelId, bus, parameterSetId, tag) + } + } +} diff --git a/dynawaltz-dsl/src/main/resources/models.cfg b/dynawaltz-dsl/src/main/resources/models.cfg index 031e71e41..a9770b504 100644 --- a/dynawaltz-dsl/src/main/resources/models.cfg +++ b/dynawaltz-dsl/src/main/resources/models.cfg @@ -40,6 +40,12 @@ hvdc { HvdcVSCEmulation } +infiniteBuses { + InfiniteBus + InfiniteBusWithImpedance + InfiniteBusWithVariations +} + loadsAlphaBeta { LoadAlphaBeta LoadAlphaBetaRestorative diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynamicModelsSupplierTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynamicModelsSupplierTest.java index 2342577fa..e209020c8 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynamicModelsSupplierTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynamicModelsSupplierTest.java @@ -22,6 +22,7 @@ import com.powsybl.dynawaltz.models.automatons.UnderVoltageAutomaton; import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterIAutomaton; import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterPAutomaton; +import com.powsybl.dynawaltz.models.buses.InfiniteBus; import com.powsybl.dynawaltz.models.buses.StandardBus; import com.powsybl.dynawaltz.models.generators.GeneratorFictitious; import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous; @@ -102,6 +103,7 @@ private static Stream provideEquipmentModelData() { Arguments.of("loadTwoTransformers", LoadTwoTransformers.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LTT", "LoadTwoTransformers"), Arguments.of("loadTwoTransformersTapChangers", LoadTwoTransformersTapChangers.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LTT", "LoadTwoTransformersTapChangers"), Arguments.of("hvdc", HvdcModel.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcPV"), + Arguments.of("infiniteBus", InfiniteBus.class, HvdcTestNetwork.createVsc(), "B1", "BBM_BUS", "b", "InfiniteBusWithVariations"), Arguments.of("line", StandardLine.class, EurostagTutorialExample1Factory.create(), "NHV1_NHV2_1", "BBM_NHV1_NHV2_1", "LINE", "Line"), Arguments.of("genFictitious", GeneratorFictitious.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GF", "GeneratorFictitious"), Arguments.of("gen", GeneratorSynchronous.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GSFWPR", "GeneratorSynchronousFourWindingsProportionalRegulations"), diff --git a/dynawaltz-dsl/src/test/resources/dynamicModels/infiniteBus.groovy b/dynawaltz-dsl/src/test/resources/dynamicModels/infiniteBus.groovy new file mode 100644 index 000000000..50c90c55d --- /dev/null +++ b/dynawaltz-dsl/src/test/resources/dynamicModels/infiniteBus.groovy @@ -0,0 +1,15 @@ +/* + * 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 dynamicModels + +InfiniteBusWithVariations { + staticId "B1" + dynamicModelId "BBM_BUS" + parameterSetId "b" +} diff --git a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/ieee14bus.par b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/ieee14bus.par index 933549c9f..0d9e58a96 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/ieee14bus.par +++ b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/ieee14bus.par @@ -1,6 +1,6 @@ - + diff --git a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.dyd b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.dyd index cd6df7cdc..fb9a2af5c 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.dyd +++ b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/powsybl_dynawaltz.dyd @@ -50,7 +50,7 @@ - + @@ -118,15 +118,15 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/ieee14bus.par b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/ieee14bus.par index 852ff339e..61f0b867e 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/ieee14bus.par +++ b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/ieee14bus.par @@ -1,6 +1,6 @@ - + diff --git a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.dyd b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.dyd index a4395e580..3d106e923 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.dyd +++ b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/powsybl_dynawaltz.dyd @@ -48,7 +48,7 @@ - + @@ -109,15 +109,15 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/ieee14bus.par b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/ieee14bus.par index e7c7dbdec..883750b05 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/ieee14bus.par +++ b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/ieee14bus.par @@ -1,6 +1,6 @@ - + diff --git a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.dyd b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.dyd index 7f4041782..ded06ec2b 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.dyd +++ b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/powsybl_dynawaltz.dyd @@ -48,7 +48,7 @@ - + @@ -105,14 +105,14 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/ieee57bus.par b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/ieee57bus.par index e63480d80..cad7b4f3a 100644 --- a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/ieee57bus.par +++ b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/ieee57bus.par @@ -1,6 +1,6 @@ - + diff --git a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.dyd b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.dyd index 07ad83c5e..481a5dde5 100644 --- a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.dyd +++ b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/powsybl_dynawaltz.dyd @@ -21,7 +21,7 @@ - + @@ -50,19 +50,19 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java index 8429083ab..29cf4d1e0 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java @@ -10,6 +10,10 @@ import com.powsybl.dynamicsimulation.Curve; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.models.*; +import com.powsybl.dynawaltz.models.buses.InfiniteBus; +import com.powsybl.dynawaltz.models.frequencysynchronizers.FrequencySynchronizerModel; +import com.powsybl.dynawaltz.models.frequencysynchronizers.OmegaRef; +import com.powsybl.dynawaltz.models.frequencysynchronizers.SetPoint; import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; import com.powsybl.dynawaltz.xml.MacroStaticReference; import com.powsybl.iidm.network.Identifiable; @@ -40,8 +44,7 @@ public class DynaWaltzContext { private final List macroConnectList = new ArrayList<>(); private final Map macroConnectorsMap = new LinkedHashMap<>(); private final NetworkModel networkModel = new NetworkModel(); - - private final OmegaRef omegaRef; + private final FrequencySynchronizerModel frequencySynchronizer; public DynaWaltzContext(Network network, String workingVariantId, List dynamicModels, List eventModels, List curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters) { @@ -56,10 +59,7 @@ public DynaWaltzContext(Network network, String workingVariantId, List new MacroStaticReference(k, bbm.getVarsMapping())); @@ -71,6 +71,13 @@ public DynaWaltzContext(Network network, String workingVariantId, List, FrequencySynchronizerModel> fsConstructor) { + return fsConstructor.apply(dynamicModels.stream() + .filter(OmegaRefGeneratorModel.class::isInstance) + .map(OmegaRefGeneratorModel.class::cast) + .collect(Collectors.toList())); + } + public Network getNetwork() { return network; } @@ -194,10 +201,10 @@ private Stream getInputBlackBoxDynamicModelStream() { } public Stream getBlackBoxDynamicModelStream() { - if (omegaRef.isEmpty()) { + if (frequencySynchronizer.isEmpty()) { return getInputBlackBoxDynamicModelStream(); } - return Stream.concat(getInputBlackBoxDynamicModelStream(), Stream.of(omegaRef)); + return Stream.concat(getInputBlackBoxDynamicModelStream(), Stream.of(frequencySynchronizer)); } public List getBlackBoxDynamicModels() { diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/AbstractBus.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/AbstractBus.java new file mode 100644 index 000000000..9db36e3be --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/AbstractBus.java @@ -0,0 +1,76 @@ +/** + * 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.buses; + +import com.powsybl.commons.PowsyblException; +import com.powsybl.dynawaltz.DynaWaltzContext; +import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; +import com.powsybl.dynawaltz.models.MacroConnectAttribute; +import com.powsybl.iidm.network.Bus; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * @author Laurent Issertial + */ +public abstract class AbstractBus extends AbstractEquipmentBlackBoxModel implements BusModel { + + protected AbstractBus(String dynamicModelId, Bus bus, String parameterSetId) { + super(dynamicModelId, parameterSetId, bus); + } + + @Override + public List getMacroConnectToAttributes() { + List attributesConnectTo = new ArrayList<>(super.getMacroConnectToAttributes()); + attributesConnectTo.add(MacroConnectAttribute.of("name2", getStaticId())); + return attributesConnectTo; + } + + @Override + public void createMacroConnections(DynaWaltzContext context) { + checkLinkedDynamicModels(equipment, context); + } + + private void checkLinkedDynamicModels(Bus bus, DynaWaltzContext context) { + bus.getConnectedTerminalStream() + .map(t -> t.getConnectable().getId()) + .filter(context::isWithoutBlackBoxDynamicModel) + .findAny() + .ifPresent(id -> { + throw new PowsyblException(String.format("The equipment %s linked to the %s %s does not possess a dynamic model", + id, this.getClass().getSimpleName(), getStaticId())); + }); + } + + @Override + public String getName() { + return getLib(); + } + + @Override + public Optional getSwitchOffSignalVarName() { + return Optional.empty(); + } + + @Override + public Optional getNumCCVarName() { + return Optional.empty(); + } + + @Override + public Optional getUImpinVarName() { + return Optional.empty(); + } + + @Override + public Optional getUpuImpinVarName() { + return Optional.empty(); + } +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/InfiniteBus.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/InfiniteBus.java new file mode 100644 index 000000000..c679d6470 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/InfiniteBus.java @@ -0,0 +1,33 @@ +/** + * 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.buses; + +import com.powsybl.iidm.network.Bus; + +/** + * @author Laurent Issertial + */ +public class InfiniteBus extends AbstractBus { + + private final String lib; + + public InfiniteBus(String dynamicModelId, Bus bus, String parameterSetId, String lib) { + super(dynamicModelId, bus, parameterSetId); + this.lib = lib; + } + + @Override + public String getLib() { + return lib; + } + + @Override + public String getTerminalVarName() { + return "infiniteBus_terminal"; + } +} 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 56ea577b4..361406c8a 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 @@ -7,26 +7,20 @@ */ package com.powsybl.dynawaltz.models.buses; -import com.powsybl.commons.PowsyblException; import com.powsybl.dynawaltz.DynaWaltzContext; -import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; -import com.powsybl.dynawaltz.models.MacroConnectAttribute; import com.powsybl.iidm.network.Bus; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; /** * @author Dimitri Baudrier * @author Laurent Issertial */ -public class StandardBus extends AbstractEquipmentBlackBoxModel implements BusModel { +public class StandardBus extends AbstractBus { public StandardBus(String dynamicModelId, Bus bus, String parameterSetId) { - super(dynamicModelId, parameterSetId, bus); + super(dynamicModelId, bus, parameterSetId); } @Override @@ -40,56 +34,8 @@ protected void writeDynamicAttributes(XMLStreamWriter writer, DynaWaltzContext c writer.writeAttribute("lib", getLib()); } - @Override - public List getMacroConnectToAttributes() { - List attributesConnectTo = new ArrayList<>(super.getMacroConnectToAttributes()); - attributesConnectTo.add(MacroConnectAttribute.of("name2", getStaticId())); - return attributesConnectTo; - } - - @Override - public void createMacroConnections(DynaWaltzContext context) { - checkLinkedDynamicModels(equipment, context); - } - - private void checkLinkedDynamicModels(Bus bus, DynaWaltzContext context) { - bus.getConnectedTerminalStream() - .map(t -> t.getConnectable().getId()) - .filter(context::isWithoutBlackBoxDynamicModel) - .findAny() - .ifPresent(id -> { - throw new PowsyblException(String.format("The equipment %s linked to the standard bus %s does not possess a dynamic model", - id, getStaticId())); - }); - } - - @Override - public String getName() { - return getLib(); - } - @Override public String getTerminalVarName() { return "bus_terminal"; } - - @Override - public Optional getSwitchOffSignalVarName() { - return Optional.empty(); - } - - @Override - public Optional getNumCCVarName() { - return Optional.empty(); - } - - @Override - public Optional getUImpinVarName() { - return Optional.empty(); - } - - @Override - public Optional getUpuImpinVarName() { - return Optional.empty(); - } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/AbstractFrequencySynchronizer.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/AbstractFrequencySynchronizer.java new file mode 100644 index 000000000..63170267c --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/AbstractFrequencySynchronizer.java @@ -0,0 +1,39 @@ +/** + * 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.frequencysynchronizers; + +import com.powsybl.dynawaltz.DynaWaltzContext; +import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel; +import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; + +import java.util.List; + +/** + * @author Laurent Issertial + */ +public abstract class AbstractFrequencySynchronizer extends AbstractPureDynamicBlackBoxModel implements FrequencySynchronizerModel { + + private static final String FREQUENCY_SYNCHRONIZER_ID = "FREQ_SYNC"; + private static final String FREQUENCY_SYNCHRONIZER_PARAMETER_SET_ID = "FREQ_SYNC_PAR"; + protected final List omegaRefGenerators; + + protected AbstractFrequencySynchronizer(List omegaRefGenerators) { + super(FREQUENCY_SYNCHRONIZER_ID, FREQUENCY_SYNCHRONIZER_PARAMETER_SET_ID); + this.omegaRefGenerators = omegaRefGenerators; + } + + @Override + public boolean isEmpty() { + return omegaRefGenerators.isEmpty(); + } + + @Override + public String getParFile(DynaWaltzContext context) { + return context.getSimulationParFile(); + } +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/FrequencySynchronizerModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/FrequencySynchronizerModel.java new file mode 100644 index 000000000..91b01f6e5 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/FrequencySynchronizerModel.java @@ -0,0 +1,18 @@ +/** + * 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.frequencysynchronizers; + +import com.powsybl.dynawaltz.models.BlackBoxModel; + +/** + * @author Laurent Issertial + */ +public interface FrequencySynchronizerModel extends BlackBoxModel { + + boolean isEmpty(); +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/OmegaRef.java similarity index 86% rename from dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java rename to dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/OmegaRef.java index a8224e14b..e6c5265cf 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/OmegaRef.java @@ -4,11 +4,13 @@ * 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/. */ -package com.powsybl.dynawaltz.models; +package com.powsybl.dynawaltz.models.frequencysynchronizers; import com.powsybl.commons.PowsyblException; import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParameters; +import com.powsybl.dynawaltz.models.MacroConnectAttribute; +import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.buses.BusModel; import com.powsybl.dynawaltz.models.generators.GeneratorSynchronousModel; import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; @@ -33,19 +35,10 @@ * @author Marcos de Miguel * @author Laurent Issertial */ -public class OmegaRef extends AbstractPureDynamicBlackBoxModel { - - public static final String OMEGA_REF_ID = "OMEGA_REF"; - private static final String OMEGA_REF_PARAMETER_SET_ID = "OMEGA_REF"; - private final List omegaRefGenerators; +public class OmegaRef extends AbstractFrequencySynchronizer { public OmegaRef(List omegaRefGenerators) { - super(OMEGA_REF_ID, OMEGA_REF_PARAMETER_SET_ID); - this.omegaRefGenerators = omegaRefGenerators; - } - - public boolean isEmpty() { - return omegaRefGenerators.isEmpty(); + super(omegaRefGenerators); } @Override @@ -98,9 +91,4 @@ public void createMacroConnections(DynaWaltzContext context) throws PowsyblExcep index++; } } - - @Override - public String getParFile(DynaWaltzContext context) { - return context.getSimulationParFile(); - } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/SetPoint.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/SetPoint.java new file mode 100644 index 000000000..11faccb7b --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/frequencysynchronizers/SetPoint.java @@ -0,0 +1,57 @@ +/** + * 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.frequencysynchronizers; + +import com.powsybl.commons.PowsyblException; +import com.powsybl.dynawaltz.DynaWaltzContext; +import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; +import com.powsybl.dynawaltz.xml.ParametersXml; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.util.List; + +import static com.powsybl.dynawaltz.parameters.ParameterType.DOUBLE; +import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; + +/** + * Special generators' frequency synchronizer used when an Infinite Bus is present in the model. + * + * @author Laurent Issertial + */ +public class SetPoint extends AbstractFrequencySynchronizer { + + public SetPoint(List omegaRefGenerators) { + super(omegaRefGenerators); + } + + @Override + public String getLib() { + return "SetPoint"; + } + + @Override + public void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { + writer.writeStartElement(DYN_URI, "set"); + writer.writeAttribute("id", getParameterSetId()); + ParametersXml.writeParameter(writer, DOUBLE, "setPoint_Value0", Double.toString(1)); + writer.writeEndElement(); + } + + private List getVarConnectionsWithOmegaRefGenerator(OmegaRefGeneratorModel connected) { + return connected.getSetPointVarConnections(); + } + + @Override + public void createMacroConnections(DynaWaltzContext context) throws PowsyblException { + for (OmegaRefGeneratorModel gen : omegaRefGenerators) { + createMacroConnections(gen, getVarConnectionsWithOmegaRefGenerator(gen), context); + } + } +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGenerator.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGenerator.java index 3b4542680..06d26e707 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGenerator.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGenerator.java @@ -10,7 +10,6 @@ import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.iidm.network.Generator; -import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -33,18 +32,25 @@ public OmegaRefGenerator(String dynamicModelId, Generator generator, String para this.generatorLib = Objects.requireNonNull(generatorLib); } - protected String getOmegaRefPuVarName() { + public String getOmegaRefPuVarName() { return "generator_omegaRefPu"; } @Override public List getOmegaRefVarConnections() { - return Arrays.asList( + return List.of( new VarConnection("omegaRef_grp_@INDEX@", getOmegaRefPuVarName()), new VarConnection("running_grp_@INDEX@", getRunningVarName()) ); } + @Override + public List getSetPointVarConnections() { + return List.of( + new VarConnection("setPoint_setPoint", getOmegaRefPuVarName()) + ); + } + @Override public String getConnectableBusId() { return getConnectableBusStaticId(equipment); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGeneratorModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGeneratorModel.java index 7be2028fc..148544d0b 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGeneratorModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGeneratorModel.java @@ -20,6 +20,10 @@ public interface OmegaRefGeneratorModel extends GeneratorModel { List getOmegaRefVarConnections(); + List getSetPointVarConnections(); + + String getOmegaRefPuVarName(); + String getConnectableBusId(); String getLib(); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/buses/StandardBusTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/buses/StandardBusTest.java index 0f4b546af..a97ff61ec 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/buses/StandardBusTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/buses/StandardBusTest.java @@ -47,6 +47,6 @@ void connectionToModelWithoutDynamicModelException() { List events = Collections.emptyList(); List curves = Collections.emptyList(); PowsyblException e = assertThrows(PowsyblException.class, () -> new DynaWaltzContext(network, workingVariantId, dynamicModels, events, curves, parameters, dynawoParameters)); - assertEquals("The equipment NHV1_NHV2_1 linked to the standard bus NHV1 does not possess a dynamic model", e.getMessage()); + assertEquals("The equipment NHV1_NHV2_1 linked to the StandardBus NHV1 does not possess a dynamic model", e.getMessage()); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/SetPointInfiniteBusModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/SetPointInfiniteBusModelXmlTest.java new file mode 100644 index 000000000..e3cc5fdf8 --- /dev/null +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/SetPointInfiniteBusModelXmlTest.java @@ -0,0 +1,44 @@ +/** + * 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.xml; + +import com.powsybl.dynawaltz.models.buses.InfiniteBus; +import com.powsybl.dynawaltz.models.generators.OmegaRefGenerator; +import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatio; +import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; + +import javax.xml.stream.XMLStreamException; +import java.io.IOException; + +/** + * @author Laurent Issertial + */ +class SetPointInfiniteBusModelXmlTest extends AbstractDynamicModelXmlTest { + + @Override + protected void setupNetwork() { + network = EurostagTutorialExample1Factory.create(); + } + + @Override + protected void addDynamicModels() { + dynamicModels.add(new OmegaRefGenerator("BBM_GEN", network.getGenerator("GEN"), "pq", "GeneratorPQ")); + dynamicModels.add(new TransformerFixedRatio("BBM_TR", network.getTwoWindingsTransformer("NGEN_NHV1"), "t", "TransformerFixedRatio")); + dynamicModels.add(new InfiniteBus("BBM_BUS", network.getBusBreakerView().getBus("NGEN"), "ib", "InfiniteBus")); + } + + @Test + void writeModel() throws SAXException, IOException, XMLStreamException { + DydXml.write(tmpDir, context); + ParametersXml.write(tmpDir, context); + validate("dyd.xsd", "set_point_inf_bus_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME)); + validate("parameters.xsd", "set_point_inf_bus_par.xml", tmpDir.resolve(context.getSimulationParFile())); + } +} diff --git a/dynawaltz/src/test/resources/dyd.xml b/dynawaltz/src/test/resources/dyd.xml index f987947d2..00766590a 100644 --- a/dynawaltz/src/test/resources/dyd.xml +++ b/dynawaltz/src/test/resources/dyd.xml @@ -32,7 +32,7 @@ - + @@ -157,18 +157,18 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/dynawaltz/src/test/resources/events.xml b/dynawaltz/src/test/resources/events.xml index ceddeffef..cf220c963 100644 --- a/dynawaltz/src/test/resources/events.xml +++ b/dynawaltz/src/test/resources/events.xml @@ -3,7 +3,7 @@ - + @@ -31,8 +31,8 @@ - - + + diff --git a/dynawaltz/src/test/resources/omega_ref.xml b/dynawaltz/src/test/resources/omega_ref.xml index 21a87d1be..8b6b1ef9e 100644 --- a/dynawaltz/src/test/resources/omega_ref.xml +++ b/dynawaltz/src/test/resources/omega_ref.xml @@ -1,6 +1,6 @@ - + diff --git a/dynawaltz/src/test/resources/omega_ref_dyd.xml b/dynawaltz/src/test/resources/omega_ref_dyd.xml index c9563cd89..587f3cc3f 100644 --- a/dynawaltz/src/test/resources/omega_ref_dyd.xml +++ b/dynawaltz/src/test/resources/omega_ref_dyd.xml @@ -9,7 +9,7 @@ - + @@ -57,10 +57,10 @@ - - - - - - + + + + + + diff --git a/dynawaltz/src/test/resources/omega_ref_par.xml b/dynawaltz/src/test/resources/omega_ref_par.xml index 6612dbbe8..96bbc8fec 100644 --- a/dynawaltz/src/test/resources/omega_ref_par.xml +++ b/dynawaltz/src/test/resources/omega_ref_par.xml @@ -1,6 +1,6 @@ - + diff --git a/dynawaltz/src/test/resources/set_point_inf_bus_dyd.xml b/dynawaltz/src/test/resources/set_point_inf_bus_dyd.xml new file mode 100644 index 000000000..86b99b3be --- /dev/null +++ b/dynawaltz/src/test/resources/set_point_inf_bus_dyd.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawaltz/src/test/resources/set_point_inf_bus_par.xml b/dynawaltz/src/test/resources/set_point_inf_bus_par.xml new file mode 100644 index 000000000..3af49fa27 --- /dev/null +++ b/dynawaltz/src/test/resources/set_point_inf_bus_par.xml @@ -0,0 +1,6 @@ + + + + + +