deltaFlow
Admittance Class Referencefinal

Computes the complex bus admittance matrix ($$ Y_{bus} $$). More...

#include <Admittance.H>

Static Public Member Functions

static Eigen::MatrixXcd build (const BusData &busData, const BranchData &branchData, ISolverObserver *observer=nullptr)
 Computes the complex bus admittance matrix ($$ Y_{bus} $$).
 

Detailed Description

Computes the complex bus admittance matrix ($$ Y_{bus} $$).

Definition at line 51 of file Admittance.H.

Member Function Documentation

◆ build()

Eigen::MatrixXcd Admittance::build ( const BusData busData,
const BranchData branchData,
ISolverObserver observer = nullptr 
)
static

Computes the complex bus admittance matrix ($$ Y_{bus} $$).

This builds the bus admittance matrix, which is essential in solving power flow equations in electrical networks. The admittance matrix is computed using the provided bus and branch data.

Parameters
busDataData representing the buses in the network.
branchDataData representing the branches (lines/transformers) in the network.
observerOptional injected log observer (DIP); nullptr means silent.
Returns
Eigen::MatrixXcd The computed $$ Y_{bus} $$ matrix as a complex matrix.

Definition at line 34 of file Admittance.C.

34 {
35 int nLine = branchData.From.size();
36 int N = std::max(branchData.From.maxCoeff(), branchData.To.maxCoeff()); // 1-based bus indexing
37
38 Eigen::MatrixXcd Ybus = Eigen::MatrixXcd::Zero(N, N); // Size N x N, 0-based indexing internally
39
40 for (int k = 0; k < nLine; ++k) {
41 int from = branchData.From(k) - 1; // Convert to 0-based
42 int to = branchData.To(k) - 1; // Convert to 0-based
43
44 std::complex<double> Z(branchData.R(k), branchData.X(k));
45 std::complex<double> Y = 1.0 / Z;
46
47 std::complex<double> B(0.0, 0.5 * branchData.B(k));
48
49 double a = branchData.tapRatio(k);
50 if (a == 0.0) {
51 a = 1.0;
52 }
53
54 // Off-diagonal
55 Ybus(from, to) -= Y / a;
56 Ybus(to, from) = Ybus(from, to); // Symmetric
57
58 // Diagonal
59 Ybus(from, from) += Y / (a * a) + B;
60 Ybus(to, to) += Y + B;
61 }
62
63 // Add shunt admittances
64 int nBuses = busData.ID.size(); // Should match Gs and Bs size
65
66 for (int n = 0; n < nBuses; ++n) {
67 int busIndex = busData.ID(n) - 1; // Convert to 0-based
68
69 if (busIndex < 0 || busIndex >= Ybus.rows()) {
70 if (observer) {
71 std::string msg = fmt::format("Warning: Bus ID {} out of bounds in Ybus", busIndex + 1);
72 observer->onMessage("Admittance", msg.c_str());
73 }
74 continue;
75 }
76
77 std::complex<double> Y_shunt(busData.Gs(n), busData.Bs(n));
78 Ybus(busIndex, busIndex) += Y_shunt;
79 }
80
81 return Ybus;
82}
virtual void onMessage(const char *solverName, const char *message)=0
Called for solver-specific diagnostic/warning messages (e.g.
Eigen::VectorXd tapRatio
Transformer tap ratio ($$ a $$)
Definition Data.H:90
Eigen::VectorXd B
Line susceptance ($$ B $$) [p.u.].
Definition Data.H:89
Eigen::VectorXd X
Reactance ($$ X $$) [p.u.].
Definition Data.H:87
Eigen::VectorXi From
From bus indices.
Definition Data.H:84
Eigen::VectorXd R
Resistance ($$ R $$) [p.u.].
Definition Data.H:86
Eigen::VectorXi To
To bus indices.
Definition Data.H:85
Eigen::VectorXi ID
Bus numbers.
Definition Data.H:56
Eigen::VectorXd Gs
Shunt conductance ($$ G_{sh} $$) [p.u.].
Definition Data.H:68
Eigen::VectorXd Bs
Shunt susceptance ($$ B_{sh} $$) [p.u.].
Definition Data.H:69

References BranchData::B, BusData::Bs, BranchData::From, BusData::Gs, BusData::ID, ISolverObserver::onMessage(), BranchData::R, BranchData::tapRatio, BranchData::To, and BranchData::X.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: