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

[CSA] Use GridStateAlterations mRIDs #1162

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -9,6 +9,8 @@
package com.powsybl.openrao.data.cracapi.networkaction;

public interface SingleNetworkElementActionAdder<T extends SingleNetworkElementActionAdder<T>> {
T withId(String id);

T withNetworkElement(String networkElementId);

T withNetworkElement(String networkElementId, String networkElementName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
*/
public abstract class AbstractSingleNetworkElementActionAdderImpl<I> {
protected NetworkActionAdderImpl ownerAdder;
protected String id;
protected String networkElementId;
private String networkElementName;

AbstractSingleNetworkElementActionAdderImpl(NetworkActionAdderImpl ownerAdder) {
this.ownerAdder = ownerAdder;
}

public I withId(String id) {
this.id = id;
return (I) this;
}

public I withNetworkElement(String networkElementId) {
this.networkElementId = networkElementId;
return (I) this;
Expand All @@ -38,7 +44,7 @@ public I withNetworkElement(String networkElementId, String networkElementName)
}

public NetworkActionAdder add() {
assertAttributeNotNull(networkElementId, getActionName(), "network element", "withNetworkElement()");
assertAttributeNotNull(networkElementId, getActionTypeName(), "network element", "withNetworkElement()");
assertSpecificAttributes();
NetworkElement networkElement = this.ownerAdder.getCrac().addNetworkElement(networkElementId, networkElementName);
ownerAdder.addElementaryAction(buildAction(), networkElement);
Expand All @@ -49,5 +55,9 @@ public NetworkActionAdder add() {

protected abstract void assertSpecificAttributes();

protected abstract String getActionName();
protected abstract String getActionTypeName();

protected String createActionName(Object specificAttribute) {
return id == null ? String.format("%s_%s_%s", getActionTypeName(), networkElementId, specificAttribute) : id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public DanglingLineActionAdder withActivePowerValue(double activePowerValue) {

protected Action buildAction() {
return new DanglingLineActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, activePowerValue))
.withId(createActionName(activePowerValue))
.withNetworkElementId(networkElementId)
.withRelativeValue(false)
.withActivePowerValue(activePowerValue)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(activePowerValue, getActionName(), "activePowerValue", "withActivePowerValue()");
assertAttributeNotNull(activePowerValue, getActionTypeName(), "activePowerValue", "withActivePowerValue()");
}

protected String getActionName() {
protected String getActionTypeName() {
return "DanglingLineAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public GeneratorActionAdder withActivePowerValue(double activePowerValue) {

protected Action buildAction() {
return new GeneratorActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, activePowerValue))
.withId(createActionName(activePowerValue))
.withNetworkElementId(networkElementId)
.withActivePowerRelativeValue(false)
.withActivePowerValue(activePowerValue)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(activePowerValue, getActionName(), "activePowerValue", "withActivePowerValue()");
assertAttributeNotNull(activePowerValue, getActionTypeName(), "activePowerValue", "withActivePowerValue()");
}

protected String getActionName() {
protected String getActionTypeName() {
return "GeneratorAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public LoadActionAdder withActivePowerValue(double activePowerValue) {

protected Action buildAction() {
return new LoadActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, activePowerValue))
.withId(createActionName(activePowerValue))
.withNetworkElementId(networkElementId)
.withRelativeValue(false)
.withActivePowerValue(activePowerValue)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(activePowerValue, getActionName(), "activePowerValue", "withActivePowerValue()");
assertAttributeNotNull(activePowerValue, getActionTypeName(), "activePowerValue", "withActivePowerValue()");
}

protected String getActionName() {
protected String getActionTypeName() {
return "LoadAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public PhaseTapChangerTapPositionActionAdder withTapPosition(int tapPosition) {

protected Action buildAction() {
return new PhaseTapChangerTapPositionActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, tapPosition))
.withId(createActionName(tapPosition))
.withNetworkElementId(networkElementId)
.withTapPosition(tapPosition)
.withRelativeValue(false)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(tapPosition, getActionName(), "tapPosition", "withTapPosition()");
assertAttributeNotNull(tapPosition, getActionTypeName(), "tapPosition", "withTapPosition()");
}

protected String getActionName() {
protected String getActionTypeName() {
return "PhaseTapChangerTapPositionAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ public ShuntCompensatorPositionActionAdder withSectionCount(int sectionCount) {

protected Action buildAction() {
return new ShuntCompensatorPositionActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, sectionCount))
.withId(createActionName(sectionCount))
.withNetworkElementId(networkElementId)
.withSectionCount(sectionCount)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(sectionCount, getActionName(), "sectionCount", "withSectionCount()");
assertAttributeNotNull(sectionCount, getActionTypeName(), "sectionCount", "withSectionCount()");
if (sectionCount < 0) {
throw new OpenRaoException("Section count should be a positive integer");
}
}

protected String getActionName() {
protected String getActionTypeName() {
return "ShuntCompensatorPositionAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public SwitchActionAdder withActionType(ActionType actionType) {

protected Action buildAction() {
return new SwitchActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, actionType))
.withId(createActionName(actionType))
.withNetworkElementId(networkElementId)
.withOpen(actionType == ActionType.OPEN)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(actionType, getActionName(), "actionType", "withActionType()");
assertAttributeNotNull(actionType, getActionTypeName(), "actionType", "withActionType()");
}

protected String getActionName() {
protected String getActionTypeName() {
return "SwitchAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public TerminalsConnectionActionAdder withActionType(ActionType actionType) {

protected Action buildAction() {
return new TerminalsConnectionActionBuilder()
.withId(String.format("%s_%s_%s", getActionName(), networkElementId, actionType))
.withId(createActionName(actionType))
.withNetworkElementId(networkElementId)
.withOpen(actionType == ActionType.OPEN)
.build();
}

protected void assertSpecificAttributes() {
assertAttributeNotNull(actionType, getActionName(), "actionType", "withActionType()");
assertAttributeNotNull(actionType, getActionTypeName(), "actionType", "withActionType()");
}

protected String getActionName() {
protected String getActionTypeName() {
return "TerminalsConnectionAction";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ void testOk() {
.add();

DanglingLineAction danglingLineAction = (DanglingLineAction) networkAction.getElementaryActions().iterator().next();
assertEquals("DanglingLineAction_groupNetworkElementId_100.0", danglingLineAction.getId());
assertEquals("groupNetworkElementId", danglingLineAction.getDanglingLineId());
assertEquals(100., danglingLineAction.getActivePowerValue().getAsDouble(), 1e-3);

// check that network element have been added to CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("groupNetworkElementId"));
}

@Test
void testOkWithId() {
NetworkAction networkAction = networkActionAdder.newDanglingLineAction()
.withId("danglingLineAction")
.withNetworkElement("groupNetworkElementId")
.withActivePowerValue(100.)
.add()
.add();

DanglingLineAction danglingLineAction = (DanglingLineAction) networkAction.getElementaryActions().iterator().next();
assertEquals("danglingLineAction", danglingLineAction.getId());
assertEquals("groupNetworkElementId", danglingLineAction.getDanglingLineId());
assertEquals(100., danglingLineAction.getActivePowerValue().getAsDouble(), 1e-3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ void testOk() {
.add();

GeneratorAction generatorAction = (GeneratorAction) networkAction.getElementaryActions().iterator().next();
assertEquals("GeneratorAction_groupNetworkElementId_100.0", generatorAction.getId());
assertEquals("groupNetworkElementId", generatorAction.getGeneratorId());
assertEquals(100., generatorAction.getActivePowerValue().getAsDouble(), 1e-3);

// check that network element have been added to CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("groupNetworkElementId"));
}

@Test
void testOkWithId() {
NetworkAction networkAction = networkActionAdder.newGeneratorAction()
.withId("generatorAction")
.withNetworkElement("groupNetworkElementId")
.withActivePowerValue(100.)
.add()
.add();

GeneratorAction generatorAction = (GeneratorAction) networkAction.getElementaryActions().iterator().next();
assertEquals("generatorAction", generatorAction.getId());
assertEquals("groupNetworkElementId", generatorAction.getGeneratorId());
assertEquals(100., generatorAction.getActivePowerValue().getAsDouble(), 1e-3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ void testOk() {
.add();

LoadAction loadAction = (LoadAction) networkAction.getElementaryActions().iterator().next();
assertEquals("LoadAction_groupNetworkElementId_100.0", loadAction.getId());
assertEquals("groupNetworkElementId", loadAction.getLoadId());
assertEquals(100., loadAction.getActivePowerValue().getAsDouble(), 1e-3);

// check that network element have been added to CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("groupNetworkElementId"));
}

@Test
void testOkWithId() {
NetworkAction networkAction = networkActionAdder.newLoadAction()
.withId("loadAction")
.withNetworkElement("groupNetworkElementId")
.withActivePowerValue(100.)
.add()
.add();

LoadAction loadAction = (LoadAction) networkAction.getElementaryActions().iterator().next();
assertEquals("loadAction", loadAction.getId());
assertEquals("groupNetworkElementId", loadAction.getLoadId());
assertEquals(100., loadAction.getActivePowerValue().getAsDouble(), 1e-3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ void testOk() {
.add();

PhaseTapChangerTapPositionAction phaseTapChangerTapPositionAction = (PhaseTapChangerTapPositionAction) networkAction.getElementaryActions().iterator().next();
assertEquals("PhaseTapChangerTapPositionAction_pstNetworkElementId_0", phaseTapChangerTapPositionAction.getId());
assertEquals("pstNetworkElementId", phaseTapChangerTapPositionAction.getTransformerId());
assertEquals(0, phaseTapChangerTapPositionAction.getTapPosition(), 1e-3);

// check that network element has been created in CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("pstNetworkElementId"));
}

@Test
void testOkWithId() {

NetworkAction networkAction = networkActionAdder.newPhaseTapChangerTapPositionAction()
.withId("phaseTapChangerTapPositionAction")
.withNetworkElement("pstNetworkElementId")
.withTapPosition(0)
.add()
.add();

PhaseTapChangerTapPositionAction phaseTapChangerTapPositionAction = (PhaseTapChangerTapPositionAction) networkAction.getElementaryActions().iterator().next();
assertEquals("phaseTapChangerTapPositionAction", phaseTapChangerTapPositionAction.getId());
assertEquals("pstNetworkElementId", phaseTapChangerTapPositionAction.getTransformerId());
assertEquals(0, phaseTapChangerTapPositionAction.getTapPosition(), 1e-3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ void testOk() {
.add();

ShuntCompensatorPositionAction shuntCompensatorPositionAction = (ShuntCompensatorPositionAction) networkAction.getElementaryActions().iterator().next();
assertEquals("ShuntCompensatorPositionAction_groupNetworkElementId_3", shuntCompensatorPositionAction.getId());
assertEquals("groupNetworkElementId", shuntCompensatorPositionAction.getShuntCompensatorId());
assertEquals(3, shuntCompensatorPositionAction.getSectionCount());

// check that network element have been added to CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("groupNetworkElementId"));
}

@Test
void testOkWithId() {
NetworkAction networkAction = networkActionAdder.newShuntCompensatorPositionAction()
.withId("shuntCompensatorPositionAction")
.withNetworkElement("groupNetworkElementId")
.withSectionCount(3)
.add()
.add();

ShuntCompensatorPositionAction shuntCompensatorPositionAction = (ShuntCompensatorPositionAction) networkAction.getElementaryActions().iterator().next();
assertEquals("shuntCompensatorPositionAction", shuntCompensatorPositionAction.getId());
assertEquals("groupNetworkElementId", shuntCompensatorPositionAction.getShuntCompensatorId());
assertEquals(3, shuntCompensatorPositionAction.getSectionCount());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ void testOk() {
.add();

SwitchAction switchAction = (SwitchAction) networkAction.getElementaryActions().iterator().next();
assertEquals("SwitchAction_branchNetworkElementId_OPEN", switchAction.getId());
assertEquals("branchNetworkElementId", switchAction.getSwitchId());
assertTrue(switchAction.isOpen());

// check that network element has been added in CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("branchNetworkElementId"));
}

@Test
void testOkWithId() {
NetworkAction networkAction = networkActionAdder.newSwitchAction()
.withId("switchAction")
.withNetworkElement("branchNetworkElementId")
.withActionType(ActionType.OPEN)
.add()
.add();

SwitchAction switchAction = (SwitchAction) networkAction.getElementaryActions().iterator().next();
assertEquals("switchAction", switchAction.getId());
assertEquals("branchNetworkElementId", switchAction.getSwitchId());
assertTrue(switchAction.isOpen());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ void testOk() {
.add();

TerminalsConnectionAction terminalsConnectionAction = (TerminalsConnectionAction) networkAction.getElementaryActions().iterator().next();
assertEquals("TerminalsConnectionAction_branchNetworkElementId_OPEN", terminalsConnectionAction.getId());
assertEquals("branchNetworkElementId", terminalsConnectionAction.getElementId());
assertTrue(terminalsConnectionAction.isOpen());

// check that network element has been added in CracImpl
assertEquals(1, ((CracImpl) crac).getNetworkElements().size());
assertNotNull(((CracImpl) crac).getNetworkElement("branchNetworkElementId"));
}

@Test
void testOkWithId() {
NetworkAction networkAction = networkActionAdder.newTerminalsConnectionAction()
.withId("terminalsConnectionAction")
.withNetworkElement("branchNetworkElementId")
.withActionType(ActionType.OPEN)
.add()
.add();

TerminalsConnectionAction terminalsConnectionAction = (TerminalsConnectionAction) networkAction.getElementaryActions().iterator().next();
assertEquals("terminalsConnectionAction", terminalsConnectionAction.getId());
assertEquals("branchNetworkElementId", terminalsConnectionAction.getElementId());
assertTrue(terminalsConnectionAction.isOpen());

Expand Down
Loading
Loading