Skip to content

Migration powsybl dependencies 2025.0.0 #517

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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e4be6ad
WIP upgrade to powsybl-dependencies 2025.0.0
Apr 3, 2025
e746596
WIP
Apr 8, 2025
3b85627
Fix bad UT removal
Apr 8, 2025
78375ba
adapt to powsybl upgrade
EtienneLt Apr 9, 2025
6a701ee
fix commentary
EtienneLt Apr 9, 2025
d2a8d2b
Merge branch 'main' into upgrade_to_powsybl_dependencies_2025.0.0
EtienneLt Apr 9, 2025
9ff0b50
implement battery shortcircuit extension
EtienneLt Apr 10, 2025
01b6e49
test
EtienneLt Apr 10, 2025
127452c
implement area
EtienneLt Apr 15, 2025
6d2b94b
fix rest client for area
EtienneLt Apr 15, 2025
a384108
fix sonar
EtienneLt Apr 15, 2025
b559c76
remove useless attribute
EtienneLt Apr 15, 2025
d23343d
remove cmes area attributes
EtienneLt Apr 16, 2025
d6e2461
fix
EtienneLt Apr 16, 2025
ce21ef2
fix setResource
EtienneLt Apr 16, 2025
0e536e3
Merge branch 'main' into upgrade_to_powsybl_dependencies_2025.0.0
EtienneLt Apr 16, 2025
6db6f48
review first part
EtienneLt Apr 18, 2025
b2dfa84
review part 2
EtienneLt Apr 18, 2025
1074b3f
refactor short circuit extension
EtienneLt Apr 18, 2025
0725696
sonar fix
EtienneLt Apr 18, 2025
2f4353e
try fixing
EtienneLt Apr 18, 2025
101b745
fix blancks
EtienneLt Apr 18, 2025
cc323d4
fix blancks 2
EtienneLt Apr 18, 2025
bd97e88
review
EtienneLt Apr 22, 2025
59d780c
review
EtienneLt Apr 23, 2025
ff804bb
Merge branch 'main' into upgrade_to_powsybl_dependencies_2025.0.0
Mathieu-Deharbe Apr 23, 2025
b3bb00d
remove old commentary
EtienneLt Apr 23, 2025
08d6123
Merge branch 'main' into upgrade_to_powsybl_dependencies_2025.0.0
antoinebhs Apr 24, 2025
f5bd8c0
Add assertj-core as dependency to fix test in NetworkTest (cf. breaki…
rolnico Apr 25, 2025
2b94616
typo
EtienneLt Apr 25, 2025
5517519
Revert Add assertj-core as dependency to fix test in NetworkTest (cf.…
rolnico Apr 25, 2025
e44c428
remove override of tests as fixed
EtienneLt Apr 25, 2025
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
5 changes: 5 additions & 0 deletions dictionary.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
core.iidm.network.alreadyConnectedTerminal = A terminal of identifiable ${identifiable} is already connected.
core.iidm.network.alreadyDisconnectedTerminal = A terminal of identifiable ${identifiable} is already disconnected.
regulatedTerminalDeleted = ${identifiableId} has been deleted and it was regulated. The following regulating equipments have their regulation set to Local : [${regulatingEquipments}]
resetPhaseTapChangerRegulationMode = Regulation mode of phase tap changer of ${identifiableId} has been reset to FIXED TAP due to deletion of its regulating terminal
resetSVCRegulationMode = Regulation mode of static var compensator ${identifiableId} has been reset to OFF due to deletion of its regulating terminal
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public class BufferedNetworkStoreClient extends AbstractForwardingNetworkStoreCl

private final NetworkCollectionIndex<CollectionBuffer<GroundAttributes>> groundResourcesToFlush
= new NetworkCollectionIndex<>(() -> new CollectionBuffer<>(delegate::createGrounds,
delegate::updateGrounds,
delegate::removeGrounds));
delegate::updateGrounds,
delegate::removeGrounds));

private final NetworkCollectionIndex<CollectionBuffer<TwoWindingsTransformerAttributes>> twoWindingsTransformerResourcesToFlush
= new NetworkCollectionIndex<>(() -> new CollectionBuffer<>(delegate::createTwoWindingsTransformers,
Expand All @@ -134,8 +134,13 @@ public class BufferedNetworkStoreClient extends AbstractForwardingNetworkStoreCl

private final NetworkCollectionIndex<CollectionBuffer<TieLineAttributes>> tieLineResourcesToFlush
= new NetworkCollectionIndex<>(() -> new CollectionBuffer<>(delegate::createTieLines,
delegate::updateTieLines,
delegate::removeTieLines));
delegate::updateTieLines,
delegate::removeTieLines));

