diff --git a/extensions/iidm/CMakeLists.txt b/extensions/iidm/CMakeLists.txt index bb8785f9..8624d474 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 diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp index 4add9cba..f2822730 100644 --- a/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/Constants.hpp @@ -16,6 +16,8 @@ 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"; @@ -36,6 +38,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/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/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/Iidm.cpp b/extensions/iidm/src/Iidm.cpp index 72242f14..285c367f 100644 --- a/extensions/iidm/src/Iidm.cpp +++ b/extensions/iidm/src/Iidm.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ 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()); 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