diff --git a/extensions/iidm/CMakeLists.txt b/extensions/iidm/CMakeLists.txt index 4d75204d..bb8785f9 100644 --- a/extensions/iidm/CMakeLists.txt +++ b/extensions/iidm/CMakeLists.txt @@ -23,12 +23,16 @@ set(EXT_SOURCES src/DiscreteMeasurementsAdder.cpp src/DiscreteMeasurementsXmlSerializer.cpp src/DiscreteMeasurementValidationUtil.cpp + src/GeneratorShortCircuit.cpp + src/GeneratorShortCircuitAdder.cpp src/HvdcAngleDroopActivePowerControl.cpp src/HvdcAngleDroopActivePowerControlAdder.cpp src/HvdcAngleDroopActivePowerControlXmlSerializer.cpp src/HvdcOperatorActivePowerRange.cpp src/HvdcOperatorActivePowerRangeAdder.cpp src/HvdcOperatorActivePowerRangeXmlSerializer.cpp + src/IdentifiableShortCircuit.cpp + src/IdentifiableShortCircuitAdder.cpp src/Iidm.cpp src/InjectionObservability.cpp src/InjectionObservabilityAdder.cpp @@ -65,9 +69,11 @@ set(UNIT_TEST_SOURCES test/BranchObservabilityTest.cpp test/CoordinatedReactiveControlTest.cpp test/DiscreteMeasurementsTest.cpp + test/GeneratorShortCircuitTest.cpp 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/GeneratorShortCircuit.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuit.hpp new file mode 100644 index 00000000..e72f141e --- /dev/null +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuit.hpp @@ -0,0 +1,84 @@ +/** + * 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_GENERATORSHORTCIRCUIT_HPP +#define POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUIT_HPP + +#include + +namespace powsybl { + +namespace iidm { + +class Generator; + +namespace extensions { + +namespace iidm { + +class GeneratorShortCircuit : public Extension { +public: // Extension + const std::string& getName() const override; + + const std::type_index& getType() const override; + +public: + /** + * Get the direct-axis subtransient reactance (also known as X''d) + */ + double getDirectSubtransX() const; + + /** + * Get the direct-axis transient reactance (also known as X'd) + */ + double getDirectTransX() const; + + /** + * Get the step-up transformer reactance if the generator has a non-modeled step-up transformer. + */ + double getStepUpTransformerX() const; + + /** + * Set the direct-axis subtransient reactance (also known as X''d) + */ + GeneratorShortCircuit& setDirectSubtransX(double directSubtransX); + + /** + * Set the direct-axis transient reactance (also known as X'd) + */ + GeneratorShortCircuit& setDirectTransX(double directTransX); + + /** + * Set the step-up transformer reactance + */ + GeneratorShortCircuit& setStepUpTransformerX(double setUpTransformerX); + +private: // Extension + void assertExtendable(const stdcxx::Reference& extendable) const override; + +private: + GeneratorShortCircuit(Generator& generator, double directSubtransX, double directTransX, double stepUpTransformerX); + + friend class GeneratorShortCircuitAdder; + +private: + double m_directSubtransX; + + double m_directTransX; + + double m_stepUpTransformerX; +}; + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUIT_HPP diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitAdder.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitAdder.hpp new file mode 100644 index 00000000..321ddc82 --- /dev/null +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/GeneratorShortCircuitAdder.hpp @@ -0,0 +1,95 @@ +/** + * 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_GENERATORSHORTCIRCUITADDER_HPP +#define POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUITADDER_HPP + +#include +#include + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +class GeneratorShortCircuitAdder : public ExtensionAdder { +public: + /** + * Constructor + */ + explicit GeneratorShortCircuitAdder(Extendable& extendable); + + /** + * Copy constructor + */ + GeneratorShortCircuitAdder(const GeneratorShortCircuitAdder&) = default; + + /** + * Move constructor + */ + GeneratorShortCircuitAdder(GeneratorShortCircuitAdder&&) = default; + + /** + * Destructor + */ + ~GeneratorShortCircuitAdder() noexcept override = default; + + /** + * Copy assignment operator + */ + GeneratorShortCircuitAdder& operator=(const GeneratorShortCircuitAdder&) = delete; + + /** + * Move assignment operator + */ + GeneratorShortCircuitAdder& operator=(GeneratorShortCircuitAdder&&) = delete; + + /** + * Set the direct-axis subtransient reactance (also known as X''d) + */ + GeneratorShortCircuitAdder& withDirectSubtransX(double directSubtransX); + + /** + * Set the direct-axis transient reactance (also known as X'd) + */ + GeneratorShortCircuitAdder& withDirectTransX(double directTransX); + + /** + * Set the step-up transformer reactance + */ + GeneratorShortCircuitAdder& withStepUpTransformerX(double stepUpTransformerX); + +protected: + /** + * Creates the GeneratorShortCircuit extension. + * + * @param extendable the extendable + * + * @return the extension + */ + std::unique_ptr createExtension(Extendable& extendable) const override; + +private: + double m_directTransX = 0.0; + + double m_directSubtransX = stdcxx::nan(); + + double m_stepUpTransformerX = stdcxx::nan(); +}; + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM_EXTENSIONS_IIDM_GENERATORSHORTCIRCUITADDER_HPP 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..52112811 --- /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 [A] + */ + double getIpMax() const; + + /** + * Get minimum allowable peak short-circuit current [A] + */ + double getIpMin() const; + + /** + * Set maximum allowable peak short-circuit current [A] + */ + 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/GeneratorShortCircuit.cpp b/extensions/iidm/src/GeneratorShortCircuit.cpp new file mode 100644 index 00000000..c51438ea --- /dev/null +++ b/extensions/iidm/src/GeneratorShortCircuit.cpp @@ -0,0 +1,76 @@ +/** + * 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 { + +GeneratorShortCircuit::GeneratorShortCircuit(Generator& generator, double directSubtransX, double directTransX, double stepUpTransformerX) : + Extension(generator), + m_directSubtransX(directSubtransX), + m_directTransX(directTransX), + m_stepUpTransformerX(stepUpTransformerX) { +} + +void GeneratorShortCircuit::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 GeneratorShortCircuit::getDirectSubtransX() const { + return m_directSubtransX; +} + +double GeneratorShortCircuit::getDirectTransX() const { + return m_directTransX; +} + +const std::string& GeneratorShortCircuit::getName() const { + static std::string s_name = "generatorShortCircuit"; + return s_name; +} + +double GeneratorShortCircuit::getStepUpTransformerX() const { + return m_stepUpTransformerX; +} + +const std::type_index& GeneratorShortCircuit::getType() const { + static std::type_index s_type = typeid(GeneratorShortCircuit); + return s_type; +} + +GeneratorShortCircuit& GeneratorShortCircuit::setDirectSubtransX(double directSubtransX) { + m_directSubtransX = directSubtransX; + return *this; +} + +GeneratorShortCircuit& GeneratorShortCircuit::setDirectTransX(double directTransX) { + m_directTransX = directTransX; + return *this; +} + +GeneratorShortCircuit& GeneratorShortCircuit::setStepUpTransformerX(double setUpTransformerX) { + m_stepUpTransformerX = setUpTransformerX; + return *this; +} + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl diff --git a/extensions/iidm/src/GeneratorShortCircuitAdder.cpp b/extensions/iidm/src/GeneratorShortCircuitAdder.cpp new file mode 100644 index 00000000..34591c08 --- /dev/null +++ b/extensions/iidm/src/GeneratorShortCircuitAdder.cpp @@ -0,0 +1,57 @@ +/** + * 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 + +namespace powsybl { + +namespace iidm { + +namespace extensions { + +namespace iidm { + +GeneratorShortCircuitAdder::GeneratorShortCircuitAdder(Extendable& extendable) : + ExtensionAdder(extendable) { +} + +std::unique_ptr GeneratorShortCircuitAdder::createExtension(Extendable& extendable) const { + if (std::isnan(m_directTransX)) { + throw PowsyblException("Undefined directTransX"); + } + if (stdcxx::isInstanceOf(extendable)) { + return std::unique_ptr(new GeneratorShortCircuit(dynamic_cast(extendable), m_directSubtransX, m_directTransX, m_stepUpTransformerX)); + } + throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); +} + +GeneratorShortCircuitAdder& GeneratorShortCircuitAdder::withDirectSubtransX(double directSubtransX) { + m_directSubtransX = directSubtransX; + return *this; +} + +GeneratorShortCircuitAdder& GeneratorShortCircuitAdder::withDirectTransX(double directTransX) { + m_directTransX = directTransX; + return *this; +} + +GeneratorShortCircuitAdder& GeneratorShortCircuitAdder::withStepUpTransformerX(double stepUpTransformerX) { + m_stepUpTransformerX = stepUpTransformerX; + return *this; +} + +} // namespace iidm + +} // namespace extensions + +} // namespace iidm + +} // namespace powsybl diff --git a/extensions/iidm/src/IdentifiableShortCircuit.cpp b/extensions/iidm/src/IdentifiableShortCircuit.cpp new file mode 100644 index 00000000..4b5fb524 --- /dev/null +++ b/extensions/iidm/src/IdentifiableShortCircuit.cpp @@ -0,0 +1,69 @@ +/** + * 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) { + if (std::isnan(ipMax)) { + throw PowsyblException("Undefined 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/GeneratorShortCircuitTest.cpp b/extensions/iidm/test/GeneratorShortCircuitTest.cpp new file mode 100644 index 00000000..c09d7214 --- /dev/null +++ b/extensions/iidm/test/GeneratorShortCircuitTest.cpp @@ -0,0 +1,74 @@ +/** + * 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(GeneratorShortCircuitTestSuite) + +BOOST_AUTO_TEST_CASE(generatorShortCircuit) { + Network network = powsybl::network::EurostagFactory::createTutorial1Network(); + Generator& generator = network.getGenerator("GEN"); + + generator.newExtension().withDirectSubtransX(1.1).withDirectTransX(2.2).withStepUpTransformerX(3.3).add(); + auto& extension = generator.getExtension(); + + BOOST_CHECK_CLOSE(1.1, extension.getDirectSubtransX(), std::numeric_limits::epsilon()); + BOOST_CHECK_CLOSE(2.2, extension.getDirectTransX(), std::numeric_limits::epsilon()); + BOOST_CHECK_CLOSE(3.3, extension.getStepUpTransformerX(), std::numeric_limits::epsilon()); + + BOOST_CHECK(stdcxx::areSame(extension, extension.setDirectSubtransX(11.1))); + BOOST_CHECK_CLOSE(11.1, extension.getDirectSubtransX(), std::numeric_limits::epsilon()); + + BOOST_CHECK(stdcxx::areSame(extension, extension.setDirectTransX(22.2))); + BOOST_CHECK_CLOSE(22.2, extension.getDirectTransX(), std::numeric_limits::epsilon()); + + BOOST_CHECK(stdcxx::areSame(extension, extension.setStepUpTransformerX(33.3))); + BOOST_CHECK_CLOSE(33.3, extension.getStepUpTransformerX(), std::numeric_limits::epsilon()); +} + +BOOST_AUTO_TEST_CASE(adder) { + Network network = powsybl::network::EurostagFactory::createTutorial1Network(); + Generator& generator = network.getGenerator("GEN"); + + auto adder = generator.newExtension(); + adder.withDirectSubtransX(stdcxx::nan()) + .withDirectTransX(stdcxx::nan()) + .withStepUpTransformerX(stdcxx::nan()); + + POWSYBL_ASSERT_THROW(adder.add(), PowsyblException, "Undefined directTransX"); + adder.withDirectTransX(0.0).add(); + + auto& extension = generator.getExtension(); + BOOST_CHECK(std::isnan(extension.getDirectSubtransX())); + BOOST_CHECK_CLOSE(0.0, extension.getDirectTransX(), std::numeric_limits::epsilon()); + BOOST_CHECK(std::isnan(extension.getStepUpTransformerX())); +} + +BOOST_AUTO_TEST_SUITE_END() + +} // 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..5f844259 --- /dev/null +++ b/extensions/iidm/test/IdentifiableShortCircuitTest.cpp @@ -0,0 +1,69 @@ +/** + * 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()); + + POWSYBL_ASSERT_THROW(extension.setIpMax(stdcxx::nan()), PowsyblException, "Undefined ipMax"); + 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