Skip to content

Commit

Permalink
Move Boundary classes formulas as util (#364)
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien LAIGRE <[email protected]>
  • Loading branch information
sebalaig authored and mathbagu committed Jan 19, 2022
1 parent f426272 commit 388768a
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 89 deletions.
88 changes: 88 additions & 0 deletions include/powsybl/iidm/util/AbstractHalfLineBoundary.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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_UTIL_ABSTRACTHALFLINEBOUNDARY_HPP
#define POWSYBL_IIDM_UTIL_ABSTRACTHALFLINEBOUNDARY_HPP

#include <powsybl/iidm/Boundary.hpp>

namespace powsybl {

namespace iidm {

class Bus;
class Terminal;
class TieLine;

namespace tie_line {

class HalfLine;

} // namespace tie_line

namespace util {

namespace half_line {

class AbstractHalfLineBoundary : public Boundary {
// side represents the network side.
// side here is Side.ONE for the half line 1 of a tie line.
// side is Side.TWO for the half line 2 of a tie line.

public: // iidm::Boundary
double getAngle() const override;

double getP() const override;

double getQ() const override;

stdcxx::optional<Branch::Side> getSide() const override;

double getV() const override;

const VoltageLevel& getVoltageLevel() const override;

VoltageLevel& getVoltageLevel() override;

public:
AbstractHalfLineBoundary(tie_line::HalfLine& halfLine, const Branch::Side& side);

AbstractHalfLineBoundary(const Boundary&) = delete;

AbstractHalfLineBoundary(Boundary&&) = delete;

~AbstractHalfLineBoundary() noexcept override = default;

AbstractHalfLineBoundary& operator=(const AbstractHalfLineBoundary&) = delete;

AbstractHalfLineBoundary& operator=(AbstractHalfLineBoundary&&) noexcept = delete;

protected:
const tie_line::HalfLine& getParent() const;

tie_line::HalfLine& getParent();

private:
const TieLine& getTieLine() const;

TieLine& getTieLine();

private:
tie_line::HalfLine& m_parent;

Branch::Side m_side;
};

} // namespace half_line

} // namespace util

} // namespace iidm

} // namespace powsybl

#endif // POWSYBL_IIDM_UTIL_ABSTRACTHALFLINEBOUNDARY_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace iidm {
class Bus;
class DanglingLine;

namespace util {

namespace dangling_line {

class Boundary : public iidm::Boundary {
Expand Down Expand Up @@ -63,6 +65,8 @@ class Boundary : public iidm::Boundary {

} // namespace dangling_line

} // namespace util

} // namespace iidm

} // namespace powsybl
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ set(IIDM_SOURCES
iidm/CurrentLimitsAdder.cpp
iidm/DanglingLine.cpp
iidm/DanglingLineAdder.cpp
iidm/DanglingLineBoundary.cpp
iidm/DanglingLineGeneration.cpp
iidm/DanglingLineGenerationAdder.cpp
iidm/EnergySource.cpp
Expand Down Expand Up @@ -198,7 +197,9 @@ set(IIDM_SOURCES
iidm/extensions/SlackTerminalAdder.cpp
iidm/extensions/SlackTerminalXmlSerializer.cpp

iidm/util/AbstractHalfLineBoundary.cpp
iidm/util/ConnectedComponents.cpp
iidm/util/DanglingLineBoundary.cpp
iidm/util/DistinctPredicate.cpp
iidm/util/Identifiables.cpp
iidm/util/LimitViolationUtils.cpp
Expand Down
5 changes: 2 additions & 3 deletions src/iidm/DanglingLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#include <powsybl/iidm/ValidationUtils.hpp>
#include <powsybl/iidm/VariantManager.hpp>

#include "DanglingLineBoundary.hpp"
#include <powsybl/iidm/util/DanglingLineBoundary.hpp>

namespace powsybl {

Expand All @@ -29,7 +28,7 @@ DanglingLine::DanglingLine(VariantManagerHolder& network, const std::string& id,
m_q0(network.getVariantManager().getVariantArraySize(), checkQ0(*this, q0)),
m_ucteXnodeCode(ucteXnodeCode),
m_generation(std::move(generation)),
m_boundary(stdcxx::make_unique<dangling_line::Boundary>(*this)) {
m_boundary(stdcxx::make_unique<util::dangling_line::Boundary>(*this)) {

if (m_generation) {
m_generation->attach(*this);
Expand Down
51 changes: 3 additions & 48 deletions src/iidm/HalfLineBoundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,15 @@ namespace iidm {
namespace half_line {

Boundary::Boundary(tie_line::HalfLine& halfline, const Branch::Side& side) :
m_parent(halfline),
m_side(side) {
}

double Boundary::getAngle() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), iidm::Boundary::getV(b), iidm::Boundary::getAngle(b), m_side).otherSideA(m_parent);
util::half_line::AbstractHalfLineBoundary(halfline, side) {
}

const Connectable& Boundary::getConnectable() const {
return m_parent.getParent();
return getParent().getParent();
}

Connectable& Boundary::getConnectable() {
return m_parent.getParent();
}

double Boundary::getP() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), iidm::Boundary::getV(b), iidm::Boundary::getAngle(b), m_side).otherSideP(m_parent);
}

double Boundary::getQ() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), iidm::Boundary::getV(b), iidm::Boundary::getAngle(b), m_side).otherSideQ(m_parent);
}

stdcxx::optional<Branch::Side> Boundary::getSide() const {
return m_side;
}

const TieLine& Boundary::getTieLine() const {
return dynamic_cast<const TieLine&>(getConnectable());
}

TieLine& Boundary::getTieLine() {
return dynamic_cast<TieLine&>(getConnectable());
}

double Boundary::getV() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), iidm::Boundary::getV(b), iidm::Boundary::getAngle(b), m_side).otherSideU(m_parent);
}

