Skip to content

Commit

Permalink
Add xml serializer and tests (#1883)
Browse files Browse the repository at this point in the history
Signed-off-by: Coline Piloquet <[email protected]>
  • Loading branch information
colinepiloquet authored Nov 3, 2021
1 parent 17197bf commit 9455229
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.iidm.xml.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.extensions.AbstractExtensionXmlSerializer;
import com.powsybl.commons.extensions.ExtensionXmlSerializer;
import com.powsybl.commons.xml.XmlReaderContext;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.commons.xml.XmlWriterContext;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuit;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder;

import javax.xml.stream.XMLStreamException;

/**
*
* @author Coline Piloquet <[email protected]>
*/
@AutoService(ExtensionXmlSerializer.class)
public class GeneratorShortCircuitXmlSerializer extends AbstractExtensionXmlSerializer<Generator, GeneratorShortCircuit> {

public GeneratorShortCircuitXmlSerializer() {
super("generatorShortCircuit", "network", GeneratorShortCircuit.class, false,
"generatorShortCircuit.xsd", "http://www.itesla_project.eu/schema/iidm/ext/generator_short_circuit/1_0",
"gsc");
}

@Override
public void write(GeneratorShortCircuit generatorShortCircuit, XmlWriterContext context) throws XMLStreamException {
XmlUtil.writeDouble("directSubtransX", generatorShortCircuit.getDirectSubtransX(), context.getWriter());
XmlUtil.writeDouble("directTransX", generatorShortCircuit.getDirectTransX(), context.getWriter());
XmlUtil.writeDouble("stepUpTransformerX", generatorShortCircuit.getStepUpTransformerX(), context.getWriter());
}

@Override
public GeneratorShortCircuit read(Generator generator, XmlReaderContext context) throws XMLStreamException {
double directSubtransX = XmlUtil.readDoubleAttribute(context.getReader(), "directSubtransX");
double directTransX = XmlUtil.readDoubleAttribute(context.getReader(), "directTransX");
double stepUpTransformerX = XmlUtil.readOptionalDoubleAttribute(context.getReader(), "stepUpTransformerX");
generator.newExtension(GeneratorShortCircuitAdder.class)
.withDirectSubtransX(directSubtransX)
.withDirectTransX(directTransX)
.withStepUpTransformerX(stepUpTransformerX)
.add();
return generator.getExtension(GeneratorShortCircuit.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.iidm.xml.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.extensions.AbstractExtensionXmlSerializer;
import com.powsybl.commons.extensions.ExtensionXmlSerializer;
import com.powsybl.commons.xml.XmlReaderContext;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.commons.xml.XmlWriterContext;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit;
import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder;

import javax.xml.stream.XMLStreamException;

/**
*
* @author Coline Piloquet <[email protected]>
*/
@AutoService(ExtensionXmlSerializer.class)
public class IdentifiableShortCircuitXmlSerializer<I extends Identifiable<I>> extends AbstractExtensionXmlSerializer<I, IdentifiableShortCircuit<I>> {

public IdentifiableShortCircuitXmlSerializer() {
super("identifiableShortCircuit", "network", IdentifiableShortCircuit.class, false,
"identifiableShortCircuit.xsd", "http://www.powsybl.org/schema/iidm/ext/identifiable_short_circuit/1_0",
"isc");
}

@Override
public void write(IdentifiableShortCircuit identifiableShortCircuit, XmlWriterContext context) throws XMLStreamException {
XmlUtil.writeDouble("ipMax", identifiableShortCircuit.getIpMax(), context.getWriter());
XmlUtil.writeDouble("ipMin", identifiableShortCircuit.getIpMin(), context.getWriter());
}

@Override
public IdentifiableShortCircuit read(I identifiable, XmlReaderContext context) throws XMLStreamException {
double ipMax = XmlUtil.readDoubleAttribute(context.getReader(), "ipMax");
double ipMin = XmlUtil.readDoubleAttribute(context.getReader(), "ipMin");
identifiable.newExtension(IdentifiableShortCircuitAdder.class)
.withIpMax(ipMax)
.withIpMin(ipMin)
.add();
return identifiable.getExtension(IdentifiableShortCircuit.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.itesla_project.eu/schema/iidm/ext/generator_short_circuit/1_0"
elementFormDefault="qualified">
<xs:element name="generatorShortCircuit">
<xs:complexType>
<xs:attribute name="directSubtransX" use="optional" type="xs:double"/>
<xs:attribute name="directTransX" use="required" type="xs:double"/>
<xs:attribute name="stepUpTransformerX" use="optional" type="xs:double"/>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.powsybl.org/schema/iidm/ext/identifiable_short_circuit/1_0"
elementFormDefault="qualified">
<xs:element name="identifiableShortCircuit">
<xs:complexType>
<xs:attribute name="ipMax" use="required" type="xs:double"/>
<xs:attribute name="ipMin" use="required" type="xs:double"/>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.iidm.xml.extensions;

import com.powsybl.commons.AbstractConverterTest;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuit;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.xml.NetworkXml;
import org.joda.time.DateTime;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* @author Coline Piloquet <[email protected]>
*/
public class GeneratorShortCircuitXmlSerializerTest extends AbstractConverterTest {
@Test
public void testXmlSerializer() throws IOException {
Network network = EurostagTutorialExample1Factory.create();
network.setCaseDate(DateTime.parse("2016-12-07T11:18:52.881+01:00"));
Generator gen = network.getGenerator("GEN");
assertNotNull(gen);
gen.newExtension(GeneratorShortCircuitAdder.class)
.withDirectTransX(20)
.withDirectSubtransX(20)
.withStepUpTransformerX(20)
.add();
GeneratorShortCircuit generatorShortCircuit = gen.getExtension(GeneratorShortCircuit.class);

Network network2 = roundTripXmlTest(network,
NetworkXml::writeAndValidate,
NetworkXml::read, "/shortcircuits/generatorShortCircuitRef.xml");

Generator gen2 = network2.getGenerator("GEN");
assertNotNull(gen2);
GeneratorShortCircuit generatorShortCircuit2 = gen2.getExtension(GeneratorShortCircuit.class);
assertNotNull(generatorShortCircuit2);

assertEquals(generatorShortCircuit.getDirectSubtransX(), generatorShortCircuit2.getDirectSubtransX(), 0);
assertEquals(generatorShortCircuit.getDirectTransX(), generatorShortCircuit2.getDirectTransX(), 0);
assertEquals(generatorShortCircuit.getStepUpTransformerX(), generatorShortCircuit2.getStepUpTransformerX(), 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.iidm.xml.extensions;;

import com.powsybl.commons.AbstractConverterTest;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit;
import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.xml.NetworkXml;
import org.joda.time.DateTime;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* @author Coline Piloquet <[email protected]>
*/
public class IdentifiableShortCircuitXmlSerializerTest extends AbstractConverterTest {
@Test
public void testXmlSerializer() throws IOException {
Network network = EurostagTutorialExample1Factory.create();
network.setCaseDate(DateTime.parse("2016-12-07T11:18:52.881+01:00"));
VoltageLevel vlhv1 = network.getVoltageLevel("VLHV1");
assertNotNull(vlhv1);
vlhv1.newExtension(IdentifiableShortCircuitAdder.class)
.withIpMin(500)
.withIpMax(1500)
.add();
IdentifiableShortCircuit voltageLevelShortCircuits = vlhv1.getExtension(IdentifiableShortCircuit.class);

Network network2 = roundTripXmlTest(network,
NetworkXml::writeAndValidate,
NetworkXml::read, "/shortcircuits/voltageLevelShortCircuitRef.xml");

VoltageLevel vlhv2 = network2.getVoltageLevel("VLHV1");
assertNotNull(vlhv2);
IdentifiableShortCircuit voltageLevelShortCircuits2 = vlhv2.getExtension(IdentifiableShortCircuit.class);
assertNotNull(voltageLevelShortCircuits2);

assertEquals(voltageLevelShortCircuits.getIpMax(), voltageLevelShortCircuits2.getIpMax(), 0);
assertEquals(voltageLevelShortCircuits.getIpMin(), voltageLevelShortCircuits2.getIpMin(), 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_6" xmlns:gsc="http://www.itesla_project.eu/schema/iidm/ext/generator_short_circuit/1_0" id="sim1" caseDate="2016-12-07T11:18:52.881+01:00" forecastDistance="0" sourceFormat="test">
<iidm:substation id="P1" country="FR" tso="RTE" geographicalTags="A">
<iidm:voltageLevel id="VLGEN" nominalV="24.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NGEN"/>
</iidm:busBreakerTopology>
<iidm:generator id="GEN" energySource="OTHER" minP="-9999.99" maxP="9999.99" voltageRegulatorOn="true" targetP="607.0" targetV="24.5" targetQ="301.0" bus="NGEN" connectableBus="NGEN">
<iidm:minMaxReactiveLimits minQ="-9999.99" maxQ="9999.99"/>
</iidm:generator>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLHV1" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NHV1"/>
</iidm:busBreakerTopology>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NGEN_NHV1" r="0.26658461538461536" x="11.104492831516762" g="0.0" b="0.0" ratedU1="24.0" ratedU2="400.0" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NHV1" connectableBus2="NHV1" voltageLevelId2="VLHV1"/>
</iidm:substation>
<iidm:substation id="P2" country="FR" tso="RTE" geographicalTags="B">
<iidm:voltageLevel id="VLHV2" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NHV2"/>
</iidm:busBreakerTopology>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLLOAD" nominalV="150.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NLOAD"/>
</iidm:busBreakerTopology>
<iidm:load id="LOAD" loadType="UNDEFINED" p0="600.0" q0="200.0" bus="NLOAD" connectableBus="NLOAD"/>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NHV2_NLOAD" r="0.04724999999999999" x="4.049724365620455" g="0.0" b="0.0" ratedU1="400.0" ratedU2="158.0" bus1="NHV2" connectableBus1="NHV2" voltageLevelId1="VLHV2" bus2="NLOAD" connectableBus2="NLOAD" voltageLevelId2="VLLOAD">
<iidm:ratioTapChanger lowTapPosition="0" tapPosition="1" loadTapChangingCapabilities="true" regulating="true" targetV="158.0" targetDeadband="0.0">
<iidm:terminalRef id="NHV2_NLOAD" side="TWO"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.8505666905244191"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0006666666666666"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.150766642808914"/>
</iidm:ratioTapChanger>
</iidm:twoWindingsTransformer>
</iidm:substation>
<iidm:line id="NHV1_NHV2_1" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2"/>
<iidm:line id="NHV1_NHV2_2" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2"/>
<iidm:extension id="GEN">
<gsc:generatorShortCircuit directSubtransX="20.0" directTransX="20.0" stepUpTransformerX="20.0"/>
</iidm:extension>
</iidm:network>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_6" xmlns:isc="http://www.powsybl.org/schema/iidm/ext/identifiable_short_circuit/1_0" id="sim1" caseDate="2016-12-07T11:18:52.881+01:00" forecastDistance="0" sourceFormat="test">
<iidm:substation id="P1" country="FR" tso="RTE" geographicalTags="A">
<iidm:voltageLevel id="VLGEN" nominalV="24.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NGEN"/>
</iidm:busBreakerTopology>
<iidm:generator id="GEN" energySource="OTHER" minP="-9999.99" maxP="9999.99" voltageRegulatorOn="true" targetP="607.0" targetV="24.5" targetQ="301.0" bus="NGEN" connectableBus="NGEN">
<iidm:minMaxReactiveLimits minQ="-9999.99" maxQ="9999.99"/>
</iidm:generator>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLHV1" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NHV1"/>
</iidm:busBreakerTopology>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NGEN_NHV1" r="0.26658461538461536" x="11.104492831516762" g="0.0" b="0.0" ratedU1="24.0" ratedU2="400.0" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NHV1" connectableBus2="NHV1" voltageLevelId2="VLHV1"/>
</iidm:substation>
<iidm:substation id="P2" country="FR" tso="RTE" geographicalTags="B">
<iidm:voltageLevel id="VLHV2" nominalV="380.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NHV2"/>
</iidm:busBreakerTopology>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLLOAD" nominalV="150.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
<iidm:bus id="NLOAD"/>
</iidm:busBreakerTopology>
<iidm:load id="LOAD" loadType="UNDEFINED" p0="600.0" q0="200.0" bus="NLOAD" connectableBus="NLOAD"/>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NHV2_NLOAD" r="0.04724999999999999" x="4.049724365620455" g="0.0" b="0.0" ratedU1="400.0" ratedU2="158.0" bus1="NHV2" connectableBus1="NHV2" voltageLevelId1="VLHV2" bus2="NLOAD" connectableBus2="NLOAD" voltageLevelId2="VLLOAD">
<iidm:ratioTapChanger lowTapPosition="0" tapPosition="1" loadTapChangingCapabilities="true" regulating="true" targetV="158.0" targetDeadband="0.0">
<iidm:terminalRef id="NHV2_NLOAD" side="TWO"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.8505666905244191"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0006666666666666"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.150766642808914"/>
</iidm:ratioTapChanger>
</iidm:twoWindingsTransformer>
</iidm:substation>
<iidm:line id="NHV1_NHV2_1" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2"/>
<iidm:line id="NHV1_NHV2_2" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NHV1" connectableBus1="NHV1" voltageLevelId1="VLHV1" bus2="NHV2" connectableBus2="NHV2" voltageLevelId2="VLHV2"/>
<iidm:extension id="VLHV1">
<isc:identifiableShortCircuit ipMin="500.0" ipMax="1500.0"/>
</iidm:extension>
</iidm:network>

0 comments on commit 9455229

Please sign in to comment.