From e8c99e2d0e16c9636d54a6abf0c7b7348bea6ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Laigre?= Date: Mon, 20 Dec 2021 12:05:16 +0100 Subject: [PATCH] Add OperationalLimitsOwner (#408) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE Signed-off-by: Mathieu BAGUE --- include/powsybl/iidm/ActivePowerLimits.hpp | 2 +- .../powsybl/iidm/ActivePowerLimitsAdder.hpp | 2 +- include/powsybl/iidm/ApparentPowerLimits.hpp | 2 +- .../powsybl/iidm/ApparentPowerLimitsAdder.hpp | 2 +- include/powsybl/iidm/CurrentLimits.hpp | 2 +- include/powsybl/iidm/CurrentLimitsAdder.hpp | 2 +- include/powsybl/iidm/LoadingLimits.hpp | 4 +- include/powsybl/iidm/LoadingLimitsAdder.hpp | 10 ++--- include/powsybl/iidm/LoadingLimitsAdder.hxx | 6 +-- include/powsybl/iidm/OperationalLimits.hpp | 6 +-- .../powsybl/iidm/OperationalLimitsHolder.hpp | 9 ++-- .../powsybl/iidm/OperationalLimitsHolder.hxx | 11 ----- .../powsybl/iidm/OperationalLimitsOwner.hpp | 44 +++++++++++++++++++ src/iidm/ActivePowerLimits.cpp | 2 +- src/iidm/ActivePowerLimitsAdder.cpp | 5 ++- src/iidm/ApparentPowerLimits.cpp | 2 +- src/iidm/ApparentPowerLimitsAdder.cpp | 5 ++- src/iidm/CurrentLimits.cpp | 2 +- src/iidm/CurrentLimitsAdder.cpp | 5 ++- src/iidm/LoadingLimits.cpp | 2 +- src/iidm/OperationalLimits.cpp | 2 +- src/iidm/OperationalLimitsHolder.cpp | 10 +++++ 22 files changed, 92 insertions(+), 45 deletions(-) create mode 100644 include/powsybl/iidm/OperationalLimitsOwner.hpp diff --git a/include/powsybl/iidm/ActivePowerLimits.hpp b/include/powsybl/iidm/ActivePowerLimits.hpp index c1b676e8..5bf07ed1 100644 --- a/include/powsybl/iidm/ActivePowerLimits.hpp +++ b/include/powsybl/iidm/ActivePowerLimits.hpp @@ -19,7 +19,7 @@ class ActivePowerLimits : public LoadingLimits { const LimitType& getLimitType() const override; public: - ActivePowerLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits); + ActivePowerLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits); ActivePowerLimits(const ActivePowerLimits&) = default; diff --git a/include/powsybl/iidm/ActivePowerLimitsAdder.hpp b/include/powsybl/iidm/ActivePowerLimitsAdder.hpp index fb3edbbf..38deb505 100644 --- a/include/powsybl/iidm/ActivePowerLimitsAdder.hpp +++ b/include/powsybl/iidm/ActivePowerLimitsAdder.hpp @@ -20,7 +20,7 @@ class ActivePowerLimitsAdder : public LoadingLimitsAdder >; public: - LoadingLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits); + LoadingLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits); LoadingLimits(const LoadingLimits&) = default; diff --git a/include/powsybl/iidm/LoadingLimitsAdder.hpp b/include/powsybl/iidm/LoadingLimitsAdder.hpp index 95a58362..5449243d 100644 --- a/include/powsybl/iidm/LoadingLimitsAdder.hpp +++ b/include/powsybl/iidm/LoadingLimitsAdder.hpp @@ -17,14 +17,14 @@ namespace powsybl { namespace iidm { -class OperationalLimitsHolder; +class OperationalLimitsOwner; template class LoadingLimitsAdder : public OperationalLimitsAdder { public: class TemporaryLimitAdder { public: - TemporaryLimitAdder(OperationalLimitsHolder& owner, LoadingLimitsAdder& parent); + TemporaryLimitAdder(OperationalLimitsOwner& owner, LoadingLimitsAdder& parent); LoadingLimitsAdder& endTemporaryLimit(); @@ -42,7 +42,7 @@ class LoadingLimitsAdder : public OperationalLimitsAdder { void checkAndGetUniqueName(); private: - OperationalLimitsHolder& m_owner; + OperationalLimitsOwner& m_owner; LoadingLimitsAdder& m_parent; @@ -58,7 +58,7 @@ class LoadingLimitsAdder : public OperationalLimitsAdder { }; public: - explicit LoadingLimitsAdder(OperationalLimitsHolder& owner); + explicit LoadingLimitsAdder(OperationalLimitsOwner& owner); LoadingLimitsAdder(const LoadingLimitsAdder&) = default; @@ -86,7 +86,7 @@ class LoadingLimitsAdder : public OperationalLimitsAdder { const LoadingLimits::TemporaryLimits& getTemporaryLimits() const; protected: - OperationalLimitsHolder& m_owner; + OperationalLimitsOwner& m_owner; private: LoadingLimitsAdder& addTemporaryLimit(const std::string& name, double value, unsigned long acceptableDuration, bool fictitious); diff --git a/include/powsybl/iidm/LoadingLimitsAdder.hxx b/include/powsybl/iidm/LoadingLimitsAdder.hxx index a469f9a6..7b1361f5 100644 --- a/include/powsybl/iidm/LoadingLimitsAdder.hxx +++ b/include/powsybl/iidm/LoadingLimitsAdder.hxx @@ -14,7 +14,7 @@ #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ namespace powsybl { namespace iidm { template -LoadingLimitsAdder::TemporaryLimitAdder::TemporaryLimitAdder(OperationalLimitsHolder& owner, LoadingLimitsAdder& parent) : +LoadingLimitsAdder::TemporaryLimitAdder::TemporaryLimitAdder(OperationalLimitsOwner& owner, LoadingLimitsAdder& parent) : m_owner(owner), m_parent(parent) { } @@ -92,7 +92,7 @@ typename LoadingLimitsAdder::TemporaryLimitAdder& LoadingLimitsAdder } template -LoadingLimitsAdder::LoadingLimitsAdder(OperationalLimitsHolder& owner) : +LoadingLimitsAdder::LoadingLimitsAdder(OperationalLimitsOwner& owner) : m_owner(owner) { } diff --git a/include/powsybl/iidm/OperationalLimits.hpp b/include/powsybl/iidm/OperationalLimits.hpp index 6c5f5294..216794ef 100644 --- a/include/powsybl/iidm/OperationalLimits.hpp +++ b/include/powsybl/iidm/OperationalLimits.hpp @@ -14,11 +14,11 @@ namespace powsybl { namespace iidm { -class OperationalLimitsHolder; +class OperationalLimitsOwner; class OperationalLimits { public: - explicit OperationalLimits(OperationalLimitsHolder& owner); + explicit OperationalLimits(OperationalLimitsOwner& owner); OperationalLimits(const OperationalLimits&) = default; @@ -35,7 +35,7 @@ class OperationalLimits { void remove(); protected: - OperationalLimitsHolder& m_owner; + OperationalLimitsOwner& m_owner; }; } // namespace iidm diff --git a/include/powsybl/iidm/OperationalLimitsHolder.hpp b/include/powsybl/iidm/OperationalLimitsHolder.hpp index bf723fa6..e4bf04bc 100644 --- a/include/powsybl/iidm/OperationalLimitsHolder.hpp +++ b/include/powsybl/iidm/OperationalLimitsHolder.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -28,10 +29,13 @@ class CurrentLimitsAdder; class FlowsLimitsHolder; class Identifiable; -class OperationalLimitsHolder : public Validable { +class OperationalLimitsHolder : public OperationalLimitsOwner { public: // Validable std::string getMessageHeader() const override; +public: // OperationalLimitsOwner + stdcxx::Reference setOperationalLimits(const LimitType& limitType, std::unique_ptr&& operationalLimits) override; + public: OperationalLimitsHolder(Identifiable& identifiable, std::string&& attributeName); @@ -64,9 +68,6 @@ class OperationalLimitsHolder : public Validable { CurrentLimitsAdder newCurrentLimits(); - template - stdcxx::Reference setOperationalLimits(const LimitType& limitType, std::unique_ptr&& operationalLimits); - private: friend class FlowsLimitsHolder; diff --git a/include/powsybl/iidm/OperationalLimitsHolder.hxx b/include/powsybl/iidm/OperationalLimitsHolder.hxx index da59ee51..effec09c 100644 --- a/include/powsybl/iidm/OperationalLimitsHolder.hxx +++ b/include/powsybl/iidm/OperationalLimitsHolder.hxx @@ -36,17 +36,6 @@ stdcxx::Reference OperationalLimitsHolder::getOperationalLimits(const LimitTy return stdcxx::ref(const_cast(this)->getOperationalLimits(type)); } -template -stdcxx::Reference OperationalLimitsHolder::setOperationalLimits(const LimitType& limitType, std::unique_ptr&& operationalLimits) { - if (!operationalLimits) { - m_operationalLimits.erase(limitType); - } else { - m_operationalLimits[limitType] = std::move(operationalLimits); - return stdcxx::ref(dynamic_cast(*m_operationalLimits.find(limitType)->second)); - } - return stdcxx::ref(); -} - } // namespace iidm } // namespace powsybl diff --git a/include/powsybl/iidm/OperationalLimitsOwner.hpp b/include/powsybl/iidm/OperationalLimitsOwner.hpp new file mode 100644 index 00000000..6af8b0d7 --- /dev/null +++ b/include/powsybl/iidm/OperationalLimitsOwner.hpp @@ -0,0 +1,44 @@ +/** + * 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/. + */ + +#ifndef POWSYBL_IIDM_OPERATIONALLIMITSOWNER_HPP +#define POWSYBL_IIDM_OPERATIONALLIMITSOWNER_HPP + +#include + +#include +#include +#include + +namespace powsybl { + +namespace iidm { + +class OperationalLimits; + +class OperationalLimitsOwner : public Validable { +public: + OperationalLimitsOwner() = default; + + OperationalLimitsOwner(const OperationalLimitsOwner&) = default; + + OperationalLimitsOwner(OperationalLimitsOwner&&) noexcept = default; + + ~OperationalLimitsOwner() noexcept override = default; + + OperationalLimitsOwner& operator=(const OperationalLimitsOwner&) = default; + + OperationalLimitsOwner& operator=(OperationalLimitsOwner&&) noexcept = default; + + virtual stdcxx::Reference setOperationalLimits(const LimitType& limitType, std::unique_ptr&& operationalLimits) = 0; +}; + +} // namespace iidm + +} // namespace powsybl + +#endif // POWSYBL_IIDM_OPERATIONALLIMITSOWNER_HPP diff --git a/src/iidm/ActivePowerLimits.cpp b/src/iidm/ActivePowerLimits.cpp index f599ea0a..2602bdf3 100644 --- a/src/iidm/ActivePowerLimits.cpp +++ b/src/iidm/ActivePowerLimits.cpp @@ -13,7 +13,7 @@ namespace powsybl { namespace iidm { -ActivePowerLimits::ActivePowerLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits) : +ActivePowerLimits::ActivePowerLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits) : LoadingLimits(owner, permanentLimit, temporaryLimits) { } diff --git a/src/iidm/ActivePowerLimitsAdder.cpp b/src/iidm/ActivePowerLimitsAdder.cpp index 6630c97f..1d449900 100644 --- a/src/iidm/ActivePowerLimitsAdder.cpp +++ b/src/iidm/ActivePowerLimitsAdder.cpp @@ -13,13 +13,14 @@ namespace powsybl { namespace iidm { -ActivePowerLimitsAdder::ActivePowerLimitsAdder(OperationalLimitsHolder& owner) : +ActivePowerLimitsAdder::ActivePowerLimitsAdder(OperationalLimitsOwner& owner) : LoadingLimitsAdder(owner) { } ActivePowerLimits& ActivePowerLimitsAdder::add() { checkLoadingLimits(); - return m_owner.setOperationalLimits(LimitType::ACTIVE_POWER, stdcxx::make_unique(m_owner, getPermanentLimit(), getTemporaryLimits())).get(); + auto limit = m_owner.setOperationalLimits(LimitType::ACTIVE_POWER, stdcxx::make_unique(m_owner, getPermanentLimit(), getTemporaryLimits())); + return static_cast(limit.get()); } } // namespace iidm diff --git a/src/iidm/ApparentPowerLimits.cpp b/src/iidm/ApparentPowerLimits.cpp index efdd7441..12517fbb 100644 --- a/src/iidm/ApparentPowerLimits.cpp +++ b/src/iidm/ApparentPowerLimits.cpp @@ -13,7 +13,7 @@ namespace powsybl { namespace iidm { -ApparentPowerLimits::ApparentPowerLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits) : +ApparentPowerLimits::ApparentPowerLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits) : LoadingLimits(owner, permanentLimit, temporaryLimits) { } diff --git a/src/iidm/ApparentPowerLimitsAdder.cpp b/src/iidm/ApparentPowerLimitsAdder.cpp index 94575ea3..e15fc837 100644 --- a/src/iidm/ApparentPowerLimitsAdder.cpp +++ b/src/iidm/ApparentPowerLimitsAdder.cpp @@ -11,13 +11,14 @@ namespace powsybl { namespace iidm { -ApparentPowerLimitsAdder::ApparentPowerLimitsAdder(OperationalLimitsHolder& owner) : +ApparentPowerLimitsAdder::ApparentPowerLimitsAdder(OperationalLimitsOwner& owner) : LoadingLimitsAdder(owner) { } ApparentPowerLimits& ApparentPowerLimitsAdder::add() { checkLoadingLimits(); - return m_owner.setOperationalLimits(LimitType::APPARENT_POWER, stdcxx::make_unique(m_owner, getPermanentLimit(), getTemporaryLimits())).get(); + auto limit = m_owner.setOperationalLimits(LimitType::APPARENT_POWER, stdcxx::make_unique(m_owner, getPermanentLimit(), getTemporaryLimits())); + return static_cast(limit.get()); } } // namespace iidm diff --git a/src/iidm/CurrentLimits.cpp b/src/iidm/CurrentLimits.cpp index 7c6fce59..d57db359 100644 --- a/src/iidm/CurrentLimits.cpp +++ b/src/iidm/CurrentLimits.cpp @@ -13,7 +13,7 @@ namespace powsybl { namespace iidm { -CurrentLimits::CurrentLimits(OperationalLimitsHolder& owner, double permanentLimit, const LoadingLimits::TemporaryLimits& temporaryLimits) : +CurrentLimits::CurrentLimits(OperationalLimitsOwner& owner, double permanentLimit, const LoadingLimits::TemporaryLimits& temporaryLimits) : LoadingLimits(owner, permanentLimit, temporaryLimits) { } diff --git a/src/iidm/CurrentLimitsAdder.cpp b/src/iidm/CurrentLimitsAdder.cpp index 3ff1271f..c9d5e3c0 100644 --- a/src/iidm/CurrentLimitsAdder.cpp +++ b/src/iidm/CurrentLimitsAdder.cpp @@ -14,13 +14,14 @@ namespace powsybl { namespace iidm { -CurrentLimitsAdder::CurrentLimitsAdder(OperationalLimitsHolder& owner) : +CurrentLimitsAdder::CurrentLimitsAdder(OperationalLimitsOwner& owner) : LoadingLimitsAdder(owner) { } CurrentLimits& CurrentLimitsAdder::add() { checkLoadingLimits(); - return m_owner.setOperationalLimits(LimitType::CURRENT, stdcxx::make_unique(m_owner, getPermanentLimit(), getTemporaryLimits())).get(); + auto limit = m_owner.setOperationalLimits(LimitType::CURRENT, stdcxx::make_unique(m_owner, getPermanentLimit(), getTemporaryLimits())); + return static_cast(limit.get()); } } // namespace iidm diff --git a/src/iidm/LoadingLimits.cpp b/src/iidm/LoadingLimits.cpp index d8335bb3..ed4b5bb7 100644 --- a/src/iidm/LoadingLimits.cpp +++ b/src/iidm/LoadingLimits.cpp @@ -39,7 +39,7 @@ bool LoadingLimits::TemporaryLimit::isFictitious() const { return m_isFictitious; } -LoadingLimits::LoadingLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits) : +LoadingLimits::LoadingLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits) : OperationalLimits(owner), m_permanentLimit(permanentLimit), m_temporaryLimits(temporaryLimits) { diff --git a/src/iidm/OperationalLimits.cpp b/src/iidm/OperationalLimits.cpp index c77a9977..d138fcb9 100644 --- a/src/iidm/OperationalLimits.cpp +++ b/src/iidm/OperationalLimits.cpp @@ -13,7 +13,7 @@ namespace powsybl { namespace iidm { -OperationalLimits::OperationalLimits(OperationalLimitsHolder& owner) : +OperationalLimits::OperationalLimits(OperationalLimitsOwner& owner) : m_owner(owner) { } diff --git a/src/iidm/OperationalLimitsHolder.cpp b/src/iidm/OperationalLimitsHolder.cpp index 719b380c..64c697ab 100644 --- a/src/iidm/OperationalLimitsHolder.cpp +++ b/src/iidm/OperationalLimitsHolder.cpp @@ -56,6 +56,16 @@ void OperationalLimitsHolder::setIdentifiable(Identifiable& identifiable) { m_identifiable = identifiable; } +stdcxx::Reference OperationalLimitsHolder::setOperationalLimits(const LimitType& limitType, std::unique_ptr&& operationalLimits) { + if (!operationalLimits) { + m_operationalLimits.erase(limitType); + } else { + m_operationalLimits[limitType] = std::move(operationalLimits); + return stdcxx::ref(*m_operationalLimits.find(limitType)->second); + } + return stdcxx::ref(); +} + } // namespace iidm } // namespace powsybl