From 727d9a61f86f3ffd0024eb50e2b4d0ca8165b4a1 Mon Sep 17 00:00:00 2001 From: dimbdr <107475235+dimbdr@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:01:51 +0100 Subject: [PATCH] Generator pq (#138) * Add OmegaRefGenerator model for GeneratorPQ model * Dedicated OmegaRefGeneratorGroovyExtension.groovy * Rename config file Signed-off-by: BAUDRIER Dimitri Co-authored-by: Florian Dupuy --- ...bstractPowsyblDynawoGroovyExtension.groovy | 2 + ...GeneratorSynchronousGroovyExtension.groovy | 11 ++-- .../OmegaRefGeneratorGroovyExtension.groovy | 50 +++++++++++++++++++ ...{synchronous_generators.cfg => models.cfg} | 6 ++- ...aWaltzGroovyDynamicModelsSupplierTest.java | 22 +++++++- .../src/test/resources/dynamicModels.groovy | 6 +++ .../powsybl/dynawaltz/DynaWaltzContext.java | 8 +-- .../powsybl/dynawaltz/models/OmegaRef.java | 33 +++++++----- .../generators/GeneratorSynchronous.java | 23 +-------- .../generators/GeneratorSynchronousModel.java | 4 +- .../models/generators/OmegaRefGenerator.java | 36 +++++++++++++ .../generators/OmegaRefGeneratorModel.java | 15 ++++++ .../dynawaltz/models/OmegaRefTest.java | 6 +-- .../dynawaltz/xml/DynaWaltzTestUtil.java | 14 ++++++ .../com/powsybl/config/test/models.par | 42 ++++++++++++++++ dynawaltz/src/test/resources/curvesInput.xml | 5 ++ dynawaltz/src/test/resources/dyd.xml | 23 ++++++++- dynawaltz/src/test/resources/omega_ref.xml | 3 +- 18 files changed, 252 insertions(+), 57 deletions(-) create mode 100644 dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/OmegaRefGeneratorGroovyExtension.groovy rename dynawaltz-dsl/src/main/resources/{synchronous_generators.cfg => models.cfg} (95%) create mode 100644 dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGenerator.java create mode 100644 dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGeneratorModel.java diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/AbstractPowsyblDynawoGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/AbstractPowsyblDynawoGroovyExtension.groovy index 727a78f4d..c584cd3b0 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/AbstractPowsyblDynawoGroovyExtension.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/AbstractPowsyblDynawoGroovyExtension.groovy @@ -17,6 +17,8 @@ import java.util.function.Consumer */ abstract class AbstractPowsyblDynawoGroovyExtension { + protected static final String MODELS_CONFIG = "models.cfg" + protected List modelTags abstract protected ModelBuilder createBuilder(String currentTag) diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/GeneratorSynchronousGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/GeneratorSynchronousGroovyExtension.groovy index fee466c38..39adbe965 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/GeneratorSynchronousGroovyExtension.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/GeneratorSynchronousGroovyExtension.groovy @@ -19,24 +19,23 @@ import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous @AutoService(DynamicModelGroovyExtension.class) class GeneratorSynchronousGroovyExtension extends AbstractPowsyblDynawoGroovyExtension implements DynamicModelGroovyExtension { - protected static final String GENERATORS_CONFIG = "synchronous_generators.cfg" protected static final String SYNCHRONOUS_GENERATORS = "synchronousGenerators" GeneratorSynchronousGroovyExtension() { ConfigSlurper config = new ConfigSlurper() - modelTags = config.parse(this.getClass().getClassLoader().getResource(GENERATORS_CONFIG)).get(SYNCHRONOUS_GENERATORS).keySet() as List + modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(SYNCHRONOUS_GENERATORS).keySet() as List } @Override - protected GeneratorBuilder createBuilder(String currentTag) { - new GeneratorBuilder(currentTag) + protected GeneratorSynchronousBuilder createBuilder(String currentTag) { + new GeneratorSynchronousBuilder(currentTag) } - static class GeneratorBuilder extends AbstractDynamicModelBuilder { + static class GeneratorSynchronousBuilder extends AbstractDynamicModelBuilder { String tag - GeneratorBuilder(String tag) { + GeneratorSynchronousBuilder(String tag) { this.tag = tag } diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/OmegaRefGeneratorGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/OmegaRefGeneratorGroovyExtension.groovy new file mode 100644 index 000000000..29fdee09b --- /dev/null +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/generators/OmegaRefGeneratorGroovyExtension.groovy @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022, 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.generators + +import com.google.auto.service.AutoService +import com.powsybl.dynamicsimulation.DynamicModel +import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension +import com.powsybl.dynawaltz.dsl.AbstractDynamicModelBuilder +import com.powsybl.dynawaltz.dsl.AbstractPowsyblDynawoGroovyExtension +import com.powsybl.dynawaltz.models.generators.OmegaRefGenerator + +/** + * @author Florian Dupuy + * @author Dimitri Baudrier + */ +@AutoService(DynamicModelGroovyExtension.class) +class OmegaRefGeneratorGroovyExtension extends AbstractPowsyblDynawoGroovyExtension implements DynamicModelGroovyExtension { + + private static final String CONNECTED_TO_OMEGA_REF_GENERATORS = "connectedToOmegaRefGenerators" + + OmegaRefGeneratorGroovyExtension() { + ConfigSlurper config = new ConfigSlurper() + modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(CONNECTED_TO_OMEGA_REF_GENERATORS).keySet() as List + } + + @Override + protected GeneratorConnectedToOmegaRefBuilder createBuilder(String currentTag) { + new GeneratorConnectedToOmegaRefBuilder(currentTag) + } + + static class GeneratorConnectedToOmegaRefBuilder extends AbstractDynamicModelBuilder { + + String tag + + GeneratorConnectedToOmegaRefBuilder(String tag) { + this.tag = tag + } + + @Override + OmegaRefGenerator build() { + checkData() + new OmegaRefGenerator(dynamicModelId, staticId, parameterSetId, tag) + } + } +} diff --git a/dynawaltz-dsl/src/main/resources/synchronous_generators.cfg b/dynawaltz-dsl/src/main/resources/models.cfg similarity index 95% rename from dynawaltz-dsl/src/main/resources/synchronous_generators.cfg rename to dynawaltz-dsl/src/main/resources/models.cfg index 583ab4be9..164dd0c4c 100644 --- a/dynawaltz-dsl/src/main/resources/synchronous_generators.cfg +++ b/dynawaltz-dsl/src/main/resources/models.cfg @@ -18,4 +18,8 @@ synchronousGenerators { GeneratorSynchronousThreeWindingsPmConstVRNordic GeneratorSynchronousThreeWindingsPmConstVRNordicTfo GeneratorSynchronousThreeWindingsProportionalRegulations - } \ No newline at end of file +} + +connectedToOmegaRefGenerators { + GeneratorPQ +} diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyDynamicModelsSupplierTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyDynamicModelsSupplierTest.java index 1898e8ad1..3ea67f158 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyDynamicModelsSupplierTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyDynamicModelsSupplierTest.java @@ -16,6 +16,7 @@ import com.powsybl.dynawaltz.DynaWaltzProvider; import com.powsybl.dynawaltz.dsl.automatons.CurrentLimitAutomatonGroovyExtension; import com.powsybl.dynawaltz.dsl.models.buses.BusGroovyExtension; +import com.powsybl.dynawaltz.dsl.models.generators.OmegaRefGeneratorGroovyExtension; import com.powsybl.dynawaltz.dsl.models.generators.GeneratorFictitiousGroovyExtension; import com.powsybl.dynawaltz.dsl.models.generators.GeneratorSynchronousGroovyExtension; import com.powsybl.dynawaltz.dsl.models.lines.LineGroovyExtension; @@ -24,6 +25,7 @@ import com.powsybl.dynawaltz.models.AbstractBlackBoxModel; import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton; import com.powsybl.dynawaltz.models.buses.StandardBus; +import com.powsybl.dynawaltz.models.generators.OmegaRefGenerator; import com.powsybl.dynawaltz.models.generators.GeneratorFictitious; import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous; import com.powsybl.dynawaltz.models.lines.StandardLine; @@ -69,7 +71,7 @@ void tearDown() throws IOException { void test() { List extensions = GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME); - assertEquals(7, extensions.size()); + assertEquals(8, extensions.size()); extensions.forEach(this::validateExtension); DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(fileSystem.getPath("/dynamicModels.groovy"), extensions); @@ -146,6 +148,17 @@ private static Network createEurostagTutorialExample1WithMoreGens() { .setTargetP(-1.3) .setTargetQ(0.9) .add(); + vlgen.newGenerator() + .setId("GEN7") + .setBus(ngen.getId()) + .setConnectableBus(ngen.getId()) + .setMinP(-9999.99) + .setMaxP(9999.99) + .setVoltageRegulatorOn(true) + .setTargetV(24.5) + .setTargetP(-1.3) + .setTargetQ(0.9) + .add(); VoltageLevel vlload = network.getVoltageLevel("VLLOAD"); Bus nload = vlload.getBusBreakerView().getBus("NLOAD"); vlload.newLoad() @@ -164,7 +177,7 @@ private void validateExtension(DynamicModelGroovyExtension extension) { boolean isLoadOneTransformerExtension = extension instanceof LoadOneTransformerGroovyExtension; boolean isLoadExtension = isLoadAlphaBetaExtension || isLoadOneTransformerExtension; - boolean isGeneratorExtension = extension instanceof GeneratorSynchronousGroovyExtension || extension instanceof GeneratorFictitiousGroovyExtension; + boolean isGeneratorExtension = extension instanceof GeneratorSynchronousGroovyExtension || extension instanceof GeneratorFictitiousGroovyExtension || extension instanceof OmegaRefGeneratorGroovyExtension; boolean isBusExtension = extension instanceof BusGroovyExtension; boolean isLineExtension = extension instanceof LineGroovyExtension; boolean isDynamicModelExtension = isLoadExtension || isGeneratorExtension || isBusExtension || isLineExtension; @@ -195,6 +208,11 @@ private void validateModel(DynamicModel dynamicModel) { assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId()); assertEquals("GF", blackBoxModel.getParameterSetId()); assertTrue(identifiable instanceof Generator); + } else if (blackBoxModel instanceof OmegaRefGenerator) { + Identifiable identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null)); + assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId()); + assertEquals("GPQ", blackBoxModel.getParameterSetId()); + assertTrue(identifiable instanceof Generator); } else if (blackBoxModel instanceof CurrentLimitAutomaton) { Identifiable identifiable = network.getIdentifiable(((CurrentLimitAutomaton) blackBoxModel).getLineStaticId()); assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId()); diff --git a/dynawaltz-dsl/src/test/resources/dynamicModels.groovy b/dynawaltz-dsl/src/test/resources/dynamicModels.groovy index 5c9c90573..22912890e 100644 --- a/dynawaltz-dsl/src/test/resources/dynamicModels.groovy +++ b/dynawaltz-dsl/src/test/resources/dynamicModels.groovy @@ -56,6 +56,12 @@ for (Generator gen : network.generators) { dynamicModelId "BBM_" + gen.id parameterSetId "GF" } + } else if (gen.id == "GEN7") { + GeneratorPQ { + staticId gen.id + dynamicModelId "BBM_" + gen.id + parameterSetId "GPQ" + } } else { GeneratorSynchronousThreeWindingsProportionalRegulations { staticId gen.id diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java index 2cb9448ea..aa0118343 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java @@ -12,7 +12,7 @@ import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.models.*; import com.powsybl.dynawaltz.models.buses.BusModel; -import com.powsybl.dynawaltz.models.generators.GeneratorSynchronousModel; +import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; import com.powsybl.dynawaltz.models.lines.LineModel; import com.powsybl.dynawaltz.models.utils.ConnectedModelTypes; import com.powsybl.dynawaltz.xml.MacroStaticReference; @@ -70,9 +70,9 @@ public DynaWaltzContext(Network network, String workingVariantId, List synchronousGenerators = dynamicModels.stream() - .filter(GeneratorSynchronousModel.class::isInstance) - .map(GeneratorSynchronousModel.class::cast) + List synchronousGenerators = dynamicModels.stream() + .filter(OmegaRefGeneratorModel.class::isInstance) + .map(OmegaRefGeneratorModel.class::cast) .collect(Collectors.toList()); this.omegaRef = new OmegaRef(synchronousGenerators); 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 5998dbd11..b092e0b6c 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java @@ -10,6 +10,7 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParametersDatabase; import com.powsybl.dynawaltz.models.buses.BusModel; +import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; import com.powsybl.dynawaltz.models.generators.GeneratorSynchronousModel; import com.powsybl.dynawaltz.models.utils.BusUtils; import com.powsybl.dynawaltz.xml.ParametersXml; @@ -39,13 +40,13 @@ 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 Map synchronousGenerators = new LinkedHashMap<>(); - private final Map> busGeneratorListMap = new LinkedHashMap<>(); + private final Map synchronousGenerators = new LinkedHashMap<>(); + private final Map> busGeneratorListMap = new LinkedHashMap<>(); - public OmegaRef(List synchronousGenerators) { + public OmegaRef(List synchronousGenerators) { super(OMEGA_REF_ID, OMEGA_REF_PARAMETER_SET_ID); int i = 0; - for (GeneratorSynchronousModel synchronousGenerator : synchronousGenerators) { + for (OmegaRefGeneratorModel synchronousGenerator : synchronousGenerators) { this.synchronousGenerators.put(synchronousGenerator, i++); } } @@ -68,8 +69,8 @@ public void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) th // The dynamic models are declared in the DYD following the order of dynamic models' supplier. // The OmegaRef parameters index the weight of each generator according to that declaration order. - for (Map.Entry e : synchronousGenerators.entrySet()) { - GeneratorSynchronousModel generator = e.getKey(); + for (Map.Entry e : synchronousGenerators.entrySet()) { + OmegaRefGeneratorModel generator = e.getKey(); double h = parDB.getDouble(generator.getParameterSetId(), "generator_H"); double snom = parDB.getDouble(generator.getParameterSetId(), "generator_SNom"); @@ -90,6 +91,12 @@ public List getVarConnectionsWith(Model connected) { new VarConnection("omegaRef_grp_@INDEX@", connectedGeneratorModel.getOmegaRefPuVarName()), new VarConnection("running_grp_@INDEX@", connectedGeneratorModel.getRunningVarName()) ); + } else if (connected instanceof OmegaRefGeneratorModel) { + OmegaRefGeneratorModel connectedOmegaRefGeneratorModel = (OmegaRefGeneratorModel) connected; + return Arrays.asList( + new VarConnection("omegaRef_grp_@INDEX@", connectedOmegaRefGeneratorModel.getOmegaRefPuVarName()), + new VarConnection("running_grp_@INDEX@", connectedOmegaRefGeneratorModel.getRunningVarName()) + ); } else if (connected instanceof BusModel) { return List.of(new VarConnection("numcc_node_@INDEX@", ((BusModel) connected).getNumCCVarName())); } else { @@ -99,7 +106,7 @@ public List getVarConnectionsWith(Model connected) { @Override public List getModelsConnectedTo(DynaWaltzContext context) throws PowsyblException { - for (GeneratorSynchronousModel g : synchronousGenerators.keySet()) { + for (OmegaRefGeneratorModel g : synchronousGenerators.keySet()) { BusModel bus = getBusAssociatedTo(g, context); busGeneratorListMap.computeIfAbsent(bus, k -> new ArrayList<>()).add(g); } @@ -107,7 +114,7 @@ public List getModelsConnectedTo(DynaWaltzContext context) throws Powsybl .collect(Collectors.toList()); } - private BusModel getBusAssociatedTo(GeneratorSynchronousModel generatorModel, DynaWaltzContext context) { + private BusModel getBusAssociatedTo(OmegaRefGeneratorModel generatorModel, DynaWaltzContext context) { Generator generator = generatorModel.getStaticId().map(staticId -> context.getNetwork().getGenerator(staticId)).orElse(null); if (generator == null) { throw new PowsyblException("Generator " + generatorModel.getLib() + " not found in DynaWaltz context. Id : " + generatorModel.getDynamicModelId()); @@ -122,21 +129,21 @@ public String getParFile(DynaWaltzContext context) { @Override public void writeMacroConnect(XMLStreamWriter writer, DynaWaltzContext context, MacroConnector macroConnector, Model connected) throws XMLStreamException { - if (connected instanceof GeneratorSynchronousModel) { - List> attributesConnectFrom = getAttributesConnectFrom((GeneratorSynchronousModel) connected); + if (connected instanceof OmegaRefGeneratorModel) { + List> attributesConnectFrom = getAttributesConnectFrom((OmegaRefGeneratorModel) connected); macroConnector.writeMacroConnect(writer, attributesConnectFrom, connected.getMacroConnectToAttributes()); } else if (connected instanceof BusModel) { BusModel bus = (BusModel) connected; - for (GeneratorSynchronousModel g : busGeneratorListMap.get(bus)) { + for (OmegaRefGeneratorModel g : busGeneratorListMap.get(bus)) { List> attributesConnectFrom = getAttributesConnectFrom(g); macroConnector.writeMacroConnect(writer, attributesConnectFrom, bus.getMacroConnectToAttributes()); } } else { - throw new PowsyblException("OmegaRef can only connect to GeneratorSynchronousModel and BusModel"); + throw new PowsyblException("OmegaRef can only connect to OmegaRefGeneratorModel and BusModel"); } } - private List> getAttributesConnectFrom(GeneratorSynchronousModel generator) { + private List> getAttributesConnectFrom(OmegaRefGeneratorModel generator) { int index = synchronousGenerators.get(generator); return List.of( Pair.of("id1", OMEGA_REF_ID), diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronous.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronous.java index 11f9c2615..b223784cc 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronous.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronous.java @@ -5,37 +5,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package com.powsybl.dynawaltz.models.generators; - /** * @author Florian Dupuy */ -public class GeneratorSynchronous extends AbstractGeneratorModel +public class GeneratorSynchronous extends OmegaRefGenerator implements GeneratorSynchronousModel { - private final String generatorLib; - public GeneratorSynchronous(String dynamicModelId, String staticId, String parameterSetId, String generatorLib) { - super(dynamicModelId, staticId, parameterSetId, - "generator_terminal", - "generator_switchOffSignal1", - "generator_switchOffSignal2", - "generator_switchOffSignal3", - "generator_running"); - this.generatorLib = generatorLib; - } - - @Override - public String getOmegaRefPuVarName() { - return "generator_omegaRefPu"; + super(dynamicModelId, staticId, parameterSetId, generatorLib); } @Override public String getOmegaPuVarName() { return "generator_omegaPu"; } - - @Override - public String getLib() { - return generatorLib; - } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronousModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronousModel.java index dcdd2c9b4..45e55e13e 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronousModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/GeneratorSynchronousModel.java @@ -9,8 +9,6 @@ /** * @author Florian Dupuy */ -public interface GeneratorSynchronousModel extends GeneratorModel { +public interface GeneratorSynchronousModel extends OmegaRefGeneratorModel { String getOmegaPuVarName(); - - String getOmegaRefPuVarName(); } 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 new file mode 100644 index 000000000..345c5000c --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGenerator.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2022, 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.generators; + +/** + * @author Dimitri Baudrier + */ +public class OmegaRefGenerator extends AbstractGeneratorModel implements OmegaRefGeneratorModel { + + private final String generatorLib; + + public OmegaRefGenerator(String dynamicModelId, String staticId, String parameterSetId, String generatorLib) { + super(dynamicModelId, staticId, parameterSetId, + "generator_terminal", + "generator_switchOffSignal1", + "generator_switchOffSignal2", + "generator_switchOffSignal3", + "generator_running"); + this.generatorLib = generatorLib; + } + + @Override + public String getOmegaRefPuVarName() { + return "generator_omegaRefPu"; + } + + @Override + public String getLib() { + return generatorLib; + } +} 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 new file mode 100644 index 000000000..6ec48f017 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/generators/OmegaRefGeneratorModel.java @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2022, 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.generators; + +/** + * @author Dimitri Baudrier + */ +public interface OmegaRefGeneratorModel extends GeneratorModel { + String getOmegaRefPuVarName(); +} diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/OmegaRefTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/OmegaRefTest.java index b6390f031..f393b08a2 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/OmegaRefTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/OmegaRefTest.java @@ -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.models; import com.powsybl.commons.PowsyblException; @@ -13,7 +12,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import javax.xml.stream.XMLStreamException; import java.util.Collections; import java.util.List; @@ -51,9 +49,9 @@ void getVarConnectionsWithVarConnectionBus() { } @Test - void writeMacroConnectException() throws XMLStreamException { + void writeMacroConnectException() { Model model = mock(Model.class); PowsyblException e = assertThrows(PowsyblException.class, () -> omegaRef.writeMacroConnect(null, null, null, model)); - assertEquals("OmegaRef can only connect to GeneratorSynchronousModel and BusModel", e.getMessage()); + assertEquals("OmegaRef can only connect to OmegaRefGeneratorModel and BusModel", 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 cad6d137c..ae26b8085 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java @@ -14,6 +14,7 @@ import com.powsybl.dynawaltz.models.buses.StandardBus; import com.powsybl.dynawaltz.models.events.EventQuadripoleDisconnection; import com.powsybl.dynawaltz.models.events.EventSetPointBoolean; +import com.powsybl.dynawaltz.models.generators.OmegaRefGenerator; import com.powsybl.dynawaltz.models.generators.GeneratorFictitious; import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous; import com.powsybl.dynawaltz.models.lines.StandardLine; @@ -83,6 +84,8 @@ void setup() { dynamicModels.add(new GeneratorSynchronous("BBM_" + g.getId(), g.getId(), "GSTW", "GeneratorSynchronousThreeWindings")); } else if (g.getId().equals("GEN6")) { dynamicModels.add(new GeneratorFictitious("BBM_" + g.getId(), g.getId(), "GF")); + } else if (g.getId().equals("GEN7")) { + dynamicModels.add(new OmegaRefGenerator("BBM_" + g.getId(), g.getId(), "GPQ", "GeneratorPQ")); } else { dynamicModels.add(new GeneratorSynchronous("BBM_" + g.getId(), g.getId(), "GSTWPR", "GeneratorSynchronousThreeWindingsProportionalRegulations")); } @@ -190,6 +193,17 @@ private static Network createEurostagTutorialExample1WithMoreLoads() { .setTargetP(-0.3) .setTargetQ(0.7) .add(); + vlgen.newGenerator() + .setId("GEN7") + .setBus(ngen.getId()) + .setConnectableBus(ngen.getId()) + .setMinP(-9999.99) + .setMaxP(9999.99) + .setVoltageRegulatorOn(true) + .setTargetV(24.5) + .setTargetP(-0.3) + .setTargetQ(0.7) + .add(); VoltageLevel vlhv1 = network.getVoltageLevel("VLHV1"); Bus nhv1 = vlhv1.getBusBreakerView().getBus("NHV1"); vlhv1.newGenerator() diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/models.par b/dynawaltz/src/test/resources/com/powsybl/config/test/models.par index 13b7c80f5..4ad5ca89b 100644 --- a/dynawaltz/src/test/resources/com/powsybl/config/test/models.par +++ b/dynawaltz/src/test/resources/com/powsybl/config/test/models.par @@ -226,4 +226,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawaltz/src/test/resources/curvesInput.xml b/dynawaltz/src/test/resources/curvesInput.xml index cbbf5eb37..9ff5b9e7d 100644 --- a/dynawaltz/src/test/resources/curvesInput.xml +++ b/dynawaltz/src/test/resources/curvesInput.xml @@ -36,6 +36,11 @@ + + + + + diff --git a/dynawaltz/src/test/resources/dyd.xml b/dynawaltz/src/test/resources/dyd.xml index d703f4524..f8374f4e8 100644 --- a/dynawaltz/src/test/resources/dyd.xml +++ b/dynawaltz/src/test/resources/dyd.xml @@ -24,6 +24,9 @@ + + + @@ -62,6 +65,10 @@ + + + + @@ -100,6 +107,10 @@ + + + + @@ -141,6 +152,11 @@ + + + + + @@ -149,6 +165,7 @@ + @@ -159,11 +176,13 @@ - + + - + + diff --git a/dynawaltz/src/test/resources/omega_ref.xml b/dynawaltz/src/test/resources/omega_ref.xml index 6d6f5dd35..aa1c0edd2 100644 --- a/dynawaltz/src/test/resources/omega_ref.xml +++ b/dynawaltz/src/test/resources/omega_ref.xml @@ -7,7 +7,8 @@ - + +