Skip to content

Commit

Permalink
Add solvedSectionCount
Browse files Browse the repository at this point in the history
Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com>
  • Loading branch information
colinepiloquet committed May 7, 2024
1 parent 110a5b9 commit bb42f79
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@
* <td style="border: 1px solid black">The maximum number of sections that may be switched on</td>
* </tr>
* <tr>
* <td style="border: 1px solid black">CurrentSectionCount</td>
* <td style="border: 1px solid black">sectionCount</td>
* <td style="border: 1px solid black">integer</td>
* <td style="border: 1px solid black">-</td>
* <td style="border: 1px solid black">yes</td>
* <td style="border: 1px solid black"> - </td>
* <td style="border: 1px solid black">The current number of section that may be switched on</td>
* </tr>
* <tr>
* <td style="border: 1px solid black">solvedSectionCount</td>
* <td style="border: 1px solid black">integer</td>
* <td style="border: 1px solid black">-</td>
* <td style="border: 1px solid black">yes</td>
* <td style="border: 1px solid black"> - </td>
* <td style="border: 1px solid black">The number of section that may be switched on calculated after the load flow</td>
* </tr>
* <tr>
* <td style="border: 1px solid black">RegulatingTerminal</td>
* <td style="border: 1px solid black">Terminal</td>
* <td style="border: 1px solid black">-</td>
Expand Down Expand Up @@ -133,6 +141,28 @@ default OptionalInt findSectionCount() {
return OptionalInt.of(getSectionCount());
}

/**
* Get the count of sections in service as calculated after the load flow.
* <p>
* It is expected to be greater than one and lesser than or equal to the
* maximum section count.
* <p>
* Depends on the working variant.
* @see VariantManager
*/
int getSolvedSectionCount();

/**
* Get the count of sections after the load flow in service if it is defined.
* Otherwise, get an empty optional.
* <p>
* Depends on the working variant.
* @see VariantManager
*/
default OptionalInt findSolvedSectionCount() {
return OptionalInt.of(getSolvedSectionCount());
}

/**
* Get the maximum number of sections that can be in service
*/
Expand All @@ -158,6 +188,25 @@ default ShuntCompensator unsetSectionCount() {
throw ValidationUtil.createUnsetMethodException();
}

/**
* Change the solved count of sections in service after the load flow calculation.
* <p>
* Depends on the working variant.
*
* @see VariantManager
* @param solvedSectionCount the number of sections wanted to be put in service
* @return the shunt compensator to chain method calls.
*/
ShuntCompensator setSolvedSectionCount(int solvedSectionCount);

/**
* Unset the solved count of sections in service.
* Note: this can be done <b>only</b> in SCADA validation level.
*/
default ShuntCompensator unsetSolvedSectionCount() {
throw ValidationUtil.createUnsetMethodException();
}

/**
* Get the susceptance (in S) of the shunt in its current state i.e. the sum of the sections' susceptances for all sections in service.
* Return 0 if no section is in service (disconnected state).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface ShuntCompensatorAdder extends InjectionAdder<ShuntCompensator,

ShuntCompensatorAdder setSectionCount(int sectionCount);

ShuntCompensatorAdder setSolvedSectionCount(int solvedSectionCount);

default ShuntCompensatorAdder setRegulatingTerminal(Terminal regulatingTerminal) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class ShuntCompensatorAdderImpl extends AbstractInjectionAdder<ShuntCompensatorA

private boolean voltageRegulatorOn = false;

private Integer solvedSectionCount;

ShuntCompensatorAdderImpl(VoltageLevelExt voltageLevel) {
this.voltageLevel = voltageLevel;
}
Expand Down Expand Up @@ -177,6 +179,12 @@ public ShuntCompensatorAdder setSectionCount(int sectionCount) {
return this;
}

@Override
public ShuntCompensatorAdder setSolvedSectionCount(int solvedSectionCount) {
this.solvedSectionCount = solvedSectionCount;
return this;
}

@Override
public ShuntCompensatorAdder setRegulatingTerminal(Terminal regulatingTerminal) {
this.regulatingTerminal = (TerminalExt) regulatingTerminal;
Expand Down Expand Up @@ -219,7 +227,7 @@ public ShuntCompensatorImpl add() {
ShuntCompensatorImpl shunt = new ShuntCompensatorImpl(getNetworkRef(),
id, getName(), isFictitious(), modelBuilder.build(), sectionCount,
regulatingTerminal == null ? terminal : regulatingTerminal,
voltageRegulatorOn, targetV, targetDeadband);
voltageRegulatorOn, targetV, targetDeadband, solvedSectionCount);

shunt.addTerminal(terminal);
voltageLevel.attach(terminal, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ class ShuntCompensatorImpl extends AbstractConnectable<ShuntCompensator> impleme
/* the target deadband */
private final TDoubleArrayList targetDeadband;

