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

Fix bus and line models #177

Merged
merged 11 commits into from
Mar 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.util.Collections;
import java.util.List;

import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.DOUBLE;
Expand Down Expand Up @@ -80,7 +81,9 @@ private List<VarConnection> getVarConnectionsWithOmegaRefGenerator(OmegaRefGener
}

private List<VarConnection> getVarConnectionsWithBus(BusModel connected) {
return List.of(new VarConnection("numcc_node_@INDEX@", connected.getNumCCVarName()));
return connected.getNumCCVarName()
.map(numCCVarName -> List.of(new VarConnection("numcc_node_@INDEX@", numCCVarName)))
.orElse(Collections.emptyList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public enum Side {
public String getSideSuffix() {
return sideSuffix;
}

public int getSideNumber() {
return ordinal() + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

import com.powsybl.dynawaltz.models.Model;

import java.util.Optional;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface BusModel extends Model {
String getTerminalVarName();

String getSwitchOffSignalVarName();
Optional<String> getSwitchOffSignalVarName();

String getNumCCVarName();
Optional<String> getNumCCVarName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.powsybl.dynawaltz.models.AbstractNetworkModel;

import java.util.Optional;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
Expand All @@ -27,12 +29,12 @@ public String getTerminalVarName() {
}

@Override
public String getSwitchOffSignalVarName() {
return "@NAME@_switchOff";
public Optional<String> getSwitchOffSignalVarName() {
return Optional.of("@NAME@_switchOff");
}

@Override
public String getNumCCVarName() {
return "@NAME@_numcc";
public Optional<String> getNumCCVarName() {
return Optional.of("@NAME@_numcc");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.xml.stream.XMLStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -82,12 +83,12 @@ public String getTerminalVarName() {
}

@Override
public String getSwitchOffSignalVarName() {
return "bus_switchOff";
public Optional<String> getSwitchOffSignalVarName() {
return Optional.empty();
}

@Override
public String getNumCCVarName() {
return "@NAME@_numcc";
public Optional<String> getNumCCVarName() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.powsybl.dynawaltz.models.utils.BusUtils;
import com.powsybl.iidm.network.Generator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -64,10 +65,12 @@ public void createMacroConnections(DynaWaltzContext context) {
}

private List<VarConnection> getVarConnectionsWithBus(BusModel connected) {
return Arrays.asList(
new VarConnection(getTerminalVarName(), connected.getTerminalVarName()),
new VarConnection(getSwitchOffSignalNodeVarName(), connected.getSwitchOffSignalVarName())
);
List<VarConnection> varConnections = new ArrayList<>(2);
varConnections.add(new VarConnection(getTerminalVarName(), connected.getTerminalVarName()));
connected.getSwitchOffSignalVarName()
.map(switchOff -> new VarConnection(getSwitchOffSignalNodeVarName(), switchOff))
.ifPresent(varConnections::add);
return varConnections;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GeneratorFictitious(String dynamicModelId, String staticId, String parame
"generator_switchOffSignal1",
"generator_switchOffSignal2",
"generator_switchOffSignal3",
"generator_fictitious");
"generator_running");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.powsybl.dynawaltz.models.utils.SideConverter;
import com.powsybl.iidm.network.Line;

import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -35,10 +34,11 @@ public String getLib() {
}

private List<VarConnection> getVarConnectionsWithBus(BusModel connected, Side side) {
return Arrays.asList(
new VarConnection(getIVarName(side), connected.getNumCCVarName()),
new VarConnection(getStateVarName(), connected.getTerminalVarName())
);
return List.of(new VarConnection(getTerminalVarName(side), connected.getTerminalVarName()));
}

private String getTerminalVarName(Side side) {
return "line_terminal" + side.getSideNumber();
}

@Override
Expand All @@ -60,22 +60,22 @@ public String getName() {
}

@Override
public String getIVarName(Side side) {
return getDynamicModelId() + side.getSideSuffix();
public String getStateVarName() {
return "line_state";
}

@Override
public String getStateVarName() {
return getDynamicModelId() + "_state";
public String getStateValueVarName() {
return "line_state_value";
}

@Override
public String getDesactivateCurrentLimitsVarName() {
return getDynamicModelId() + "_desactivate_currentLimits";
public String getIVarName(Side side) {
throw new UnsupportedOperationException("i variable not implemented in StandardLine dynawo's model");
}

@Override
public String getStateValueVarName() {
return getDynamicModelId() + "_state_value";
public String getDesactivateCurrentLimitsVarName() {
throw new UnsupportedOperationException("deactivateCurrentLimits variable not implemented in StandardLine dynawo's model");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.dynawaltz.models.VarMapping;
import com.powsybl.dynawaltz.models.buses.BusModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -38,11 +39,17 @@ public List<VarMapping> getVarsMapping() {
return VAR_MAPPING;
}

private String getTerminalVarName() {
return "load_terminal";
}

@Override
protected List<VarConnection> getVarConnectionsWithBus(BusModel connected) {
return Arrays.asList(
new VarConnection("load_terminal", connected.getTerminalVarName()),
new VarConnection("load_switchOffSignal1", connected.getSwitchOffSignalVarName())
);
List<VarConnection> varConnections = new ArrayList<>(2);
varConnections.add(new VarConnection(getTerminalVarName(), connected.getTerminalVarName()));
connected.getSwitchOffSignalVarName()
.map(switchOff -> new VarConnection("load_switchOffSignal1", switchOff))
.ifPresent(varConnections::add);
return varConnections;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.dynawaltz.models.VarMapping;
import com.powsybl.dynawaltz.models.buses.BusModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -38,12 +39,20 @@ public List<VarMapping> getVarsMapping() {
return VAR_MAPPING;
}

private String getTerminalVarName() {
return "transformer_terminal";
}

@Override
protected List<VarConnection> getVarConnectionsWithBus(BusModel connected) {
return Arrays.asList(
new VarConnection("transformer_terminal", connected.getTerminalVarName()),
new VarConnection("transformer_switchOffSignal1", connected.getSwitchOffSignalVarName()),
new VarConnection("load_switchOffSignal1", connected.getSwitchOffSignalVarName())
);
List<VarConnection> varConnections = new ArrayList<>(3);
varConnections.add(new VarConnection(getTerminalVarName(), connected.getTerminalVarName()));
connected.getSwitchOffSignalVarName()
.map(switchOff -> new VarConnection("transformer_switchOffSignal1", switchOff))
.ifPresent(varConnections::add);
connected.getSwitchOffSignalVarName()
.map(switchOff -> new VarConnection("load_switchOffSignal1", switchOff))
.ifPresent(varConnections::add);
return varConnections;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.lines;

import com.powsybl.dynamicsimulation.Curve;
import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.DynaWaltzParameters;
import com.powsybl.dynawaltz.models.BlackBoxModel;
import com.powsybl.dynawaltz.models.Side;
import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton;
import com.powsybl.iidm.network.*;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
class StandardLineTest {

@Test
void connectionToCurrentLimitAutomatonException() {
Network network = Network.create("test", "test");
Substation s = network.newSubstation().setId("s").add();
VoltageLevel vl1 = s.newVoltageLevel().setId("vl1").setNominalV(400).setTopologyKind(TopologyKind.BUS_BREAKER).add();
VoltageLevel vl2 = s.newVoltageLevel().setId("vl2").setNominalV(400).setTopologyKind(TopologyKind.BUS_BREAKER).add();
Bus b1 = vl1.getBusBreakerView().newBus().setId("bus1").add();
Bus b2 = vl2.getBusBreakerView().newBus().setId("bus2").add();
Line l = network.newLine().setId("l").setVoltageLevel1(vl1.getId()).setBus1(b1.getId()).setVoltageLevel2(vl2.getId()).setBus2(b2.getId())
.setR(1).setX(3).setG1(0).setG2(0).setB1(0).setB2(0).add();

List<BlackBoxModel> dynamicModels = new ArrayList<>();
dynamicModels.add(new StandardLine("BBM_l", l.getId(), "SL"));
dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA", l.getId(), "CLA", Side.ONE));
DynamicSimulationParameters parameters = DynamicSimulationParameters.load();
DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load();
String workingVariantId = network.getVariantManager().getWorkingVariantId();
List<BlackBoxModel> events = Collections.emptyList();
List<Curve> curves = Collections.emptyList();
UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class,
() -> new DynaWaltzContext(network, workingVariantId, dynamicModels, events, curves, parameters, dynawoParameters));
assertEquals("i variable not implemented in StandardLine dynawo's model", e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import com.powsybl.dynawaltz.models.lines.StandardLine;
import com.powsybl.dynawaltz.models.loads.LoadAlphaBeta;
import com.powsybl.dynawaltz.models.loads.LoadOneTransformer;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.NetworkFactory;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.jupiter.api.BeforeEach;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -61,6 +58,7 @@ void setup() {

curves = new ArrayList<>();
network.getBusBreakerView().getBusStream().forEach(b -> curves.add(new DynaWaltzCurve("NETWORK", b.getId() + "_Upu_value")));

// A curve is made up of the id of the dynamic model and the variable to plot.
// The static id of the generator is used as the id of the dynamic model (dynamicModelId).
network.getGeneratorStream().forEach(g -> {
Expand Down Expand Up @@ -95,14 +93,12 @@ void setup() {
dynamicModels.add(new GeneratorSynchronous("BBM_" + g.getId(), g.getId(), "GSTWPR", "GeneratorSynchronousThreeWindingsProportionalRegulations"));
}
});
network.getBusBreakerView().getBuses().forEach(b -> {
if (b.getId().equals("NHV2") || b.getId().equals("NHV1")) {
dynamicModels.add(new StandardBus("BBM_" + b.getId(), b.getId(), "SB"));
}
});
network.getLineStream().forEach(l ->
dynamicModels.add(new StandardLine("Line_" + l.getId(), l.getId(), "SL"))
);

Bus standardBus = network.getBusBreakerView().getBus("NLOAD");
dynamicModels.add(new StandardBus("BBM_" + standardBus.getId(), standardBus.getId(), "SB"));

Line standardLine = network.getLine("NHV1_NHV2_1");
dynamicModels.add(new StandardLine("Line_" + standardLine.getId(), standardLine.getId(), "SL"));

// Events
eventModels = new ArrayList<>();
Expand All @@ -114,7 +110,8 @@ void setup() {
});

// Automatons
network.getLineStream().forEach(l -> dynamicModels.add(new CurrentLimitAutomaton("BBM_" + l.getId(), l.getId(), "CLA", Side.ONE)));
network.getLineStream().filter(line -> line != standardLine)
.forEach(l -> dynamicModels.add(new CurrentLimitAutomaton("BBM_" + l.getId(), l.getId(), "CLA", Side.ONE)));
}

public void validate(String schemaDefinition, String expectedResourceName, Path xmlFile) throws SAXException, IOException {
Expand Down
Loading