-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IdentifiableShortCircuit extension
Signed-off-by: Sébastien LAIGRE <[email protected]>
- Loading branch information
Showing
6 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <powsybl/iidm/Extension.hpp> | ||
|
||
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>& 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 |
82 changes: 82 additions & 0 deletions
82
extensions/iidm/include/powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <powsybl/iidm/ExtensionAdder.hpp> | ||
#include <powsybl/stdcxx/math.hpp> | ||
|
||
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<Extension> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp> | ||
|
||
#include <powsybl/iidm/Identifiable.hpp> | ||
|
||
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>& extendable) const { | ||
if (extendable && !stdcxx::isInstanceOf<Identifiable>(extendable.get())) { | ||
throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable.get()), stdcxx::demangle<Identifiable>())); | ||
} | ||
} | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp> | ||
|
||
#include <powsybl/PowsyblException.hpp> | ||
#include <powsybl/iidm/Identifiable.hpp> | ||
#include <powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp> | ||
#include <powsybl/stdcxx/format.hpp> | ||
#include <powsybl/stdcxx/instanceof.hpp> | ||
|
||
namespace powsybl { | ||
|
||
namespace iidm { | ||
|
||
namespace extensions { | ||
|
||
namespace iidm { | ||
|
||
IdentifiableShortCircuitAdder::IdentifiableShortCircuitAdder(Extendable& extendable) : | ||
ExtensionAdder(extendable) { | ||
} | ||
|
||
std::unique_ptr<Extension> IdentifiableShortCircuitAdder::createExtension(Extendable& extendable) const { | ||
if (std::isnan(m_ipMax)) { | ||
throw PowsyblException("Undefined ipMax"); | ||
} | ||
if (stdcxx::isInstanceOf<Identifiable>(extendable)) { | ||
return std::unique_ptr<IdentifiableShortCircuit>(new IdentifiableShortCircuit(dynamic_cast<Identifiable&>(extendable), m_ipMin, m_ipMax)); | ||
} | ||
throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle<Identifiable>())); | ||
} | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <boost/test/unit_test.hpp> | ||
|
||
#include <powsybl/iidm/Generator.hpp> | ||
#include <powsybl/iidm/Network.hpp> | ||
#include <powsybl/iidm/extensions/iidm/IdentifiableShortCircuit.hpp> | ||
#include <powsybl/iidm/extensions/iidm/IdentifiableShortCircuitAdder.hpp> | ||
#include <powsybl/network/EurostagFactory.hpp> | ||
#include <powsybl/test/AssertionUtils.hpp> | ||
|
||
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<IdentifiableShortCircuitAdder>().withIpMin(1.1).withIpMax(2.2).add(); | ||
auto& extension = generator.getExtension<IdentifiableShortCircuit>(); | ||
|
||
BOOST_CHECK_CLOSE(1.1, extension.getIpMin(), std::numeric_limits<double>::epsilon()); | ||
BOOST_CHECK_CLOSE(2.2, extension.getIpMax(), std::numeric_limits<double>::epsilon()); | ||
|
||
BOOST_CHECK(stdcxx::areSame(extension, extension.setIpMin(11.1))); | ||
BOOST_CHECK_CLOSE(11.1, extension.getIpMin(), std::numeric_limits<double>::epsilon()); | ||
|
||
BOOST_CHECK(stdcxx::areSame(extension, extension.setIpMax(22.2))); | ||
BOOST_CHECK_CLOSE(22.2, extension.getIpMax(), std::numeric_limits<double>::epsilon()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(adder) { | ||
Network network = powsybl::network::EurostagFactory::createTutorial1Network(); | ||
Identifiable& Identifiable = network.getIdentifiable("GEN"); | ||
|
||
auto adder = Identifiable.newExtension<IdentifiableShortCircuitAdder>(); | ||
adder.withIpMin(stdcxx::nan()) | ||
.withIpMax(stdcxx::nan()); | ||
|
||
POWSYBL_ASSERT_THROW(adder.add(), PowsyblException, "Undefined ipMax"); | ||
adder.withIpMax(1.0).add(); | ||
|
||
auto& extension = Identifiable.getExtension<IdentifiableShortCircuit>(); | ||
BOOST_CHECK(std::isnan(extension.getIpMin())); | ||
BOOST_CHECK_CLOSE(1.0, extension.getIpMax(), std::numeric_limits<double>::epsilon()); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
|
||
} // namespace iidm | ||
|
||
} // namespace extensions | ||
|
||
} // namespace iidm | ||
|
||
} // namespace powsybl |