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

Refactoring voltage control #168

Merged
merged 52 commits into from
Mar 4, 2021
Merged

Refactoring voltage control #168

merged 52 commits into from
Mar 4, 2021

Conversation

flo-dup
Copy link
Contributor

@flo-dup flo-dup commented Nov 10, 2020

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, ...)
Refactoring voltage control to have a structure similar to PhaseDiscreteControl / VoltageDiscreteControl, that is, a "control" object which makes the link between the controller and the controllee.

@flo-dup flo-dup changed the title Refactoring voltage control [WIP] Refactoring voltage control Nov 10, 2020
@flo-dup flo-dup requested a review from annetill November 10, 2020 15:51
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.

I have left the review of abstract lf bus and lf network loader impl for latter. I think that we have to review bases before in having a unique voltage control in case of remote shared control but split it in several voltage control if remote voltage control is desactivated. This solution is not clear enough to be prefer at the current one.

annetill and others added 15 commits November 12, 2020 08:56
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
First import of VoltageControl.

Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Remove the HashMap previously used

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Done in createVoltageControls, together with various consistency checks

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
AcEquationSystemCreationParameters.voltageRemoteControl now useless thus removed

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Some tests were not included in build check as they were annotated with org.junit.api.Test
Code smells corrections

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Nothing done in AbstractLfBus anymore, now in:
- AbstractLfGenerator when setting targetV
- LfNetworkLoaderImpl when creating controller - controllee links

Unit tests are slightly changed as a consequence

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Instead of controllersBus list / controlledBus optional

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
@flo-dup flo-dup force-pushed the refactoring-voltage-control branch from d4f8013 to d8b3498 Compare November 17, 2020 14:41
@flo-dup flo-dup requested a review from annetill November 17, 2020 14:49
@annetill annetill changed the title [WIP] Refactoring voltage control Refactoring voltage control Nov 19, 2020
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 3 Code Smells

91.2% 91.2% Coverage
0.0% 0.0% Duplication

@annetill annetill requested a review from geofjamg November 19, 2020 16:11
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.

Some small changes. After @geofjamg review, I will perform a functional validation as the feature is central.

}
});
}
public void setVoltageControl(boolean voltageControl) {
Copy link
Member

Choose a reason for hiding this comment

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

You have to renamed ths function for sure. I thought that you can make it using the Mode OFF of the voltageControl ?

Copy link
Member

Choose a reason for hiding this comment

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

No clear to me too what is the difference between mode of the VoltageControl and property voltageControlEnabled ? Is mode really usefull as mode is kind of result of individual voltage control enable status of all controllers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the mode, as VoltageControl is only structural, the state (voltageControlEnabled) remains in LfBus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setVoltageControl() is moreover renamed into setVoltageControlEnabled()

if (!(creationParameters.isVoltageRemoteControl() && bus.getControlledBus().isPresent()) && bus.getControllerBuses().isEmpty()) {
equationSystem.createEquation(bus.getNum(), EquationType.BUS_V).addTerm(new BusVoltageEquationTerm(bus, variableSet));
}
boolean hasLocalControl = bus.isVoltageController() && bus.getVoltageControl().isVoltageControlLocal();
Copy link
Member

Choose a reason for hiding this comment

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

This function could be more clear.

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
annetill and others added 2 commits March 2, 2021 18:29
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
@Override
public String getControlledBusId(boolean breakers) {
Terminal terminal = generator.getRegulatingTerminal();
Bus controlled = breakers ? terminal.getBusBreakerView().getBus() : terminal.getBusView().getBus();
Copy link
Member

Choose a reason for hiding this comment

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

You have to fix this: you have to check if the bus is not null and not creating the voltage control if it is. We do that for the discrete voltage control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. In the last commit I do it earlier, in the LfGenerator constructor, so that the voltage control is disabled from the start.

flo-dup added 2 commits March 3, 2021 09:11
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
controllerBusCount++;
}
}
long controllerBusCount = busesById.values().stream().filter(LfBus::isVoltageControllerEnabled).count();
Copy link
Member

Choose a reason for hiding this comment

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

This log is not equivalent to what was count before. Here we just want to know in all voltage control remote and local, how many controlled buses have at least one remote controller and for all controllers how many are remote. This is important if we want to compare.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected, but what was counted before included the voltage controls discarded for too small max reactive ranges and for not started generators... so it's still annoying to compare the results.

@@ -68,7 +68,7 @@ private static void createVoltageControls(LfNetwork lfNetwork, List<LfBus> lfBus
// check target voltage
checkUniqueTargetVControllerBus(lfGenerator, controllerTargetV, controllerBus, generatorControlledBus);

if (lfGenerator.hasVoltageControl()) {
if (lfGenerator.hasVoltageControl() && controllerBus.isVoltageControllerEnabled()) {
Copy link
Member

@annetill annetill Mar 3, 2021

Choose a reason for hiding this comment

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

This condition can be done before to avoid not usuful checks ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done; in fact some refactoring has been done here, to avoid the null/NaN initialization and the useless checks.

flo-dup added 6 commits March 3, 2021 09:27
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Comment on lines +77 to +78
if (!voltageRemoteControl && controlledBus != controllerBus) {
// if voltage remote control deactivated and remote control, set local control instead
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be done earlier to have the lfGenerator consistent with the local voltage control, but for now it's easier to do it here.

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.

Just minor remarks or questions. This is a large refactoring, lots of code has been moved and so this is very difficult to review. But new design looks good and is clearly better than previous one.

controllerBus.setVoltageControl(this);
}

public boolean isVoltageControlLocal() {
Copy link
Member

Choose a reason for hiding this comment

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

The name is not clear, at first read I was thinking it means this is only a local control

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, but in fact we call it only once, to check just after if it is only local! hence I changed its content to return whether it is a local control only.

@@ -164,7 +164,7 @@ void testMaxIterationReached() {
parameters.setWriteSlackBus(true);
Network network = EurostagTutorialExample1Factory.create();
LoadFlow.Runner loadFlowRunner = new LoadFlow.Runner(new OpenLoadFlowProvider(new SparseMatrixFactory()));
network.getGenerator("GEN").setTargetV(5);
network.getVoltageLevelStream().forEach(vl -> vl.setNominalV(21));
Copy link
Member

Choose a reason for hiding this comment

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

Why ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was just a way to get max iteration reached, as setting a target value too far from nominal voltage is not possible anymore. I improved it with a clearer and cleaner change, and added a comment.

@@ -45,7 +45,7 @@ void localTest() {
.setMinP(0)
.setMaxP(200)
.setTargetP(100)
.setTargetV(413)
.setTargetV(23)
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why you changed unit tests?

Copy link
Member

Choose a reason for hiding this comment

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

Because the previous test was not real with two generators connected to a 20 kV voltage level and with target V around 400 kV, without any remote regulating terminal.

private final boolean phaseControl;

private final boolean transformerVoltageControl;

private final boolean forceA1Var;

public AcEquationSystemCreationParameters(boolean voltageRemoteControl, boolean phaseControl, boolean transformerVoltageControl) {
this(voltageRemoteControl, phaseControl, transformerVoltageControl, false);
public AcEquationSystemCreationParameters(boolean phaseControl, boolean transformerVoltageControl) {
Copy link
Member

Choose a reason for hiding this comment

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

Ok so remote voltage control de-activation is only managed at network creation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, after that we do not need that boolean anymore.

Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
// check that targetV has a plausible value (wrong nominal voltage issue)
if (targetV < PlausibleValues.MIN_TARGET_VOLTAGE_PU || targetV > PlausibleValues.MAX_TARGET_VOLTAGE_PU) {
LOGGER.warn("Generator '{}' has an inconsistent target voltage: {} pu", getId(), targetV);
newTargetV = (targetV > PlausibleValues.MAX_TARGET_VOLTAGE_PU) ? PlausibleValues.MAX_TARGET_VOLTAGE_PU : PlausibleValues.MIN_TARGET_VOLTAGE_PU;
Copy link
Member

Choose a reason for hiding this comment

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

@geofjamg Just tell if if this fix on targetV is okay for you.

Copy link
Member

Choose a reason for hiding this comment

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

why not!

flo-dup added 8 commits March 4, 2021 13:03
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2021

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

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

What a great work @floriand-e2r ! Thanks a lot !

@flo-dup flo-dup merged commit c3472c2 into master Mar 4, 2021
@flo-dup flo-dup deleted the refactoring-voltage-control branch March 4, 2021 16:23
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