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

Aggredated loads properties #592

Merged
merged 6 commits into from
Sep 9, 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 @@ -24,7 +24,7 @@ public BusDcState(LfBus bus) {
this.loadTargetP = bus.getLoadTargetP();
this.generatorsTargetP = bus.getGenerators().stream().collect(Collectors.toMap(LfGenerator::getId, LfGenerator::getTargetP));
this.participatingGenerators = bus.getGenerators().stream().collect(Collectors.toMap(LfGenerator::getId, LfGenerator::isParticipating));
this.absVariableLoadTargetP = bus.getLoads().getAbsVariableLoadTargetP();
this.absVariableLoadTargetP = bus.getAggregatedLoads().getAbsVariableLoadTargetP();
}

@Override
Expand All @@ -33,7 +33,7 @@ public void restore() {
element.setLoadTargetP(loadTargetP);
element.getGenerators().forEach(g -> g.setTargetP(generatorsTargetP.get(g.getId())));
element.getGenerators().forEach(g -> g.setParticipating(participatingGenerators.get(g.getId())));
element.getLoads().setAbsVariableLoadTargetP(absVariableLoadTargetP);
element.getAggregatedLoads().setAbsVariableLoadTargetP(absVariableLoadTargetP);
}

public static BusDcState save(LfBus bus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Anne Tilloy <anne.tilloy at rte-france.com>
*/
public interface LfLoads {
public interface LfAggregatedLoads extends PropertyBag {

List<String> getOriginalIds();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/powsybl/openloadflow/network/LfBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ default double getHighVoltageLimit() {

Optional<LfShunt> getControllerShunt();

LfLoads getLoads();
LfAggregatedLoads getAggregatedLoads();

List<LfBranch> getBranches();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void apply(LoadFlowParameters.BalanceType balanceType) {
PowerShift shift = e.getValue();
bus.setLoadTargetP(bus.getLoadTargetP() - getUpdatedLoadP0(bus, balanceType, shift.getActive(), shift.getVariableActive()));
bus.setLoadTargetQ(bus.getLoadTargetQ() - shift.getReactive());
bus.getLoads().setAbsVariableLoadTargetP(bus.getLoads().getAbsVariableLoadTargetP() - Math.abs(shift.getVariableActive()) * PerUnit.SB);
bus.getAggregatedLoads().setAbsVariableLoadTargetP(bus.getAggregatedLoads().getAbsVariableLoadTargetP() - Math.abs(shift.getVariableActive()) * PerUnit.SB);
}
Set<LfBus> generatorBuses = new HashSet<>();
for (LfGenerator generator : lostGenerators) {
Expand All @@ -138,11 +138,11 @@ public void apply(LoadFlowParameters.BalanceType balanceType) {

public static double getUpdatedLoadP0(LfBus bus, LoadFlowParameters.BalanceType balanceType, double initialP0, double initialVariableActivePower) {
double factor = 0.0;
if (bus.getLoads().getLoadCount() > 0) {
if (bus.getAggregatedLoads().getLoadCount() > 0) {
if (balanceType == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD) {
factor = Math.abs(initialP0) / (bus.getLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
factor = Math.abs(initialP0) / (bus.getAggregatedLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
} else if (balanceType == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD) {
factor = initialVariableActivePower / (bus.getLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
factor = initialVariableActivePower / (bus.getAggregatedLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
}
}
return initialP0 + (bus.getLoadTargetP() - bus.getInitialLoadTargetP()) * factor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public abstract class AbstractLfBus extends AbstractElement implements LfBus {

protected LfShunt controllerShunt;

protected final LfLoadsImpl lfLoads = new LfLoadsImpl();
protected final LfAggregatedLoadsImpl lfAggregatedLoads;

protected boolean ensurePowerFactorConstantByLoad = false;

Expand All @@ -82,8 +82,9 @@ public abstract class AbstractLfBus extends AbstractElement implements LfBus {

protected double remoteVoltageControlReactivePercent = Double.NaN;

protected AbstractLfBus(LfNetwork network, double v, double angle) {
protected AbstractLfBus(LfNetwork network, double v, double angle, boolean distributedOnConformLoad) {
super(network);
lfAggregatedLoads = new LfAggregatedLoadsImpl(distributedOnConformLoad);
this.v = v;
this.angle = angle;
}
Expand Down Expand Up @@ -197,15 +198,15 @@ public void setVoltageControlSwitchOffCount(int voltageControlSwitchOffCount) {
this.voltageControlSwitchOffCount = voltageControlSwitchOffCount;
}

void addLoad(Load load, boolean distributedOnConformLoad) {
void addLoad(Load load) {
double p0 = load.getP0();
loadTargetP += p0;
initialLoadTargetP += p0;
loadTargetQ += load.getQ0();
if (p0 < 0) {
ensurePowerFactorConstantByLoad = true;
}
lfLoads.add(load, distributedOnConformLoad);
lfAggregatedLoads.add(load);
}

void addLccConverterStation(LccConverterStation lccCs) {
Expand Down Expand Up @@ -399,8 +400,8 @@ public List<LfGenerator> getGenerators() {
}

@Override
public LfLoads getLoads() {
return lfLoads;
public LfAggregatedLoads getAggregatedLoads() {
return lfAggregatedLoads;
}

@Override
Expand Down Expand Up @@ -468,7 +469,7 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus, boolean d
updateGeneratorsState(voltageControlEnabled ? q.eval() * PerUnit.SB + loadTargetQ : generationTargetQ, reactiveLimits);

// update load power
lfLoads.updateState(getLoadTargetP() - getInitialLoadTargetP(), loadPowerFactorConstant);
lfAggregatedLoads.updateState(getLoadTargetP() - getInitialLoadTargetP(), loadPowerFactorConstant);

// update lcc converter station power
for (LccConverterStation lccCs : lccCss) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.extensions.LoadDetail;
import com.powsybl.openloadflow.network.LfLoads;
import com.powsybl.openloadflow.network.AbstractPropertyBag;
import com.powsybl.openloadflow.network.LfAggregatedLoads;
import com.powsybl.openloadflow.util.PerUnit;

import java.util.ArrayList;
Expand All @@ -19,26 +20,30 @@
/**
* @author Anne Tilloy <anne.tilloy at rte-france.com>
*/
public class LfLoadsImpl implements LfLoads {
class LfAggregatedLoadsImpl extends AbstractPropertyBag implements LfAggregatedLoads {

private final List<Load> loads = new ArrayList<>();

private double[] participationFactors;

private double absVariableLoadTargetP = 0;
private double absVariableLoadTargetP;

private boolean distributedOnConformLoad;
private final boolean distributedOnConformLoad;

private boolean isInitialized;
private boolean initialized;

LfAggregatedLoadsImpl(boolean distributedOnConformLoad) {
this.distributedOnConformLoad = distributedOnConformLoad;
}

@Override
public List<String> getOriginalIds() {
return loads.stream().map(Identifiable::getId).collect(Collectors.toList());
}

void add(Load load, boolean distributedOnConformLoad) {
void add(Load load) {
loads.add(load);
this.distributedOnConformLoad = distributedOnConformLoad; // TODO: put in constructor instead
initialized = false;
}

@Override
Expand All @@ -53,11 +58,12 @@ public void setAbsVariableLoadTargetP(double absVariableLoadTargetP) {
}

private void init() {
if (isInitialized) {
if (initialized) {
return;
}

participationFactors = new double[loads.size()];
absVariableLoadTargetP = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have private double absVariableLoadTargetP = 0;, so we must clean?

for (int i = 0; i < loads.size(); i++) {
Load load = loads.get(i);
double value;
Expand All @@ -76,7 +82,7 @@ private void init() {
}
}

isInitialized = true;
initialized = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ public class LfBusImpl extends AbstractLfBus {

private final boolean participating;

protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, boolean participating) {
super(network, v, angle);
protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, boolean distributedOnConformLoad, boolean participating) {
super(network, v, angle, distributedOnConformLoad);
this.bus = bus;
nominalV = bus.getVoltageLevel().getNominalV();
lowVoltageLimit = bus.getVoltageLevel().getLowVoltageLimit();
highVoltageLimit = bus.getVoltageLevel().getHighVoltageLimit();
this.participating = participating;
}

public static LfBusImpl create(Bus bus, LfNetwork network, boolean participating) {
public static LfBusImpl create(Bus bus, LfNetwork network, boolean distributedOnConformLoad, boolean participating) {
Objects.requireNonNull(bus);
return new LfBusImpl(bus, network, bus.getV(), bus.getAngle(), participating);
return new LfBusImpl(bus, network, bus.getV(), bus.getAngle(), distributedOnConformLoad, participating);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LfDanglingLineBus extends AbstractLfBus {

public LfDanglingLineBus(LfNetwork network, DanglingLine danglingLine, boolean reactiveLimits, LfNetworkLoadingReport report,
double minPlausibleTargetVoltage, double maxPlausibleTargetVoltage) {
super(network, Networks.getPropertyV(danglingLine), Networks.getPropertyAngle(danglingLine));
super(network, Networks.getPropertyV(danglingLine), Networks.getPropertyAngle(danglingLine), false);
this.danglingLine = Objects.requireNonNull(danglingLine);
nominalV = danglingLine.getTerminal().getVoltageLevel().getNominalV();
loadTargetP += danglingLine.getP0();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private static Bus getBus(Terminal terminal, boolean breakers) {

private static LfBusImpl createBus(Bus bus, LfNetworkParameters parameters, LfNetwork lfNetwork, LoadingContext loadingContext,
LfNetworkLoadingReport report, List<LfNetworkLoaderPostProcessor> postProcessors) {
LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork, participateToSlackDistribution(parameters, bus));
LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork, parameters.isDistributedOnConformLoad(), participateToSlackDistribution(parameters, bus));

List<ShuntCompensator> shuntCompensators = new ArrayList<>();

Expand Down Expand Up @@ -256,7 +256,7 @@ public void visitGenerator(Generator generator) {

@Override
public void visitLoad(Load load) {
lfBus.addLoad(load, parameters.isDistributedOnConformLoad());
lfBus.addLoad(load);
postProcessors.forEach(pp -> pp.onInjectionAdded(load, lfBus));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LfStarBus extends AbstractLfBus {
private final double nominalV;

public LfStarBus(LfNetwork network, ThreeWindingsTransformer t3wt) {
super(network, Networks.getPropertyV(t3wt), Networks.getPropertyAngle(t3wt));
super(network, Networks.getPropertyV(t3wt), Networks.getPropertyAngle(t3wt), false);
this.t3wt = t3wt;
nominalV = t3wt.getRatedU0();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public String getElementType() {
@Override
public List<ParticipatingElement> getParticipatingElements(Collection<LfBus> buses) {
return buses.stream()
.filter(bus -> bus.getLoads().getLoadCount() > 0 && bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious())
.filter(bus -> bus.getAggregatedLoads().getLoadCount() > 0 && bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious())
.map(bus -> new ParticipatingElement(bus, getParticipationFactor(bus)))
.collect(Collectors.toList());
}

private double getParticipationFactor(LfBus bus) {
return bus.getLoads().getAbsVariableLoadTargetP();
return bus.getAggregatedLoads().getAbsVariableLoadTargetP();
}

@Override
Expand Down Expand Up @@ -89,7 +89,7 @@ private static void ensurePowerFactorConstant(LfBus bus, double newLoadTargetP)
// we have to keep the power factor constant by updating targetQ.
double newLoadTargetQ;
if (bus.ensurePowerFactorConstantByLoad()) {
newLoadTargetQ = bus.getLoads().getLoadTargetQ(newLoadTargetP - bus.getInitialLoadTargetP());
newLoadTargetQ = bus.getAggregatedLoads().getLoadTargetQ(newLoadTargetP - bus.getInitialLoadTargetP());
} else {
newLoadTargetQ = newLoadTargetP * bus.getLoadTargetQ() / bus.getLoadTargetP();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void testWith3wtNetwork() {
assertEquals(List.of("3wt"), lfNetwork.getBusById("3wt_BUS0").getOriginalIds());
assertEquals(List.of("vl1_0"), lfNetwork.getBusById("vl1_0").getOriginalIds());
assertEquals("g1", lfNetwork.getGeneratorById("g1").getOriginalId());
assertEquals(List.of("ld2"), lfNetwork.getBusById("vl2_0").getLoads().getOriginalIds());
assertEquals(List.of("ld2"), lfNetwork.getBusById("vl2_0").getAggregatedLoads().getOriginalIds());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void updateGeneratorsStateTest() {
List<LfNetwork> networks = Networks.load(EurostagTutorialExample1Factory.create(), new MostMeshedSlackBusSelector());
LfNetwork mainNetwork = networks.get(0);

LfBusImpl lfBus = new LfBusImpl(bus1, mainNetwork, 385, 0, true);
LfBusImpl lfBus = new LfBusImpl(bus1, mainNetwork, 385, 0, false, true);
LfNetworkLoadingReport lfNetworkLoadingReport = new LfNetworkLoadingReport();
lfBus.addStaticVarCompensator(svc1, false, true, true, lfNetworkLoadingReport, 0.8, 1.2);
lfBus.addStaticVarCompensator(svc2, false, true, true, lfNetworkLoadingReport, 0.8, 1.2);
Expand Down