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

Clean LfGenerator #626

Merged
merged 3 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ default double getDroop() {

void updateState();

LfBus getControlledBus(LfNetwork lfNetwork);
LfBus getControlledBus();

default double getSlope() {
return 0;
Expand All @@ -79,7 +79,7 @@ default void setSlope(double slope) {
// nothing to do
}

LfBranch getControlledBranch(LfNetwork lfNetwork);
LfBranch getControlledBranch();

ReactivePowerControl.ControlledSide getControlledBranchSide();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ protected void add(LfGenerator generator) {

void addGenerator(Generator generator, boolean breakers, double plausibleActivePowerLimit, boolean reactiveLimits,
LfNetworkLoadingReport report, double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
add(LfGeneratorImpl.create(generator, breakers, plausibleActivePowerLimit, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage));
add(LfGeneratorImpl.create(generator, network, breakers, plausibleActivePowerLimit, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage));
}

void addStaticVarCompensator(StaticVarCompensator staticVarCompensator, boolean voltagePerReactivePowerControl,
boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
if (staticVarCompensator.getRegulationMode() != StaticVarCompensator.RegulationMode.OFF) {
LfStaticVarCompensatorImpl lfSvc = LfStaticVarCompensatorImpl.create(staticVarCompensator, this, voltagePerReactivePowerControl,
LfStaticVarCompensatorImpl lfSvc = LfStaticVarCompensatorImpl.create(staticVarCompensator, network, this, voltagePerReactivePowerControl,
breakers, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage);
add(lfSvc);
if (lfSvc.getSlope() != 0) {
Expand All @@ -245,11 +245,11 @@ void addStaticVarCompensator(StaticVarCompensator staticVarCompensator, boolean

void addVscConverterStation(VscConverterStation vscCs, boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
add(LfVscConverterStationImpl.create(vscCs, breakers, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage));
add(LfVscConverterStationImpl.create(vscCs, network, breakers, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage));
}

void addBattery(Battery generator, double plausibleActivePowerLimit, LfNetworkLoadingReport report) {
add(LfBatteryImpl.create(generator, plausibleActivePowerLimit, report));
add(LfBatteryImpl.create(generator, network, plausibleActivePowerLimit, report));
}

void setShuntCompensators(List<ShuntCompensator> shuntCompensators, boolean isShuntVoltageControl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public abstract class AbstractLfGenerator extends AbstractPropertyBag implements

protected static final double DEFAULT_DROOP = 4; // why not

protected final LfNetwork network;

protected double targetP;

protected LfBus bus;
Expand All @@ -45,7 +47,8 @@ public abstract class AbstractLfGenerator extends AbstractPropertyBag implements

protected double remoteTargetQ = Double.NaN;

protected AbstractLfGenerator(double targetP) {
protected AbstractLfGenerator(LfNetwork network, double targetP) {
this.network = Objects.requireNonNull(network);
this.targetP = targetP;
}

Expand Down Expand Up @@ -167,8 +170,8 @@ public void setCalculatedQ(double calculatedQ) {
}

@Override
public LfBus getControlledBus(LfNetwork lfNetwork) {
return lfNetwork.getBusById(controlledBusId);
public LfBus getControlledBus() {
return network.getBusById(controlledBusId);
}

protected void setVoltageControl(double targetV, Terminal terminal, Terminal regulatingTerminal, boolean breakers,
Expand Down Expand Up @@ -259,8 +262,8 @@ protected void setReactivePowerControl(Terminal regulatingTerminal, double targe
}

@Override
public LfBranch getControlledBranch(LfNetwork lfNetwork) {
return lfNetwork.getBranchById(controlledBranchId);
public LfBranch getControlledBranch() {
return network.getBranchById(controlledBranchId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.ReactiveLimits;
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.util.PerUnit;

import java.util.Objects;
Expand All @@ -25,8 +26,8 @@ public final class LfBatteryImpl extends AbstractLfGenerator {

private double droop;

private LfBatteryImpl(Battery battery, double plausibleActivePowerLimit, LfNetworkLoadingReport report) {
super(battery.getTargetP());
private LfBatteryImpl(Battery battery, LfNetwork network, double plausibleActivePowerLimit, LfNetworkLoadingReport report) {
super(network, battery.getTargetP());
this.battery = battery;
participating = true;
droop = DEFAULT_DROOP;
Expand All @@ -44,10 +45,10 @@ private LfBatteryImpl(Battery battery, double plausibleActivePowerLimit, LfNetwo
}
}

public static LfBatteryImpl create(Battery generator, double plausibleActivePowerLimit, LfNetworkLoadingReport report) {
Objects.requireNonNull(generator);
public static LfBatteryImpl create(Battery battery, LfNetwork network, double plausibleActivePowerLimit, LfNetworkLoadingReport report) {
Objects.requireNonNull(battery);
Objects.requireNonNull(report);
return new LfBatteryImpl(generator, plausibleActivePowerLimit, report);
return new LfBatteryImpl(battery, network, plausibleActivePowerLimit, report);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public LfDanglingLineBus(LfNetwork network, DanglingLine danglingLine, boolean r
loadTargetQ += danglingLine.getQ0();
DanglingLine.Generation generation = danglingLine.getGeneration();
if (generation != null) {
add(new LfDanglingLineGenerator(danglingLine, getId(), reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage));
add(new LfDanglingLineGenerator(danglingLine, network, getId(), reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.iidm.network.DanglingLine;
import com.powsybl.iidm.network.ReactiveLimits;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.util.PerUnit;

import java.util.Objects;
Expand All @@ -21,9 +22,9 @@ public class LfDanglingLineGenerator extends AbstractLfGenerator {

private final DanglingLine danglingLine;

public LfDanglingLineGenerator(DanglingLine danglingLine, String controlledLfBusId, boolean reactiveLimits, LfNetworkLoadingReport report,
public LfDanglingLineGenerator(DanglingLine danglingLine, LfNetwork network, String controlledLfBusId, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
super(danglingLine.getGeneration().getTargetP());
super(network, danglingLine.getGeneration().getTargetP());
this.danglingLine = danglingLine;

// local control only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.iidm.network.extensions.CoordinatedReactiveControl;
import com.powsybl.iidm.network.extensions.RemoteReactivePowerControl;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.util.PerUnit;

import java.util.Objects;
Expand All @@ -28,9 +29,9 @@ public final class LfGeneratorImpl extends AbstractLfGenerator {

private double droop;

private LfGeneratorImpl(Generator generator, boolean breakers, double plausibleActivePowerLimit, boolean reactiveLimits,
private LfGeneratorImpl(Generator generator, LfNetwork network, boolean breakers, double plausibleActivePowerLimit, boolean reactiveLimits,
LfNetworkLoadingReport report, double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
super(generator.getTargetP());
super(network, generator.getTargetP());
this.generator = generator;
participating = true;
droop = DEFAULT_DROOP;
Expand Down Expand Up @@ -58,12 +59,12 @@ private LfGeneratorImpl(Generator generator, boolean breakers, double plausibleA
}
}

public static LfGeneratorImpl create(Generator generator, boolean breakers, double plausibleActivePowerLimit,
public static LfGeneratorImpl create(Generator generator, LfNetwork network, boolean breakers, double plausibleActivePowerLimit,
boolean reactiveLimits, LfNetworkLoadingReport report, double minPlausibleTargetVoltage,
double maxPlausibleTargetVoltage) {
Objects.requireNonNull(generator);
Objects.requireNonNull(report);
return new LfGeneratorImpl(generator, breakers, plausibleActivePowerLimit, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage);
return new LfGeneratorImpl(generator, network, breakers, plausibleActivePowerLimit, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void createBuses(List<Bus> buses, LfNetworkParameters parameters,
}
}

private static void createVoltageControls(LfNetwork lfNetwork, List<LfBus> lfBuses, boolean voltageRemoteControl, boolean voltagePerReactivePowerControl) {
private static void createVoltageControls(List<LfBus> lfBuses, boolean voltageRemoteControl, boolean voltagePerReactivePowerControl) {
List<VoltageControl> voltageControls = new ArrayList<>();

// set controller -> controlled link
Expand All @@ -83,11 +83,11 @@ private static void createVoltageControls(LfNetwork lfNetwork, List<LfBus> lfBus
if (!voltageControlGenerators.isEmpty()) {

LfGenerator lfGenerator0 = voltageControlGenerators.get(0);
LfBus controlledBus = lfGenerator0.getControlledBus(lfNetwork);
LfBus controlledBus = lfGenerator0.getControlledBus();
double controllerTargetV = lfGenerator0.getTargetV();

voltageControlGenerators.stream().skip(1).forEach(lfGenerator -> {
LfBus generatorControlledBus = lfGenerator.getControlledBus(lfNetwork);
LfBus generatorControlledBus = lfGenerator.getControlledBus();

// check that remote control bus is the same for the generators of current controller bus which have voltage control on
if (checkUniqueControlledBus(controlledBus, generatorControlledBus, controllerBus)) {
Expand Down Expand Up @@ -190,7 +190,7 @@ private static void createRemoteReactivePowerControl(LfBranch controlledBranch,
controlledBranch.setReactivePowerControl(control);
}

private static void createReactivePowerControls(LfNetwork lfNetwork, List<LfBus> lfBuses) {
private static void createReactivePowerControls(List<LfBus> lfBuses) {
for (LfBus controllerBus : lfBuses) {
List<LfGenerator> generators = controllerBus.getGenerators().stream()
.filter(LfGenerator::hasRemoteReactivePowerControl).collect(Collectors.toList());
Expand All @@ -202,12 +202,12 @@ private static void createReactivePowerControls(LfNetwork lfNetwork, List<LfBus>
}
if (generators.size() == 1) {
LfGenerator lfGenerator = generators.get(0);
LfBranch controlledBranch = lfGenerator.getControlledBranch(lfNetwork);
LfBranch controlledBranch = lfGenerator.getControlledBranch();
Optional<ReactivePowerControl> control = controlledBranch.getReactivePowerControl();
if (control.isPresent()) {
LOGGER.warn("Branch {} is remotely controlled by a generator: no new remote reactive control created", controlledBranch.getId());
} else {
createRemoteReactivePowerControl(lfGenerator.getControlledBranch(lfNetwork), lfGenerator.getControlledBranchSide(), controllerBus, lfGenerator.getRemoteTargetQ());
createRemoteReactivePowerControl(lfGenerator.getControlledBranch(), lfGenerator.getControlledBranchSide(), controllerBus, lfGenerator.getRemoteTargetQ());
}
} else { // generators.size() > 1 (as > 0 and not equal to 1)
LOGGER.warn("Bus {} has more than one generator controlling reactive power remotely: not yet supported", controllerBus.getId());
Expand Down Expand Up @@ -730,9 +730,9 @@ private LfNetwork create(int numCC, int numSC, List<Bus> buses, List<Switch> swi
createBranches(lfBuses, lfNetwork, loadingContext, report, parameters, postProcessors);

if (!parameters.isDc()) {
createVoltageControls(lfNetwork, lfBuses, parameters.isGeneratorVoltageRemoteControl(), parameters.isVoltagePerReactivePowerControl());
createVoltageControls(lfBuses, parameters.isGeneratorVoltageRemoteControl(), parameters.isVoltagePerReactivePowerControl());
if (parameters.isReactivePowerRemoteControl()) {
createReactivePowerControls(lfNetwork, lfBuses);
createReactivePowerControls(lfBuses);
}
if (parameters.isTransformerVoltageControl()) {
// Discrete voltage controls need to be created after voltage controls (to test if both generator and transformer voltage control are on)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.VoltagePerReactivePowerControl;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.util.PerUnit;

import java.util.Objects;
Expand All @@ -26,10 +27,10 @@ public final class LfStaticVarCompensatorImpl extends AbstractLfGenerator {

private double slope = 0;

private LfStaticVarCompensatorImpl(StaticVarCompensator svc, AbstractLfBus bus, boolean voltagePerReactivePowerControl,
private LfStaticVarCompensatorImpl(StaticVarCompensator svc, LfNetwork network, AbstractLfBus bus, boolean voltagePerReactivePowerControl,
boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
super(0);
super(network, 0);
this.svc = svc;
this.nominalV = svc.getTerminal().getVoltageLevel().getNominalV();
this.reactiveLimits = new MinMaxReactiveLimits() {
Expand Down Expand Up @@ -71,11 +72,11 @@ public double getMaxQ(double p) {
}
}

public static LfStaticVarCompensatorImpl create(StaticVarCompensator svc, AbstractLfBus bus, boolean voltagePerReactivePowerControl,
public static LfStaticVarCompensatorImpl create(StaticVarCompensator svc, LfNetwork network, AbstractLfBus bus, boolean voltagePerReactivePowerControl,
boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
Objects.requireNonNull(svc);
return new LfStaticVarCompensatorImpl(svc, bus, voltagePerReactivePowerControl, breakers, reactiveLimits,
return new LfStaticVarCompensatorImpl(svc, network, bus, voltagePerReactivePowerControl, breakers, reactiveLimits,
report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.openloadflow.network.impl;

import com.powsybl.iidm.network.*;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.LfVscConverterStation;
import com.powsybl.openloadflow.util.PerUnit;

Expand All @@ -22,9 +23,9 @@ public class LfVscConverterStationImpl extends AbstractLfGenerator implements Lf

private final double lossFactor;

public LfVscConverterStationImpl(VscConverterStation station, boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
public LfVscConverterStationImpl(VscConverterStation station, LfNetwork network, boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
super(HvdcConverterStations.getConverterStationTargetP(station));
super(network, HvdcConverterStations.getConverterStationTargetP(station));
this.station = station;
this.lossFactor = station.getLossFactor();

Expand All @@ -35,10 +36,10 @@ public LfVscConverterStationImpl(VscConverterStation station, boolean breakers,
}
}

public static LfVscConverterStationImpl create(VscConverterStation station, boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
public static LfVscConverterStationImpl create(VscConverterStation station, LfNetwork network, boolean breakers, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
Objects.requireNonNull(station);
return new LfVscConverterStationImpl(station, breakers, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage);
return new LfVscConverterStationImpl(station, network, breakers, reactiveLimits, report, minPlausibleTargetVoltage, maxPlausibleTargetVoltage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import com.powsybl.iidm.network.extensions.VoltagePerReactivePowerControlAdder;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.openloadflow.network.LfGenerator;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.MostMeshedSlackBusSelector;
import com.powsybl.openloadflow.graph.NaiveGraphConnectivityFactory;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.util.PerUnit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -146,16 +145,17 @@ void updateGeneratorsStateTest() {
Assertions.assertEquals(generationQ, sumQ, DELTA_POWER, "sum of generators calculatedQ should be equals to qToDispatch");
}

private List<LfGenerator> createLfGeneratorsWithInitQ(List<Double> initQs) {
private static List<LfGenerator> createLfGeneratorsWithInitQ(List<Double> initQs) {
Network network = FourSubstationsNodeBreakerFactory.create();
LfNetwork lfNetwork = new LfNetwork(0, 0, new FirstSlackBusSelector(), new NaiveGraphConnectivityFactory<>(LfBus::getNum));
LfNetworkLoadingReport lfNetworkLoadingReport = new LfNetworkLoadingReport();
LfGenerator lfGenerator1 = LfGeneratorImpl.create(network.getGenerator("GH1"),
LfGenerator lfGenerator1 = LfGeneratorImpl.create(network.getGenerator("GH1"), lfNetwork,
false, 100, true, lfNetworkLoadingReport, 0.9, 1.1);
lfGenerator1.setCalculatedQ(initQs.get(0));
LfGenerator lfGenerator2 = LfGeneratorImpl.create(network.getGenerator("GH2"),
LfGenerator lfGenerator2 = LfGeneratorImpl.create(network.getGenerator("GH2"), lfNetwork,
false, 200, true, lfNetworkLoadingReport, 0.9, 1.1);
lfGenerator2.setCalculatedQ(initQs.get(1));
LfGenerator lfGenerator3 = LfGeneratorImpl.create(network.getGenerator("GH3"),
LfGenerator lfGenerator3 = LfGeneratorImpl.create(network.getGenerator("GH3"), lfNetwork,
false, 200, true, lfNetworkLoadingReport, 0.9, 1.1);
lfGenerator3.setCalculatedQ(initQs.get(2));
List<LfGenerator> generators = new ArrayList<>();
Expand Down