Skip to content

Commit

Permalink
rename + clean
Browse files Browse the repository at this point in the history
Signed-off-by: vmouradian <valentin.mouradian@artelys.com>
  • Loading branch information
vmouradian committed Jul 19, 2024
1 parent 097d801 commit 5a29ee9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ public boolean isGeneratorReactivePowerRemoteControl() {
return generatorReactivePowerRemoteControl;
}

public OpenLoadFlowParameters setVoltagePerReactivePowerControl(boolean voltagePerReactivePowerControl) {
this.voltagePerReactivePowerControl = voltagePerReactivePowerControl;
return this;
}

public OpenLoadFlowParameters setGeneratorReactivePowerRemoteControl(boolean generatorReactivePowerRemoteControl) {
this.generatorReactivePowerRemoteControl = generatorReactivePowerRemoteControl;
return this;
Expand Down Expand Up @@ -1236,11 +1241,6 @@ public OpenLoadFlowParameters setAreaInterchangeControlAreaType(String areaInter
return this;
}

public OpenLoadFlowParameters setVoltagePerReactivePowerControl(boolean voltagePerReactivePowerControl) {
this.voltagePerReactivePowerControl = voltagePerReactivePowerControl;
return this;
}

public static OpenLoadFlowParameters load() {
return load(PlatformConfig.defaultConfig());
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/powsybl/openloadflow/network/LfNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class LfNetwork extends AbstractPropertyBag implements PropertyBag {

private final Map<String, LfLoad> loadsById = new HashMap<>();

private final Map<String, LfArea> controlAreasById = new HashMap<>();
private final Map<String, LfArea> areasById = new HashMap<>();

private final List<LfHvdc> hvdcs = new ArrayList<>();

Expand Down Expand Up @@ -301,9 +301,9 @@ public void addBus(LfBus bus) {
bus.getLoads().forEach(load -> load.getOriginalIds().forEach(id -> loadsById.put(id, load)));
}

public void addControlArea(LfArea controlArea) {
Objects.requireNonNull(controlArea);
controlAreasById.put(controlArea.getId(), controlArea);
public void addArea(LfArea area) {
Objects.requireNonNull(area);
areasById.put(area.getId(), area);
}

public List<LfBus> getBuses() {
Expand Down Expand Up @@ -373,9 +373,13 @@ public LfLoad getLoadById(String id) {
return loadsById.get(id);
}

public LfArea getControlAreaById(String id) {
public List<LfArea> getAreas() {
return new ArrayList<>(areasById.values());
}

public LfArea getAreaById(String id) {
Objects.requireNonNull(id);
return controlAreasById.get(id);
return areasById.get(id);
}

public void addHvdc(LfHvdc hvdc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static class LoadingContext {

private final Set<HvdcLine> hvdcLineSet = new LinkedHashSet<>();

private final Map<Terminal, LfArea> areaBoundaries = new HashMap<>();
private final Map<Terminal, LfArea> areaTerminalMap = new HashMap<>();
}

private final Supplier<List<LfNetworkLoaderPostProcessor>> postProcessorsSupplier;
Expand Down Expand Up @@ -319,7 +319,7 @@ private static LfBusImpl createBus(Bus bus, LfNetworkParameters parameters, LfNe

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

updateControlArea(bus, lfBus, lfNetwork, parameters, loadingContext, report);
updateArea(bus, lfBus, lfNetwork, parameters, loadingContext, report);

bus.visitConnectedEquipments(new DefaultTopologyVisitor() {

Expand Down Expand Up @@ -433,7 +433,7 @@ private static void createBranches(List<LfBus> lfBuses, LfNetwork lfNetwork, LfT
LfBus lfBus2 = getLfBus(branch.getTerminal2(), lfNetwork, parameters.isBreakers());
LfBranchImpl lfBranch = LfBranchImpl.create(branch, lfNetwork, lfBus1, lfBus2, topoConfig, parameters);
addBranch(lfNetwork, lfBranch, report);
addLineAreaBoundaries(branch, lfBranch, loadingContext);
addBranchAreaBoundaries(branch, lfBranch, loadingContext);
postProcessors.forEach(pp -> pp.onBranchAdded(branch, lfBranch));
}

Expand Down Expand Up @@ -511,28 +511,29 @@ private static void createBranches(List<LfBus> lfBuses, LfNetwork lfNetwork, LfT
}
}

private static void updateControlArea(Bus bus, LfBus lfBus, LfNetwork network, LfNetworkParameters parameters, LoadingContext loadingContext, LfNetworkLoadingReport report) {
private static void updateArea(Bus bus, LfBus lfBus, LfNetwork network, LfNetworkParameters parameters, LoadingContext loadingContext, LfNetworkLoadingReport report) {
// Consider only the area type that should be used for area interchange control
Optional<Area> areaOpt = bus.getVoltageLevel().getArea(parameters.getAreaInterchangeControlAreaType());
areaOpt.ifPresent(area -> {
LfArea controlArea = network.getControlAreaById(area.getId());
if (controlArea == null) {
controlArea = createControlArea(area, parameters, loadingContext, network);
LfArea lfArea = network.getAreaById(area.getId());
if (lfArea == null) {
lfArea = createControlArea(area, parameters, loadingContext, network);
}
controlArea.addBus(lfBus);
lfArea.addBus(lfBus);
});
}

private static LfArea createControlArea(Area area, LfNetworkParameters parameters, LoadingContext loadingContext, LfNetwork network) {
LfArea lfArea = LfAreaImpl.create(area, network, parameters);
network.addControlArea(lfArea);
network.addArea(lfArea);
area.getAreaBoundaryStream().forEach(areaBoundary -> {
if (areaBoundary.getTerminal().isPresent()) {
Terminal terminal = areaBoundary.getTerminal().get();
loadingContext.areaBoundaries.put(terminal, lfArea);
loadingContext.areaTerminalMap.put(terminal, lfArea);
}
if (areaBoundary.getBoundary().isPresent()) {
DanglingLine danglingLine = areaBoundary.getBoundary().get().getDanglingLine();
loadingContext.areaBoundaries.put(danglingLine.getTerminal(), lfArea);
loadingContext.areaTerminalMap.put(danglingLine.getTerminal(), lfArea);
}
});
return lfArea;
Expand All @@ -542,7 +543,7 @@ private static LfArea createControlArea(Area area, LfNetworkParameters parameter
* Add the terminals active power to the calculation of their Area's interchange (load convention) if they are boundaries.
* For simple branches (lines, transformers, switches), the terminal declared as the boundary must be the one which active power is used.
*/
private static void addLineAreaBoundaries(Branch<?> branch, LfBranch lfBranch, LoadingContext loadingContext) {
private static void addBranchAreaBoundaries(Branch<?> branch, LfBranch lfBranch, LoadingContext loadingContext) {
addAreaBoundary(branch.getTerminal1(), lfBranch::getP1, loadingContext);
addAreaBoundary(branch.getTerminal2(), lfBranch::getP2, loadingContext);
}
Expand All @@ -565,8 +566,8 @@ private static void addDanglingLineAreaBoundary(DanglingLine danglingLine, LfBra
}

private static void addAreaBoundary(Terminal terminal, Supplier<Evaluable> getP, LoadingContext loadingContext) {
if (loadingContext.areaBoundaries.containsKey(terminal)) {
loadingContext.areaBoundaries.get(terminal).addBoundaryP(getP);
if (loadingContext.areaTerminalMap.containsKey(terminal)) {
loadingContext.areaTerminalMap.get(terminal).addBoundaryP(getP);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ void networkWithControlAreasTest() {
List<LfNetwork> lfNetworks = Networks.load(network, new FirstSlackBusSelector());
assertEquals(1, lfNetworks.size());
LfNetwork mainNetwork = lfNetworks.get(0);
LfArea lfArea = mainNetwork.getControlAreaById("ControlArea_A");
assertNull(mainNetwork.getControlAreaById("Region_AB"));
LfArea lfArea = mainNetwork.getAreaById("ControlArea_A");
assertNull(mainNetwork.getAreaById("Region_AB"));
assertEquals(-602.6, lfArea.getInterchangeTarget());
}

Expand Down

0 comments on commit 5a29ee9

Please sign in to comment.