/* the current number of solved section switched on */
private final ArrayList<Integer> solvedSectionCount;

ShuntCompensatorImpl(Ref<NetworkImpl> network,
String id, String name, boolean fictitious, ShuntCompensatorModelExt model,
Integer sectionCount, TerminalExt regulatingTerminal, Boolean voltageRegulatorOn,
double targetV, double targetDeadband) {
double targetV, double targetDeadband, Integer solvedSectionCount) {
super(network, id, name, fictitious);
this.network = network;
int variantArraySize = this.network.get().getVariantManager().getVariantArraySize();
Expand All @@ -50,10 +53,12 @@ class ShuntCompensatorImpl extends AbstractConnectable<ShuntCompensator> impleme
this.sectionCount = new ArrayList<>(variantArraySize);
this.targetV = new TDoubleArrayList(variantArraySize);
this.targetDeadband = new TDoubleArrayList(variantArraySize);
this.solvedSectionCount = new ArrayList<>(variantArraySize);
for (int i = 0; i < variantArraySize; i++) {
this.sectionCount.add(sectionCount);
this.targetV.add(targetV);
this.targetDeadband.add(targetDeadband);
this.solvedSectionCount.add(solvedSectionCount);
}
this.model = Objects.requireNonNull(model).attach(this);
}
Expand All @@ -78,6 +83,21 @@ public OptionalInt findSectionCount() {
return section == null ? OptionalInt.empty() : OptionalInt.of(section);
}

@Override
public int getSolvedSectionCount() {
Integer solvedSection = solvedSectionCount.get(network.get().getVariantIndex());
if (solvedSection == null) {
throw ValidationUtil.createUndefinedValueGetterException();
}
return solvedSection;
}

@Override
public OptionalInt findSolvedSectionCount() {
Integer solvedSection = solvedSectionCount.get(network.get().getVariantIndex());
return solvedSection == null ? OptionalInt.empty() : OptionalInt.of(solvedSection);
}

