Skip to content

Commit

Permalink
Fix: Update TapChanger neutralPosition after using a stepsReplacer (#…
Browse files Browse the repository at this point in the history
…3094)

Fix: Update TapChanger neutralPosition after using a stepsReplacer

Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
(cherry picked from commit db50dc9)
  • Loading branch information
AbdelHedhili authored and olperr1 committed Jul 11, 2024
1 parent be4f762 commit d852aac
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 1 deletion.
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 @@ -204,6 +204,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(), 0.0);
assertEquals(1, neutralStep.getRho(), 0.0);
assertEquals(1, neutralStep.getR(), 0.0);
assertEquals(2, neutralStep.getX(), 0.0);
assertEquals(3, neutralStep.getG(), 0.0);
assertEquals(4, neutralStep.getB(), 0.0);

//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(), 0.0);
assertEquals(1, neutralStep.getRho(), 0.0);
assertEquals(9, neutralStep.getR(), 0.0);
assertEquals(10, neutralStep.getX(), 0.0);
assertEquals(11, neutralStep.getG(), 0.0);
assertEquals(12, neutralStep.getB(), 0.0);
}

@Test
public void invalidTapPositionPhase() {
ValidationException e = assertThrows(ValidationException.class, () -> createPhaseTapChangerWith2Steps(3, 0, false,
Expand Down Expand Up @@ -521,6 +607,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

0 comments on commit d852aac

Please sign in to comment.