From b3b6c11e4eeb08431402ba33f4b7e048dc6f4ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Laigre?= Date: Wed, 13 Jul 2022 14:31:27 +0200 Subject: [PATCH] Add xml serializers for shortcircuit extensions (#437) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add GeneratorShortCircuitXmlSerializer * Add IdentifiableShortCircuitXmlSerializer Signed-off-by: Sébastien LAIGRE --- extensions/iidm/CMakeLists.txt | 2 + .../iidm/extensions/iidm/Constants.hpp | 5 ++ .../GeneratorShortCircuitXmlSerializer.hpp | 41 ++++++++++++ .../IdentifiableShortCircuitXmlSerializer.hpp | 41 ++++++++++++ .../resources/generatorShortCircuitRef.xml | 45 ++++++++++++++ .../resources/voltageLevelShortCircuitRef.xml | 45 ++++++++++++++ .../GeneratorShortCircuitXmlSerializer.cpp | 62 +++++++++++++++++++ .../IdentifiableShortCircuitXmlSerializer.cpp | 59 ++++++++++++++++++ extensions/iidm/src/Iidm.cpp | 4 ++ .../iidm/test/GeneratorShortCircuitTest.cpp | 17 +++++ .../test/IdentifiableShortCircuitTest.cpp | 17 +++++ 11 files changed, 338 insertions(+) create mode 100644 extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitXmlSerializer.hpp create mode 100644 extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitXmlSerializer.hpp create mode 100644 extensions/iidm/resources/generatorShortCircuitRef.xml create mode 100644 extensions/iidm/resources/voltageLevelShortCircuitRef.xml create mode 100644 extensions/iidm/src/GeneratorShortCircuitXmlSerializer.cpp create mode 100644 extensions/iidm/src/IdentifiableShortCircuitXmlSerializer.cpp diff --git a/extensions/iidm/CMakeLists.txt b/extensions/iidm/CMakeLists.txt index bb8785f9..c5d10793 100644 --- a/extensions/iidm/CMakeLists.txt +++ b/extensions/iidm/CMakeLists.txt @@ -25,6 +25,7 @@ set(EXT_SOURCES src/DiscreteMeasurementValidationUtil.cpp src/GeneratorShortCircuit.cpp src/GeneratorShortCircuitAdder.cpp + src/GeneratorShortCircuitXmlSerializer.cpp src/HvdcAngleDroopActivePowerControl.cpp src/HvdcAngleDroopActivePowerControlAdder.cpp src/HvdcAngleDroopActivePowerControlXmlSerializer.cpp @@ -33,6 +34,7 @@ set(EXT_SOURCES src/HvdcOperatorActivePowerRangeXmlSerializer.cpp src/IdentifiableShortCircuit.cpp src/IdentifiableShortCircuitAdder.cpp + src/IdentifiableShortCircuitXmlSerializer.cpp src/Iidm.cpp src/InjectionObservability.cpp src/InjectionObservabilityAdder.cpp diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp index 4add9cba..ea06611a 100644 --- a/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp @@ -16,9 +16,13 @@ namespace extensions { namespace iidm { +static const char* const DIRECT_SUBTRANS_X = "directSubtransX"; +static const char* const DIRECT_TRANS_X = "directTransX"; static const char* const DISCRETE_MEASUREMENT = "discreteMeasurement"; static const char* const DISCRETE_MEASUREMENTS = "discreteMeasurements"; static const char* const ID = "id"; +static const char* const IP_MAX = "ipMax"; +static const char* const IP_MIN = "ipMin"; static const char* const NAME = "name"; static const char* const OBSERVABLE = "observable"; static const char* const PHASE_TAP_CHANGER_STATUS = "phaseTapChangerStatus"; @@ -36,6 +40,7 @@ static const char* const RATIO_TAP_CHANGER_3_STATUS = "ratioTapChanger3Status"; static const char* const REDUNDANT = "redundant"; static const char* const SIDE = "side"; static const char* const STANDARD_DEVIATION = "standardDeviation"; +static const char* const STEP_UP_TRANSFORMER_X = "stepUpTransformerX"; static const char* const TAP_CHANGER = "tapChanger"; static const char* const TYPE = "type"; static const char* const VALID = "valid"; diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitXmlSerializer.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitXmlSerializer.hpp new file mode 100644 index 00000000..42576f3a --- /dev/null +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitXmlSerializer.hpp @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022, 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/. + */ + +#ifndef POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUITXMLSERIALIZER_HPP +#define POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUITXMLSERIALIZER_HPP + +#include + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +class GeneratorShortCircuitXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { +public: // ExtensionXmlSerializer + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + + void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; + +public: + GeneratorShortCircuitXmlSerializer(); + + ~GeneratorShortCircuitXmlSerializer() noexcept override = default; +}; + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUITXMLSERIALIZER_HPP diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitXmlSerializer.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitXmlSerializer.hpp new file mode 100644 index 00000000..02baecd5 --- /dev/null +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitXmlSerializer.hpp @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2022, 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/. + */ + +#ifndef POWSYBL_IIDM4CPP_IDENTIFIABLESHORTCIRCUITXMLSERIALIZER_HPP +#define POWSYBL_IIDM4CPP_IDENTIFIABLESHORTCIRCUITXMLSERIALIZER_HPP + +#include + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +class IdentifiableShortCircuitXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { +public: // ExtensionXmlSerializer + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + + void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; + +public: + IdentifiableShortCircuitXmlSerializer(); + + ~IdentifiableShortCircuitXmlSerializer() noexcept override = default; +}; + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM4CPP_IDENTIFIABLESHORTCIRCUITXMLSERIALIZER_HPP diff --git a/extensions/iidm/resources/generatorShortCircuitRef.xml b/extensions/iidm/resources/generatorShortCircuitRef.xml new file mode 100644 index 00000000..7946265e --- /dev/null +++ b/extensions/iidm/resources/generatorShortCircuitRef.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/iidm/resources/voltageLevelShortCircuitRef.xml b/extensions/iidm/resources/voltageLevelShortCircuitRef.xml new file mode 100644 index 00000000..7e047e90 --- /dev/null +++ b/extensions/iidm/resources/voltageLevelShortCircuitRef.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/iidm/src/GeneratorShortCircuitXmlSerializer.cpp b/extensions/iidm/src/GeneratorShortCircuitXmlSerializer.cpp new file mode 100644 index 00000000..5c5afe9a --- /dev/null +++ b/extensions/iidm/src/GeneratorShortCircuitXmlSerializer.cpp @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2022, 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/. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +GeneratorShortCircuitXmlSerializer::GeneratorShortCircuitXmlSerializer() : + AbstractExtensionXmlSerializer("generatorShortCircuit", "network", "gsc", "http://www.itesla_project.eu/schema/iidm/ext/generator_short_circuit/1_0") { +} + +Extension& GeneratorShortCircuitXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { + if (!stdcxx::isInstanceOf(extendable)) { + throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); + } + double directSubtransX = context.getReader().getOptionalAttributeValue(DIRECT_SUBTRANS_X, stdcxx::nan()); + double directTransX = context.getReader().getOptionalAttributeValue(DIRECT_TRANS_X, stdcxx::nan()); + double stepUpTransformerX = context.getReader().getOptionalAttributeValue(STEP_UP_TRANSFORMER_X, stdcxx::nan()); + extendable.newExtension() + .withDirectSubtransX(directSubtransX) + .withDirectTransX(directTransX) + .withStepUpTransformerX(stepUpTransformerX) + .add(); + return extendable.getExtension(); +} + +void GeneratorShortCircuitXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { + const auto& gsc = safeCast(extension); + context.getWriter().writeAttribute(DIRECT_SUBTRANS_X, gsc.getDirectSubtransX()); + context.getWriter().writeAttribute(DIRECT_TRANS_X, gsc.getDirectTransX()); + context.getWriter().writeAttribute(STEP_UP_TRANSFORMER_X, gsc.getStepUpTransformerX()); +} + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl diff --git a/extensions/iidm/src/IdentifiableShortCircuitXmlSerializer.cpp b/extensions/iidm/src/IdentifiableShortCircuitXmlSerializer.cpp new file mode 100644 index 00000000..b6e63c85 --- /dev/null +++ b/extensions/iidm/src/IdentifiableShortCircuitXmlSerializer.cpp @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022, 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/. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +IdentifiableShortCircuitXmlSerializer::IdentifiableShortCircuitXmlSerializer() : + AbstractExtensionXmlSerializer("identifiableShortCircuit", "network", "isc", "http://www.powsybl.org/schema/iidm/ext/identifiable_short_circuit/1_0") { +} + +Extension& IdentifiableShortCircuitXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { + if (!stdcxx::isInstanceOf(extendable)) { + throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); + } + const auto& ipMax = context.getReader().getAttributeValue(IP_MAX); + const auto& ipMin = context.getReader().getOptionalAttributeValue(IP_MIN, stdcxx::nan()); + extendable.newExtension() + .withIpMax(ipMax) + .withIpMin(ipMin) + .add(); + return extendable.getExtension(); +} + +void IdentifiableShortCircuitXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { + const auto& isc = safeCast(extension); + context.getWriter().writeAttribute(IP_MAX, isc.getIpMax()); + context.getWriter().writeAttribute(IP_MIN, isc.getIpMin()); +} + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl diff --git a/extensions/iidm/src/Iidm.cpp b/extensions/iidm/src/Iidm.cpp index 72242f14..8161d39a 100644 --- a/extensions/iidm/src/Iidm.cpp +++ b/extensions/iidm/src/Iidm.cpp @@ -14,8 +14,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -39,8 +41,10 @@ std::vector> create() { serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); + serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); + serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); serializers.emplace_back(stdcxx::make_unique()); diff --git a/extensions/iidm/test/GeneratorShortCircuitTest.cpp b/extensions/iidm/test/GeneratorShortCircuitTest.cpp index c09d7214..914baa47 100644 --- a/extensions/iidm/test/GeneratorShortCircuitTest.cpp +++ b/extensions/iidm/test/GeneratorShortCircuitTest.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace powsybl { @@ -63,6 +65,21 @@ BOOST_AUTO_TEST_CASE(adder) { BOOST_CHECK(std::isnan(extension.getStepUpTransformerX())); } +BOOST_FIXTURE_TEST_CASE(GeneratorShortCircuitXmlSerializerTest, test::ResourceFixture) { + Network network = powsybl::network::EurostagFactory::createTutorial1Network(); + network.setCaseDate(stdcxx::DateTime::parse("2016-12-07T11:18:52.881+01:00")); + Generator& gen = network.getGenerator("GEN"); + gen.newExtension() + .withDirectTransX(20) + .withDirectSubtransX(20) + .withStepUpTransformerX(20) + .add(); + + const std::string& networkStrRef = ResourceFixture::getResource("/generatorShortCircuitRef.xml"); + + test::converter::RoundTrip::runXml(network, networkStrRef); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace iidm diff --git a/extensions/iidm/test/IdentifiableShortCircuitTest.cpp b/extensions/iidm/test/IdentifiableShortCircuitTest.cpp index 5f844259..52e4bc5f 100644 --- a/extensions/iidm/test/IdentifiableShortCircuitTest.cpp +++ b/extensions/iidm/test/IdentifiableShortCircuitTest.cpp @@ -9,10 +9,13 @@ #include #include +#include #include #include #include #include +#include +#include namespace powsybl { @@ -58,6 +61,20 @@ BOOST_AUTO_TEST_CASE(adder) { BOOST_CHECK_CLOSE(1.0, extension.getIpMax(), std::numeric_limits::epsilon()); } +BOOST_FIXTURE_TEST_CASE(IdentifiableShortCircuitXmlSerializerTest, test::ResourceFixture) { + Network network = powsybl::network::EurostagFactory::createTutorial1Network(); + network.setCaseDate(stdcxx::DateTime::parse("2016-12-07T11:18:52.881+01:00")); + VoltageLevel& vlhv1 = network.getVoltageLevel("VLHV1"); + vlhv1.newExtension() + .withIpMin(500) + .withIpMax(1500) + .add(); + + const std::string& networkStrRef = ResourceFixture::getResource("/voltageLevelShortCircuitRef.xml"); + + test::converter::RoundTrip::runXml(network, networkStrRef); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace iidm