Skip to content

Commit

Permalink
Add OperationalLimitsOwner (#408)
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien LAIGRE <[email protected]>
Signed-off-by: Mathieu BAGUE <[email protected]>
  • Loading branch information
sebalaig authored Dec 20, 2021
1 parent 11a1ae0 commit e8c99e2
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 45 deletions.
2 changes: 1 addition & 1 deletion include/powsybl/iidm/ActivePowerLimits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion include/powsybl/iidm/ActivePowerLimitsAdder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActivePowerLimitsAdder : public LoadingLimitsAdder<ActivePowerLimits, Acti
ActivePowerLimits& add() override;

public:
explicit ActivePowerLimitsAdder(OperationalLimitsHolder& owner);
explicit ActivePowerLimitsAdder(OperationalLimitsOwner& owner);

ActivePowerLimitsAdder(const ActivePowerLimitsAdder&) = default;

Expand Down
2 changes: 1 addition & 1 deletion include/powsybl/iidm/ApparentPowerLimits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ApparentPowerLimits : public LoadingLimits {
const LimitType& getLimitType() const override;

public:
ApparentPowerLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits);
ApparentPowerLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits);

ApparentPowerLimits(const ApparentPowerLimits&) = default;

Expand Down
2 changes: 1 addition & 1 deletion include/powsybl/iidm/ApparentPowerLimitsAdder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ApparentPowerLimitsAdder : public LoadingLimitsAdder<ApparentPowerLimits,
ApparentPowerLimits& add() override;

public:
explicit ApparentPowerLimitsAdder(OperationalLimitsHolder& owner);
explicit ApparentPowerLimitsAdder(OperationalLimitsOwner& owner);

ApparentPowerLimitsAdder(const ApparentPowerLimitsAdder&) = default;

Expand Down
2 changes: 1 addition & 1 deletion include/powsybl/iidm/CurrentLimits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CurrentLimits : public LoadingLimits {
const LimitType& getLimitType() const override;

public:
CurrentLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits);
CurrentLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits);

CurrentLimits(const CurrentLimits&) = default;

Expand Down
2 changes: 1 addition & 1 deletion include/powsybl/iidm/CurrentLimitsAdder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CurrentLimitsAdder : public LoadingLimitsAdder<CurrentLimits, CurrentLimit
CurrentLimits& add() override;

public:
explicit CurrentLimitsAdder(OperationalLimitsHolder& owner);
explicit CurrentLimitsAdder(OperationalLimitsOwner& owner);

CurrentLimitsAdder(const CurrentLimitsAdder&) = default;

