Skip to content

Commit

Permalink
Remove dynawaltz.models.Side and use TwoSides instead
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <[email protected]>
  • Loading branch information
flo-dup committed Nov 23, 2023
1 parent 63c38df commit 9c8f01b
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.dsl.DslEquipment
import com.powsybl.dynawaltz.dsl.Reporters
import com.powsybl.dynawaltz.dsl.builders.AbstractPureDynamicModelBuilder
import com.powsybl.dynawaltz.models.Side
import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton
import com.powsybl.dynawaltz.models.utils.SideConverter
import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.IdentifiableType
import com.powsybl.iidm.network.Network
import com.powsybl.iidm.network.TwoSides

Expand Down Expand Up @@ -47,7 +44,7 @@ class CurrentLimitAutomatonGroovyExtension extends AbstractPureDynamicGroovyExte
static class CurrentLimitAutomatonBuilder extends AbstractPureDynamicModelBuilder {

protected final DslEquipment<Branch> iMeasurement
protected Side iMeasurementSide
protected TwoSides iMeasurementSide
protected final DslEquipment<Branch> controlledEquipment

CurrentLimitAutomatonBuilder(Network network, String lib, Reporter reporter) {
Expand All @@ -61,7 +58,7 @@ class CurrentLimitAutomatonGroovyExtension extends AbstractPureDynamicGroovyExte
}

void iMeasurementSide(TwoSides side) {
this.iMeasurementSide = SideConverter.convert(side)
this.iMeasurementSide = side
}

void controlledQuadripole(String staticId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.dsl.DslEquipment
import com.powsybl.dynawaltz.dsl.Reporters
import com.powsybl.dynawaltz.models.Side
import com.powsybl.dynawaltz.models.automatons.CurrentLimitTwoLevelsAutomaton
import com.powsybl.dynawaltz.models.utils.SideConverter
import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.Network
import com.powsybl.iidm.network.TwoSides
Expand All @@ -43,7 +41,7 @@ class CurrentLimitTwoLevelsAutomatonGroovyExtension extends AbstractPureDynamicG
static class CurrentLimitAutomatonTwoLevelBuilder extends CurrentLimitAutomatonGroovyExtension.CurrentLimitAutomatonBuilder {

protected final DslEquipment<Branch> iMeasurement2
protected Side iMeasurement2Side
protected TwoSides iMeasurement2Side

CurrentLimitAutomatonTwoLevelBuilder(Network network, String lib, Reporter reporter) {
super(network, lib, reporter)
Expand All @@ -63,7 +61,7 @@ class CurrentLimitTwoLevelsAutomatonGroovyExtension extends AbstractPureDynamicG
}

void iMeasurement2Side(TwoSides side) {
this.iMeasurement2Side = SideConverter.convert(side)
this.iMeasurement2Side = side
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import com.powsybl.commons.reporter.Reporter
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.dsl.Reporters
import com.powsybl.dynawaltz.dsl.builders.AbstractEquipmentModelBuilder
import com.powsybl.dynawaltz.models.Side
import com.powsybl.dynawaltz.models.utils.SideConverter
import com.powsybl.iidm.network.HvdcLine
import com.powsybl.iidm.network.IdentifiableType
import com.powsybl.iidm.network.Network
Expand All @@ -23,14 +21,14 @@ import com.powsybl.iidm.network.TwoSides
*/
abstract class AbstractHvdcBuilder extends AbstractEquipmentModelBuilder<HvdcLine> {

protected Side danglingSide
protected TwoSides danglingSide

AbstractHvdcBuilder(Network network, EquipmentConfig equipmentConfig, Reporter reporter) {
super(network, equipmentConfig, IdentifiableType.HVDC_LINE, reporter)
}

void dangling(TwoSides danglingSide) {
this.danglingSide = SideConverter.convert(danglingSide)
this.danglingSide = danglingSide
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.powsybl.dynawaltz.xml.MacroStaticReference;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TwoSides;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -229,7 +230,7 @@ public String addMacroConnector(String name1, String name2, List<VarConnection>
return macroConnectorId;
}

public String addMacroConnector(String name1, String name2, Side side, List<VarConnection> varConnections) {
public String addMacroConnector(String name1, String name2, TwoSides side, List<VarConnection> varConnections) {
String macroConnectorId = MacroConnector.createMacroConnectorId(name1, name2, side);
macroConnectorsMap.computeIfAbsent(macroConnectorId, k -> new MacroConnector(macroConnectorId, varConnections));
return macroConnectorId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.DynaWaltzParameters;
import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint;
import com.powsybl.dynawaltz.models.macroconnections.MacroConnectAttribute;
import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionSuffix;
import com.powsybl.dynawaltz.parameters.ParametersSet;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint;
import com.powsybl.dynawaltz.models.utils.BusUtils;
import com.powsybl.dynawaltz.models.utils.SideConverter;
import com.powsybl.dynawaltz.parameters.ParametersSet;
import com.powsybl.iidm.network.*;

import javax.xml.stream.XMLStreamException;
Expand Down Expand Up @@ -142,13 +140,13 @@ protected <T extends Model> boolean createMacroConnectionsOrSkip(Identifiable<?>
/**
* Suffixes MacroConnector id with side name
*/
protected final <T extends Model> void createMacroConnections(String modelStaticId, Class<T> modelClass, BiFunction<T, Side, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, Side side) {
protected final <T extends Model> void createMacroConnections(String modelStaticId, Class<T> modelClass, BiFunction<T, TwoSides, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) {
T connectedModel = context.getDynamicModel(modelStaticId, modelClass);
String macroConnectorId = context.addMacroConnector(getName(), connectedModel.getName(), side, varConnectionsSupplier.apply(connectedModel, side));
context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes());
}

protected final <T extends Model> void createMacroConnections(Identifiable<?> equipment, Class<T> modelClass, BiFunction<T, Side, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, Side side) {
protected final <T extends Model> void createMacroConnections(Identifiable<?> equipment, Class<T> modelClass, BiFunction<T, TwoSides, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) {
T connectedModel = context.getDynamicModel(equipment, modelClass);
String macroConnectorId = context.addMacroConnector(getName(), connectedModel.getName(), side, varConnectionsSupplier.apply(connectedModel, side));
context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes());
Expand Down Expand Up @@ -182,14 +180,14 @@ protected void createTerminalMacroConnections(Injection<?> equipment, Function<E
context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes());
}

protected final void createTerminalMacroConnections(Terminal terminal, BiFunction<EquipmentConnectionPoint, Side, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, Side side) {
protected final void createTerminalMacroConnections(Terminal terminal, BiFunction<EquipmentConnectionPoint, TwoSides, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) {
EquipmentConnectionPoint connectedModel = context.getConnectionPointDynamicModel(BusUtils.getConnectableBusStaticId(terminal));
String macroConnectorId = context.addMacroConnector(getName(), connectedModel.getName(), side, varConnectionsSupplier.apply(connectedModel, side));
context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes());
}

protected final void createTerminalMacroConnections(HvdcLine hvdc, BiFunction<EquipmentConnectionPoint, Side, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, Side side) {
HvdcConverterStation<?> station = hvdc.getConverterStation(SideConverter.convert(side));
protected final void createTerminalMacroConnections(HvdcLine hvdc, BiFunction<EquipmentConnectionPoint, TwoSides, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) {
HvdcConverterStation<?> station = hvdc.getConverterStation(side);
createTerminalMacroConnections(station.getTerminal(), varConnectionsSupplier, context, side);
}
}
35 changes: 0 additions & 35 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.utils.SideUtils;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.TwoSides;

import java.util.Arrays;
import java.util.List;
Expand All @@ -26,19 +27,19 @@ public class CurrentLimitAutomaton extends AbstractPureDynamicBlackBoxModel {
protected static final String CONTROL_SUFFIX = "Control";

protected final Branch<?> measuredQuadripole;
protected final Side measuredSide;
protected final TwoSides measuredSide;
protected final Branch<?> controlledQuadripole;
protected final String lib;

public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, Side measuredSide, Branch<?> controlledQuadripole, String lib) {
public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, TwoSides measuredSide, Branch<?> controlledQuadripole, String lib) {
super(dynamicModelId, parameterSetId);
this.measuredQuadripole = Objects.requireNonNull(measuredQuadripole);
this.measuredSide = Objects.requireNonNull(measuredSide);
this.controlledQuadripole = Objects.requireNonNull(controlledQuadripole);
this.lib = lib;
}

public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, Side measuredSide, String lib) {
public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, TwoSides measuredSide, String lib) {
this(dynamicModelId, parameterSetId, measuredQuadripole, measuredSide, measuredQuadripole, lib);
}

Expand All @@ -49,7 +50,7 @@ public String getLib() {

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, MEASURE_SUFFIX + measuredSide.getSideSuffix());
createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, MEASURE_SUFFIX + SideUtils.getSideSuffix(measuredSide));
createMacroConnections(controlledQuadripole, QuadripoleModel.class, this::getVarConnectionsWithControlledQuadripole, context, CONTROL_SUFFIX);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
package com.powsybl.dynawaltz.models.automatons;

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.utils.SideUtils;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.TwoSides;

import java.util.Arrays;
import java.util.List;
Expand All @@ -25,18 +26,18 @@ public class CurrentLimitTwoLevelsAutomaton extends CurrentLimitAutomaton {
protected static final String SECOND_MEASURE_SUFFIX = MEASURE_SUFFIX + "2";

private final Branch<?> secondMeasuredQuadripole;
private final Side secondMeasuredSide;
private final TwoSides secondMeasuredSide;

public CurrentLimitTwoLevelsAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, Side measuredSide, Branch<?> secondMeasuredQuadripole, Side secondMeasuredSide, Branch<?> controlledQuadripole, String lib) {
public CurrentLimitTwoLevelsAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, TwoSides measuredSide, Branch<?> secondMeasuredQuadripole, TwoSides secondMeasuredSide, Branch<?> controlledQuadripole, String lib) {
super(dynamicModelId, parameterSetId, measuredQuadripole, measuredSide, controlledQuadripole, lib);
this.secondMeasuredQuadripole = Objects.requireNonNull(secondMeasuredQuadripole);
this.secondMeasuredSide = Objects.requireNonNull(secondMeasuredSide);
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, FIRST_MEASURE_SUFFIX + measuredSide.getSideSuffix());
createMacroConnections(secondMeasuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithSecondMeasuredQuadripole, context, SECOND_MEASURE_SUFFIX + secondMeasuredSide.getSideSuffix());
createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, FIRST_MEASURE_SUFFIX + SideUtils.getSideSuffix(measuredSide));
createMacroConnections(secondMeasuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithSecondMeasuredQuadripole, context, SECOND_MEASURE_SUFFIX + SideUtils.getSideSuffix(secondMeasuredSide));
createMacroConnections(controlledQuadripole, QuadripoleModel.class, this::getVarConnectionsWithControlledQuadripole, context, CONTROL_SUFFIX);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
package com.powsybl.dynawaltz.models.automatons;

import com.powsybl.dynawaltz.models.Model;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.iidm.network.TwoSides;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public interface QuadripoleModel extends Model {

String getIVarName(Side side);
String getIVarName(TwoSides side);

String getStateVarName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
package com.powsybl.dynawaltz.models.buses;

import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.macroconnections.MacroConnectAttribute;
import com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants;
import com.powsybl.iidm.network.TwoSides;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -42,8 +42,8 @@ public String getTerminalVarName() {
}

@Override
public String getTerminalVarName(Side side) {
return "@STATIC_ID@@NODE" + side.getSideNumber() + "@_ACPIN";
public String getTerminalVarName(TwoSides side) {
return "@STATIC_ID@@NODE" + side.getNum() + "@_ACPIN";
}

@Override
Expand All @@ -52,8 +52,8 @@ public Optional<String> getSwitchOffSignalVarName() {
}

@Override
public Optional<String> getSwitchOffSignalVarName(Side side) {
return Optional.of("@STATIC_ID@@NODE" + side.getSideNumber() + "@_switchOff");
public Optional<String> getSwitchOffSignalVarName(TwoSides side) {
return Optional.of("@STATIC_ID@@NODE" + side.getNum() + "@_switchOff");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package com.powsybl.dynawaltz.models.buses;

import com.powsybl.dynawaltz.models.Model;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.iidm.network.TwoSides;

import java.util.Optional;

Expand All @@ -20,13 +20,13 @@ public interface EquipmentConnectionPoint extends Model {

String getTerminalVarName();

default String getTerminalVarName(Side side) {
default String getTerminalVarName(TwoSides side) {
return getTerminalVarName();
}

Optional<String> getSwitchOffSignalVarName();

default Optional<String> getSwitchOffSignalVarName(Side side) {
default Optional<String> getSwitchOffSignalVarName(TwoSides side) {
return getSwitchOffSignalVarName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
package com.powsybl.dynawaltz.models.events;

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.hvdc.HvdcModel;
import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.TwoSides;

import java.util.List;

Expand All @@ -34,11 +34,11 @@ public EventHvdcDisconnection(HvdcLine equipment, double startTime) {
}

private List<VarConnection> getVarConnectionsWithHvdcModel(HvdcModel connected) {
return List.of(new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(Side.ONE)),
new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(Side.TWO)));
return List.of(new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(TwoSides.ONE)),
new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(TwoSides.TWO)));
}

private List<VarConnection> getVarConnectionsWithHvdcModelSide(HvdcModel connected, Side side) {
private List<VarConnection> getVarConnectionsWithHvdcModelSide(HvdcModel connected, TwoSides side) {
return List.of(new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(side)));
}

Expand All @@ -47,9 +47,9 @@ public void createMacroConnections(DynaWaltzContext context) {
if (disconnectOrigin && disconnectExtremity) {
createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModel, context);
} else if (disconnectOrigin) {
createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, Side.ONE);
createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, TwoSides.ONE);
} else if (disconnectExtremity) {
createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, Side.TWO);
createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, TwoSides.TWO);
}
}
}
Loading

0 comments on commit 9c8f01b

Please sign in to comment.