Skip to content

Commit

Permalink
Refactor Dangling Hvdc model (#379)
Browse files Browse the repository at this point in the history
* Combine HvdcP and HvdcVsc classes in BaseHvdc
* Delete DanglingSide
* Fix duplication code

Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte authored Sep 11, 2024
1 parent 9666e7f commit 582e0f1
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
import com.powsybl.dynawo.models.buses.StandardBus;
import com.powsybl.dynawo.models.generators.*;
import com.powsybl.dynawo.models.loads.*;
import com.powsybl.dynawo.models.hvdc.HvdcP;
import com.powsybl.dynawo.models.hvdc.HvdcPDangling;
import com.powsybl.dynawo.models.hvdc.HvdcVsc;
import com.powsybl.dynawo.models.hvdc.HvdcVscDangling;
import com.powsybl.dynawo.models.hvdc.BaseHvdc;
import com.powsybl.dynawo.models.hvdc.HvdcDangling;
import com.powsybl.dynawo.models.lines.StandardLine;
import com.powsybl.dynawo.models.svarcs.BaseStaticVarCompensator;
import com.powsybl.dynawo.models.transformers.TransformerFixedRatio;
Expand Down Expand Up @@ -118,10 +116,10 @@ void assertPureDynamicBlackBoxModel(BlackBoxModel bbm, String dynamicId, String
private static Stream<Arguments> provideEquipmentModelData() {
return Stream.of(
Arguments.of("/dynamicModels/bus.groovy", StandardBus.class, EurostagTutorialExample1Factory.create(), "NGEN", "BBM_NGEN", "SB", "Bus"),
Arguments.of("/dynamicModels/hvdcP.groovy", HvdcP.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/hvdcPDangling.groovy", HvdcPDangling.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/hvdcP.groovy", BaseHvdc.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcPV"),
Arguments.of("/dynamicModels/hvdcVsc.groovy", BaseHvdc.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcVSC"),
Arguments.of("/dynamicModels/hvdcPDangling.groovy", HvdcDangling.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcPVDanglingDiagramPQ"),
Arguments.of("/dynamicModels/hvdcVscDangling.groovy", HvdcDangling.class, HvdcTestNetwork.createVsc(), "L", "BBM_HVDC_L", "HVDC", "HvdcVSCDanglingUdc"),
Arguments.of("/dynamicModels/loadAB.groovy", BaseLoad.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LAB", "LoadAlphaBetaRestorative"),
Arguments.of("/dynamicModels/loadABControllable.groovy", BaseLoadControllable.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LAB", "LoadAlphaBeta"),
Arguments.of("/dynamicModels/loadTransformer.groovy", LoadOneTransformer.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LOT", "LoadOneTransformer"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
import com.powsybl.dynawo.builders.BuilderReports;
import com.powsybl.iidm.network.*;

import java.util.function.Function;

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

protected TwoSides danglingSide;
private final Function<TwoSides, String> eventVarNameSupplier;

protected AbstractHvdcBuilder(Network network, ModelConfig modelConfig, IdentifiableType identifiableType, ReportNode reportNode) {
protected AbstractHvdcBuilder(Network network, ModelConfig modelConfig, IdentifiableType identifiableType,
ReportNode reportNode, Function<TwoSides, String> eventVarNameSupplier) {
super(network, modelConfig, identifiableType, reportNode);
this.eventVarNameSupplier = eventVarNameSupplier;
}

protected AbstractHvdcBuilder(Network network, ModelConfig modelConfig, String equipmentType, ReportNode reportNode) {
protected AbstractHvdcBuilder(Network network, ModelConfig modelConfig, String equipmentType, ReportNode reportNode,
Function<TwoSides, String> eventVarNameSupplier) {
super(network, modelConfig, equipmentType, reportNode);
this.eventVarNameSupplier = eventVarNameSupplier;
}

public R dangling(TwoSides danglingSide) {
Expand All @@ -45,4 +52,16 @@ protected void checkData() {
isInstantiable = false;
}
}

@Override
public BaseHvdc build() {
if (isInstantiable()) {
if (modelConfig.isDangling()) {
return new HvdcDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), eventVarNameSupplier, danglingSide);
} else {
return new BaseHvdc(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), eventVarNameSupplier);
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public abstract class AbstractHvdc extends AbstractEquipmentBlackBoxModel<HvdcLine> implements HvdcModel {
public class BaseHvdc extends AbstractEquipmentBlackBoxModel<HvdcLine> implements HvdcModel {

private static final List<VarMapping> VAR_MAPPING = Arrays.asList(
new VarMapping("hvdc_PInj1Pu", "p1"),
Expand All @@ -36,8 +37,11 @@ public abstract class AbstractHvdc extends AbstractEquipmentBlackBoxModel<HvdcLi

protected static final String TERMINAL_PREFIX = "hvdc_terminal";

protected AbstractHvdc(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String lib) {
private final Function<TwoSides, String> eventVarNameSupplier;

protected BaseHvdc(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String lib, Function<TwoSides, String> eventVarNameSupplier) {
super(dynamicModelId, parameterSetId, hvdc, lib);
this.eventVarNameSupplier = eventVarNameSupplier;
}

@Override
Expand Down Expand Up @@ -67,4 +71,9 @@ protected final VarConnection getSimpleVarConnectionWithBus(EquipmentConnectionP
public List<HvdcConverterStation<?>> getConnectedStations() {
return List.of(equipment.getConverterStation1(), equipment.getConverterStation2());
}

@Override
public String getSwitchOffSignalEventVarName(TwoSides side) {
return eventVarNameSupplier.apply(side);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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.dynawo.models.hvdc;

import com.powsybl.commons.PowsyblException;
import com.powsybl.dynawo.models.VarConnection;
import com.powsybl.dynawo.models.buses.EquipmentConnectionPoint;
import com.powsybl.dynawo.models.macroconnections.MacroConnectionsAdder;
import com.powsybl.dynawo.models.utils.SideUtils;
import com.powsybl.iidm.network.HvdcConverterStation;
import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.TwoSides;

import java.util.List;
import java.util.function.Function;

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

private final TwoSides danglingSide;

protected HvdcDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib,
Function<TwoSides, String> eventVarNameSupplier, TwoSides danglingSide) {
super(dynamicModelId, hvdc, parameterSetId, hvdcLib, eventVarNameSupplier);
this.danglingSide = danglingSide;
}

@Override
public void createMacroConnections(MacroConnectionsAdder adder) {
adder.createTerminalMacroConnections(this, equipment, this::getVarConnectionsWithDangling, danglingSide);
adder.createTerminalMacroConnections(this, equipment, this::getVarConnectionsWith, SideUtils.getOppositeSide(danglingSide));
}

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

@Override
public List<HvdcConverterStation<?>> getConnectedStations() {
return List.of(danglingSide == TwoSides.ONE ? equipment.getConverterStation2() : equipment.getConverterStation1());
}

private List<VarConnection> getVarConnectionsWithDangling(EquipmentConnectionPoint connected, TwoSides side) {
return List.of(new VarConnection(TERMINAL_PREFIX + side.getNum(), connected.getTerminalVarName(side)));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

import com.powsybl.commons.report.ReportNode;
import com.powsybl.dynawo.builders.*;
import com.powsybl.dynawo.models.utils.SideUtils;
import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TwoSides;

import java.util.Collection;
import java.util.function.Function;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand All @@ -22,6 +25,7 @@ public class HvdcPBuilder extends AbstractHvdcBuilder<HvdcPBuilder> {

public static final String CATEGORY = "HVDC_P";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);
private static final Function<TwoSides, String> EVENT_VAR_NAME_SUPPLIER = ts -> String.format("hvdc_switchOffSignal2%s", SideUtils.getSideSuffix(ts));

public static HvdcPBuilder of(Network network) {
return of(network, ReportNode.NO_OP);
Expand Down Expand Up @@ -49,19 +53,7 @@ public static Collection<ModelInfo> getSupportedModelInfos() {
}

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

@Override
public HvdcP build() {
if (isInstantiable()) {
if (modelConfig.isDangling()) {
return new HvdcPDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), danglingSide);
} else {
return new HvdcP(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib());
}
}
return null;
super(network, modelConfig, IdentifiableType.HVDC_LINE, reportNode, EVENT_VAR_NAME_SUPPLIER);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.iidm.network.*;

import java.util.Collection;
import java.util.function.Function;
import java.util.function.Predicate;

/**
Expand All @@ -21,6 +22,7 @@ public class HvdcVscBuilder extends AbstractHvdcBuilder<HvdcVscBuilder> {

public static final String CATEGORY = "HVDC_VSC";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);
private static final Function<TwoSides, String> EVENT_VAR_NAME_SUPPLIER = ts -> String.format("hvdc_Conv%s_switchOffSignal2", ts.getNum());
private static final Predicate<HvdcLine> IS_VSC = eq -> HvdcConverterStation.HvdcType.VSC == eq.getConverterStation1().getHvdcType();

public static HvdcVscBuilder of(Network network) {
Expand Down Expand Up @@ -49,22 +51,10 @@ public static Collection<ModelInfo> getSupportedModelInfos() {
}

protected HvdcVscBuilder(Network network, ModelConfig modelConfig, ReportNode reportNode) {
super(network, modelConfig, "VSC " + IdentifiableType.HVDC_LINE, reportNode);
super(network, modelConfig, "VSC " + IdentifiableType.HVDC_LINE, reportNode, EVENT_VAR_NAME_SUPPLIER);
addEquipmentPredicate(IS_VSC);
}

@Override
public HvdcVsc build() {
if (isInstantiable()) {
if (modelConfig.isDangling()) {
return new HvdcVscDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), danglingSide);
} else {
return new HvdcVsc(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib());
}
}
return null;
}

@Override
protected HvdcLine findEquipment(String staticId) {
HvdcLine line = network.getHvdcLine(staticId);
Expand Down
Loading

0 comments on commit 582e0f1

Please sign in to comment.