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

Add Shunt dynamic models #360

Merged
merged 5 commits into from
Jul 2, 2024
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
1 change: 1 addition & 0 deletions docs/dynamic_simulation/dynamic-models-dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The list is statically loaded via [ModelConfigLoader](https://javadoc.io/doc/com
Ultimately, all groovy scripts call dedicated builders that can be used directly by developers.
### Equipments
* BaseStaticVarCompensatorBuilder
* BaseShuntBuilder
* HvdcPBuilder
* HvdcVscBuilder
* GeneratorFictitiousBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.powsybl.dynawaltz.models.hvdc.HvdcVscBuilder;
import com.powsybl.dynawaltz.models.lines.LineBuilder;
import com.powsybl.dynawaltz.models.loads.*;
import com.powsybl.dynawaltz.models.shunts.BaseShuntBuilder;
import com.powsybl.dynawaltz.models.svarcs.BaseStaticVarCompensatorBuilder;
import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatioBuilder;

Expand Down Expand Up @@ -54,6 +55,7 @@ public final class ModelConfigLoaderImpl implements ModelConfigLoader {
new BuilderConfig(LoadOneTransformerTapChangerBuilder.CATEGORY, LoadOneTransformerTapChangerBuilder::of, LoadOneTransformerTapChangerBuilder::getSupportedLibs),
new BuilderConfig(LoadTwoTransformersBuilder.CATEGORY, LoadTwoTransformersBuilder::of, LoadTwoTransformersBuilder::getSupportedLibs),
new BuilderConfig(LoadTwoTransformersTapChangersBuilder.CATEGORY, LoadTwoTransformersTapChangersBuilder::of, LoadTwoTransformersTapChangersBuilder::getSupportedLibs),
new BuilderConfig(BaseShuntBuilder.CATEGORY, BaseShuntBuilder::of, BaseShuntBuilder::getSupportedLibs),
new BuilderConfig(BaseStaticVarCompensatorBuilder.CATEGORY, BaseStaticVarCompensatorBuilder::of, BaseStaticVarCompensatorBuilder::getSupportedLibs),
new BuilderConfig(GeneratorFictitiousBuilder.CATEGORY, GeneratorFictitiousBuilder::of, GeneratorFictitiousBuilder::getSupportedLibs),
new BuilderConfig(SynchronizedGeneratorBuilder.CATEGORY, SynchronizedGeneratorBuilder::of, SynchronizedGeneratorBuilder::getSupportedLibs),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2024, 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.shunts;

import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint;
import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder;
import com.powsybl.iidm.network.ShuntCompensator;

import java.util.List;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class BaseShunt extends AbstractEquipmentBlackBoxModel<ShuntCompensator> implements ShuntModel {

protected BaseShunt(String dynamicModelId, ShuntCompensator svarc, String parameterSetId, String lib) {
super(dynamicModelId, parameterSetId, svarc, lib);
}

@Override
public void createMacroConnections(MacroConnectionsAdder adder) {
adder.createTerminalMacroConnections(this, equipment.getTerminal(), this::getVarConnectionsWith);
}

private List<VarConnection> getVarConnectionsWith(EquipmentConnectionPoint connected) {
return List.of(new VarConnection("shunt_terminal", connected.getTerminalVarName()));
}

@Override
public String getSwitchOffSignalEventVarName() {
return "shunt_switchOffSignal2";
}

@Override
public String getStateVarName() {
return "shunt_state";
}

@Override
public String getIsCapacitorVarName() {
return "shunt_isCapacitor";
}

@Override
public String getIsAvailableVarName() {
return "shunt_isAvailable";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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.shunts;

import com.powsybl.commons.report.ReportNode;
import com.powsybl.dynawaltz.builders.*;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.ShuntCompensator;

import java.util.Set;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class BaseShuntBuilder extends AbstractEquipmentModelBuilder<ShuntCompensator, BaseShuntBuilder> {

public static final String CATEGORY = "BASE_SHUNT";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

public static BaseShuntBuilder of(Network network) {
return of(network, ReportNode.NO_OP);
}

public static BaseShuntBuilder of(Network network, ReportNode reportNode) {
return new BaseShuntBuilder(network, MODEL_CONFIGS.getDefaultModelConfig(), reportNode);
}

public static BaseShuntBuilder of(Network network, String lib) {
return of(network, lib, ReportNode.NO_OP);
}

public static BaseShuntBuilder of(Network network, String lib, ReportNode reportNode) {
ModelConfig modelConfig = MODEL_CONFIGS.getModelConfig(lib);
if (modelConfig == null) {
BuilderReports.reportLibNotFound(reportNode, BaseShuntBuilder.class.getSimpleName(), lib);
return null;
}
return new BaseShuntBuilder(network, modelConfig, reportNode);
}

public static Set<String> getSupportedLibs() {
return MODEL_CONFIGS.getSupportedLibs();
}

protected BaseShuntBuilder(Network network, ModelConfig modelConfig, ReportNode reportNode) {
super(network, modelConfig, IdentifiableType.SHUNT_COMPENSATOR, reportNode);
}

@Override
protected ShuntCompensator findEquipment(String staticId) {
return network.getShuntCompensator(staticId);
}

@Override
public BaseShunt build() {
return isInstantiable() ? new BaseShunt(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib()) : null;
}

@Override
protected BaseShuntBuilder self() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public interface ShuntModel extends InjectionModel {

String getStateVarName();

String getIsCapacitorVarName();
Expand Down
11 changes: 11 additions & 0 deletions dynawaltz/src/main/resources/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@
}
]
},
"BASE_SHUNT": {
"defaultLib": "ShuntB",
"libs": [
{
"lib": "ShuntB"
},
{
"lib": "ShuntBWithSections"
}
]
},
"BASE_STATIC_VAR_COMPENSATOR": {
"defaultLib": "StaticVarCompensator",
"libs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@
import com.powsybl.dynawaltz.models.hvdc.HvdcVscBuilder;
import com.powsybl.dynawaltz.models.lines.LineBuilder;
import com.powsybl.dynawaltz.models.loads.*;
import com.powsybl.dynawaltz.models.shunts.BaseShuntBuilder;
import com.powsybl.dynawaltz.models.svarcs.BaseStaticVarCompensatorBuilder;
import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatioBuilder;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
class DefaultLibBuilderTest {

private static final Network NETWORK = SvcTestCaseFactory.create();
private static final String WRONG_LIB = "wrongLib";

@Test
void testDefaultLibAutomatons() {
Expand Down Expand Up @@ -71,8 +74,50 @@ void testDefaultLibEquipments() {
// HVDC
assertNotNull(HvdcPBuilder.of(NETWORK));
assertNotNull(HvdcVscBuilder.of(NETWORK));
// Shunt
assertNotNull(BaseShuntBuilder.of(NETWORK));
// Static var comp
assertNotNull(BaseStaticVarCompensatorBuilder.of(NETWORK));
}

@Test
void testWrongLibAutomatons() {
assertNull(UnderVoltageAutomationSystemBuilder.of(NETWORK, WRONG_LIB));
assertNull(TapChangerBlockingAutomationSystemBuilder.of(NETWORK, WRONG_LIB));
assertNull(TapChangerAutomationSystemBuilder.of(NETWORK, WRONG_LIB));
assertNull(DynamicOverloadManagementSystemBuilder.of(NETWORK, WRONG_LIB));
assertNull(DynamicTwoLevelsOverloadManagementSystemBuilder.of(NETWORK, WRONG_LIB));
assertNull(PhaseShifterIAutomationSystemBuilder.of(NETWORK, WRONG_LIB));
assertNull(PhaseShifterPAutomationSystemBuilder.of(NETWORK, WRONG_LIB));
}

@Test
void testWrongLibEquipments() {
// Load
assertNull(BaseLoadBuilder.of(NETWORK, WRONG_LIB));
assertNull(LoadOneTransformerBuilder.of(NETWORK, WRONG_LIB));
assertNull(LoadOneTransformerTapChangerBuilder.of(NETWORK, WRONG_LIB));
assertNull(LoadTwoTransformersBuilder.of(NETWORK, WRONG_LIB));
assertNull(LoadTwoTransformersTapChangersBuilder.of(NETWORK, WRONG_LIB));
// Bus
assertNull(StandardBusBuilder.of(NETWORK, WRONG_LIB));
assertNull(InfiniteBusBuilder.of(NETWORK, WRONG_LIB));
// Transformer
assertNull(TransformerFixedRatioBuilder.of(NETWORK, WRONG_LIB));
// Line
assertNull(LineBuilder.of(NETWORK, WRONG_LIB));
// Generator
assertNull(GeneratorFictitiousBuilder.of(NETWORK, WRONG_LIB));
assertNull(SynchronizedGeneratorBuilder.of(NETWORK, WRONG_LIB));
assertNull(SynchronousGeneratorBuilder.of(NETWORK, WRONG_LIB));
assertNull(WeccBuilder.of(NETWORK, WRONG_LIB));
assertNull(GridFormingConverterBuilder.of(NETWORK, WRONG_LIB));
// HVDC
assertNull(HvdcPBuilder.of(NETWORK, WRONG_LIB));
assertNull(HvdcVscBuilder.of(NETWORK, WRONG_LIB));
// Shunt
assertNull(BaseShuntBuilder.of(NETWORK, WRONG_LIB));
// Static var comp
assertNull(BaseStaticVarCompensatorBuilder.of(NETWORK, WRONG_LIB));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.powsybl.dynawaltz.models.events.EventDisconnectionBuilder;
import com.powsybl.dynawaltz.models.generators.GeneratorFictitiousBuilder;
import com.powsybl.dynawaltz.models.shunts.BaseShuntBuilder;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
Expand Down Expand Up @@ -46,6 +47,11 @@ protected void addDynamicModels() {
.staticId("G1")
.parameterSetId("GF")
.build());
dynamicModels.add(BaseShuntBuilder.of(network)
.dynamicModelId("BBM_SHUNT")
.staticId("SH1")
.parameterSetId("BS")
.build());
eventModels.add(EventDisconnectionBuilder.of(network)
.staticId("G1")
.startTime(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2024, 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.shunts.BaseShuntBuilder;
import com.powsybl.iidm.network.test.ShuntTestCaseFactory;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

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

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

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

@Override
protected void addDynamicModels() {
dynamicModels.add(BaseShuntBuilder.of(network, "ShuntB")
.dynamicModelId("BBM_SHUNT")
.staticId("SHUNT")
.parameterSetId("sh")
.build());
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "shunt_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME));
}
}
13 changes: 9 additions & 4 deletions dynawaltz/src/test/resources/disconnect_dyd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
<dyn:blackBoxModel id="BBM_GEN" lib="GeneratorFictitious" parFile="models.par" parId="GF" staticId="G1">
<dyn:macroStaticRef id="MSR_GeneratorFictitious"/>
</dyn:blackBoxModel>
<dyn:blackBoxModel id="BBM_SHUNT" lib="ShuntB" parFile="models.par" parId="BS" staticId="SH1"/>
<dyn:blackBoxModel id="Disconnect_G1" lib="EventSetPointBoolean" parFile="svcTestCase.par" parId="Disconnect_G1"/>
<dyn:blackBoxModel id="Disconnect_L2" lib="EventConnectedStatus" parFile="svcTestCase.par" parId="Disconnect_L2"/>
<dyn:blackBoxModel id="Disconnect_SVC2" lib="EventConnectedStatus" parFile="svcTestCase.par" parId="Disconnect_SVC2"/>
<dyn:blackBoxModel id="Disconnect_SH1" lib="EventConnectedStatus" parFile="svcTestCase.par" parId="Disconnect_SH1"/>
<dyn:blackBoxModel id="Disconnect_SH1" lib="EventSetPointBoolean" parFile="svcTestCase.par" parId="Disconnect_SH1"/>
<dyn:macroConnector id="MC_GeneratorFictitious-DefaultEquipmentConnectionPoint">
<dyn:connect var1="generator_terminal" var2="@STATIC_ID@@NODE@_ACPIN"/>
<dyn:connect var1="generator_switchOffSignal1" var2="@STATIC_ID@@NODE@_switchOff"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_ShuntB-DefaultEquipmentConnectionPoint">
<dyn:connect var1="shunt_terminal" var2="@STATIC_ID@@NODE@_ACPIN"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventInjectionDisconnection-GeneratorFictitious">
<dyn:connect var1="event_state1" var2="generator_switchOffSignal2"/>
</dyn:macroConnector>
Expand All @@ -20,17 +24,18 @@
<dyn:macroConnector id="MC_EventInjectionDisconnection-DefaultStaticVarCompensator">
<dyn:connect var1="event_state1" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventInjectionDisconnection-DefaultShunt">
<dyn:connect var1="event_state1" var2="@NAME@_state_value"/>
<dyn:macroConnector id="MC_EventInjectionDisconnection-ShuntB">
<dyn:connect var1="event_state1" var2="shunt_switchOffSignal2"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="MSR_GeneratorFictitious">
<dyn:staticRef var="generator_PGenPu" staticVar="p"/>
<dyn:staticRef var="generator_QGenPu" staticVar="q"/>
<dyn:staticRef var="generator_state" staticVar="state"/>
</dyn:macroStaticReference>
<dyn:macroConnect connector="MC_GeneratorFictitious-DefaultEquipmentConnectionPoint" id1="BBM_GEN" id2="NETWORK"/>
<dyn:macroConnect connector="MC_ShuntB-DefaultEquipmentConnectionPoint" id1="BBM_SHUNT" id2="NETWORK"/>
<dyn:macroConnect connector="MC_EventInjectionDisconnection-GeneratorFictitious" id1="Disconnect_G1" id2="BBM_GEN"/>
<dyn:macroConnect connector="MC_EventInjectionDisconnection-DefaultLoad" id1="Disconnect_L2" id2="NETWORK" name2="L2"/>
<dyn:macroConnect connector="MC_EventInjectionDisconnection-DefaultStaticVarCompensator" id1="Disconnect_SVC2" id2="NETWORK" name2="SVC2"/>
<dyn:macroConnect connector="MC_EventInjectionDisconnection-DefaultShunt" id1="Disconnect_SH1" id2="NETWORK" name2="SH1"/>
<dyn:macroConnect connector="MC_EventInjectionDisconnection-ShuntB" id1="Disconnect_SH1" id2="BBM_SHUNT"/>
</dyn:dynamicModelsArchitecture>
8 changes: 8 additions & 0 deletions dynawaltz/src/test/resources/shunt_dyd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<dyn:dynamicModelsArchitecture xmlns:dyn="http://www.rte-france.com/dynawo">
<dyn:blackBoxModel id="BBM_SHUNT" lib="ShuntB" parFile="models.par" parId="sh" staticId="SHUNT"/>
<dyn:macroConnector id="MC_ShuntB-DefaultEquipmentConnectionPoint">
<dyn:connect var1="shunt_terminal" var2="@STATIC_ID@@NODE@_ACPIN"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_ShuntB-DefaultEquipmentConnectionPoint" id1="BBM_SHUNT" id2="NETWORK"/>
</dyn:dynamicModelsArchitecture>
Loading