Skip to content

Commit

Permalink
Add dangling HVDC models (#249)
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte committed Jun 21, 2023
1 parent 9848db4 commit f46a068
Show file tree
Hide file tree
Showing 29 changed files with 535 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.powsybl.dynawaltz.dsl
class EquipmentConfig {

static final String CONTROLLABLE_PROPERTY = "CONTROLLABLE"
static final String DANGLING_PROPERTY = "DANGLING"
static final String SYNCHRONIZED_PROPERTY = "SYNCHRONIZED"

final String lib
Expand All @@ -20,6 +21,10 @@ class EquipmentConfig {
properties.contains(CONTROLLABLE_PROPERTY)
}

boolean isDangling() {
properties.contains(DANGLING_PROPERTY)
}

boolean isSynchronized() {
properties.contains(SYNCHRONIZED_PROPERTY)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
package com.powsybl.dynawaltz.dsl.models.hvdc

import com.powsybl.dsl.DslException
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder
import com.powsybl.dynawaltz.models.Side
import com.powsybl.dynawaltz.models.utils.SideConverter
import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.HvdcLine
import com.powsybl.iidm.network.Network

Expand All @@ -18,9 +22,20 @@ import com.powsybl.iidm.network.Network
abstract class AbstractHvdcBuilder extends AbstractDynamicModelBuilder {

HvdcLine hvdc
EquipmentConfig equipmentConfig
Side danglingSide

AbstractHvdcBuilder(Network network) {
AbstractHvdcBuilder(Network network, EquipmentConfig equipmentConfig) {
super(network)
this.equipmentConfig = equipmentConfig
}

void dangling(Branch.Side danglingSide) {
if (equipmentConfig.isDangling()) {
this.danglingSide = SideConverter.convert(danglingSide)
} else {
throw new DslException("'dangling' field is set on a non dangling hvdc : ${equipmentConfig.lib}")
}
}

void checkData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.models.hvdc.HvdcPv
import com.powsybl.iidm.network.HvdcLine
import com.powsybl.dynawaltz.models.hvdc.HvdcPvDangling
import com.powsybl.iidm.network.Network

/**
Expand All @@ -39,17 +39,18 @@ class HvdcPvGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicMode

static class HvdcBuilder extends AbstractHvdcBuilder {

EquipmentConfig equipmentConfig

HvdcBuilder(Network network, EquipmentConfig equipmentConfig) {
super(network)
this.equipmentConfig = equipmentConfig
super(network, equipmentConfig)
}

@Override
HvdcPv build() {
checkData()
new HvdcPv(dynamicModelId, hvdc, parameterSetId, equipmentConfig.lib)
if (equipmentConfig.isDangling()) {
new HvdcPvDangling(dynamicModelId, hvdc, parameterSetId, equipmentConfig.lib, danglingSide)
} else {
new HvdcPv(dynamicModelId, hvdc, parameterSetId, equipmentConfig.lib)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.models.hvdc.HvdcVsc
import com.powsybl.dynawaltz.models.hvdc.HvdcVscDangling
import com.powsybl.iidm.network.Network

/**
Expand All @@ -34,17 +35,18 @@ class HvdcVscGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicMod

static class HvdcBuilder extends AbstractHvdcBuilder {

EquipmentConfig equipmentConfig

HvdcBuilder(Network network, EquipmentConfig equipmentConfig) {
super(network)
this.equipmentConfig = equipmentConfig
super(network, equipmentConfig)
}

@Override
HvdcVsc build() {
checkData()
new HvdcVsc(dynamicModelId, hvdc, parameterSetId, equipmentConfig.lib)
if (equipmentConfig.isDangling()) {
new HvdcVscDangling(dynamicModelId, hvdc, parameterSetId, equipmentConfig.lib, danglingSide)
} else {
new HvdcVsc(dynamicModelId, hvdc, parameterSetId, equipmentConfig.lib)
}
}
}
}
6 changes: 6 additions & 0 deletions dynawaltz-dsl/src/main/resources/models.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ hvdcPv {
HvdcPVDiagramPQEmulationSet
HvdcPTanPhi
HvdcPTanPhiDiagramPQ
HvdcPVDangling.properties = ["Dangling"]
HvdcPVDanglingDiagramPQ.properties = ["Dangling"]
HvdcPTanPhiDangling.properties = ["Dangling"]
HvdcPTanPhiDanglingDiagramPQ.properties = ["Dangling"]
}

hvdcVsc {
HvdcVSC
HvdcVSCEmulation
HvdcVSCDanglingP.properties = ["Dangling"]
HvdcVSCDanglingUdc.properties = ["Dangling"]
}

infiniteBuses {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.powsybl.dynawaltz.models.buses.StandardBus;
import com.powsybl.dynawaltz.models.generators.*;
import com.powsybl.dynawaltz.models.hvdc.HvdcPv;
import com.powsybl.dynawaltz.models.hvdc.HvdcPvDangling;
import com.powsybl.dynawaltz.models.hvdc.HvdcVsc;
import com.powsybl.dynawaltz.models.hvdc.HvdcVscDangling;
import com.powsybl.dynawaltz.models.lines.StandardLine;
import com.powsybl.dynawaltz.models.loads.*;
import com.powsybl.dynawaltz.models.svcs.StaticVarCompensator;
Expand Down Expand Up @@ -97,6 +99,8 @@ private static Stream<Arguments> provideEquipmentModelData() {
Arguments.of("/dynamicModels/bus.groovy", StandardBus.class, EurostagTutorialExample1Factory.create(), "NGEN", "BBM_NGEN", "SB", "Bus"),
Arguments.of("/dynamicModels/hvdcPv.groovy", HvdcPv.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcPV"),
Arguments.of("/dynamicModels/hvdcVsc.groovy", HvdcVsc.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcVSC"),
Arguments.of("/dynamicModels/hvdcPvDangling.groovy", HvdcPvDangling.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcPVDanglingDiagramPQ"),
Arguments.of("/dynamicModels/hvdcVscDangling.groovy", HvdcVscDangling.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcVSCDanglingUdc"),
Arguments.of("/dynamicModels/loadAB.groovy", LoadAlphaBeta.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LAB", "LoadAlphaBetaRestorative"),
Arguments.of("/dynamicModels/loadABControllable.groovy", LoadAlphaBetaControllable.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LAB", "LoadAlphaBeta"),
Arguments.of("/dynamicModels/loadTransformer.groovy", LoadOneTransformer.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LOT", "LoadOneTransformer"),
Expand Down Expand Up @@ -137,7 +141,8 @@ private static Stream<Arguments> provideExceptionsModel() {
Arguments.of("/dynamicModels/phaseShifterTransformerException.groovy", EurostagTutorialExample1Factory.create(), "Transformer static id unknown: NGEN"),
Arguments.of("/dynamicModels/tapChangerBusException.groovy", EurostagTutorialExample1Factory.create(), "Bus static id unknown: LOAD"),
Arguments.of("/dynamicModels/tapChangerCompatibleException.groovy", EurostagTutorialExample1Factory.create(), "GENERATOR GEN is not compatible"),
Arguments.of("/dynamicModels/underVoltageGeneratorException.groovy", EurostagTutorialExample1Factory.create(), "Generator static id unknown: NGEN")
Arguments.of("/dynamicModels/underVoltageGeneratorException.groovy", EurostagTutorialExample1Factory.create(), "Generator static id unknown: NGEN"),
Arguments.of("/dynamicModels/danglingHvdcException.groovy", HvdcTestNetwork.createVsc(), "'dangling' field is set on a non dangling hvdc : HvdcPV")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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

import com.powsybl.iidm.network.Branch

HvdcPV {
staticId "L"
dynamicModelId "BBM_HVDC_L"
parameterSetId "HVDC"
dangling Branch.Side.ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ HvdcPV {
dynamicModelId "BBM_HVDC_L"
parameterSetId "HVDC"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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

import com.powsybl.iidm.network.Branch

HvdcPVDanglingDiagramPQ {
staticId "L"
dynamicModelId "BBM_HVDC_L"
parameterSetId "HVDC"
dangling Branch.Side.ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ HvdcVSC {
dynamicModelId "BBM_HVDC_L"
parameterSetId "HVDC"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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

import com.powsybl.iidm.network.Branch

HvdcVSCDanglingUdc {
staticId "L"
dynamicModelId "BBM_HVDC_L"
parameterSetId "HVDC"
dangling Branch.Side.TWO
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ public String getSideSuffix() {
public int getSideNumber() {
return ordinal() + 1;
}

public Side getOppositeSide() {
return this == ONE ? TWO : ONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,33 @@ public abstract class AbstractHvdc extends AbstractEquipmentBlackBoxModel<HvdcLi
new VarMapping("hvdc_QInj2Pu", "q2"),
new VarMapping("hvdc_state", "state2"));

protected static final String TERMINAL_PREFIX = "hvdc_terminal";

protected AbstractHvdc(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String lib) {
super(dynamicModelId, parameterSetId, hvdc, lib);
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(BusUtils.getConnectableBusStaticId(equipment.getConverterStation1().getTerminal()), BusModel.class, this::getVarConnectionsWithBus, context, Side.ONE);
createMacroConnections(BusUtils.getConnectableBusStaticId(equipment.getConverterStation2().getTerminal()), BusModel.class, this::getVarConnectionsWithBus, context, Side.TWO);
createMacroConnections(BusUtils.getConnectableBusStaticId(equipment.getConverterStation1().getTerminal()), BusModel.class, this::getVarConnectionsWith, context, Side.ONE);
createMacroConnections(BusUtils.getConnectableBusStaticId(equipment.getConverterStation2().getTerminal()), BusModel.class, this::getVarConnectionsWith, context, Side.TWO);
}

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

private List<VarConnection> getVarConnectionsWithBus(BusModel connected, Side side) {
protected List<VarConnection> getVarConnectionsWith(BusModel connected, Side side) {
List<VarConnection> varConnections = new ArrayList<>(2);
varConnections.add(new VarConnection("hvdc_terminal" + side.getSideNumber(), connected.getTerminalVarName()));
varConnections.add(getSimpleVarConnectionWithBus(connected, side));
connected.getSwitchOffSignalVarName()
.map(switchOff -> new VarConnection("hvdc_switchOffSignal1" + side.getSideSuffix(), switchOff))
.ifPresent(varConnections::add);
return varConnections;
}

protected final VarConnection getSimpleVarConnectionWithBus(BusModel connected, Side side) {
return new VarConnection(TERMINAL_PREFIX + side.getSideNumber(), connected.getTerminalVarName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.powsybl.dynawaltz.models.hvdc;

import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.buses.BusModel;

import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;

public final class DanglingSide {

private final String prefix;
private final Side side;

public DanglingSide(String prefix, Side side) {
this.prefix = Objects.requireNonNull(prefix);
this.side = Objects.requireNonNull(side);
}

boolean isDangling(Side side) {
return this.side == side;
}

public int getSideNumber() {
return side.getSideNumber();
}

public void createMacroConnections(BiFunction<BusModel, Side, List<VarConnection>> basicVarConnectionsSupplier,
BiConsumer<BiFunction<BusModel, Side, List<VarConnection>>, Side> connectionCreator) {
connectionCreator.accept(this::getVarConnectionsWith, side);
connectionCreator.accept(basicVarConnectionsSupplier, side.getOppositeSide());
}

private List<VarConnection> getVarConnectionsWith(BusModel connected, Side side) {
return List.of(new VarConnection(prefix + side.getSideNumber(), connected.getTerminalVarName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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.hvdc;

import com.powsybl.commons.PowsyblException;
import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.buses.BusModel;
import com.powsybl.dynawaltz.models.utils.BusUtils;
import com.powsybl.iidm.network.HvdcLine;

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

private final DanglingSide danglingSide;

public HvdcPvDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib, Side danglingSide) {
super(dynamicModelId, hvdc, parameterSetId, hvdcLib);
this.danglingSide = new DanglingSide(TERMINAL_PREFIX, danglingSide);
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
danglingSide.createMacroConnections(
this::getVarConnectionsWith,
(varCoSupplier, side) -> createMacroConnections(BusUtils.getConnectableBusStaticId(equipment, side), BusModel.class, varCoSupplier, context, side)
);
}

@Override
public String getSwitchOffSignalEventVarName(Side side) {
if (danglingSide.isDangling(side)) {
throw new PowsyblException(String.format("Equipment %s side %s is dangling and can't be disconnected with an event", getLib(), danglingSide.getSideNumber()));
}
return super.getSwitchOffSignalEventVarName(side);
}
}
Loading

0 comments on commit f46a068

Please sign in to comment.