Skip to content

Commit

Permalink
Add a test with extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 committed Aug 18, 2023
1 parent 53b677f commit 5b1d4e5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.LoadDetail;
import com.powsybl.iidm.network.extensions.LoadDetailAdder;
import com.powsybl.iidm.network.extensions.SecondaryVoltageControl;
import com.powsybl.iidm.network.extensions.SecondaryVoltageControlAdder;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -143,9 +150,46 @@ private void checkSubstationAndVoltageLevelCounts(Network n, long substationCoun
assertEquals(voltageLevelCount, n.getVoltageLevelCount());
}

private void checkValidPAndQ(DanglingLine dl) {
assertEquals(0.0, dl.getP0());
assertEquals(0.0, dl.getQ0());
@Test
public void testMergeAndDetachWithExtensions() {
n1 = EurostagTutorialExample1Factory.createWithMoreGenerators();
addSubstationAndVoltageLevel(n2, "s2", Country.BE, "vl2", "b2");
addDanglingLines(n1, "VLGEN", "dl1", "code", "NGEN");
addDanglingLines(n2, "vl2", "dl2", "code", "b2");

// Add extension at network level
n1.newExtension(SecondaryVoltageControlAdder.class)
.addControlZone(new SecondaryVoltageControl.ControlZone("z1",
new SecondaryVoltageControl.PilotPoint(List.of("NLOAD"), 15d),
List.of(new SecondaryVoltageControl.ControlUnit("GEN", false),
new SecondaryVoltageControl.ControlUnit("GEN2"))))
.add();
// Add extension at inner element level
n1.getLoad("LOAD").newExtension(LoadDetailAdder.class)
.withFixedActivePower(40f)
.withFixedReactivePower(20f)
.withVariableActivePower(60f)
.withVariableReactivePower(30f)
.add();

merge = Network.create(MERGE, n1, n2);
Network subnetwork1 = merge.getSubnetwork("sim1");
checkExtensions(subnetwork1);

Network detachedN1 = subnetwork1.detach();
checkExtensions(detachedN1);
}

private static void checkExtensions(Network network) {
// Check that the Network extension is present on the subnetwork
assertEquals(1, network.getExtensions().size());
assertNotNull(network.getExtensionByName(SecondaryVoltageControl.NAME));
assertNotNull(network.getExtension(SecondaryVoltageControl.class));

// Check that the Load extension is visible from the subnetwork
assertEquals(1, network.getLoad("LOAD").getExtensions().size());
assertNotNull(network.getLoad("LOAD").getExtensionByName(LoadDetail.NAME));
assertNotNull(network.getLoad("LOAD").getExtension(LoadDetail.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ public void testValidationWithSubnetworkChanges(String networkId) {
assertValidationLevels(ValidationLevel.STEADY_STATE_HYPOTHESIS);
}

static Stream<Arguments> networkParameters() {
return Stream.of(
Arguments.of("Root"),
Arguments.of("Sub1"),
Arguments.of("Sub2")
);
}

@Test
public void testListeners() {
MutableBoolean listenerCalled = new MutableBoolean(false);
Expand Down Expand Up @@ -340,14 +348,6 @@ void assertValidationLevels(ValidationLevel expected) {
assertEquals(expected, subnetwork2.getValidationLevel());
}

static Stream<Arguments> networkParameters() {
return Stream.of(
Arguments.of("Root"),
Arguments.of("Sub1"),
Arguments.of("Sub2")
);
}

private Substation addSubstation(Network network, String substationId) {
return network.newSubstation()
.setId(substationId)
Expand Down

0 comments on commit 5b1d4e5

Please sign in to comment.