-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix syncv #460
Open
jonenst
wants to merge
17
commits into
main
Choose a base branch
from
fixsyncv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+969
−98
Open
fix syncv #460
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a43f002
Synchronization between views for v and angle bus values.
FranckLecuyer 8492ef9
Merge branch 'main' into synchronize_set_v_angle_on_bus_between_views
FranckLecuyer 3afafdd
Merge branch 'main' into synchronize_set_v_angle_on_bus_between_views
FranckLecuyer 9ce5cb7
Merge branch 'main' into synchronize_set_v_angle_on_bus_between_views
FranckLecuyer 6661c1f
Changes after review
FranckLecuyer 3b26409
Fix sonar issue
FranckLecuyer 98bf508
Merge branch 'main' into synchronize_set_v_angle_on_bus_between_views
FranckLecuyer 4c2dffb
more exhaustive test
jonenst d09854e
wip fix syncv
jonenst ed42836
more fixes using busnum instead of vertex
jonenst 54ef522
Fix updateBusesAttributes method in CalculatedBus.java
FranckLecuyer d59aada
Cleaning and optimizing code
FranckLecuyer ebe387e
Move methods in another file
FranckLecuyer 16edded
Add configuration similar to the one in AbstractMainConnectedComponen…
FranckLecuyer 15df0fa
Clean code in getVAndAngleFromOtherView method
FranckLecuyer 6853516
VoltageLevelTest, Add more combinations to setV/setAngle for cache ex…
jonenst 9c17fe0
Improve exhaustive test, make nodebreaker consistent with invalid vie…
jonenst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,18 @@ | |
*/ | ||
package com.powsybl.network.store.iidm.impl; | ||
|
||
import com.google.common.util.concurrent.AtomicDouble; | ||
import com.powsybl.commons.config.PlatformConfig; | ||
import com.powsybl.iidm.network.*; | ||
import com.powsybl.network.store.model.*; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.jgrapht.Graph; | ||
import org.jgrapht.alg.connectivity.ConnectivityInspector; | ||
import org.jgrapht.graph.DirectedPseudograph; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
|
@@ -358,18 +362,77 @@ private void setCalculatedBuses(Resource<VoltageLevelAttributes> voltageLevelRes | |
} | ||
} | ||
|
||
private void getVAndAngleFromConfiguredBus(NetworkObjectIndex index, | ||
Resource<VoltageLevelAttributes> voltageLevelResource, | ||
ConnectedSetResult<T> connectedSet, | ||
AtomicDouble v, | ||
AtomicDouble angle) { | ||
AtomicReference<ConfiguredBusImpl> foundConfiguredBus = new AtomicReference<>(); | ||
index.getConfiguredBuses(voltageLevelResource.getId()).forEach(bus -> { | ||
if (foundConfiguredBus.get() == null) { | ||
ConfiguredBusImpl configuredBus = (ConfiguredBusImpl) bus; | ||
configuredBus.getAllTerminals().stream() | ||
.filter(Terminal::isConnected) | ||
.forEach(t -> { | ||
if (foundConfiguredBus.get() == null) { | ||
connectedSet.getConnectedVertices().stream().filter(vertex -> | ||
vertex.getId().equals(t.getConnectable().getId()) | ||
).findFirst().ifPresent(vertex -> foundConfiguredBus.set(configuredBus)); | ||
} | ||
}); | ||
} | ||
}); | ||
if (foundConfiguredBus.get() != null) { | ||
v.set(foundConfiguredBus.get().getResource().getAttributes().getV()); | ||
angle.set(foundConfiguredBus.get().getResource().getAttributes().getAngle()); | ||
} | ||
} | ||
|
||
private void getVAndAngleFromOtherView(NetworkObjectIndex index, | ||
Resource<VoltageLevelAttributes> voltageLevelResource, | ||
ConnectedSetResult<T> connectedSet, | ||
AtomicDouble v, | ||
AtomicDouble angle, | ||
boolean isBusView) { | ||
if (voltageLevelResource.getAttributes().getTopologyKind() == TopologyKind.NODE_BREAKER) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we use if (isCalculatedBusesValid(voltageLevelResource, !isBusView)) { |
||
List<CalculatedBusAttributes> calculatedBusAttributes = isBusView ? voltageLevelResource.getAttributes().getCalculatedBusesForBusBreakerView() : voltageLevelResource.getAttributes().getCalculatedBusesForBusView(); | ||
if (!CollectionUtils.isEmpty(calculatedBusAttributes)) { | ||
Map<Integer, Integer> nodesToCalculatedBuses = isBusView ? voltageLevelResource.getAttributes().getNodeToCalculatedBusForBusBreakerView() : voltageLevelResource.getAttributes().getNodeToCalculatedBusForBusView(); | ||
if (!MapUtils.isEmpty(nodesToCalculatedBuses)) { | ||
Integer node = (Integer) connectedSet.getConnectedNodesOrBuses().iterator().next(); | ||
Integer busNum = nodesToCalculatedBuses.get(node); | ||
if (busNum != null) { | ||
CalculatedBusAttributes busAttributes = calculatedBusAttributes.get(busNum); | ||
if (busAttributes != null) { | ||
v.set(busAttributes.getV()); | ||
angle.set(busAttributes.getAngle()); | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
// get V and Angle values from configured buses | ||
getVAndAngleFromConfiguredBus(index, voltageLevelResource, connectedSet, v, angle); | ||
} | ||
} | ||
|
||
private CalculationResult<T> getCalculatedBusAttributesList(NetworkObjectIndex index, Resource<VoltageLevelAttributes> voltageLevelResource, boolean isBusView) { | ||
List<CalculatedBusAttributes> calculatedBusAttributesList; | ||
Map<T, Integer> nodeOrBusToCalculatedBusNum; | ||
if (isCalculatedBusesValid(voltageLevelResource, isBusView)) { | ||
calculatedBusAttributesList = isBusView ? voltageLevelResource.getAttributes().getCalculatedBusesForBusView() : voltageLevelResource.getAttributes().getCalculatedBusesForBusBreakerView(); | ||
nodeOrBusToCalculatedBusNum = getNodeOrBusToCalculatedBusNum(voltageLevelResource, isBusView); | ||
} else { | ||
// calculate buses | ||
List<ConnectedSetResult<T>> connectedSetList = findConnectedSetList(index, voltageLevelResource, isBusView); | ||
calculatedBusAttributesList = connectedSetList | ||
.stream() | ||
.map(connectedSet -> new CalculatedBusAttributes(connectedSet.getConnectedVertices(), null, null, Double.NaN, Double.NaN)) | ||
.map(connectedSet -> { | ||
AtomicDouble v = new AtomicDouble(Double.NaN); | ||
AtomicDouble angle = new AtomicDouble(Double.NaN); | ||
// get V and Angle values from other view if available | ||
getVAndAngleFromOtherView(index, voltageLevelResource, connectedSet, v, angle, isBusView); | ||
return new CalculatedBusAttributes(connectedSet.getConnectedVertices(), null, null, v.get(), angle.get()); | ||
}) | ||
.collect(Collectors.toList()); | ||
setCalculatedBuses(voltageLevelResource, isBusView, calculatedBusAttributesList); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break early instead of checking if found in the loop