@Override
public int getMaximumSectionCount() {
return model.getMaximumSectionCount();
Expand Down Expand Up @@ -110,6 +130,21 @@ public ShuntCompensator unsetSectionCount() {
return this;
}

@Override
public ShuntCompensatorImpl setSolvedSectionCount(int solvedSectionCount) {
NetworkImpl n = getNetwork();
ValidationUtil.checkSections(this, solvedSectionCount, model.getMaximumSectionCount(), getNetwork().getMinValidationLevel());
if (solvedSectionCount < 0 || solvedSectionCount > model.getMaximumSectionCount()) {
throw new ValidationException(this, "unexpected solved section number (" + solvedSectionCount + "): no existing associated section");
}
int variantIndex = n.getVariantIndex();
Integer oldValue = this.solvedSectionCount.set(variantIndex, solvedSectionCount);
String variantId = n.getVariantManager().getVariantId(variantIndex);
n.invalidateValidationLevel();
notifyUpdate("solvedSectionCount", variantId, oldValue, solvedSectionCount);
return this;
}

@Override
public double getB() {
return model.getB(sectionCount.get(network.get().getVariantIndex()));
Expand Down Expand Up @@ -230,10 +265,12 @@ public void extendVariantArraySize(int initVariantArraySize, int number, int sou
sectionCount.ensureCapacity(sectionCount.size() + number);
targetV.ensureCapacity(targetV.size() + number);
targetDeadband.ensureCapacity(targetDeadband.size() + number);
solvedSectionCount.ensureCapacity(solvedSectionCount.size() + number);
for (int i = 0; i < number; i++) {
sectionCount.add(sectionCount.get(sourceIndex));
targetV.add(targetV.get(sourceIndex));
targetDeadband.add(targetDeadband.get(sourceIndex));
solvedSectionCount.add(solvedSectionCount.get(sourceIndex));
}
regulatingPoint.extendVariantArraySize(initVariantArraySize, number, sourceIndex);
}
Expand All @@ -247,6 +284,9 @@ public void reduceVariantArraySize(int number) {
targetV.remove(targetV.size() - number, number);
targetDeadband.remove(targetDeadband.size() - number, number);
regulatingPoint.reduceVariantArraySize(number);
List<Integer> tmpSolvedSectionCount = new ArrayList<>(solvedSectionCount.subList(0, solvedSectionCount.size() - number));
solvedSectionCount.clear();
solvedSectionCount.addAll(tmpSolvedSectionCount);
}

@Override
Expand All @@ -262,6 +302,7 @@ public void allocateVariantArrayElement(int[] indexes, final int sourceIndex) {
sectionCount.set(index, sectionCount.get(sourceIndex));
targetV.set(index, targetV.get(sourceIndex));
targetDeadband.set(index, targetDeadband.get(sourceIndex));
solvedSectionCount.set(index, solvedSectionCount.get(sourceIndex));
}
regulatingPoint.allocateVariantArrayElement(indexes, sourceIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ protected void writeRootElementAttributes(ShuntCompensator sc, VoltageLevel vl,
OptionalInt sectionCount = sc.findSectionCount();
context.getWriter().writeOptionalIntAttribute("sectionCount", sectionCount.isPresent() ? sectionCount.getAsInt() : null);
});

IidmSerDeUtil.runFromMinimumVersion(IidmVersion.V_1_13, context, () -> {
OptionalInt solvedSectionCount = sc.findSolvedSectionCount();
context.getWriter().writeOptionalIntAttribute("solvedSectionCount", solvedSectionCount.isPresent() ? solvedSectionCount.getAsInt() : null);
});

IidmSerDeUtil.writeBooleanAttributeFromMinimumVersion(ROOT_ELEMENT_NAME, "voltageRegulatorOn", sc.isVoltageRegulatorOn(), false, IidmSerDeUtil.ErrorMessage.NOT_DEFAULT_NOT_SUPPORTED, IidmVersion.V_1_2, context);
IidmSerDeUtil.writeDoubleAttributeFromMinimumVersion(ROOT_ELEMENT_NAME, "targetV", sc.getTargetV(),
IidmSerDeUtil.ErrorMessage.NOT_DEFAULT_NOT_SUPPORTED, IidmVersion.V_1_2, context);
Expand Down Expand Up @@ -150,6 +156,10 @@ protected void readRootElementAttributes(ShuntCompensatorAdder adder, VoltageLev
OptionalInt sectionCount = context.getReader().readOptionalIntAttribute("sectionCount");
sectionCount.ifPresent(adder::setSectionCount);
});
IidmSerDeUtil.runFromMinimumVersion(IidmVersion.V_1_13, context, () -> {
OptionalInt solvedSectionCount = context.getReader().readOptionalIntAttribute("solvedSectionCount");
solvedSectionCount.ifPresent(adder::setSolvedSectionCount);
});
IidmSerDeUtil.runFromMinimumVersion(IidmVersion.V_1_2, context, () -> {
boolean voltageRegulatorOn = context.getReader().readBooleanAttribute("voltageRegulatorOn");
double targetV = context.getReader().readDoubleAttribute("targetV");
Expand Down
1 change: 1 addition & 0 deletions iidm/iidm-serde/src/main/resources/xsd/iidm_V1_13.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
<xs:element name="regulatingTerminal" minOccurs="0" type="iidm:TerminalRef"/>
</xs:sequence>
<xs:attribute name="sectionCount" use="required" type="xs:int"/>
<xs:attribute name="solvedSectionCount" use="optional" type="xs:int"/>
<xs:attribute name="voltageRegulatorOn" use="required" type="xs:boolean"/>
<xs:attribute name="targetV" use="optional" type="xs:double"/>
<xs:attribute name="targetDeadband" use="optional" type="xs:double"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
<xs:element name="regulatingTerminal" minOccurs="0" type="iidm:TerminalRef"/>
</xs:sequence>
<xs:attribute name="sectionCount" use="optional" type="xs:int"/>
<xs:attribute name="solvedSectionCount" use="optional" type="xs:int"/>
<xs:attribute name="voltageRegulatorOn" use="required" type="xs:boolean"/>
<xs:attribute name="targetV" use="optional" type="xs:double"/>
<xs:attribute name="targetDeadband" use="optional" type="xs:double"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Properties;

import static com.powsybl.iidm.serde.IidmSerDeConstants.CURRENT_IIDM_VERSION;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -87,6 +88,13 @@ void nullBPerSection() {
assertEquals(Double.MIN_NORMAL, sc2.getModel(ShuntCompensatorLinearModel.class).getBPerSection(), 0.0);
}

@Test
void shuntWithSolvedSectionCountTest() throws IOException {
Network network = ShuntTestCaseFactory.createWithSolvedSectionCount(1);
network.write("XIIDM", new Properties(), Path.of("/home/piloquetcol/test/shunt.xiidm"));
allFormatsRoundTripTest(network, "shuntWithSolvedSectionCountRoundTripRef.xml", CURRENT_IIDM_VERSION);
}

private void write(Network network, String version) {
try {
ExportOptions options = new ExportOptions().setVersion(version);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="shuntTestCase" caseDate="2019-09-30T16:29:18.263+02:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="S1" country="FR">
<iidm:voltageLevel id="VL1" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="B1"/>
</iidm:busBreakerTopology>
<iidm:shunt id="SHUNT" sectionCount="1" solvedSectionCount="1" voltageRegulatorOn="true" targetV="200.0" targetDeadband="5.0" bus="B1" connectableBus="B1">
<iidm:alias>Alias</iidm:alias>
<iidm:shuntLinearModel bPerSection="1.0E-5" maximumSectionCount="1"/>
<iidm:regulatingTerminal id="LOAD"/>
</iidm:shunt>
</iidm:voltageLevel>
</iidm:substation>
<iidm:substation id="S2" country="FR">
<iidm:voltageLevel id="VL2" nominalV="220.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="B2"/>
</iidm:busBreakerTopology>
<iidm:load id="LOAD" loadType="UNDEFINED" p0="100.0" q0="50.0" bus="B2" connectableBus="B2"/>
</iidm:voltageLevel>
</iidm:substation>
</iidm:network>
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,18 @@ public void testSetTerminalP() {
assertEquals(10, sbNonLinear.getTerminal().getP(), 0.0);
}

@Test
public void testSolvedSectionCount() {
ShuntCompensatorAdder adder = createShuntAdder(SHUNT, "shuntName", 6, terminal, true, 200, 10);
adder.newLinearModel()
.setBPerSection(5.0)
.setMaximumSectionCount(10)
.add();
adder.setSolvedSectionCount(5);
ShuntCompensator shuntCompensator = adder.add();
assertEquals(5, shuntCompensator.getSolvedSectionCount());
}

private ShuntCompensator createLinearShunt(String id, String name, double bPerSection, double gPerSection, int sectionCount, int maxSectionCount, Terminal regulatingTerminal, boolean voltageRegulatorOn, double targetV, double targetDeadband) {
return createShuntAdder(id, name, sectionCount, regulatingTerminal, voltageRegulatorOn, targetV, targetDeadband)
.newLinearModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ public static Network create() {
return create(NetworkFactory.findDefault());
}

public static Network createWithSolvedSectionCount(Integer solvedSectionCount) {
return create(NetworkFactory.findDefault(), 1e-5, solvedSectionCount);
}

public static Network create(double bPerSection) {
return create(NetworkFactory.findDefault(), bPerSection);
return create(NetworkFactory.findDefault(), bPerSection, null);
}

public static Network create(NetworkFactory networkFactory) {
return create(networkFactory, 1e-5);
return create(networkFactory, 1e-5, null);
}

public static Network create(NetworkFactory networkFactory, double bPerSection) {
public static Network create(NetworkFactory networkFactory, double bPerSection, Integer solvedSectionCount) {
Network network = createBase(networkFactory);

network.getVoltageLevel("VL1")
ShuntCompensatorAdder adder = network.getVoltageLevel("VL1")
.newShuntCompensator()
.setId(SHUNT)
.setBus("B1")
Expand All @@ -48,11 +52,15 @@ public static Network create(NetworkFactory networkFactory, double bPerSection)
.setTargetV(200)
.setTargetDeadband(5.0)
.newLinearModel()
.setMaximumSectionCount(1)
.setBPerSection(bPerSection)
.add()
.add()
.addAlias("Alias");
.setMaximumSectionCount(1)
.setBPerSection(bPerSection)
.add();

if (solvedSectionCount != null) {
adder.setSolvedSectionCount(solvedSectionCount);
}

adder.add().addAlias("Alias");

return network;
}
Expand Down

0 comments on commit bb42f79

Please sign in to comment.