Skip to content

Commit

Permalink
Add Static var compensator model
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte authored and flo-dup committed Apr 19, 2023
1 parent c339335 commit 08ae043
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 1 deletion.
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 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
@@ -0,0 +1,48 @@
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;

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 @@ -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>

0 comments on commit 08ae043

Please sign in to comment.