Skip to content

Commit

Permalink
Add IdentifiableShortCircuit extension
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien LAIGRE <[email protected]>
  • Loading branch information
sebalaig committed May 11, 2022
1 parent a970c01 commit a69b496
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 0 deletions.
3 changes: 3 additions & 0 deletions extensions/iidm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
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
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
66 changes: 66 additions & 0 deletions extensions/iidm/src/IdentifiableShortCircuit.cpp
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
54 changes: 54 additions & 0 deletions extensions/iidm/src/IdentifiableShortCircuitAdder.cpp
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
68 changes: 68 additions & 0 deletions extensions/iidm/test/IdentifiableShortCircuitTest.cpp
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

0 comments on commit a69b496

Please sign in to comment.