private final NetworkCollectionIndex<CollectionBuffer<AreaAttributes>> areaResourcesToFlush
= new NetworkCollectionIndex<>(() -> new CollectionBuffer<>(delegate::createAreas,
delegate::updateAreas,
delegate::removeAreas));

private final List<NetworkCollectionIndex<? extends CollectionBuffer<? extends IdentifiableAttributes>>> allBuffers = List.of(
networkResourcesToFlush,
Expand All @@ -157,7 +162,8 @@ public class BufferedNetworkStoreClient extends AbstractForwardingNetworkStoreCl
threeWindingsTransformerResourcesToFlush,
lineResourcesToFlush,
busResourcesToFlush,
tieLineResourcesToFlush);
tieLineResourcesToFlush,
areaResourcesToFlush);

private final ExecutorService executorService;

Expand Down Expand Up @@ -563,6 +569,26 @@ public void removeTieLines(UUID networkUuid, int variantNum, List<String> tieLin
tieLineResourcesToFlush.getCollection(networkUuid, variantNum).remove(tieLinesId);
}

// Areas
@Override
public void createAreas(UUID networkUuid, List<Resource<AreaAttributes>> areaResources) {
for (Resource<AreaAttributes> areaResource : areaResources) {
areaResourcesToFlush.getCollection(networkUuid, areaResource.getVariantNum()).create(areaResource);
}
}

@Override
public void updateAreas(UUID networkUuid, List<Resource<AreaAttributes>> areaResources, AttributeFilter attributeFilter) {
for (Resource<AreaAttributes> areaResource : areaResources) {
areaResourcesToFlush.getCollection(networkUuid, areaResource.getVariantNum()).update(areaResource, attributeFilter);
}
}

@Override
public void removeAreas(UUID networkUuid, int variantNum, List<String> areasId) {
areaResourcesToFlush.getCollection(networkUuid, variantNum).remove(areasId);
}

