Skip to content

Commit

Permalink
Fix thanks to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Bague committed Nov 21, 2016
1 parent 59023c1 commit 5112016
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Mathieu Bague <mathieu.bague at rte-france.com>
*/
class LccFilterAdderImpl implements LccFilterAdder {
class LccFilterAdderImpl implements LccFilterAdder, Validable {

private final LccConverterStationImpl converterStation;

Expand All @@ -26,6 +26,11 @@ class LccFilterAdderImpl implements LccFilterAdder {
this.converterStation = Objects.requireNonNull(converterStation);
}

@Override
public String getMessageHeader() {
return converterStation.getMessageHeader() + "filter.";
}

@Override
public LccFilterAdder setB(float b) {
this.b = b;
Expand All @@ -40,6 +45,8 @@ public LccFilterAdder setConnected(boolean connected) {

@Override
public LccFilterImpl add() {
ValidationUtil.checkConnected(this, connected);
ValidationUtil.checkB(this, b);
LccFilterImpl filter = new LccFilterImpl(converterStation, b, connected);
converterStation.addFilter(filter);
return filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import eu.itesla_project.iidm.network.LccFilter;

import java.util.BitSet;
import java.util.Objects;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Mathieu Bague <mathieu.bague at rte-france.com>
*/
class LccFilterImpl implements LccFilter, Stateful {
class LccFilterImpl implements LccFilter, Stateful, Validable {

private float b;

Expand All @@ -23,14 +24,19 @@ class LccFilterImpl implements LccFilter, Stateful {
private final LccConverterStationImpl converterStation;

LccFilterImpl(LccConverterStationImpl converterStation, float b, boolean connected) {
this.converterStation = converterStation;
this.converterStation = Objects.requireNonNull(converterStation);
this.b = b;

int stateArraySize = getNetwork().getStateManager().getStateArraySize();
this.connected = new BitSet(stateArraySize);
this.connected.set(0, stateArraySize, connected);
}

@Override
public String getMessageHeader() {
return converterStation.getMessageHeader() + "filter.";
}

private NetworkImpl getNetwork() {
return converterStation.getNetwork();
}
Expand All @@ -46,6 +52,7 @@ public float getB() {

@Override
public LccFilterImpl setB(float b) {
ValidationUtil.checkB(this, b);
float oldValue = this.b;
this.b = b;
notifyUpdate("b", oldValue, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,15 @@ static void checkConvertersMode(Validable validable, HvdcLine.ConvertersMode con
}
}

public static void checkPowerFactor(Validable validable, float powerFactor) {
static void checkPowerFactor(Validable validable, float powerFactor) {
if (Float.isNaN(powerFactor)) {
throw new ValidationException(validable, "power factor is invalid");
}
}

static void checkConnected(Validable validable, Boolean connected) {
if (connected == null) {
throw new ValidationException(validable, "connection status is invalid");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public VscConverterStationImpl setVoltageSetPoint(float targetV) {
int stateIndex = getNetwork().getStateIndex();
ValidationUtil.checkVoltageControl(this, voltageRegulatorOn.get(stateIndex), targetV, reactivePowerSetPoint.get(stateIndex));
float oldValue = this.voltageSetPoint.set(stateIndex, targetV);
notifyUpdate("targetV", oldValue, targetV);
notifyUpdate("voltageSetPoint", oldValue, targetV);
return this;
}

Expand All @@ -91,7 +91,7 @@ public VscConverterStationImpl setReactivePowerSetPoint(float targetQ) {
int stateIndex = getNetwork().getStateIndex();
ValidationUtil.checkVoltageControl(this, voltageRegulatorOn.get(stateIndex), voltageSetPoint.get(stateIndex), targetQ);
float oldValue = this.reactivePowerSetPoint.set(stateIndex, targetQ);
notifyUpdate("targetQ", oldValue, targetQ);
notifyUpdate("reactivePowerSetPoint", oldValue, targetQ);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import eu.itesla_project.iidm.network.test.HvdcTestNetwork;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -68,6 +66,24 @@ public void testFilterRemove() {
assertTrue(cs1.getFilterCount() == 1);
assertTrue(cs1.getFilterAt(0).getB() == 0.00002f);
assertFalse(cs1.getFilterAt(0).isConnected());
}

@Test
public void testAddInvalidFilter() {
try {
Network network = HvdcTestNetwork.createLcc();
LccConverterStation cs1 = (LccConverterStation) network.getHvdcConverterStation("C1");
cs1.newFilter().setB(1.0f).add();
fail();
} catch (ValidationException exc) {
}

try {
Network network = HvdcTestNetwork.createLcc();
LccConverterStation cs1 = (LccConverterStation) network.getHvdcConverterStation("C1");
cs1.newFilter().setConnected(true).add();
fail();
} catch (ValidationException exc) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public static Network createVsc() {
.setQ(50.0f);
cs1.newReactiveCapabilityCurve()
.beginPoint()
.setP(5)
.setMinQ(0)
.setMaxQ(10)
.setP(5)
.setMinQ(0)
.setMaxQ(10)
.endPoint()
.beginPoint()
.setP(10)
.setMinQ(0)
.setMaxQ(10)
.setP(10)
.setMinQ(0)
.setMaxQ(10)
.endPoint()
.add();
VoltageLevel vl2 = network.getVoltageLevel("VL2");
Expand Down
4 changes: 2 additions & 2 deletions iidm-xml-converter/src/main/resources/xsd/iidm.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
<xs:element name="shunt" type="iidm:ShuntCompensator"/>
<xs:element name="danglingLine" type="iidm:DanglingLine"/>
<xs:element name="staticVarCompensator" type="iidm:StaticVarCompensator"/>
<xs:element name="vscConverterStation" minOccurs="0" maxOccurs="unbounded" type="iidm:VscConverterStation"/>
<xs:element name="lccConverterStation" minOccurs="0" maxOccurs="unbounded" type="iidm:LccConverterStation"/>
<xs:element name="vscConverterStation" type="iidm:VscConverterStation"/>
<xs:element name="lccConverterStation" type="iidm:LccConverterStation"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="nominalV" use="required" type="xs:float"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public void roundTripTest() throws IOException {
roundTripXmlTest(createNetwork(),
NetworkXml::writeAndValidate,
NetworkXml::read,
"/reactiveLimitsTripRef.xml");
"/reactiveLimitsRoundTripRef.xml");
}
}

0 comments on commit 5112016

Please sign in to comment.