Skip to content

Commit

Permalink
Combine HvdcP and HvdcVsc classes in BaseHvdc
Browse files Browse the repository at this point in the history
Delete DanglingSide

Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Sep 10, 2024
1 parent a4cea8d commit 3fb49cc
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 214 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 @@ -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 @@ -53,12 +57,12 @@ protected HvdcPBuilder(Network network, ModelConfig modelConfig, ReportNode repo
}

@Override
public HvdcP build() {
public BaseHvdc build() {
if (isInstantiable()) {
if (modelConfig.isDangling()) {
return new HvdcPDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), danglingSide);
return new HvdcDangling(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), EVENT_VAR_NAME_SUPPLIER, danglingSide);
} else {
return new HvdcP(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib());
return new BaseHvdc(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib(), EVENT_VAR_NAME_SUPPLIER);
}
}
return null;
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 @@ -54,12 +56,12 @@ protected HvdcVscBuilder(Network network, ModelConfig modelConfig, ReportNode re
}

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

This file was deleted.

Loading

0 comments on commit 3fb49cc

Please sign in to comment.