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

Fix: Update TapChanger neutralPosition after using a stepsReplacer #3094

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractTapChanger<H extends TapChangerParent, C extends Abstract

protected int lowTapPosition;

protected final Integer relativeNeutralPosition;
protected Integer relativeNeutralPosition;

protected List<S> steps;

Expand Down Expand Up @@ -160,6 +160,7 @@ protected C setSteps(List<S> steps) {
}

this.steps = steps;
this.relativeNeutralPosition = getRelativeNeutralPosition();
return (C) this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,92 @@ public void testDefaultPhaseTapChangerStep() {
assertEquals(1.0, step.getRho(), 0.0);
}

@Test
public void testPhaseTapChangerStepsReplacer() {
PhaseTapChanger phaseTapChanger = twt.newPhaseTapChanger()
.setTapPosition(1)
.setLowTapPosition(0)
.setRegulating(true)
.setTargetDeadband(1.0)
.setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL)
.setRegulationValue(10.0)
.setRegulationTerminal(terminal)
.beginStep()
.setR(1.0)
.setX(2.0)
.setG(3.0)
.setB(4.0)
.setAlpha(0.0)
.setRho(1.0)
.endStep()
.beginStep()
.setR(1.0)
.setX(2.0)
.setG(3.0)
.setB(4.0)
.setAlpha(5.0)
.setRho(6.0)
.endStep()
.add();
assertEquals(2, phaseTapChanger.getStepCount());
assertEquals(2, phaseTapChanger.getAllSteps().size());
assertEquals(0, phaseTapChanger.getLowTapPosition());
assertEquals(1, phaseTapChanger.getHighTapPosition());
assertEquals(0, phaseTapChanger.getNeutralPosition().orElseThrow());

//check neutral step attributes
PhaseTapChangerStep neutralStep = phaseTapChanger.getNeutralStep().orElseThrow();
assertEquals(0, neutralStep.getAlpha());
assertEquals(1, neutralStep.getRho());
assertEquals(1, neutralStep.getR());
assertEquals(2, neutralStep.getX());
assertEquals(3, neutralStep.getG());
assertEquals(4, neutralStep.getB());

//replace steps
phaseTapChanger.stepsReplacer()
.beginStep()
.setR(1.0)
.setX(2.0)
.setG(3.0)
.setB(4.0)
.setAlpha(5.0)
.setRho(6.0)
.endStep()
.beginStep()
.setR(5.0)
.setX(6.0)
.setG(7.0)
.setB(8.0)
.setAlpha(6.0)
.setRho(7.0)
.endStep()
.beginStep()
.setR(9.0)
.setX(10.0)
.setG(11.0)
.setB(12.0)
.setAlpha(0.0)
.setRho(1.0)
.endStep()
.replaceSteps();

assertEquals(3, phaseTapChanger.getStepCount());
assertEquals(3, phaseTapChanger.getAllSteps().size());
assertEquals(0, phaseTapChanger.getLowTapPosition());
assertEquals(2, phaseTapChanger.getHighTapPosition());
assertEquals(2, phaseTapChanger.getNeutralPosition().orElseThrow());

//check neutral step attributes
neutralStep = phaseTapChanger.getNeutralStep().orElseThrow();
assertEquals(0, neutralStep.getAlpha());
AbdelHedhili marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(1, neutralStep.getRho());
assertEquals(9, neutralStep.getR());
assertEquals(10, neutralStep.getX());
assertEquals(11, neutralStep.getG());
assertEquals(12, neutralStep.getB());
}

@Test
public void invalidTapPositionPhase() {
ValidationException e = assertThrows(ValidationException.class, () -> createPhaseTapChangerWith2Steps(3, 0, false,
Expand Down Expand Up @@ -516,6 +602,85 @@ public void testDefaultRatioTapChangerStep() {
assertEquals(0.0, step.getB(), 0.0);
}

@Test
public void testRatioTapChangerStepsReplacer() {
RatioTapChanger ratioTapChanger = twt.newRatioTapChanger()
.setTapPosition(1)
.setLowTapPosition(0)
.setRegulating(true)
.setTargetDeadband(1.0)
.setRegulationMode(RatioTapChanger.RegulationMode.REACTIVE_POWER)
.setRegulationValue(10.0)
.setRegulationTerminal(terminal)
.beginStep()
.setR(1.0)
.setX(2.0)
.setG(3.0)
.setB(4.0)
.setRho(1.0)
.endStep()
.beginStep()
.setR(1.0)
.setX(2.0)
.setG(3.0)
.setB(4.0)
.setRho(6.0)
.endStep()
.add();
assertEquals(2, ratioTapChanger.getStepCount());
assertEquals(2, ratioTapChanger.getAllSteps().size());
assertEquals(0, ratioTapChanger.getLowTapPosition());
assertEquals(1, ratioTapChanger.getHighTapPosition());
assertEquals(0, ratioTapChanger.getNeutralPosition().orElseThrow());

//check neutral step attributes
RatioTapChangerStep neutralStep = ratioTapChanger.getNeutralStep().orElseThrow();
assertEquals(1, neutralStep.getRho());
assertEquals(1, neutralStep.getR());
assertEquals(2, neutralStep.getX());
assertEquals(3, neutralStep.getG());
assertEquals(4, neutralStep.getB());

//replace steps
ratioTapChanger.stepsReplacer()
.beginStep()
.setR(1.0)
.setX(2.0)
.setG(3.0)
.setB(4.0)
.setRho(6.0)
.endStep()
.beginStep()
.setR(5.0)
.setX(6.0)
.setG(7.0)
.setB(8.0)
.setRho(7.0)
.endStep()
.beginStep()
.setR(9.0)
.setX(10.0)
.setG(11.0)
.setB(12.0)
.setRho(1.0)
.endStep()
.replaceSteps();

assertEquals(3, ratioTapChanger.getStepCount());
assertEquals(3, ratioTapChanger.getAllSteps().size());
assertEquals(0, ratioTapChanger.getLowTapPosition());
assertEquals(2, ratioTapChanger.getHighTapPosition());
assertEquals(2, ratioTapChanger.getNeutralPosition().orElseThrow());

//check neutral step attributes
neutralStep = ratioTapChanger.getNeutralStep().orElseThrow();
assertEquals(1, neutralStep.getRho());
assertEquals(9, neutralStep.getR());
assertEquals(10, neutralStep.getX());
assertEquals(11, neutralStep.getG());
assertEquals(12, neutralStep.getB());
}

@Test
public void invalidRatioTapChangerWithoutSteps() {
ValidationException e = assertThrows(ValidationException.class, () -> twt.newRatioTapChanger()
Expand Down