Skip to content

Commit

Permalink
Add a gPerSection parameter in the ShuntCompensator class #87
Browse files Browse the repository at this point in the history
  • Loading branch information
yichen88 committed Oct 12, 2018
1 parent 10356b9 commit cf02fc9
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,30 @@ public interface ShuntCompensator extends Injection<ShuntCompensator> {
*/
double getCurrentB();

/**
* Get the conductance per section in S.
*/
double getgPerSection();

/**
* Set the conductance per section in S.
*
* @param bPerSection the conductance per section
* @return the shunt compensator to chain method calls.
*/
ShuntCompensator setgPerSection(double gPerSection);

/**
* Get the conductance for the maximum section count.
*/
double getMaximumG();

/**
* Get the conductance for the current section counts.
* <p>
* Depends on the working state.
* @see StateManager
*/
double getCurrentG();

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface ShuntCompensatorAdder extends InjectionAdder<ShuntCompensatorAd

ShuntCompensatorAdder setbPerSection(double bPerSection);

ShuntCompensatorAdder setgPerSection(double gPerSection);

ShuntCompensatorAdder setMaximumSectionCount(int maximumSectionCount);

ShuntCompensatorAdder setCurrentSectionCount(int currentSectionCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ShuntCompensatorAdderImpl extends AbstractInjectionAdder<ShuntCompensatorA

private double bPerSection;

private double gPerSection = 0.0;

private int maximumSectionCount;

private int currentSectionCount;
Expand All @@ -42,6 +44,12 @@ public ShuntCompensatorAdder setbPerSection(double bPerSection) {
return this;
}

@Override
public ShuntCompensatorAdder setgPerSection(double gPerSection) {
this.gPerSection = gPerSection;
return this;
}

@Override
public ShuntCompensatorAdder setMaximumSectionCount(int maximumSectionCount) {
this.maximumSectionCount = maximumSectionCount;
Expand All @@ -59,10 +67,11 @@ public ShuntCompensatorImpl add() {
String id = checkAndGetUniqueId();
TerminalExt terminal = checkAndGetTerminal();
ValidationUtil.checkbPerSection(this, bPerSection);
ValidationUtil.checkgPerSection(this, gPerSection);
ValidationUtil.checkSections(this, currentSectionCount, maximumSectionCount);
ShuntCompensatorImpl shunt
= new ShuntCompensatorImpl(getNetwork().getRef(),
id, getName(), bPerSection, maximumSectionCount,
id, getName(), bPerSection, gPerSection, maximumSectionCount,
currentSectionCount);
shunt.addTerminal(terminal);
voltageLevel.attach(terminal, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ShuntCompensatorImpl extends AbstractConnectable<ShuntCompensator> impleme
/* susceptance per section */
private double bPerSection;

private double gPerSection;

/* the maximum number of section */
private int maximumSectionCount;

Expand All @@ -31,11 +33,12 @@ class ShuntCompensatorImpl extends AbstractConnectable<ShuntCompensator> impleme
private final TIntArrayList currentSectionCount;

ShuntCompensatorImpl(Ref<? extends MultiStateObject> network,
String id, String name, double bPerSection, int maximumSectionCount,
String id, String name, double bPerSection, double gPerSection, int maximumSectionCount,
int currentSectionCount) {
super(id, name);
this.network = network;
this.bPerSection = bPerSection;
this.gPerSection = gPerSection;
this.maximumSectionCount = maximumSectionCount;
int stateArraySize = network.get().getStateManager().getStateArraySize();
this.currentSectionCount = new TIntArrayList(stateArraySize);
Expand All @@ -59,6 +62,11 @@ public double getbPerSection() {
return bPerSection;
}

@Override
public double getgPerSection() {
return gPerSection;
}

@Override
public ShuntCompensatorImpl setbPerSection(double bPerSection) {
ValidationUtil.checkbPerSection(this, bPerSection);
Expand All @@ -68,6 +76,15 @@ public ShuntCompensatorImpl setbPerSection(double bPerSection) {
return this;
}

@Override
public ShuntCompensator setgPerSection(double gPerSection) {
ValidationUtil.checkgPerSection(this, gPerSection);
double oldValue = this.gPerSection;
this.gPerSection = gPerSection;
notifyUpdate("gPerSection", oldValue, gPerSection);
return this;
}

@Override
public int getMaximumSectionCount() {
return maximumSectionCount;
Expand Down Expand Up @@ -100,11 +117,21 @@ public double getCurrentB() {
return bPerSection * getCurrentSectionCount();
}

@Override
public double getCurrentG() {
return gPerSection * getCurrentSectionCount();
}

@Override
public double getMaximumB() {
return bPerSection * maximumSectionCount;
}

@Override
public double getMaximumG() {
return gPerSection * maximumSectionCount;
}

@Override
public void extendStateArraySize(int initStateArraySize, int number, int sourceIndex) {
super.extendStateArraySize(initStateArraySize, number, sourceIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ static void checkbPerSection(Validable validable, double bPerSection) {
}
}

static void checkgPerSection(Validable validable, double gPerSection) {
if (Double.isNaN(gPerSection)) {
throw new ValidationException(validable, "conductance per section is invalid");
}
}

static void checkSections(Validable validable, int currentSectionCount, int maximumSectionCount) {
if (currentSectionCount < 0) {
throw new ValidationException(validable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ public void baseTest() {
.setName("shuntName")
.setConnectableBus("busA")
.setbPerSection(5.0)
.setgPerSection(0.001)
.setCurrentSectionCount(6)
.setMaximumSectionCount(10)
.add();
assertEquals(ConnectableType.SHUNT_COMPENSATOR, shuntCompensator.getType());
assertEquals("shuntName", shuntCompensator.getName());
assertEquals("shunt", shuntCompensator.getId());
assertEquals(5.0, shuntCompensator.getbPerSection(), 0.0);
assertEquals(0.001, shuntCompensator.getgPerSection(), 0.0);
assertEquals(0.006, shuntCompensator.getCurrentG(), 0.0);
assertEquals(0.010, shuntCompensator.getMaximumG(), 0.0);
assertEquals(6, shuntCompensator.getCurrentSectionCount());
assertEquals(10, shuntCompensator.getMaximumSectionCount());

Expand All @@ -60,6 +64,12 @@ public void baseTest() {
shuntCompensator.setbPerSection(1.0);
assertEquals(1.0, shuntCompensator.getbPerSection(), 0.0);

try {
shuntCompensator.setgPerSection(Double.NaN);
fail();
} catch (ValidationException ignored) {
}

try {
shuntCompensator.setCurrentSectionCount(-1);
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected boolean hasSubElements(ShuntCompensator sc) {
@Override
protected void writeRootElementAttributes(ShuntCompensator sc, VoltageLevel vl, NetworkXmlWriterContext context) throws XMLStreamException {
XmlUtil.writeDouble("bPerSection", sc.getbPerSection(), context.getWriter());
XmlUtil.writeOptionalDouble("gPerSection", sc.getgPerSection(), 0.0, context.getWriter());
context.getWriter().writeAttribute("maximumSectionCount", Integer.toString(sc.getMaximumSectionCount()));
context.getWriter().writeAttribute("currentSectionCount", Integer.toString(sc.getCurrentSectionCount()));
writeNodeOrBus(null, sc.getTerminal(), context);
Expand All @@ -50,9 +51,11 @@ protected ShuntCompensatorAdder createAdder(VoltageLevel vl) {
@Override
protected ShuntCompensator readRootElementAttributes(ShuntCompensatorAdder adder, NetworkXmlReaderContext context) {
double bPerSection = XmlUtil.readDoubleAttribute(context.getReader(), "bPerSection");
double gPerSection = XmlUtil.readOptionalDoubleAttribute(context.getReader(), "gPerSection", 0.0);
int maximumSectionCount = XmlUtil.readIntAttribute(context.getReader(), "maximumSectionCount");
int currentSectionCount = XmlUtil.readIntAttribute(context.getReader(), "currentSectionCount");
adder.setbPerSection(bPerSection)
.setgPerSection(gPerSection)
.setMaximumSectionCount(maximumSectionCount)
.setCurrentSectionCount(currentSectionCount);
readNodeOrBus(adder, context);
Expand Down
1 change: 1 addition & 0 deletions iidm/iidm-xml-converter/src/main/resources/xsd/iidm.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<xs:complexContent>
<xs:extension base="iidm:Injection">
<xs:attribute name="bPerSection" use="required" type="xs:double"/>
<xs:attribute name="gPerSection" use="optional" type="xs:double" default="0.0"/>
<xs:attribute name="maximumSectionCount" use="required" type="xs:int"/>
<xs:attribute name="currentSectionCount" use="required" type="xs:int"/>
</xs:extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.iidm.xml;

import com.powsybl.commons.AbstractConverterTest;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import org.junit.Test;

Expand All @@ -25,6 +26,16 @@ public void roundTripLccTest() throws IOException {
"/LccRoundTripRef.xml");
}

@Test
public void roundTripShuntWithGPerSection() throws IOException {
Network network = HvdcTestNetwork.createLcc();
network.getShunt("C2_Filter1").setgPerSection(0.002);
roundTripXmlTest(network,
NetworkXml::writeAndValidate,
NetworkXml::read,
"/LccRoundTripRef2.xml");
}

@Test
public void roundTripVscTest() throws IOException {
roundTripXmlTest(HvdcTestNetwork.createVsc(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<iidm:switch id="DISC_BBS1_BK3" name="Disconnector" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="5"/>
<iidm:switch id="BK3" name="Breaker" kind="BREAKER" retained="true" open="false" node1="5" node2="6"/>
</iidm:nodeBreakerTopology>
<iidm:shunt id="C2_Filter1" name="Filter 3" bPerSection="3.0E-5" maximumSectionCount="1" currentSectionCount="1" node="4" q="12.5"/>
<iidm:shunt id="C2_Filter1" name="Filter 3" bPerSection="3.0E-5" maximumSectionCount="1" currentSectionCount="1" node="4" q="12.5"/>
<iidm:shunt id="C2_Filter2" name="Filter 4" bPerSection="4.0E-5" maximumSectionCount="1" currentSectionCount="1" node="6" q="12.5"/>
<iidm:lccConverterStation id="C2" name="Converter2" lossFactor="0.011" powerFactor="0.6" node="2" p="75.0" q="25.0"/>
</iidm:voltageLevel>
Expand Down
31 changes: 31 additions & 0 deletions iidm/iidm-xml-converter/src/test/resources/LccRoundTripRef2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- License Here -->
<iidm:network xmlns:iidm="http://www.itesla_project.eu/schema/iidm/1_1" id="hvdctest" caseDate="2016-06-27T16:34:55.930+02:00" forecastDistance="0" sourceFormat="test">
<iidm:substation id="S1" country="FR">
<iidm:voltageLevel id="VL1" nominalV="400.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="B1"/>
</iidm:busBreakerTopology>
<iidm:shunt id="C1_Filter1" name="Filter 1" bPerSection="1.0E-5" maximumSectionCount="1" currentSectionCount="1" bus="B1" connectableBus="B1" q="25.0"/>
<iidm:shunt id="C1_Filter2" name="Filter 2" bPerSection="2.0E-5" maximumSectionCount="1" currentSectionCount="0" connectableBus="B1" q="25.0"/>
<iidm:lccConverterStation id="C1" name="Converter1" lossFactor="0.011" powerFactor="0.5" bus="B1" connectableBus="B1" p="100.0" q="50.0"/>
</iidm:voltageLevel>
</iidm:substation>
<iidm:substation id="S2" country="FR">
<iidm:voltageLevel id="VL2" nominalV="400.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology nodeCount="7">
<iidm:busbarSection id="BBS1" name="BusbarSection" node="0"/>
<iidm:switch id="DISC_BBS1_BK1" name="Disconnector" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="1"/>
<iidm:switch id="BK1" name="Breaker" kind="BREAKER" retained="true" open="false" node1="1" node2="2"/>
<iidm:switch id="DISC_BBS1_BK2" name="Disconnector" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="3"/>
<iidm:switch id="BK2" name="Breaker" kind="BREAKER" retained="true" open="false" node1="3" node2="4"/>
<iidm:switch id="DISC_BBS1_BK3" name="Disconnector" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="5"/>
<iidm:switch id="BK3" name="Breaker" kind="BREAKER" retained="true" open="false" node1="5" node2="6"/>
</iidm:nodeBreakerTopology>
<iidm:shunt id="C2_Filter1" name="Filter 3" bPerSection="3.0E-5" gPerSection="0.002" maximumSectionCount="1" currentSectionCount="1" node="4" q="12.5"/>
<iidm:shunt id="C2_Filter2" name="Filter 4" bPerSection="4.0E-5" maximumSectionCount="1" currentSectionCount="1" node="6" q="12.5"/>
<iidm:lccConverterStation id="C2" name="Converter2" lossFactor="0.011" powerFactor="0.6" node="2" p="75.0" q="25.0"/>
</iidm:voltageLevel>
</iidm:substation>
<iidm:hvdcLine id="L" name="HVDC" r="1.0" nominalV="400.0" convertersMode="SIDE_1_INVERTER_SIDE_2_RECTIFIER" activePowerSetpoint="280.0" maxP="300.0" converterStation1="C1" converterStation2="C2"/>
</iidm:network>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<iidm:switch id="DISC_BBS1_BK3" name="Disconnector" kind="DISCONNECTOR" retained="false" open="false" node1="0" node2="5"/>
<iidm:switch id="BK3" name="Breaker" kind="BREAKER" retained="true" open="false" node1="5" node2="6"/>
</iidm:nodeBreakerTopology>
<iidm:shunt id="C2_Filter1" name="Filter 3" bPerSection="3.0E-5" maximumSectionCount="1" currentSectionCount="1" node="4" q="12.5"/>
<iidm:shunt id="C2_Filter1" name="Filter 3" bPerSection="3.0E-5" maximumSectionCount="1" currentSectionCount="1" node="4" q="12.5"/>
<iidm:shunt id="C2_Filter2" name="Filter 4" bPerSection="4.0E-5" maximumSectionCount="1" currentSectionCount="1" node="6" q="12.5"/>
<iidm:lccConverterStation id="C2" name="Converter2" lossFactor="0.011" powerFactor="0.6" node="2" p="75.0" q="25.0"/>
</iidm:voltageLevel>
Expand Down

0 comments on commit cf02fc9

Please sign in to comment.