From a69b4963af425d5411ba87d140e3f86e2aab67e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Wed, 11 May 2022 18:00:21 +0200 Subject: [PATCH] Add IdentifiableShortCircuit extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- extensions/iidm/CMakeLists.txt | 3 + .../iidm/IdentifiableShortCircuit.hpp | 78 ++++++++++++++++++ .../iidm/IdentifiableShortCircuitAdder.hpp | 82 +++++++++++++++++++ .../iidm/src/IdentifiableShortCircuit.cpp | 66 +++++++++++++++ .../src/IdentifiableShortCircuitAdder.cpp | 54 ++++++++++++ .../test/IdentifiableShortCircuitTest.cpp | 68 +++++++++++++++ 6 files changed, 351 insertions(+) create mode 100644 extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp create mode 100644 extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp create mode 100644 extensions/iidm/src/IdentifiableShortCircuit.cpp create mode 100644 extensions/iidm/src/IdentifiableShortCircuitAdder.cpp create mode 100644 extensions/iidm/test/IdentifiableShortCircuitTest.cpp diff --git a/extensions/iidm/CMakeLists.txt b/extensions/iidm/CMakeLists.txt index 6502c8d5..bb8785f9 100644 --- a/extensions/iidm/CMakeLists.txt +++ b/extensions/iidm/CMakeLists.txt @@ -31,6 +31,8 @@ set(EXT_SOURCES src/HvdcOperatorActivePowerRange.cpp src/HvdcOperatorActivePowerRangeAdder.cpp src/HvdcOperatorActivePowerRangeXmlSerializer.cpp + src/IdentifiableShortCircuit.cpp + src/IdentifiableShortCircuitAdder.cpp src/Iidm.cpp src/InjectionObservability.cpp src/InjectionObservabilityAdder.cpp @@ -71,6 +73,7 @@ set(UNIT_TEST_SOURCES test/HvdcAngleDroopActivePowerControlTest.cpp test/HvdcOperatorActivePowerRangeTest.cpp test/iidm.cpp + test/IdentifiableShortCircuitTest.cpp test/InjectionObservabilityTest.cpp test/MeasurementsTest.cpp test/RemoteReactivePowerControlTest.cpp diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp new file mode 100644 index 00000000..391aef97 --- /dev/null +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp @@ -0,0 +1,78 @@ +/** + * 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_IDENTIFIABLESHORTCIRCUIT_HPP +#define POWSYBL_IIDM_EXTENSIONS_IIDM_IDENTIFIABLESHORTCIRCUIT_HPP + +#include + +namespace powsybl { + +namespace iidm { + +class Identifiable; + +namespace extensions { + +namespace iidm { + +class IdentifiableShortCircuit : public Extension { +public: // Extension + const std::string& getName() const override; + + const std::type_index& getType() const override; + +public: + /** + * Get maximum allowable peak short-circuit current + */ + double getIpMax() const; + + /** + * Get minimum allowable peak short-circuit current [A] + */ + double getIpMin() const; + + /** + * Set maximum allowable peak short-circuit current + */ + IdentifiableShortCircuit& setIpMax(double ipMax); + + /** + * Set minimum allowable peak short-circuit current [A] + */ + IdentifiableShortCircuit& setIpMin(double ipMin); + +private: // Extension + void assertExtendable(const stdcxx::Reference& extendable) const override; + +private: + IdentifiableShortCircuit(Identifiable& identifiable, double ipMin, double ipMax); + + friend class IdentifiableShortCircuitAdder; + +private: + /** + * Minimum allowable peak short-circuit current + */ + double m_ipMin; + + /** + * Maximum allowable peak short-circuit current + */ + double m_ipMax; +}; + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM_EXTENSIONS_IIDM_IDENTIFIABLESHORTCIRCUIT_HPP diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp new file mode 100644 index 00000000..c0b1d88a --- /dev/null +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp @@ -0,0 +1,82 @@ +/** + * 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_IDENTIFIABLESHORTCIRCUITADDER_HPP +#define POWSYBL_IIDM_EXTENSIONS_IIDM_IDENTIFIABLESHORTCIRCUITADDER_HPP + +#include +#include + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +class IdentifiableShortCircuitAdder : public ExtensionAdder { +public: + /** + * Constructor + */ + explicit IdentifiableShortCircuitAdder(Extendable& extendable); + + /** + * Copy constructor + */ + IdentifiableShortCircuitAdder(const IdentifiableShortCircuitAdder&) = default; + + /** + * Move constructor + */ + IdentifiableShortCircuitAdder(IdentifiableShortCircuitAdder&&) = default; + + /** + * Destructor + */ + ~IdentifiableShortCircuitAdder() noexcept override = default; + + /** + * Copy assignment operator + */ + IdentifiableShortCircuitAdder& operator=(const IdentifiableShortCircuitAdder&) = delete; + + /** + * Move assignment operator + */ + IdentifiableShortCircuitAdder& operator=(IdentifiableShortCircuitAdder&&) = delete; + + IdentifiableShortCircuitAdder& withIpMax(double ipMax); + + IdentifiableShortCircuitAdder& withIpMin(double ipMin); + +protected: + /** + * Creates the IdentifiableShortCircuit extension. + * + * @param extendable the extendable + * + * @return the extension + */ + std::unique_ptr createExtension(Extendable& extendable) const override; + +private: + double m_ipMin = stdcxx::nan(); + + double m_ipMax = stdcxx::nan(); +}; + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM_EXTENSIONS_IIDM_IDENTIFIABLESHORTCIRCUITADDER_HPP diff --git a/extensions/iidm/src/IdentifiableShortCircuit.cpp b/extensions/iidm/src/IdentifiableShortCircuit.cpp new file mode 100644 index 00000000..4d714e7d --- /dev/null +++ b/extensions/iidm/src/IdentifiableShortCircuit.cpp @@ -0,0 +1,66 @@ +/** + * 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 + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +IdentifiableShortCircuit::IdentifiableShortCircuit(Identifiable& identifiable, double ipMin, double ipMax) : + Extension(identifiable), + m_ipMin(ipMin), + m_ipMax(ipMax) { +} + +void IdentifiableShortCircuit::assertExtendable(const stdcxx::Reference& extendable) const { + if (extendable && !stdcxx::isInstanceOf(extendable.get())) { + throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable.get()), stdcxx::demangle())); + } +} + +double IdentifiableShortCircuit::getIpMax() const { + return m_ipMax; +} + +double IdentifiableShortCircuit::getIpMin() const { + return m_ipMin; +} + +const std::string& IdentifiableShortCircuit::getName() const { + static std::string s_name = "identifiableShortCircuit"; + return s_name; +} + +const std::type_index& IdentifiableShortCircuit::getType() const { + static std::type_index s_type = typeid(IdentifiableShortCircuit); + return s_type; +} + +IdentifiableShortCircuit& IdentifiableShortCircuit::setIpMax(double ipMax) { + m_ipMax = ipMax; + return *this; +} + +IdentifiableShortCircuit& IdentifiableShortCircuit::setIpMin(double ipMin) { + m_ipMin = ipMin; + return *this; +} + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl diff --git a/extensions/iidm/src/IdentifiableShortCircuitAdder.cpp b/extensions/iidm/src/IdentifiableShortCircuitAdder.cpp new file mode 100644 index 00000000..53030b18 --- /dev/null +++ b/extensions/iidm/src/IdentifiableShortCircuitAdder.cpp @@ -0,0 +1,54 @@ +/** + * 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 + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +IdentifiableShortCircuitAdder::IdentifiableShortCircuitAdder(Extendable& extendable) : + ExtensionAdder(extendable) { +} + +std::unique_ptr IdentifiableShortCircuitAdder::createExtension(Extendable& extendable) const { + if (std::isnan(m_ipMax)) { + throw PowsyblException("Undefined ipMax"); + } + if (stdcxx::isInstanceOf(extendable)) { + return std::unique_ptr(new IdentifiableShortCircuit(dynamic_cast(extendable), m_ipMin, m_ipMax)); + } + throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); +} + +IdentifiableShortCircuitAdder& IdentifiableShortCircuitAdder::withIpMax(double ipMax) { + m_ipMax = ipMax; + return *this; +} + +IdentifiableShortCircuitAdder& IdentifiableShortCircuitAdder::withIpMin(double ipMin) { + m_ipMin = ipMin; + return *this; +} + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl diff --git a/extensions/iidm/test/IdentifiableShortCircuitTest.cpp b/extensions/iidm/test/IdentifiableShortCircuitTest.cpp new file mode 100644 index 00000000..06c597d0 --- /dev/null +++ b/extensions/iidm/test/IdentifiableShortCircuitTest.cpp @@ -0,0 +1,68 @@ +/** + * 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 + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +BOOST_AUTO_TEST_SUITE(IdentifiableShortCircuitTestSuite) + +BOOST_AUTO_TEST_CASE(identifiableShortCircuit) { + Network network = powsybl::network::EurostagFactory::createTutorial1Network(); + Generator& generator = network.getGenerator("GEN"); + + generator.newExtension().withIpMin(1.1).withIpMax(2.2).add(); + auto& extension = generator.getExtension(); + + BOOST_CHECK_CLOSE(1.1, extension.getIpMin(), std::numeric_limits::epsilon()); + BOOST_CHECK_CLOSE(2.2, extension.getIpMax(), std::numeric_limits::epsilon()); + + BOOST_CHECK(stdcxx::areSame(extension, extension.setIpMin(11.1))); + BOOST_CHECK_CLOSE(11.1, extension.getIpMin(), std::numeric_limits::epsilon()); + + BOOST_CHECK(stdcxx::areSame(extension, extension.setIpMax(22.2))); + BOOST_CHECK_CLOSE(22.2, extension.getIpMax(), std::numeric_limits::epsilon()); +} + +BOOST_AUTO_TEST_CASE(adder) { + Network network = powsybl::network::EurostagFactory::createTutorial1Network(); + Identifiable& Identifiable = network.getIdentifiable("GEN"); + + auto adder = Identifiable.newExtension(); + adder.withIpMin(stdcxx::nan()) + .withIpMax(stdcxx::nan()); + + POWSYBL_ASSERT_THROW(adder.add(), PowsyblException, "Undefined ipMax"); + adder.withIpMax(1.0).add(); + + auto& extension = Identifiable.getExtension(); + BOOST_CHECK(std::isnan(extension.getIpMin())); + BOOST_CHECK_CLOSE(1.0, extension.getIpMax(), std::numeric_limits::epsilon()); +} + +BOOST_AUTO_TEST_SUITE_END() + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl