-
Notifications
You must be signed in to change notification settings - Fork 43
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
Create adders from existing objects: ReactiveCapabilityCurve, PhaseTapChanger, RatioTapChanger #3130
Merged
Merged
Create adders from existing objects: ReactiveCapabilityCurve, PhaseTapChanger, RatioTapChanger #3130
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
171c4b5
add reactive capability curve builder using existing reactive capabil…
bc-rte 6180bf7
add way to build tap changers by copying existing ones
bc-rte 22000de
Merge branch 'main' into add_builders_from_existing_objects
flo-dup 629615e
Update iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/Abstr…
bc-rte a239827
license
bc-rte 93eb8d8
Merge branch 'main' into add_builders_from_existing_objects
flo-dup 6919780
Merge branch 'main' into add_builders_from_existing_objects
flo-dup 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
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
6 changes: 6 additions & 0 deletions
6
iidm/iidm-impl/src/test/java/com/powsybl/iidm/network/impl/tck/TapChangerHolderTest.java
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.powsybl.iidm.network.impl.tck; | ||
flo-dup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import com.powsybl.iidm.network.tck.AbstractTapChangerHolderTest; | ||
|
||
public class TapChangerHolderTest extends AbstractTapChangerHolderTest { | ||
} |
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
195 changes: 195 additions & 0 deletions
195
iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractTapChangerHolderTest.java
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 |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/** | ||
* Copyright (c) 2024, All partners of the iTesla project (http://www.itesla-project.eu/consortium) | ||
bc-rte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.iidm.network.tck; | ||
|
||
import com.powsybl.iidm.network.*; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.powsybl.iidm.network.PhaseTapChanger.RegulationMode.FIXED_TAP; | ||
import static com.powsybl.iidm.network.RatioTapChanger.RegulationMode.VOLTAGE; | ||
import static com.powsybl.iidm.network.TopologyKind.BUS_BREAKER; | ||
import static com.powsybl.iidm.network.TwoSides.ONE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Benoît Chiquet {@literal <benoit.chiquet at rte-france.com>} | ||
*/ | ||
public abstract class AbstractTapChangerHolderTest { | ||
|
||
@Test | ||
void shouldReuseCopiedPhaseTapChangerPropertiesFixedTapExample() { | ||
Network network = exampleNetwork(); | ||
PhaseTapChanger existingPhaseTapChanger = network.getTwoWindingsTransformer("transformer") | ||
.newPhaseTapChanger() | ||
.setTapPosition(1) | ||
.setRegulationValue(12) | ||
.setRegulationMode(FIXED_TAP) | ||
.setLowTapPosition(0) | ||
.setRegulating(false) | ||
.setTargetDeadband(3) | ||
.beginStep().setAlpha(1).setRho(2).setR(3).setG(4).setB(5).setX(6) | ||
.endStep() | ||
.beginStep().setAlpha(2).setRho(3).setR(4).setG(5).setB(6).setX(7) | ||
.endStep() | ||
.beginStep().setAlpha(3).setRho(4).setR(5).setG(6).setB(7).setX(8) | ||
.endStep() | ||
.add(); | ||
|
||
PhaseTapChanger newPhaseTapChanger = network.getTwoWindingsTransformer("transformer2") | ||
.newPhaseTapChanger(existingPhaseTapChanger) | ||
.add(); | ||
|
||
assertEquals(existingPhaseTapChanger.getTapPosition(), newPhaseTapChanger.getTapPosition()); | ||
assertEquals(existingPhaseTapChanger.getLowTapPosition(), newPhaseTapChanger.getLowTapPosition()); | ||
assertEquals(existingPhaseTapChanger.getRegulationValue(), newPhaseTapChanger.getRegulationValue()); | ||
assertEquals(existingPhaseTapChanger.getRegulationMode(), newPhaseTapChanger.getRegulationMode()); | ||
assertEquals(existingPhaseTapChanger.isRegulating(), newPhaseTapChanger.isRegulating()); | ||
assertEquals(existingPhaseTapChanger.getTargetDeadband(), newPhaseTapChanger.getTargetDeadband()); | ||
|
||
newPhaseTapChanger.getAllSteps().forEach((tap, newStep) -> { | ||
PhaseTapChangerStep existingStep = existingPhaseTapChanger.getStep(tap); | ||
assertEquals(existingStep.getAlpha(), newStep.getAlpha()); | ||
assertEquals(existingStep.getRho(), newStep.getRho()); | ||
assertEquals(existingStep.getR(), newStep.getR()); | ||
assertEquals(existingStep.getG(), newStep.getG()); | ||
assertEquals(existingStep.getB(), newStep.getB()); | ||
assertEquals(existingStep.getX(), newStep.getX()); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldReuseCopiedPhaseTapChangerPropertiesActivePowerControlExample() { | ||
Network network = exampleNetwork(); | ||
PhaseTapChanger existingPhaseTapChanger = network.getTwoWindingsTransformer("transformer") | ||
.newPhaseTapChanger() | ||
.setTapPosition(1) | ||
.setRegulationValue(12) | ||
.setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL) | ||
.setRegulationTerminal(network.getTwoWindingsTransformer("transformer").getTerminal(ONE)) | ||
.setLowTapPosition(0) | ||
.setRegulating(false) | ||
.setTargetDeadband(3) | ||
.beginStep().setAlpha(1).setRho(2).setR(3).setG(4).setB(5).setX(6) | ||
.endStep() | ||
.beginStep().setAlpha(2).setRho(3).setR(4).setG(5).setB(6).setX(7) | ||
.endStep() | ||
.beginStep().setAlpha(3).setRho(4).setR(5).setG(6).setB(7).setX(8) | ||
.endStep() | ||
.add(); | ||
|
||
PhaseTapChanger newPhaseTapChanger = network.getTwoWindingsTransformer("transformer2") | ||
.newPhaseTapChanger(existingPhaseTapChanger) | ||
.add(); | ||
|
||
assertEquals(existingPhaseTapChanger.getTapPosition(), newPhaseTapChanger.getTapPosition()); | ||
assertEquals(existingPhaseTapChanger.getLowTapPosition(), newPhaseTapChanger.getLowTapPosition()); | ||
assertEquals(existingPhaseTapChanger.getRegulationValue(), newPhaseTapChanger.getRegulationValue()); | ||
assertEquals(existingPhaseTapChanger.getRegulationMode(), newPhaseTapChanger.getRegulationMode()); | ||
assertEquals(existingPhaseTapChanger.isRegulating(), newPhaseTapChanger.isRegulating()); | ||
assertEquals(existingPhaseTapChanger.getTargetDeadband(), newPhaseTapChanger.getTargetDeadband()); | ||
assertEquals(existingPhaseTapChanger.getRegulationTerminal(), newPhaseTapChanger.getRegulationTerminal()); | ||
|
||
newPhaseTapChanger.getAllSteps().forEach((tap, newStep) -> { | ||
PhaseTapChangerStep existingStep = existingPhaseTapChanger.getStep(tap); | ||
assertEquals(existingStep.getAlpha(), newStep.getAlpha()); | ||
assertEquals(existingStep.getRho(), newStep.getRho()); | ||
assertEquals(existingStep.getR(), newStep.getR()); | ||
assertEquals(existingStep.getG(), newStep.getG()); | ||
assertEquals(existingStep.getB(), newStep.getB()); | ||
assertEquals(existingStep.getX(), newStep.getX()); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldReuseCopiedRatioTapChangerProperties() { | ||
Network network = exampleNetwork(); | ||
RatioTapChanger existingRatioTapChanger = network.getTwoWindingsTransformer("transformer").newRatioTapChanger() | ||
.setTapPosition(1) | ||
.setTargetV(400) | ||
.setRegulationValue(12) | ||
.setRegulationMode(VOLTAGE) | ||
.setLowTapPosition(0) | ||
.setRegulating(false) | ||
.setLoadTapChangingCapabilities(true) | ||
.setTargetDeadband(3) | ||
.beginStep().setRho(2).setR(3).setG(4).setB(5).setX(6) | ||
.endStep() | ||
.beginStep().setRho(3).setR(4).setG(5).setB(6).setX(7) | ||
.endStep() | ||
.beginStep().setRho(4).setR(5).setG(6).setB(7).setX(8) | ||
.endStep() | ||
.add(); | ||
|
||
RatioTapChanger newRatioTapChanger = network.getTwoWindingsTransformer("transformer2") | ||
.newRatioTapChanger(existingRatioTapChanger) | ||
.add(); | ||
|
||
assertEquals(existingRatioTapChanger.getTapPosition(), newRatioTapChanger.getTapPosition()); | ||
assertEquals(existingRatioTapChanger.getLowTapPosition(), newRatioTapChanger.getLowTapPosition()); | ||
assertEquals(existingRatioTapChanger.getRegulationValue(), newRatioTapChanger.getRegulationValue()); | ||
assertEquals(existingRatioTapChanger.getRegulationMode(), newRatioTapChanger.getRegulationMode()); | ||
assertEquals(existingRatioTapChanger.isRegulating(), newRatioTapChanger.isRegulating()); | ||
assertEquals(existingRatioTapChanger.getTargetDeadband(), newRatioTapChanger.getTargetDeadband()); | ||
assertEquals(existingRatioTapChanger.getRegulationTerminal(), newRatioTapChanger.getRegulationTerminal()); | ||
assertEquals(existingRatioTapChanger.getTargetV(), newRatioTapChanger.getTargetV()); | ||
assertEquals(existingRatioTapChanger.hasLoadTapChangingCapabilities(), newRatioTapChanger.hasLoadTapChangingCapabilities()); | ||
|
||
newRatioTapChanger.getAllSteps().forEach((tap, newStep) -> { | ||
RatioTapChangerStep existingStep = existingRatioTapChanger.getStep(tap); | ||
assertEquals(existingStep.getRho(), newStep.getRho()); | ||
assertEquals(existingStep.getR(), newStep.getR()); | ||
assertEquals(existingStep.getG(), newStep.getG()); | ||
assertEquals(existingStep.getB(), newStep.getB()); | ||
assertEquals(existingStep.getX(), newStep.getX()); | ||
}); | ||
} | ||
|
||
Network exampleNetwork() { | ||
Network network = Network.create("test", "test"); | ||
Substation substation = network.newSubstation() | ||
.setId("substation") | ||
.setCountry(Country.AD) | ||
.add(); | ||
VoltageLevel vl1 = substation.newVoltageLevel() | ||
.setId("vl1") | ||
.setTopologyKind(BUS_BREAKER) | ||
.setName("name") | ||
.setNominalV(225) | ||
.setLowVoltageLimit(200) | ||
.setHighVoltageLimit(250) | ||
.add(); | ||
vl1.getBusBreakerView().newBus().setId("bus1").add(); | ||
VoltageLevel vl2 = substation.newVoltageLevel() | ||
.setId("vl2") | ||
.setTopologyKind(BUS_BREAKER) | ||
.setName("name") | ||
.setNominalV(90) | ||
.setLowVoltageLimit(80) | ||
.setHighVoltageLimit(100) | ||
.add(); | ||
vl2.getBusBreakerView().newBus().setId("bus2").add(); | ||
|
||
substation.newTwoWindingsTransformer() | ||
.setId("transformer") | ||
.setR(17) | ||
.setX(10) | ||
.setBus1("bus1") | ||
.setBus2("bus2") | ||
.add(); | ||
|
||
substation.newTwoWindingsTransformer() | ||
.setId("transformer2") | ||
.setR(12) | ||
.setX(15) | ||
.setBus1("bus1") | ||
.setBus2("bus2") | ||
.add(); | ||
|
||
return network; | ||
} | ||
} |
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.
wouldn't it be interesting to add a
A beginStep(D step)
inTapChangerAdder
interface? It's probably not very useful, but in that way each level would have its copy method.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.
I would prefer to stick to the perimeter you defined previously.
If the need for copy-adder on steps solidifies, they could be added in a separate PR.
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.
Even if you consider the code duplication in PhaseTapChangerHolder and RatioTapChangerHolder?
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.
After looking back into it, the issue I have with it is that
beginStep
carries a state that would be unrelated to existing step: the order in which steps are created currently encodes the tap position. Being able to initializebeginStep
by copying a step with a different tap position may be confusing for users.A helper class could be used to mutualize the code, but it is unclear to me whether this would be better than the current situation.