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

Get original ID #494

Merged
merged 9 commits into from
Apr 8, 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 @@ -7,6 +7,7 @@
package com.powsybl.openloadflow.network;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

Expand All @@ -27,6 +28,11 @@ protected AbstractElement(LfNetwork network) {
this.network = Objects.requireNonNull(network);
}

@Override
public List<String> getOriginalIds() {
return List.of(getId());
}

public int getNum() {
return num;
}
Expand Down
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.getLfLoads().getAbsVariableLoadTargetP();
this.absVariableLoadTargetP = bus.getLoads().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.getLfLoads().setAbsVariableLoadTargetP(absVariableLoadTargetP);
element.getLoads().setAbsVariableLoadTargetP(absVariableLoadTargetP);
}

public static BusDcState save(LfBus bus) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public interface LfBranch extends LfElement {

double LOW_IMPEDANCE_THRESHOLD = Math.pow(10, -8); // in per unit

enum BranchType {
LINE,
TRANSFO_2,
TRANSFO_3_LEG_1,
TRANSFO_3_LEG_2,
TRANSFO_3_LEG_3,
DANGLING_LINE,
SWITCH
}

class LfLimit {

private int acceptableDuration;
Expand Down Expand Up @@ -55,6 +65,8 @@ public void setAcceptableDuration(int acceptableDuration) {
}
}

BranchType getBranchType();

LfBus getBus1();

LfBus getBus2();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/powsybl/openloadflow/network/LfBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.openloadflow.network;

import com.powsybl.openloadflow.network.impl.LfLoads;
import com.powsybl.openloadflow.util.Evaluable;
import com.powsybl.security.results.BusResults;

Expand Down Expand Up @@ -118,7 +117,7 @@ default double getHighVoltageLimit() {

Optional<LfShunt> getControllerShunt();

LfLoads getLfLoads();
LfLoads getLoads();
Copy link
Member

Choose a reason for hiding this comment

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

You really prefer that name? It is a bit confusing with the Load of IIDM network, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

For any other element accessors we did not use lf


List<LfBranch> getBranches();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void apply(LoadFlowParameters parameters) {
PowerShift shift = e.getValue();
bus.setLoadTargetP(bus.getLoadTargetP() - getUpdatedLoadP0(bus, parameters.getBalanceType(), shift.getActive(), shift.getVariableActive()));
bus.setLoadTargetQ(bus.getLoadTargetQ() - shift.getReactive());
bus.getLfLoads().setAbsVariableLoadTargetP(bus.getLfLoads().getAbsVariableLoadTargetP() - Math.abs(shift.getVariableActive()) * PerUnit.SB);
bus.getLoads().setAbsVariableLoadTargetP(bus.getLoads().getAbsVariableLoadTargetP() - Math.abs(shift.getVariableActive()) * PerUnit.SB);
}
for (LfGenerator generator : generators) {
generator.setTargetP(0);
Expand All @@ -124,9 +124,9 @@ public void apply(LoadFlowParameters parameters) {
public static double getUpdatedLoadP0(LfBus bus, LoadFlowParameters.BalanceType balanceType, double initialP0, double initialVariableActivePower) {
double factor = 0.0;
if (balanceType == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD) {
factor = Math.abs(initialP0) / (bus.getLfLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
factor = Math.abs(initialP0) / (bus.getLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
} else if (balanceType == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD) {
factor = initialVariableActivePower / (bus.getLfLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
factor = initialVariableActivePower / (bus.getLoads().getAbsVariableLoadTargetP() / PerUnit.SB);
}
return initialP0 + (bus.getLoadTargetP() - bus.getInitialLoadTargetP()) * factor;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
*/
package com.powsybl.openloadflow.network;

import java.util.List;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public interface LfElement {

String getId();

List<String> getOriginalIds();

ElementType getType();

int getNum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ enum GeneratorControlType {

String getId();

String getOriginalId();

LfBus getBus();

void setBus(LfBus bus);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfLoads.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2021, 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/.
*/
package com.powsybl.openloadflow.network;

import java.util.List;

/**
* @author Anne Tilloy <anne.tilloy at rte-france.com>
*/
public interface LfLoads {

List<String> getOriginalIds();

double getAbsVariableLoadTargetP();

void setAbsVariableLoadTargetP(double absVariableLoadTargetP);

double getLoadCount();

double getLoadTargetQ(double diffLoadTargetP);
}
4 changes: 2 additions & 2 deletions src/main/java/com/powsybl/openloadflow/network/LfNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public void addBus(LfBus bus) {
bus.getShunt().ifPresent(shunt -> {
shunt.setNum(shuntCount++);
shuntsByIndex.add(shunt);
shunt.getIds().forEach(id -> shuntsById.put(id, shunt));
shunt.getOriginalIds().forEach(id -> shuntsById.put(id, shunt));
});
bus.getControllerShunt().ifPresent(shunt -> {
shunt.setNum(shuntCount++);
shuntsByIndex.add(shunt);
shunt.getIds().forEach(id -> shuntsById.put(id, shunt));
shunt.getOriginalIds().forEach(id -> shuntsById.put(id, shunt));
});
bus.getGenerators().forEach(gen -> generatorsById.put(gen.getId(), gen));
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/powsybl/openloadflow/network/LfShunt.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
*/
package com.powsybl.openloadflow.network;

import java.util.List;
import java.util.Optional;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public interface LfShunt extends LfElement {

List<String> getIds();

double getB();

void setB(double b);
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 LfLoads lfLoads = new LfLoads();
protected final LfLoadsImpl lfLoads = new LfLoadsImpl();

protected boolean ensurePowerFactorConstantByLoad = false;

Expand Down Expand Up @@ -397,7 +397,7 @@ public List<LfGenerator> getGenerators() {
}

@Override
public LfLoads getLfLoads() {
public LfLoads getLoads() {
return lfLoads;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ protected AbstractLfGenerator(double targetP) {
this.targetP = targetP;
}

@Override
public String getOriginalId() {
return getId();
}

public LfBus getBus() {
return bus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public String getId() {
return branch.getId();
}

@Override
public BranchType getBranchType() {
return branch instanceof Line ? BranchType.LINE : BranchType.TRANSFO_2;
}

@Override
public boolean hasPhaseControlCapability() {
return branch.getType() == IdentifiableType.TWO_WINDINGS_TRANSFORMER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public String getId() {
return danglingLine.getId();
}

@Override
public BranchType getBranchType() {
return BranchType.DANGLING_LINE;
}

@Override
public boolean hasPhaseControlCapability() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.iidm.network.DanglingLine;
import com.powsybl.openloadflow.network.LfNetwork;

import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -36,6 +37,11 @@ public static String getId(DanglingLine danglingLine) {
return danglingLine.getId() + "_BUS";
}

@Override
public List<String> getOriginalIds() {
return List.of(danglingLine.getId());
}

@Override
public String getId() {
return getId(danglingLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public String getId() {
return danglingLine.getId() + "_GEN";
}

@Override
public String getOriginalId() {
return danglingLine.getId();
}

@Override
public OptionalDouble getRemoteControlReactiveKey() {
return OptionalDouble.empty();
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/com/powsybl/openloadflow/network/impl/LfHvdcImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,46 @@
/**
* @author Anne Tilloy <anne.tilloy at rte-france.com>
*/
public final class LfHvdcImpl extends AbstractElement implements LfHvdc {
public class LfHvdcImpl extends AbstractElement implements LfHvdc {

private String id;
private final String id;

private LfBus bus1;
private final LfBus bus1;

private LfBus bus2;
private final LfBus bus2;

private Evaluable p1 = NAN;

private Evaluable p2 = NAN;

private double droop;
private final double droop;

private double p0;
private final double p0;

private LfVscConverterStationImpl vsc1;

private LfVscConverterStationImpl vsc2;

public LfHvdcImpl(HvdcAngleDroopActivePowerControl control, LfBus bus1, LfBus bus2, LfNetwork network, String hvdcId) {
public LfHvdcImpl(String id, LfBus bus1, LfBus bus2, LfNetwork network, HvdcAngleDroopActivePowerControl control) {
super(network);
this.id = hvdcId;
this.id = Objects.requireNonNull(id);
this.bus1 = bus1;
this.bus2 = bus2;
Objects.requireNonNull(control);
droop = control.getDroop();
p0 = control.getP0();
}

@Override
public ElementType getType() {
return ElementType.HVDC;
}

@Override
public String getId() {
return id;
}

@Override
public LfBus getBus1() {
return this.bus1;
Expand Down Expand Up @@ -109,16 +120,6 @@ public void setConverterStation2(LfVscConverterStationImpl converterStation2) {
converterStation2.setTargetP(0);
}

@Override
public ElementType getType() {
return ElementType.HVDC;
}

@Override
public String getId() {
return id;
}

@Override
public void updateState() {
// Should be done before updating state of generators.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ public String getId() {
return getId(twt.getId(), getLegNum());
}

@Override
public BranchType getBranchType() {
if (leg == twt.getLeg1()) {
return BranchType.TRANSFO_3_LEG_1;
} else if (leg == twt.getLeg2()) {
return BranchType.TRANSFO_3_LEG_2;
} else {
return BranchType.TRANSFO_3_LEG_3;
}
}

@Override
public List<String> getOriginalIds() {
return List.of(twt.getId());
}

@Override
public boolean hasPhaseControlCapability() {
return leg.getPhaseTapChanger() != null;
Expand Down
Loading