const VoltageLevel& Boundary::getVoltageLevel() const {
return getTieLine().getTerminal(m_side).getVoltageLevel();
}

VoltageLevel& Boundary::getVoltageLevel() {
return getTieLine().getTerminal(m_side).getVoltageLevel();
return getParent().getParent();
}

} // namespace half_line
Expand Down
38 changes: 2 additions & 36 deletions src/iidm/HalfLineBoundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,24 @@
#ifndef POWSYBL_IIDM_HALFLINEBOUNDARY_HPP
#define POWSYBL_IIDM_HALFLINEBOUNDARY_HPP

#include <powsybl/iidm/Boundary.hpp>
#include <powsybl/iidm/util/AbstractHalfLineBoundary.hpp>

namespace powsybl {

namespace iidm {

namespace tie_line {

class HalfLine;

} // namespace tie_line

class Bus;
class Terminal;
class TieLine;

namespace half_line {

class Boundary : public iidm::Boundary {
class Boundary : public util::half_line::AbstractHalfLineBoundary {
// side represents the network side.
// side here is Side.ONE for the half line 1 of a tie line.
// side is Side.TWO for the half line 2 of a tie line.

public: // iidm::Boundary
double getAngle() const override;

const Connectable& getConnectable() const override;

Connectable& getConnectable() override;

double getP() const override;

double getQ() const override;

stdcxx::optional<Branch::Side> getSide() const override;

double getV() const override;

const VoltageLevel& getVoltageLevel() const override;

VoltageLevel& getVoltageLevel() override;

public:
Boundary(tie_line::HalfLine& halfLine, const Branch::Side& side);

Expand All @@ -62,16 +38,6 @@ class Boundary : public iidm::Boundary {
Boundary& operator=(const Boundary&) = delete;

Boundary& operator=(Boundary&&) noexcept = delete;

private:
const TieLine& getTieLine() const;

TieLine& getTieLine();

private:
tie_line::HalfLine& m_parent;

Branch::Side m_side;
};

} // namespace half_line
Expand Down
87 changes: 87 additions & 0 deletions src/iidm/util/AbstractHalfLineBoundary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* 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/util/AbstractHalfLineBoundary.hpp>

#include <powsybl/iidm/Bus.hpp>
#include <powsybl/iidm/HalfLine.hpp>
#include <powsybl/iidm/Terminal.hpp>
#include <powsybl/iidm/TieLine.hpp>
#include <powsybl/iidm/util/SV.hpp>

namespace powsybl {

namespace iidm {

namespace util {

namespace half_line {

AbstractHalfLineBoundary::AbstractHalfLineBoundary(tie_line::HalfLine& halfline, const Branch::Side& side) :
m_parent(halfline),
m_side(side) {
}

double AbstractHalfLineBoundary::getAngle() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), Boundary::getV(b), Boundary::getAngle(b), m_side).otherSideA(m_parent);
}

double AbstractHalfLineBoundary::getP() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), Boundary::getV(b), Boundary::getAngle(b), m_side).otherSideP(m_parent);
}

const tie_line::HalfLine& AbstractHalfLineBoundary::getParent() const {
return m_parent;
}

tie_line::HalfLine& AbstractHalfLineBoundary::getParent() {
return m_parent;
}

double AbstractHalfLineBoundary::getQ() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), Boundary::getV(b), Boundary::getAngle(b), m_side).otherSideQ(m_parent);
}

stdcxx::optional<Branch::Side> AbstractHalfLineBoundary::getSide() const {
return m_side;
}

const TieLine& AbstractHalfLineBoundary::getTieLine() const {
return dynamic_cast<const TieLine&>(getConnectable());
}

TieLine& AbstractHalfLineBoundary::getTieLine() {
return dynamic_cast<TieLine&>(getConnectable());
}

double AbstractHalfLineBoundary::getV() const {
const Terminal& t = getTieLine().getTerminal(m_side);
const auto& b = t.getBusView().getBus();
return SV(t.getP(), t.getQ(), Boundary::getV(b), Boundary::getAngle(b), m_side).otherSideU(m_parent);
}

const VoltageLevel& AbstractHalfLineBoundary::getVoltageLevel() const {
return getTieLine().getTerminal(m_side).getVoltageLevel();
}

VoltageLevel& AbstractHalfLineBoundary::getVoltageLevel() {
return getTieLine().getTerminal(m_side).getVoltageLevel();
}

} // namespace half_line

} // namespace util

} // namespace iidm

} // namespace powsybl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "DanglingLineBoundary.hpp"
#include <powsybl/iidm/util/DanglingLineBoundary.hpp>

#include <powsybl/iidm/Bus.hpp>
#include <powsybl/iidm/DanglingLine.hpp>
Expand All @@ -17,6 +17,8 @@ namespace powsybl {

namespace iidm {

namespace util {

namespace dangling_line {

Boundary::Boundary(DanglingLine& parent) :
Expand Down Expand Up @@ -69,6 +71,8 @@ VoltageLevel& Boundary::getVoltageLevel() {

} // namespace dangling_line

} // namespace util

} // namespace iidm

} // namespace powsybl

0 comments on commit 388768a

Please sign in to comment.