Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 @@ -389,6 +389,12 @@ static PowsyblException createNotSupportedBusBreakerTopologyException() {
}

private final VoltageLevelExt.NodeBreakerViewExt nodeBreakerView = new VoltageLevelExt.NodeBreakerViewExt() {

@Override
public boolean hasFictitiousP0() {
throw createNotSupportedBusBreakerTopologyException();
}

@Override
public double getFictitiousP0(int node) {
throw createNotSupportedBusBreakerTopologyException();
Expand All @@ -399,6 +405,11 @@ public VoltageLevel.NodeBreakerView setFictitiousP0(int node, double p0) {
throw createNotSupportedBusBreakerTopologyException();
}

@Override
public boolean hasFictitiousQ0() {
throw createNotSupportedBusBreakerTopologyException();
}

@Override
public double getFictitiousQ0(int node) {
throw createNotSupportedBusBreakerTopologyException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public double getQ() {
@Override
public double getFictitiousP0() {
checkValidity();
if (voltageLevel.getNodeBreakerView().hasFictitiousP0()) {
return 0.0;
}
return Networks.getNodes(id, voltageLevel, getBusFromTerminal)
.mapToDouble(n -> voltageLevel.getNodeBreakerView().getFictitiousP0(n))
.reduce(0.0, Double::sum);
Expand All @@ -165,6 +168,9 @@ public Bus setFictitiousP0(double p0) {
@Override
public double getFictitiousQ0() {
checkValidity();
if (!voltageLevel.getNodeBreakerView().hasFictitiousQ0()) {
return 0.0;
}
return Networks.getNodes(id, voltageLevel, getBusFromTerminal)
.mapToDouble(n -> voltageLevel.getNodeBreakerView().getFictitiousQ0(n))
.reduce(0.0, Double::sum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,21 @@ void removeSwitchFromTopology(String switchId, boolean notify) {
private final TIntObjectMap<TDoubleArrayList> fictitiousP0ByNode = TCollections.synchronizedMap(new TIntObjectHashMap<>());
private final TIntObjectMap<TDoubleArrayList> fictitiousQ0ByNode = TCollections.synchronizedMap(new TIntObjectHashMap<>());

@Override
public boolean hasFictitiousP0() {
if (fictitiousP0ByNode.isEmpty()) {
return false;
}
int variantIndex = getNetwork().getVariantIndex();
for (int node : fictitiousP0ByNode.keys()) {
TDoubleArrayList p0ByVariant = fictitiousP0ByNode.get(node);
if (p0ByVariant != null && p0ByVariant.get(variantIndex) != 0.0) {
return true;
}
}
return false;
Copy link
Member

Choose a reason for hiding this comment

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

you can avoid duplication by creating a small private method with the map (fictitiousP0ByNode or fictitiousQ0ByNode) as argument

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍

}

@Override
public double getFictitiousP0(int node) {
TDoubleArrayList fictP0 = fictitiousP0ByNode.get(node);
Expand Down Expand Up @@ -684,6 +699,21 @@ public VoltageLevel.NodeBreakerView setFictitiousP0(int node, double p0) {
return this;
}

@Override
public boolean hasFictitiousQ0() {
if (fictitiousQ0ByNode.isEmpty()) {
return false;
}
int variantIndex = getNetwork().getVariantIndex();
for (int node : fictitiousQ0ByNode.keys()) {
TDoubleArrayList p0ByVariant = fictitiousQ0ByNode.get(node);
if (p0ByVariant != null && p0ByVariant.get(variantIndex) != 0.0) {
return true;
}
}
return false;
}

@Override
public double getFictitiousQ0(int node) {
TDoubleArrayList fictQ0 = fictitiousQ0ByNode.get(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ interface VoltageLevelExt extends VoltageLevel, MultiVariantObject, Validable {

interface NodeBreakerViewExt extends NodeBreakerView {

/**
* Returns true if any node has a non-zero fictitious active power injection.
*/
default boolean hasFictitiousP0() {
return false;
}

/**
* Returns true if any node has a non-zero fictitious reactive power injection.
*/
default boolean hasFictitiousQ0() {
return false;
}

}

interface BusBreakerViewExt extends BusBreakerView {
Expand Down
Loading