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

Add new method withNetworkElement for InjectionRangeActionAdder #1087

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public interface InjectionRangeActionAdder extends StandardRangeActionAdder<Inje

InjectionRangeActionAdder withNetworkElementAndKey(double key, String networkElementId, String networkElementName);

InjectionRangeActionAdder withNetworkElement(String networkElementId);

InjectionRangeActionAdder withNetworkElement(String networkElementId, String networkElementName);

InjectionRangeActionAdder withInitialSetpoint(double initialSetpoint);

StandardRangeAdder<InjectionRangeActionAdder> newRange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ public InjectionRangeActionAdder withNetworkElementAndKey(double key, String net
return this;
}

@Override
public InjectionRangeActionAdder withNetworkElement(String networkElementId) {
if (distributionKeys.isEmpty()) {
return withNetworkElementAndKey(1.0, networkElementId, networkElementId);
} else {
throw new OpenRaoException("There are already NetworkElements tied to this injection. Use instead withNetworkElementAndKey() to add multiple NetworkElements");
}
}

@Override
public InjectionRangeActionAdder withNetworkElement(String networkElementId, String networkElementName) {
if (distributionKeys.isEmpty()) {
return withNetworkElementAndKey(1.0, networkElementId, networkElementName);
} else {
throw new OpenRaoException("There are already NetworkElements tied to this injection. Use instead withNetworkElementAndKey() to add multiple NetworkElements");
}
}

@Override
public InjectionRangeAction add() {
checkId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,70 @@ void testAddWithoutGroupId() {
assertEquals(2, crac.getNetworkElements().size());
}

@Test
void testAddDefaultKey() {
InjectionRangeAction injectionRangeAction1 = crac.newInjectionRangeAction()
.withId("id1")
.withOperator("BE")
.withGroupId("groupId1")
.withNetworkElement(injectionId1)
.newRange().withMin(-5).withMax(10).add()
.newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add()
.add();

assertEquals("id1", injectionRangeAction1.getId());
assertEquals("id1", injectionRangeAction1.getName());
assertEquals("BE", injectionRangeAction1.getOperator());
assertTrue(injectionRangeAction1.getGroupId().isPresent());
assertEquals("groupId1", injectionRangeAction1.getGroupId().get());
assertEquals(1, injectionRangeAction1.getRanges().size());
assertEquals(1, injectionRangeAction1.getUsageRules().size());
assertEquals(1, injectionRangeAction1.getInjectionDistributionKeys().size());
assertEquals(1., injectionRangeAction1.getInjectionDistributionKeys().get(crac.getNetworkElement(injectionId1)), 1e-6);

InjectionRangeAction injectionRangeAction2 = crac.newInjectionRangeAction()
.withId("id2")
.withOperator("DE")
.withGroupId("groupId2")
.withNetworkElement(injectionId2, injectionName2)
.newRange().withMin(-5).withMax(10).add()
.newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add()
.add();

assertEquals("id2", injectionRangeAction2.getId());
assertEquals("id2", injectionRangeAction2.getName());
assertEquals("DE", injectionRangeAction2.getOperator());
assertTrue(injectionRangeAction2.getGroupId().isPresent());
assertEquals("groupId2", injectionRangeAction2.getGroupId().get());
assertEquals(1, injectionRangeAction2.getRanges().size());
assertEquals(1, injectionRangeAction2.getUsageRules().size());
assertEquals(1, injectionRangeAction2.getInjectionDistributionKeys().size());
assertEquals(1., injectionRangeAction2.getInjectionDistributionKeys().get(crac.getNetworkElement(injectionId2)), 1e-6);

assertEquals(2, crac.getNetworkElements().size());
assertNotNull(crac.getNetworkElement(injectionId1));
assertNotNull(crac.getNetworkElement(injectionId2));

assertEquals(2, crac.getRangeActions().size());

Exception e1 = assertThrows(OpenRaoException.class, () ->
crac.newInjectionRangeAction()
.withId("id_error_1")
.withNetworkElement(injectionId1)
.withNetworkElement(injectionId2, injectionName2)
);
assertEquals("There are already NetworkElements tied to this injection. Use instead withNetworkElementAndKey() to add multiple NetworkElements", e1.getMessage());

Exception e2 = assertThrows(OpenRaoException.class, () ->
crac.newInjectionRangeAction()
.withId("id_error_2")
.withNetworkElement(injectionId2, injectionName2)
.withNetworkElement(injectionId1)
);
assertEquals("There are already NetworkElements tied to this injection. Use instead withNetworkElementAndKey() to add multiple NetworkElements", e2.getMessage());

}

@Test
void testAddWithoutUsageRule() {
/*
Expand Down
Loading