Skip to content

Commit

Permalink
Add static var compensator (#201)
Browse files Browse the repository at this point in the history
* Add Static var compensator model
* Add SVC integration test
* Refactor Objects.requireNonNull use in equipment instantiation

Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte authored Apr 20, 2023
1 parent 8afb34d commit 52e6f81
Show file tree
Hide file tree
Showing 22 changed files with 379 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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.svcs

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.svcs.StaticVarCompensatorModel
import com.powsybl.iidm.network.Network
import com.powsybl.iidm.network.StaticVarCompensator

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class SvcGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {

protected static final String SVC = "staticVarCompensators"

SvcGroovyExtension() {
ConfigSlurper config = new ConfigSlurper()
modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(SVC).keySet() as List
}

@Override
protected SvcBuilder createBuilder(Network network, String currentTag) {
new SvcBuilder(network, currentTag)
}

static class SvcBuilder extends AbstractDynamicModelBuilder {

StaticVarCompensator svc
String tag

SvcBuilder(Network network, String tag) {
super(network)
this.tag = tag
}

void checkData() {
super.checkData()
svc = network.getStaticVarCompensator(staticId)
if (svc == null) {
throw new DslException("Static var compensator static id unknown: " + staticId)
}
}

@Override
StaticVarCompensatorModel build() {
checkData()
new StaticVarCompensatorModel(dynamicModelId, svc, parameterSetId, tag)
}
}
}
12 changes: 12 additions & 0 deletions dynawaltz-dsl/src/main/resources/models.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ loadsAlphaBeta {
LoadAlphaBetaRestorativeLimitsRecalc
LoadAlphaBetaMotor
}

staticVarCompensators {
StaticVarCompensator
StaticVarCompensatorPV
StaticVarCompensatorPVModeHandling
StaticVarCompensatorPVRemote
StaticVarCompensatorPVRemoteModeHandling
StaticVarCompensatorPVProp
StaticVarCompensatorPVPropModeHandling
StaticVarCompensatorPVPropRemote
StaticVarCompensatorPVPropRemoteModeHandling
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import com.powsybl.dynawaltz.models.lines.StandardLine;
import com.powsybl.dynawaltz.models.loads.LoadAlphaBeta;
import com.powsybl.dynawaltz.models.loads.LoadOneTransformer;
import com.powsybl.dynawaltz.models.svcs.StaticVarCompensatorModel;
import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatio;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -48,7 +50,7 @@ class DynamicModelsSupplierTest extends AbstractModelSupplierTest {

@Test
void testGroovyExtensionCount() {
assertEquals(10, EXTENSIONS.size());
assertEquals(11, EXTENSIONS.size());
}

@ParameterizedTest(name = "{0}")
Expand Down Expand Up @@ -91,7 +93,8 @@ private static Stream<Arguments> provideEquipmentModelData() {
Arguments.of("genFictitious", GeneratorFictitious.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GF", "GeneratorFictitious"),
Arguments.of("gen", GeneratorSynchronous.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GSFWPR", "GeneratorSynchronousFourWindingsProportionalRegulations"),
Arguments.of("omegaGen", OmegaRefGenerator.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GPQ", "GeneratorPQ"),
Arguments.of("transformer", TransformerFixedRatio.class, EurostagTutorialExample1Factory.create(), "NGEN_NHV1", "BBM_NGEN_NHV1", "TFR", "TransformerFixedRatio")
Arguments.of("transformer", TransformerFixedRatio.class, EurostagTutorialExample1Factory.create(), "NGEN_NHV1", "BBM_NGEN_NHV1", "TFR", "TransformerFixedRatio"),
Arguments.of("svc", StaticVarCompensatorModel.class, SvcTestCaseFactory.create(), "SVC2", "BBM_SVC", "svc", "StaticVarCompensatorPV")
);
}

Expand Down
15 changes: 15 additions & 0 deletions dynawaltz-dsl/src/test/resources/dynamicModels/svc.groovy
Original file line number Diff line number Diff line change
@@ -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

StaticVarCompensatorPV {
staticId "SVC2"
dynamicModelId "BBM_SVC"
parameterSetId "svc"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import java.util.Objects;

import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI;

/**
Expand All @@ -26,7 +28,7 @@ public abstract class AbstractEquipmentBlackBoxModel<T extends Identifiable<?>>

protected AbstractEquipmentBlackBoxModel(String dynamicModelId, String parameterSetId, T equipment) {
super(dynamicModelId, parameterSetId);
this.equipment = equipment;
this.equipment = Objects.requireNonNull(equipment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface BlackBoxModel extends Model {

List<VarMapping> getVarsMapping();

void createMacroConnections(DynaWaltzContext dynaWaltzContext);
void createMacroConnections(DynaWaltzContext context);

String getParFile(DynaWaltzContext context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javax.xml.stream.XMLStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -27,7 +26,7 @@
public class StandardBus extends AbstractEquipmentBlackBoxModel<Bus> implements BusModel {

public StandardBus(String dynamicModelId, Bus bus, String parameterSetId) {
super(dynamicModelId, parameterSetId, Objects.requireNonNull(bus));
super(dynamicModelId, parameterSetId, bus);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
* @author Marcos de Miguel <demiguelm at aia.es>
Expand All @@ -40,7 +39,7 @@ protected AbstractGeneratorModel(String dynamicModelId, Generator generator, Str
String terminalVarName, String switchOffSignalNodeVarName,
String switchOffSignalEventVarName, String switchOffSignalAutomatonVarName,
String runningVarName) {
super(dynamicModelId, parameterSetId, Objects.requireNonNull(generator));
super(dynamicModelId, parameterSetId, generator);
this.terminalVarName = terminalVarName;
this.switchOffSignalNodeVarName = switchOffSignalNodeVarName;
this.switchOffSignalEventVarName = switchOffSignalEventVarName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static com.powsybl.dynawaltz.models.utils.BusUtils.getConnectableBusStaticId;

Expand All @@ -29,7 +30,7 @@ public OmegaRefGenerator(String dynamicModelId, Generator generator, String para
"generator_switchOffSignal2",
"generator_switchOffSignal3",
"generator_running");
this.generatorLib = generatorLib;
this.generatorLib = Objects.requireNonNull(generatorLib);
}

protected String getOmegaRefPuVarName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class HvdcModel extends AbstractEquipmentBlackBoxModel<HvdcLine> {
private final String hvdcLib;

public HvdcModel(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib) {
super(dynamicModelId, parameterSetId, Objects.requireNonNull(hvdc));
this.hvdcLib = hvdcLib;
super(dynamicModelId, parameterSetId, hvdc);
this.hvdcLib = Objects.requireNonNull(hvdcLib);
}

public String getLib() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import com.powsybl.iidm.network.Line;

import java.util.List;
import java.util.Objects;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public class StandardLine extends AbstractEquipmentBlackBoxModel<Line> implements LineModel {

public StandardLine(String dynamicModelId, Line line, String parameterSetId) {
super(dynamicModelId, parameterSetId, Objects.requireNonNull(line));
super(dynamicModelId, parameterSetId, line);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.powsybl.iidm.network.Load;

import java.util.List;
import java.util.Objects;

/**
* @author Marcos de Miguel <demiguelm at aia.es>
Expand All @@ -25,7 +24,7 @@ public abstract class AbstractLoad extends AbstractEquipmentBlackBoxModel<Load>
protected final String terminalVarName;

protected AbstractLoad(String dynamicModelId, Load load, String parameterSetId, String terminalVarName) {
super(dynamicModelId, parameterSetId, Objects.requireNonNull(load));
super(dynamicModelId, parameterSetId, load);
this.terminalVarName = terminalVarName;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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.svcs;

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.VarMapping;
import com.powsybl.dynawaltz.models.buses.BusModel;
import com.powsybl.dynawaltz.models.utils.BusUtils;
import com.powsybl.iidm.network.StaticVarCompensator;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public class StaticVarCompensatorModel extends AbstractEquipmentBlackBoxModel<StaticVarCompensator> {

private static final List<VarMapping> VAR_MAPPING = Arrays.asList(
new VarMapping("SVarC_injector_PInjPu", "p"),
new VarMapping("SVarC_injector_QInjPu", "q"),
new VarMapping("SVarC_injector_state", "state"),
new VarMapping("SVarC_modeHandling_mode_value", "regulatingMode"));

private final String compensatorLib;

public StaticVarCompensatorModel(String dynamicModelId, StaticVarCompensator svc, String parameterSetId, String compensatorLib) {
super(dynamicModelId, parameterSetId, svc);
this.compensatorLib = Objects.requireNonNull(compensatorLib);
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(BusUtils.getConnectableBusStaticId(equipment), BusModel.class, this::getVarConnectionsWithBus, context);
}

private List<VarConnection> getVarConnectionsWithBus(BusModel connected) {
return List.of(new VarConnection("SVarC_terminal", connected.getTerminalVarName()));
}

@Override
public List<VarMapping> getVarsMapping() {
return VAR_MAPPING;
}

@Override
public String getLib() {
return compensatorLib;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class TransformerFixedRatio extends AbstractEquipmentBlackBoxModel<TwoWin
private final String transformerLib;

public TransformerFixedRatio(String dynamicModelId, TwoWindingsTransformer transformer, String parameterSetId, String lib) {
super(dynamicModelId, parameterSetId, Objects.requireNonNull(transformer));
this.transformerLib = lib;
super(dynamicModelId, parameterSetId, transformer);
this.transformerLib = Objects.requireNonNull(lib);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.StaticVarCompensator;
import com.powsybl.iidm.network.Terminal;

/**
Expand All @@ -27,6 +28,10 @@ public static String getConnectableBusStaticId(Generator generator) {
return getConnectableBusStaticId(generator.getTerminal());
}

public static String getConnectableBusStaticId(StaticVarCompensator svc) {
return getConnectableBusStaticId(svc.getTerminal());
}

public static String getConnectableBusStaticId(Load load) {
return getConnectableBusStaticId(load.getTerminal());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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.svcs.StaticVarCompensatorModel;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
class SvcModelXmlTest extends AbstractDynamicModelXmlTest {

@Override
protected void setupNetwork() {
network = SvcTestCaseFactory.create();
}

@Override
protected void addDynamicModels() {
dynamicModels.add(new StaticVarCompensatorModel("BBM_SVC2", network.getStaticVarCompensator("SVC2"), "svc", "StaticVarCompensator"));
}

@Test
void writeSvcModel() throws SAXException, IOException, XMLStreamException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "svc_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME));
}
}
16 changes: 16 additions & 0 deletions dynawaltz/src/test/resources/svc_dyd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<dyn:dynamicModelsArchitecture xmlns:dyn="http://www.rte-france.com/dynawo">
<dyn:blackBoxModel id="BBM_SVC2" lib="StaticVarCompensator" parFile="models.par" parId="svc" staticId="SVC2">
<dyn:macroStaticRef id="MSR_StaticVarCompensator"/>
</dyn:blackBoxModel>
<dyn:macroConnector id="MC_StaticVarCompensator-NetworkBus">
<dyn:connect var1="SVarC_terminal" var2="@NAME@_ACPIN"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="MSR_StaticVarCompensator">
<dyn:staticRef var="SVarC_injector_PInjPu" staticVar="p"/>
<dyn:staticRef var="SVarC_injector_QInjPu" staticVar="q"/>
<dyn:staticRef var="SVarC_injector_state" staticVar="state"/>
<dyn:staticRef var="SVarC_modeHandling_mode_value" staticVar="regulatingMode"/>
</dyn:macroStaticReference>
<dyn:macroConnect connector="MC_StaticVarCompensator-NetworkBus" id1="BBM_SVC2" id2="NETWORK" name2="B2"/>
</dyn:dynamicModelsArchitecture>
Loading

0 comments on commit 52e6f81

Please sign in to comment.