Expand Down
4 changes: 2 additions & 2 deletions include/powsybl/iidm/LoadingLimits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace powsybl {

namespace iidm {

class OperationalLimitsHolder;
class OperationalLimitsOwner;

class LoadingLimits : public OperationalLimits {
public:
Expand Down Expand Up @@ -52,7 +52,7 @@ class LoadingLimits : public OperationalLimits {
using TemporaryLimits = std::map<unsigned long, TemporaryLimit, std::greater<unsigned long> >;

public:
LoadingLimits(OperationalLimitsHolder& owner, double permanentLimit, const TemporaryLimits& temporaryLimits);
LoadingLimits(OperationalLimitsOwner& owner, double permanentLimit, const TemporaryLimits& temporaryLimits);

LoadingLimits(const LoadingLimits&) = default;

Expand Down
10 changes: 5 additions & 5 deletions include/powsybl/iidm/LoadingLimitsAdder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace powsybl {

namespace iidm {

class OperationalLimitsHolder;
class OperationalLimitsOwner;

template <typename L, typename A>
class LoadingLimitsAdder : public OperationalLimitsAdder<L> {
public:
class TemporaryLimitAdder {
public:
TemporaryLimitAdder(OperationalLimitsHolder& owner, LoadingLimitsAdder<L, A>& parent);
TemporaryLimitAdder(OperationalLimitsOwner& owner, LoadingLimitsAdder<L, A>& parent);

LoadingLimitsAdder<L, A>& endTemporaryLimit();

Expand All @@ -42,7 +42,7 @@ class LoadingLimitsAdder : public OperationalLimitsAdder<L> {
void checkAndGetUniqueName();

private:
OperationalLimitsHolder& m_owner;
OperationalLimitsOwner& m_owner;

LoadingLimitsAdder<L, A>& m_parent;

Expand All @@ -58,7 +58,7 @@ class LoadingLimitsAdder : public OperationalLimitsAdder<L> {
};

public:
explicit LoadingLimitsAdder(OperationalLimitsHolder& owner);
explicit LoadingLimitsAdder(OperationalLimitsOwner& owner);

LoadingLimitsAdder(const LoadingLimitsAdder&) = default;

Expand Down Expand Up @@ -86,7 +86,7 @@ class LoadingLimitsAdder : public OperationalLimitsAdder<L> {
const LoadingLimits::TemporaryLimits& getTemporaryLimits() const;

protected:
OperationalLimitsHolder& m_owner;
OperationalLimitsOwner& m_owner;

private:
LoadingLimitsAdder<L, A>& addTemporaryLimit(const std::string& name, double value, unsigned long acceptableDuration, bool fictitious);
Expand Down
6 changes: 3 additions & 3 deletions include/powsybl/iidm/LoadingLimitsAdder.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <boost/range/adaptor/map.hpp>

#include <powsybl/iidm/OperationalLimitsHolder.hpp>
#include <powsybl/iidm/OperationalLimitsOwner.hpp>
#include <powsybl/iidm/ValidationException.hpp>
#include <powsybl/iidm/ValidationUtils.hpp>
#include <powsybl/logging/Logger.hpp>
Expand All @@ -25,7 +25,7 @@ namespace powsybl {
namespace iidm {

template <typename L, typename A>
LoadingLimitsAdder<L, A>::TemporaryLimitAdder::TemporaryLimitAdder(OperationalLimitsHolder& owner, LoadingLimitsAdder<L, A>& parent) :
LoadingLimitsAdder<L, A>::TemporaryLimitAdder::TemporaryLimitAdder(OperationalLimitsOwner& owner, LoadingLimitsAdder<L, A>& parent) :
m_owner(owner),
m_parent(parent) {
}
Expand Down Expand Up @@ -92,7 +92,7 @@ typename LoadingLimitsAdder<L, A>::TemporaryLimitAdder& LoadingLimitsAdder<L, A>
}

template <typename L, typename A>
LoadingLimitsAdder<L, A>::LoadingLimitsAdder(OperationalLimitsHolder& owner) :
LoadingLimitsAdder<L, A>::LoadingLimitsAdder(OperationalLimitsOwner& owner) :
m_owner(owner) {
}

Expand Down
6 changes: 3 additions & 3 deletions include/powsybl/iidm/OperationalLimits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,7 +35,7 @@ class OperationalLimits {
void remove();

protected:
OperationalLimitsHolder& m_owner;
OperationalLimitsOwner& m_owner;
};

} // namespace iidm
Expand Down
9 changes: 5 additions & 4 deletions include/powsybl/iidm/OperationalLimitsHolder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <powsybl/iidm/LimitType.hpp>
#include <powsybl/iidm/OperationalLimits.hpp>
#include <powsybl/iidm/OperationalLimitsOwner.hpp>
#include <powsybl/iidm/Validable.hpp>
#include <powsybl/stdcxx/range.hpp>
#include <powsybl/stdcxx/reference.hpp>
Expand All @@ -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<OperationalLimits> setOperationalLimits(const LimitType& limitType, std::unique_ptr<OperationalLimits>&& operationalLimits) override;

public:
OperationalLimitsHolder(Identifiable& identifiable, std::string&& attributeName);

Expand Down Expand Up @@ -64,9 +68,6 @@ class OperationalLimitsHolder : public Validable {

CurrentLimitsAdder newCurrentLimits();

template <typename T>
stdcxx::Reference<T> setOperationalLimits(const LimitType& limitType, std::unique_ptr<T>&& operationalLimits);

private:
friend class FlowsLimitsHolder;

Expand Down
11 changes: 0 additions & 11 deletions include/powsybl/iidm/OperationalLimitsHolder.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ stdcxx::Reference<T> OperationalLimitsHolder::getOperationalLimits(const LimitTy
return stdcxx::ref(const_cast<const OperationalLimitsHolder*>(this)->getOperationalLimits<const T>(type));
}

template <typename T>
stdcxx::Reference<T> OperationalLimitsHolder::setOperationalLimits(const LimitType& limitType, std::unique_ptr<T>&& operationalLimits) {
if (!operationalLimits) {
m_operationalLimits.erase(limitType);
} else {
m_operationalLimits[limitType] = std::move(operationalLimits);
return stdcxx::ref<T>(dynamic_cast<T&>(*m_operationalLimits.find(limitType)->second));
}
return stdcxx::ref<T>();
}

} // namespace iidm

} // namespace powsybl
Expand Down
44 changes: 44 additions & 0 deletions include/powsybl/iidm/OperationalLimitsOwner.hpp
Original file line number Diff line number Diff line change
@@ -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 <memory>

#include <powsybl/iidm/LimitType.hpp>
#include <powsybl/iidm/Validable.hpp>
#include <powsybl/stdcxx/reference.hpp>

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<OperationalLimits> setOperationalLimits(const LimitType& limitType, std::unique_ptr<OperationalLimits>&& operationalLimits) = 0;
};

} // namespace iidm

} // namespace powsybl

#endif // POWSYBL_IIDM_OPERATIONALLIMITSOWNER_HPP
2 changes: 1 addition & 1 deletion src/iidm/ActivePowerLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
5 changes: 3 additions & 2 deletions src/iidm/ActivePowerLimitsAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivePowerLimits>(m_owner, getPermanentLimit(), getTemporaryLimits())).get();
auto limit = m_owner.setOperationalLimits(LimitType::ACTIVE_POWER, stdcxx::make_unique<ActivePowerLimits>(m_owner, getPermanentLimit(), getTemporaryLimits()));
return static_cast<ActivePowerLimits&>(limit.get());
}

} // namespace iidm
Expand Down
2 changes: 1 addition & 1 deletion src/iidm/ApparentPowerLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
5 changes: 3 additions & 2 deletions src/iidm/ApparentPowerLimitsAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApparentPowerLimits>(m_owner, getPermanentLimit(), getTemporaryLimits())).get();
auto limit = m_owner.setOperationalLimits(LimitType::APPARENT_POWER, stdcxx::make_unique<ApparentPowerLimits>(m_owner, getPermanentLimit(), getTemporaryLimits()));
return static_cast<ApparentPowerLimits&>(limit.get());
}

} // namespace iidm
Expand Down
2 changes: 1 addition & 1 deletion src/iidm/CurrentLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
5 changes: 3 additions & 2 deletions src/iidm/CurrentLimitsAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CurrentLimits>(m_owner, getPermanentLimit(), getTemporaryLimits())).get();
auto limit = m_owner.setOperationalLimits(LimitType::CURRENT, stdcxx::make_unique<CurrentLimits>(m_owner, getPermanentLimit(), getTemporaryLimits()));
return static_cast<CurrentLimits&>(limit.get());
}

} // namespace iidm
Expand Down
2 changes: 1 addition & 1 deletion src/iidm/LoadingLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/iidm/OperationalLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace powsybl {

namespace iidm {

OperationalLimits::OperationalLimits(OperationalLimitsHolder& owner) :
OperationalLimits::OperationalLimits(OperationalLimitsOwner& owner) :
m_owner(owner) {
}

Expand Down
10 changes: 10 additions & 0 deletions src/iidm/OperationalLimitsHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ void OperationalLimitsHolder::setIdentifiable(Identifiable& identifiable) {
m_identifiable = identifiable;
}

stdcxx::Reference<OperationalLimits> OperationalLimitsHolder::setOperationalLimits(const LimitType& limitType, std::unique_ptr<OperationalLimits>&& 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<OperationalLimits>();
}

} // namespace iidm

} // namespace powsybl

0 comments on commit e8c99e2

Please sign in to comment.