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

Handle all connected components of a network #295

Merged
merged 35 commits into from
May 20, 2021

Conversation

obrix
Copy link
Member

@obrix obrix commented Apr 29, 2021

Try handling all the connected components in a network when building a LfNetwork and executing a loadflow.

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Introduce a boolean value in the network loader to chose to load only the main connected component of a network, or all connected components.

What is the current behavior? (You can also link to an open issue here)

Only the main connected component was loaded.

What is the new behavior (if this is a feature change)?

All connected components can now be loaded.

Does this PR introduce a breaking change or deprecate an API? If yes, check the following:

  • The Breaking Change or Deprecated label has been added
  • The migration guide has been updated in the github wiki (What changes might users need to make in their application due to this PR?)

…a LfNetwork and executing a loadflow.

Signed-off-by: Bertrand Rix <[email protected]>
@obrix obrix requested a review from annetill April 29, 2021 07:44
Copy link
Member

@geofjamg geofjamg left a comment

Choose a reason for hiding this comment

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

This feature should be configurable (OpenLoadFlowParameters)

@obrix
Copy link
Member Author

obrix commented Apr 29, 2021

@geofjamg Yes, what should be the default behavior ? Loading all connected components or only the main one ?

@annetill
Copy link
Member

Only the main one.

obrix added 3 commits April 29, 2021 10:49
…it a part of LfNetworkParameters.

Signed-off-by: Bertrand Rix <[email protected]>
…DefaultOpenLoadflowConfig.

Signed-off-by: Bertrand Rix <[email protected]>
Signed-off-by: Bertrand Rix <[email protected]>
Copy link
Member

@annetill annetill left a comment

Choose a reason for hiding this comment

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

You need to add tests for sure, for simple load flows but also for secruity analysis and sensitivity analysis. I am not sure the code is robust enough because sometimes we just take the first synchronous component of the main connected component and we want to keep that. @geofjamg do you agree?

@@ -42,7 +42,9 @@ public DcLoadFlowEngine(LfNetwork network, MatrixFactory matrixFactory, boolean
}

public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter) {
LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false, parameters.getPlausibleActivePowerLimit(), false);
LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false,
Copy link
Member

Choose a reason for hiding this comment

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

Be careful here as we have in the code a LfNetwork network = networks.get(0); that says that we only deal with the first synchronous component. Do we want to do better here? Handle several synchronous components? Handle several connected components?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I made some changes in the code : I replaced all the get(0) I could find in the code by the use of a filter on the network num on what is defined as the "main num". I use the constant parameter ComponentConstants.MAIN_NUM provided by the core for that.
This is just a begining while waiting to see what we do with several connected components more largely.

public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean setVToNan) {
this(slackBusSelector, matrixFactory, false, true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, false,
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan);
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, ParameterConstants.LOAD_MAIN_CONNECTED_COMPONENT_ONLY_DEFAULT_VALUE);
Copy link
Member

Choose a reason for hiding this comment

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

See above.

@@ -68,10 +72,17 @@ private static double getActivePowerMismatch(Collection<LfBus> buses) {

public DcLoadFlowResult run(Reporter reporter) {
// only process main (largest) connected component
LfNetwork network = networks.get(0);
LfNetwork network = networks.stream().filter(n -> n.getNum() == ComponentConstants.MAIN_NUM).findAny().orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

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

I need the main synchronous component here.

Copy link
Member

Choose a reason for hiding this comment

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

Can you create a method for that?

Copy link
Member Author

@obrix obrix Apr 30, 2021

Choose a reason for hiding this comment

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

After our discussion : on lfNetwork I will use the existing connected component num and store the synchronous component num at loading, I will then update all filter I added to filter on CC num and SC num with MAIN_NUM value instead of just filter on CC num.

@obrix obrix force-pushed the handle_several_cc_networks branch from 6d8be2e to bb9e415 Compare April 30, 2021 14:23
…network. Just test the computation is ok, only the main cc is computed.

Signed-off-by: Bertrand Rix <[email protected]>
this.slackBusSelector = Objects.requireNonNull(slackBusSelector);
}

public int getNum() {
return num;
public int getNumCC() {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for this, I know that you are close to become totally crazy but... you are right, we need both NumCC and NumSC, but from now when you want to log or store results linked to a LfNetwork, you really have to put the pair and not just NumCC. It will lead to change a bit some logs to be clear. But the big change will be in powsybl-core because the object LoadFlowResult only has one getComponentNum(). So it means that if you want to serenely finish this PR, you have to create a new feature in powsybl-core (so a new PR).

@@ -47,7 +48,7 @@ void testLineCurrentLimits() {
Network network = EurostagTutorialExample1Factory.createWithFixedCurrentLimits();
List<LfNetwork> lfNetworks = LfNetwork.load(network, new MostMeshedSlackBusSelector());
assertEquals(1, lfNetworks.size());
LfNetwork lfNetwork = lfNetworks.get(0);
LfNetwork lfNetwork = lfNetworks.stream().filter(n -> n.getNumCC() == ComponentConstants.MAIN_NUM && n.getNumSC() == ComponentConstants.MAIN_NUM).findAny().orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

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

These is boiler plate code. We have it everywhere in unit tests. Either we move it to a utility class of better we can just rely on the fact that first network is always the (main, main) one.

@flo-dup flo-dup force-pushed the handle_several_cc_networks branch from 9a2a03e to c6d8435 Compare May 18, 2021 09:21
flo-dup added 2 commits May 18, 2021 21:14
Signed-off-by: Florian Dupuy <[email protected]>
Signed-off-by: Florian Dupuy <[email protected]>
Signed-off-by: Florian Dupuy <[email protected]>
flo-dup and others added 2 commits May 20, 2021 13:24
Signed-off-by: Anne Tilloy <[email protected]>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

93.3% 93.3% Coverage
0.0% 0.0% Duplication

Copy link
Member

@annetill annetill left a comment

Choose a reason for hiding this comment

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

Thanks a lot @obrix and @flo-dup for this feature more complex to handle than expected!

@annetill annetill merged commit c5a3efd into master May 20, 2021
@annetill annetill deleted the handle_several_cc_networks branch May 20, 2021 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants