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

Use tie line util get paired dangling line #114

Merged
merged 20 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 @@ -8,6 +8,7 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.util.TieLineUtil;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -35,13 +36,13 @@ public CountryArea(Network network, List<Country> countries) {

danglingLineBordersCache = network.getDanglingLineStream()
.filter(this::isAreaBorder)
.collect(Collectors.toList());
.toList();
lineBordersCache = network.getLineStream()
.filter(this::isAreaBorder)
.collect(Collectors.toList());
.toList();
hvdcLineBordersCache = network.getHvdcLineStream()
.filter(this::isAreaBorder)
.collect(Collectors.toList());
.toList();

busesCache = network.getBusView().getBusStream()
.filter(bus -> bus.getVoltageLevel().getSubstation().flatMap(Substation::getCountry).map(countries::contains).orElse(false))
Expand Down Expand Up @@ -73,7 +74,7 @@ public double getLeavingFlowToCountry(CountryArea otherCountryArea) {
});
double sum = 0;
for (DanglingLine danglingLine : danglingLineBordersCache) {
if (otherSideIsInArea(danglingLine, otherCountryArea)) {
if (isOtherSideInArea(danglingLine, otherCountryArea)) {
sum += getLeavingFlow(danglingLine);
}
}
Expand All @@ -90,15 +91,8 @@ public double getLeavingFlowToCountry(CountryArea otherCountryArea) {
return sum;
}

private boolean otherSideIsInArea(DanglingLine danglingLine, CountryArea countryArea) {
Optional<TieLine> optionalTieLine = danglingLine.getTieLine();
if (optionalTieLine.isPresent()) {
TieLine tieLine = optionalTieLine.get();
DanglingLine otherSide = tieLine.getDanglingLine1() == danglingLine ? tieLine.getDanglingLine2() : tieLine.getDanglingLine1();
return countryArea.isAreaBorder(otherSide);
} else {
return false;
}
private boolean isOtherSideInArea(DanglingLine danglingLine, CountryArea countryArea) {
return TieLineUtil.getPairedDanglingLine(danglingLine).filter(countryArea::isAreaBorder).isPresent();
}

private boolean isAreaBorder(DanglingLine danglingLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.powsybl.iidm.network.extensions.LoadDetail;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author Miora Ralambotiana <miora.ralambotiana at rte-france.com>
Expand All @@ -33,14 +32,14 @@ public static Scalable createConformLoadScalable(NetworkArea area) {
.map(t -> (Load) t.getConnectable())
.filter(load -> load.getP0() >= 0)
.filter(load -> load.getExtension(LoadDetail.class) != null && load.getExtension(LoadDetail.class).getVariableActivePower() != 0)
.collect(Collectors.toList());
.toList();
if (loads.isEmpty()) {
loads = area.getContainedBusViewBuses().stream()
.flatMap(Bus::getConnectedTerminalStream)
.filter(t -> t.getConnectable() instanceof Load)
.map(t -> (Load) t.getConnectable())
.filter(load -> load.getP0() >= 0)
.collect(Collectors.toList());
.toList();
if (loads.isEmpty()) {
throw new PowsyblException("There is no load in this area");
}
Expand All @@ -49,8 +48,8 @@ public static Scalable createConformLoadScalable(NetworkArea area) {
if (totalP0 == 0.0) {
throw new PowsyblException("All loads' active power flows is null"); // this case should never happen
}
List<Float> percentages = loads.stream().map(load -> (float) (100f * load.getP0() / totalP0)).collect(Collectors.toList());
return Scalable.proportional(percentages, loads.stream().map(inj -> (Scalable) Scalable.onLoad(inj.getId())).collect(Collectors.toList()));
List<Double> percentages = loads.stream().map(load -> 100.0 * load.getP0() / totalP0).toList();
return Scalable.proportional(percentages, loads.stream().map(inj -> (Scalable) Scalable.onLoad(inj.getId())).toList());
}

private NetworkAreaUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void setUp() {

loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new DenseMatrixFactory()));

scalableFR = Scalable.proportional(Arrays.asList(60f, 30f, 10f),
scalableFR = Scalable.proportional(Arrays.asList(60.0, 30.0, 10.0),
Arrays.asList(Scalable.onGenerator("FFR1AA1 _generator"), Scalable.onGenerator("FFR2AA1 _generator"), Scalable.onGenerator("FFR3AA1 _generator")));
scalableBE = Scalable.proportional(Arrays.asList(60f, 30f, 10f),
scalableBE = Scalable.proportional(Arrays.asList(60.0, 30.0, 10.0),
Arrays.asList(Scalable.onGenerator("BBE1AA1 _generator"), Scalable.onGenerator("BBE3AA1 _generator"), Scalable.onGenerator("BBE2AA1 _generator")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void setUp() {

loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new DenseMatrixFactory()));

scalableFR = Scalable.proportional(Arrays.asList(60f, 40f),
scalableFR = Scalable.proportional(Arrays.asList(60.0, 40.0),
Arrays.asList(Scalable.onGenerator("GENERATOR_FR"), Scalable.onLoad("LOAD_FR")));

scalableBE = Scalable.proportional(Arrays.asList(60f, 40f),
scalableBE = Scalable.proportional(Arrays.asList(60.0, 40.0),
Arrays.asList(Scalable.onGenerator("GENERATOR_BE"), Scalable.onLoad("LOAD_BE")));

generatorFr = simpleNetwork.getGenerator("GENERATOR_FR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void setUp() {

loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new DenseMatrixFactory()));

scalableFR = Scalable.proportional(Arrays.asList(60f, 30f, 10f),
scalableFR = Scalable.proportional(Arrays.asList(60.0, 30.0, 10.0),
Arrays.asList(Scalable.onGenerator("FFR1AA1 _generator"), Scalable.onGenerator("FFR2AA1 _generator"), Scalable.onGenerator("FFR3AA1 _generator")));
scalableBE = Scalable.proportional(Arrays.asList(60f, 30f, 10f),
scalableBE = Scalable.proportional(Arrays.asList(60.0, 30.0, 10.0),
Arrays.asList(Scalable.onGenerator("BBE1AA1 _generator"), Scalable.onGenerator("BBE3AA1 _generator"), Scalable.onGenerator("BBE2AA1 _generator")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"dcPowerFactor" : 1.0
},
"scaling-parameters" : {
"version" : "1.0",
"version" : "1.1",
"scalingConvention" : "GENERATOR",
"constantPowerFactor" : false,
"reconnect" : false,
"iterative" : false
"priority" : "ONESHOT"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"dcPowerFactor" : 1.0
},
"scaling-parameters" : {
"version" : "1.0",
"version" : "1.1",
"scalingConvention" : "GENERATOR",
"constantPowerFactor" : false,
"reconnect" : false,
"iterative" : false
"priority" : "ONESHOT"
},
"extensions" : {
"dummy-extension" : { }
Expand Down
4 changes: 0 additions & 4 deletions emf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-cgmes-conversion</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-mergingview</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-cgmes-conformity</artifactId>
Expand Down
Loading
Loading