@Override
public void flush(UUID networkUuid) {
Stopwatch stopwatch = Stopwatch.createStarted();
Expand Down Expand Up @@ -618,6 +644,7 @@ public void cloneNetwork(UUID networkUuid, int sourceVariantNum, int targetVaria
cloneBuffer(substationResourcesToFlush, networkUuid, sourceVariantNum, targetVariantNum, objectMapper);
cloneBuffer(voltageLevelResourcesToFlush, networkUuid, sourceVariantNum, targetVariantNum, objectMapper);
cloneBuffer(tieLineResourcesToFlush, networkUuid, sourceVariantNum, targetVariantNum, objectMapper);
cloneBuffer(areaResourcesToFlush, networkUuid, sourceVariantNum, targetVariantNum, objectMapper);
cloneBuffer(networkResourcesToFlush, networkUuid, sourceVariantNum, targetVariantNum, objectMapper,
networkResource -> {
NetworkAttributes networkAttributes = networkResource.getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class RestNetworkStoreClient implements NetworkStoreClient {
private static final String STR_DANGLING_LINE = "dangling line";
private static final String STR_HVDC_LINE = "hvdc line";
private static final String STR_TIE_LINE = "tie line";
private static final String STR_AREA = "area";
private static final String STR_GROUND = "ground";

private final RestClient restClient;
Expand Down Expand Up @@ -878,6 +879,32 @@ public void updateTieLines(UUID networkUuid, List<Resource<TieLineAttributes>> t
updateAll(STR_TIE_LINE, "/networks/{networkUuid}/tie-lines", tieLineResources, attributeFilter, networkUuid);
}

// Areas
@Override
public void createAreas(UUID networkUuid, List<Resource<AreaAttributes>> areaResources) {
create(STR_AREA, "/networks/{networkUuid}/areas", areaResources, networkUuid);
}

@Override
public List<Resource<AreaAttributes>> getAreas(UUID networkUuid, int variantNum) {
return getAll(STR_AREA, "/networks/{networkUuid}/{variantNum}/areas", networkUuid, variantNum);
}

@Override
public Optional<Resource<AreaAttributes>> getArea(UUID networkUuid, int variantNum, String areaId) {
return get(STR_AREA, "/networks/{networkUuid}/{variantNum}/areas/{AreaId}", networkUuid, variantNum, areaId);
}

@Override
public void removeAreas(UUID networkUuid, int variantNum, List<String> areasIds) {
removeAll(STR_AREA, "/networks/{networkUuid}/{variantNum}/areas", networkUuid, variantNum, areasIds);
}

@Override
public void updateAreas(UUID networkUuid, List<Resource<AreaAttributes>> areaResources, AttributeFilter attributeFilter) {
updateAll(STR_AREA, "/networks/{networkUuid}/areas", areaResources, attributeFilter, networkUuid);
}

@Override
public Optional<Resource<IdentifiableAttributes>> getIdentifiable(UUID networkUuid, int variantNum, String id) {
return get("identifiable", "/networks/{networkUuid}/{variantNum}/identifiables/{id}", networkUuid, variantNum, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ public Resource<D> getNullableResource() {
}

public void setResource(Resource<D> resource) {
idBeforeRemoval = resource == null ? this.resource.getId() : null;
idBeforeRemoval = resource == null && this.resource != null ? this.resource.getId() : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

@SlimaneAmar I have problems in network store server test if I do not check that

Copy link
Contributor

@etiennehomer etiennehomer Apr 18, 2025

Choose a reason for hiding this comment

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

We'll have to do another PR with this fix before this one and ask Slimane for review

this.resource = resource;
}

public Resource<D> getResource() {
return getResource("Object has been removed in current variant");
}

public Resource<D> getResource(String errorMessageIfResourceNull) {
if (resource == null) {
throw new PowsyblException("Object has been removed in current variant");
throw new PowsyblException(errorMessageIfResourceNull);
}
if (index.getWorkingVariantNum() == -1) {
throw new PowsyblException("Variant index not set");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (c) 2025, 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.network.store.iidm.impl;

import com.powsybl.iidm.network.*;
import com.powsybl.network.store.model.AreaAttributes;
import com.powsybl.network.store.model.Resource;
import com.powsybl.network.store.model.ResourceType;

import java.util.*;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public class AreaAdderImpl extends AbstractIdentifiableAdder<AreaAdderImpl> implements AreaAdder {

private String areaType;
private final Map<Terminal, Boolean> terminalAreaBoundaries;
private final Map<Boundary, Boolean> boundaryAreaBoundaries;
private final Set<String> voltageLevelIds;
private double interchangeTarget;

AreaAdderImpl(NetworkObjectIndex index) {
super(index);
terminalAreaBoundaries = new HashMap<>();
boundaryAreaBoundaries = new HashMap<>();
voltageLevelIds = new HashSet<>();
interchangeTarget = Double.NaN;
}

@Override
public AreaAdderImpl setAreaType(String areaType) {
this.areaType = areaType;
return this;
}

@Override
public AreaAdder setInterchangeTarget(double v) {
interchangeTarget = v;
return this;
}

@Override
public AreaAdder addVoltageLevel(VoltageLevel voltageLevel) {
voltageLevelIds.add(voltageLevel.getId());
return this;
}

@Override
public AreaAdder addAreaBoundary(Terminal terminal, boolean ac) {
terminalAreaBoundaries.put(terminal, ac);
return this;
}

@Override
public AreaAdder addAreaBoundary(Boundary boundary, boolean ac) {
boundaryAreaBoundaries.put(boundary, ac);
return this;
}

@Override
public Area add() {
String id = checkAndGetUniqueId();
Resource<AreaAttributes> resource = Resource.areaBuilder()
.id(id)
.variantNum(index.getWorkingVariantNum())
.attributes(AreaAttributes.builder()
.name(getName())
.fictitious(isFictitious())
.areaType(areaType)
.interchangeTarget(interchangeTarget)
.voltageLevelIds(new LinkedHashSet<>())
.areaBoundaries(new ArrayList<>())
.build())
.build();
AreaImpl area = getIndex().createArea(resource);
terminalAreaBoundaries.forEach((terminal, ac) -> area.newAreaBoundary().setTerminal(terminal).setAc(ac).add());
boundaryAreaBoundaries.forEach((boundary, ac) -> area.newAreaBoundary().setBoundary(boundary).setAc(ac).add());
voltageLevelIds.forEach(voltageLevelId -> index.getVoltageLevel(voltageLevelId)
.ifPresent(voltageLevel -> voltageLevel.addArea(area)));
return area;
}

@Override
protected String getTypeDescription() {
return ResourceType.AREA.getDescription();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2025, 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.network.store.iidm.impl;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Area;
import com.powsybl.iidm.network.AreaBoundaryAdder;
import com.powsybl.iidm.network.Boundary;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.network.store.model.AreaBoundaryAttributes;
import com.powsybl.network.store.model.TerminalRefAttributes;

import java.util.Objects;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public class AreaBoundaryAdderImpl implements AreaBoundaryAdder {
AreaImpl area;

Boundary boundary;

Terminal terminal;

Boolean ac;

NetworkObjectIndex index;

AreaBoundaryAdderImpl(AreaImpl area, NetworkObjectIndex index) {
this.area = Objects.requireNonNull(area);
this.index = Objects.requireNonNull(index);
}

@Override
public AreaBoundaryAdder setBoundary(Boundary boundary) {
this.boundary = boundary;
this.terminal = null;
return this;
}

@Override
public AreaBoundaryAdder setTerminal(Terminal terminal) {
this.terminal = terminal;
this.boundary = null;
return this;
}

@Override
public AreaBoundaryAdder setAc(boolean ac) {
this.ac = ac;
return this;
}

@Override
public Area add() {
if (ac == null) {
throw new PowsyblException("AreaBoundary AC flag is not set.");
}
// we remove before adding, to forbid duplicates and allow updating ac to true/false
AreaBoundaryAttributes areaBoundaryAttributes;
if (boundary != null) {
areaBoundaryAttributes = new AreaBoundaryAttributes(null, ac, area.getId(), boundary.getDanglingLine().getId());
area.removeAreaBoundary(boundary);
} else if (terminal != null) {
TerminalRefAttributes terminalRefAttributes = TerminalRefUtils.getTerminalRefAttributes(terminal);
areaBoundaryAttributes = new AreaBoundaryAttributes(terminalRefAttributes, ac, area.getId(), null);
area.removeAreaBoundary(terminal);
} else {
throw new PowsyblException("No AreaBoundary element (terminal or boundary) is set.");
}
area.addAreaBoundary(new AreaBoundaryImpl(areaBoundaryAttributes, index));
return area;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright (c) 2025, 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.network.store.iidm.impl;

import com.powsybl.iidm.network.Area;
import com.powsybl.iidm.network.AreaBoundary;
import com.powsybl.iidm.network.Boundary;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.util.DanglingLineBoundaryImpl;
import com.powsybl.network.store.model.AreaBoundaryAttributes;
import com.powsybl.network.store.model.TerminalRefAttributes;

import java.util.Optional;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public class AreaBoundaryImpl implements AreaBoundary {

protected final NetworkObjectIndex index;

private final AreaBoundaryAttributes areaBoundaryAttributes;

protected AreaBoundaryImpl(AreaBoundaryAttributes areaBoundaryAttributes, NetworkObjectIndex index) {
this.index = index;
this.areaBoundaryAttributes = areaBoundaryAttributes;
}

@Override
public Area getArea() {
return this.index.getArea(areaBoundaryAttributes.getAreaId()).orElse(null);
}

@Override
public Optional<Terminal> getTerminal() {
return Optional.ofNullable(getRefTerminal());
}

private Terminal getRefTerminal() {
TerminalRefAttributes terminalRefAttributes = areaBoundaryAttributes.getTerminal();
return TerminalRefUtils.getTerminal(index, terminalRefAttributes);
}

@Override
public Optional<Boundary> getBoundary() {
if (areaBoundaryAttributes.getBoundaryDanglingLineId() == null) {
return Optional.empty();
}
Optional<DanglingLineImpl> danglingLine = index.getDanglingLine(areaBoundaryAttributes.getBoundaryDanglingLineId());
return danglingLine.map(DanglingLineBoundaryImpl::new);
}

@Override
public boolean isAc() {
return areaBoundaryAttributes.getAc();
}

@Override
public double getP() {
return getBoundary().map(Boundary::getP).orElseGet(() -> getRefTerminal().getP());
}

@Override
public double getQ() {
return getBoundary().map(Boundary::getQ).orElseGet(() -> getRefTerminal().getQ());
}
}
Loading