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

Network listener #215

Merged
merged 15 commits into from
Mar 1, 2021
Merged

Network listener #215

merged 15 commits into from
Mar 1, 2021

Conversation

geofjamg
Copy link
Member

@geofjamg geofjamg commented Feb 6, 2021

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)

Does this PR already have an issue describing the problem ? If so, link to this issue using '#XXX' and skip the rest
No

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

What is the new behavior (if this is a feature change)?
In order to centralize, network modification to equation system change, a listener has been added to the LF network and is used by AC equation system to auto update

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?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
@geofjamg geofjamg requested review from annetill and flo-dup February 7, 2021 20:58
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
# Conflicts:
#	src/main/java/com/powsybl/openloadflow/network/LfNetwork.java
#	src/main/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysis.java
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>

// also create an inactive equation to have a1 variable constant
LfBranch controller = phaseControl.getController();
equationSystem.createEquation(controller.getNum(), EquationType.BRANCH_ALPHA1)
Copy link
Member

Choose a reason for hiding this comment

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

The equation type BRANCH_ALPHA1 you introduce recently is in fact very confusing for me as we already a variable type BRANCH_ALPHA1. And here I am not sure to get what you have in mind to add these lines.

Copy link
Member

Choose a reason for hiding this comment

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

It is to keep the same matrix size?

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted the phase control refactoring. I will add it in another PR and will explain better why.


@Override
public void onPhaseControlModeChange(DiscretePhaseControl phaseControl, DiscretePhaseControl.Mode oldMode, DiscretePhaseControl.Mode newMode) {
boolean on = newMode != DiscretePhaseControl.Mode.OFF;
Copy link
Member

Choose a reason for hiding this comment

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

Here, the code on master is:

LfBranch controllerBranch = branch.getDiscretePhaseControl().getController();
 Variable a1 = context.getVariableSet().getVariable(controllerBranch.getNum(), VariableType.BRANCH_ALPHA1);
 a1.setActive(false);

 Equation t = context.getEquationSystem().createEquation(branch.getNum(), EquationType.BRANCH_P);
 t.setActive(false);

Why we don't have any variable management?

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted the phase control refactoring. I will add it in another PR and will explain better why.


for (LfBranch controllerBranch : bus.getDiscreteVoltageControl().getControllers()) {
// de-activate r1 variable
Variable r1 = variableSet.getVariable(controllerBranch.getNum(), VariableType.BRANCH_RHO1);
Copy link
Member

Choose a reason for hiding this comment

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

Here you manage the variable BRANCH_RHO1, so why BRANCH_ALPHA1 has disappeared?

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted the phase control refactoring. I will add it in another PR and will explain better why.

@@ -450,4 +451,21 @@ private void reactivateEquations(List<Equation> deactivatedEquations, List<Equat
return connectivity;
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

Why do you have these "new" lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

they are old lines in fact which have been moved recently, so they can be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

No more new lines

@@ -450,4 +451,21 @@ private void reactivateEquations(List<Equation> deactivatedEquations, List<Equat
return connectivity;
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

they are old lines in fact which have been moved recently, so they can be removed

@@ -350,6 +373,70 @@ public static EquationSystem create(LfNetwork network, VariableSet variableSet,
createBusEquations(network, variableSet, creationParameters, equationSystem);
createBranchEquations(network, variableSet, creationParameters, equationSystem);

network.addListener(new LfNetworkListener() {
@Override
public void onVoltageControlChange(LfBus bus, boolean oldVoltageControl, boolean newVoltageControl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

oldVoltageControl not very necessary as we always have oldVoltageControl == !newVoltageControl, but conform to other methods so...

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree this is ugly, I removed oldVoltageControl

@@ -350,6 +373,70 @@ public static EquationSystem create(LfNetwork network, VariableSet variableSet,
createBusEquations(network, variableSet, creationParameters, equationSystem);
createBranchEquations(network, variableSet, creationParameters, equationSystem);

network.addListener(new LfNetworkListener() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not very fond of anonymous classes, don't you think this one is big enough to be explicit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I moved everything in a AcEquationSystemUpdater class.

*/
public abstract class AbstractElement {

protected final LfNetwork network;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we give the access to the whole LfNetwork to all elements or wouldn't a Supplier<LfNetworkListener> be enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it could be useful to go back to network from an element

@@ -18,17 +20,16 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class LfShuntImpl implements LfShunt {
public class LfShuntImpl extends AbstractElement implements LfShunt {
Copy link
Contributor

Choose a reason for hiding this comment

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

For now there's no use for LfShuntImpl to extend AbstractElement, but I suppose you're anticipating some feature?
I'm asking as if we don't extend it, it would give more consistency to AbstractElement in a way (and some more LfBus / LfBranch common methods could be added)

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly, I only added AbstractElement to fix a Sonar duplicated code issue at the moment. But for sure we can probably share more code. I Propose to do it in an other PR as it was really not the aim of this one.

# Conflicts:
#	src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java
#	src/main/java/com/powsybl/openloadflow/ac/outerloop/OuterLoopContext.java
#	src/main/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysis.java
#	src/main/java/com/powsybl/openloadflow/util/BusState.java
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
@geofjamg
Copy link
Member Author

@annetill @floriand-e2r I removed the phase control refactoring from this PR to only keep the listener part. So this PR now """"only""""" contains code move and is supposed to be functionnally equivalent. I will create to dedicated PR to refactor the AC equation system to avoid variable de-activation.

@geofjamg geofjamg requested review from annetill and flo-dup February 28, 2021 14:26
@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 1 Code Smell

94.2% 94.2% 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.

It is really pretty like this and for sure more easy to use as the AC equation system is hidden. We have to make an issue not to forget to implement it for DC equation system when we will be able to have a regulation on phase tap changers.

@geofjamg geofjamg merged commit 48b763a into master Mar 1, 2021
@geofjamg geofjamg deleted the network_listener branch March 1, 2021 09:42
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.

3 participants