Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator pq #138

Merged
merged 8 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import java.util.function.Consumer
*/
abstract class AbstractPowsyblDynawoGroovyExtension<T> {

protected static final String MODELS_CONFIG = "models.cfg"

protected List<String> modelTags

abstract protected ModelBuilder<T> createBuilder(String currentTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous
@AutoService(DynamicModelGroovyExtension.class)
class GeneratorSynchronousGroovyExtension extends AbstractPowsyblDynawoGroovyExtension<DynamicModel> 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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <florian.dupuy at rte-france.com>
* @author Dimitri Baudrier <dimitri.baudrier at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class OmegaRefGeneratorGroovyExtension extends AbstractPowsyblDynawoGroovyExtension<DynamicModel> 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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ synchronousGenerators {
GeneratorSynchronousThreeWindingsPmConstVRNordic
GeneratorSynchronousThreeWindingsPmConstVRNordicTfo
GeneratorSynchronousThreeWindingsProportionalRegulations
}
}

connectedToOmegaRefGenerators {
GeneratorPQ
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -69,7 +71,7 @@ void tearDown() throws IOException {
void test() {

List<DynamicModelGroovyExtension> 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);
Expand Down Expand Up @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions dynawaltz-dsl/src/test/resources/dynamicModels.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,9 +70,9 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters);
this.platformConfig = Objects.requireNonNull(platformConfig);
this.parametersDatabase = loadDatabase(dynaWaltzParameters.getParametersFile(), platformConfig);
List<GeneratorSynchronousModel> synchronousGenerators = dynamicModels.stream()
.filter(GeneratorSynchronousModel.class::isInstance)
.map(GeneratorSynchronousModel.class::cast)
List<OmegaRefGeneratorModel> synchronousGenerators = dynamicModels.stream()
.filter(OmegaRefGeneratorModel.class::isInstance)
.map(OmegaRefGeneratorModel.class::cast)
.collect(Collectors.toList());
this.omegaRef = new OmegaRef(synchronousGenerators);

Expand Down
33 changes: 20 additions & 13 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GeneratorSynchronousModel, Integer> synchronousGenerators = new LinkedHashMap<>();
private final Map<BusModel, List<GeneratorSynchronousModel>> busGeneratorListMap = new LinkedHashMap<>();
private final Map<OmegaRefGeneratorModel, Integer> synchronousGenerators = new LinkedHashMap<>();
private final Map<BusModel, List<OmegaRefGeneratorModel>> busGeneratorListMap = new LinkedHashMap<>();

public OmegaRef(List<GeneratorSynchronousModel> synchronousGenerators) {
public OmegaRef(List<OmegaRefGeneratorModel> 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++);
}
}
Expand All @@ -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<GeneratorSynchronousModel, Integer> e : synchronousGenerators.entrySet()) {
GeneratorSynchronousModel generator = e.getKey();
for (Map.Entry<OmegaRefGeneratorModel, Integer> e : synchronousGenerators.entrySet()) {
OmegaRefGeneratorModel generator = e.getKey();
double h = parDB.getDouble(generator.getParameterSetId(), "generator_H");
double snom = parDB.getDouble(generator.getParameterSetId(), "generator_SNom");

Expand All @@ -90,6 +91,12 @@ public List<VarConnection> 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 {
Expand All @@ -99,15 +106,15 @@ public List<VarConnection> getVarConnectionsWith(Model connected) {

@Override
public List<Model> 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);
}
return Stream.concat(synchronousGenerators.keySet().stream(), busGeneratorListMap.keySet().stream())
.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());
Expand All @@ -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<Pair<String, String>> attributesConnectFrom = getAttributesConnectFrom((GeneratorSynchronousModel) connected);
if (connected instanceof OmegaRefGeneratorModel) {
List<Pair<String, String>> 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<Pair<String, String>> 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<Pair<String, String>> getAttributesConnectFrom(GeneratorSynchronousModel generator) {
private List<Pair<String, String>> getAttributesConnectFrom(OmegaRefGeneratorModel generator) {
int index = synchronousGenerators.get(generator);
return List.of(
Pair.of("id1", OMEGA_REF_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <florian.dupuy at rte-france.com>
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface GeneratorSynchronousModel extends GeneratorModel {
public interface GeneratorSynchronousModel extends OmegaRefGeneratorModel {
String getOmegaPuVarName();

String getOmegaRefPuVarName();
}
Original file line number Diff line number Diff line change
@@ -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 <dimitri.baudrier at rte-france.com>
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <dimitri.baudrier at rte-france.com>
*/
public interface OmegaRefGeneratorModel extends GeneratorModel {
String getOmegaRefPuVarName();
}
Loading