deltaFlow
GaussSeidel Class Referencefinal

Gauss-Seidel power flow solver implementing the ISolver interface. More...

#include <GaussSeidel.H>

Inheritance diagram for GaussSeidel:
Collaboration diagram for GaussSeidel:

Public Member Functions

bool solve (SolverContext &ctx) override
 Run the Gauss-Seidel solver using the given context.
 
const char * name () const override
 Human-readable solver name (e.g.
 
- Public Member Functions inherited from ISolver
virtual ~ISolver ()=default
 

Static Public Member Functions

static bool run (const Eigen::MatrixXcd &Y, Eigen::VectorXd &V, Eigen::VectorXd &delta, const Eigen::VectorXi &type_bus, const Eigen::VectorXd &P, const Eigen::VectorXd &Q, int N, int maxIter=1024, double tolerance=1E-8, double omega=1.0, std::vector< std::pair< int, double > > *iterHistory=nullptr, ISolverObserver *observer=nullptr)
 Solves the power flow equations using the Gauss-Seidel iterative method.
 

Detailed Description

Gauss-Seidel power flow solver implementing the ISolver interface.

Pure solver: no Q-limit checking (handled by outer loop via checkQlimits). PV buses maintain their scheduled voltage magnitude; PQ buses are fully updated.

Definition at line 88 of file GaussSeidel.H.

Member Function Documentation

◆ name()

const char * GaussSeidel::name ( ) const
inlineoverridevirtual

Human-readable solver name (e.g.

for logging/output).

Implements ISolver.

Definition at line 97 of file GaussSeidel.H.

97{ return "Gauss-Seidel"; }

◆ run()

bool GaussSeidel::run ( const Eigen::MatrixXcd &  Y,
Eigen::VectorXd &  V,
Eigen::VectorXd &  delta,
const Eigen::VectorXi &  type_bus,
const Eigen::VectorXd &  P,
const Eigen::VectorXd &  Q,
int  N,
int  maxIter = 1024,
double  tolerance = 1E-8,
double  omega = 1.0,
std::vector< std::pair< int, double > > *  iterHistory = nullptr,
ISolverObserver observer = nullptr 
)
static

Solves the power flow equations using the Gauss-Seidel iterative method.

Parameters
YThe bus admittance matrix ($$ Y_{bus} $$).
V(in/out) Voltage magnitudes [p.u.]. PV buses maintain scheduled value.
delta(in/out) Voltage angles [rad].
type_busBus type vector (1=Slack, 2=PV, 3=PQ).
PScheduled net active power injections [p.u.] ($$ P_g - P_l $$).
QScheduled net reactive power injections [p.u.] ($$ Q_g - Q_l $$). Used only for PQ buses.
NTotal number of buses.
maxIterMaximum number of iterations (default: 1024).
toleranceConvergence tolerance for bus voltage updates (default: $$ 1 \times 10^{-8} $$).
omegaRelaxation parameter for the Successive Over-Relaxation (SOR) method (default: 1.0; SOR not applied).
iterHistoryOptional pointer to store iteration number and error at each step.
observerOptional injected progress/log observer (DIP); nullptr means silent (pure solve).
Returns
true if the algorithm converged within the specified number of iterations, false otherwise.

Definition at line 50 of file GaussSeidel.C.

63 {
64 // Store scheduled voltage magnitudes for PV buses
65 Eigen::VectorXd Vmag_sched = Vmag;
66
67 // Initialize complex voltage vector
68 Eigen::VectorXcd V(N);
69 for (int i = 0; i < N; ++i)
70 V(i) = std::polar(Vmag(i), delta(i));
71
72 int iteration = 0;
73 double error = std::numeric_limits<double>::infinity();
74
75 if (omega <= 0.0 || omega >= 2.0) {
76 if (observer) observer->onMessage("Gauss-Seidel", "Invalid input: Relaxation coefficient must be between 0 and 2. Setting Relaxation coefficient to 1.");
77 omega = 1.0;
78 }
79
80 if (observer) {
81 if (omega < 1.0) {
82 observer->onMessage("Gauss-Seidel", "Under-relaxation enabled (omega < 1), this will slow down convergence.");
83 } else if (omega == 1.0) {
84 observer->onMessage("Gauss-Seidel", "Standard Gauss-Seidel enabled (omega = 1).");
85 } else {
86 observer->onMessage("Gauss-Seidel", "Over-relaxation enabled (omega > 1), this will accelerate convergence.");
87 }
88 }
89
90 while (error >= tolerance && iteration < maxIter) {
91 Eigen::VectorXcd dV = Eigen::VectorXcd::Zero(N);
92
93 for (int n = 0; n < N; ++n) {
94 if (type_bus(n) == 1) continue; // Skip slack bus
95
96 std::complex<double> In = Y.row(n) * V;
97
98 if (type_bus(n) == 2) { // PV Bus
99 // Compute Q from current solution (no clamping)
100 double Qn = -std::imag(std::conj(V(n)) * In);
101
102 // GS update maintaining scheduled voltage magnitude
103 std::complex<double> I_excl = In - Y(n, n) * V(n);
104 std::complex<double> V_updated = ((P(n) - std::complex<double>(0, 1) * Qn) / std::conj(V(n)) - I_excl) / Y(n, n);
105 std::complex<double> V_corrected = Vmag_sched(n) * V_updated / std::abs(V_updated);
106 dV(n) = V_corrected - V(n);
107 V(n) = V_corrected;
108
109 } else if (type_bus(n) == 3) { // PQ Bus
110 std::complex<double> I_excl = In - Y(n, n) * V(n);
111 std::complex<double> V_updated = ((P(n) - std::complex<double>(0, 1) * Q(n)) / std::conj(V(n)) - I_excl) / Y(n, n);
112 std::complex<double> V_relaxed = V(n) + omega * (V_updated - V(n));
113 dV(n) = V_relaxed - V(n);
114 V(n) = V_relaxed;
115 }
116 }
117
118 error = dV.norm();
119 iteration++;
120 if (iterHistory) iterHistory->emplace_back(iteration, error);
121 if (observer) observer->onIteration("Gauss-Seidel", iteration, maxIter, error, tolerance);
122 }
123
124 if (iteration >= maxIter) {
125 if (observer) observer->onFinished("Gauss-Seidel", false, iteration, maxIter, error, tolerance);
126 return false;
127 }
128
129 // Extract converged V magnitudes and angles
130 for (int i = 0; i < N; ++i) {
131 Vmag(i) = std::abs(V(i));
132 delta(i) = std::arg(V(i));
133 }
134
135 if (observer) observer->onFinished("Gauss-Seidel", true, iteration, maxIter, error, tolerance);
136
137 return true;
138}
virtual void onIteration(const char *solverName, int iter, int maxIter, double error, double tolerance)=0
Called after every iteration with the current error/tolerance.
virtual void onFinished(const char *solverName, bool converged, int iter, int maxIter, double error, double tolerance)=0
Called once after the iteration loop ends (converged or not).
virtual void onMessage(const char *solverName, const char *message)=0
Called for solver-specific diagnostic/warning messages (e.g.

References ISolverObserver::onFinished(), ISolverObserver::onIteration(), and ISolverObserver::onMessage().

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

◆ solve()

bool GaussSeidel::solve ( SolverContext ctx)
overridevirtual

Run the Gauss-Seidel solver using the given context.

Parameters
ctxSolver context (in/out parameters; see SolverContext).
Returns
true if the algorithm converged within the specified number of iterations.

Implements ISolver.

Definition at line 33 of file GaussSeidel.C.

33 {
34 return GaussSeidel::run(
35 *ctx.Y,
36 *ctx.V,
37 *ctx.delta,
38 *ctx.type_bus,
39 *ctx.P,
40 *ctx.Q,
41 ctx.N,
42 ctx.maxIter,
43 ctx.tolerance,
44 ctx.omega,
45 ctx.iterHistory,
46 ctx.observer
47 );
48}
static bool run(const Eigen::MatrixXcd &Y, Eigen::VectorXd &V, Eigen::VectorXd &delta, const Eigen::VectorXi &type_bus, const Eigen::VectorXd &P, const Eigen::VectorXd &Q, int N, int maxIter=1024, double tolerance=1E-8, double omega=1.0, std::vector< std::pair< int, double > > *iterHistory=nullptr, ISolverObserver *observer=nullptr)
Solves the power flow equations using the Gauss-Seidel iterative method.
Definition GaussSeidel.C:50
const Eigen::VectorXd * Q
Scheduled reactive power injections (Qg - Ql).
Definition ISolver.H:65
double tolerance
Convergence tolerance.
Definition ISolver.H:73
Eigen::VectorXd * V
Voltage magnitudes [p.u.].
Definition ISolver.H:56
const Eigen::MatrixXcd * Y
Bus admittance matrix (used by Gauss-Seidel).
Definition ISolver.H:51
const Eigen::VectorXd * P
Scheduled active power injections (Pg - Pl).
Definition ISolver.H:64
int maxIter
Maximum number of iterations.
Definition ISolver.H:72
int N
Total number of buses.
Definition ISolver.H:68
Eigen::VectorXd * delta
Voltage angles [rad].
Definition ISolver.H:57
Eigen::VectorXi * type_bus
Bus type vector (1=Slack, 2=PV, 3=PQ).
Definition ISolver.H:60
class ISolverObserver * observer
Optional injected progress/log observer (DIP); nullptr = silent.
Definition ISolver.H:78
std::vector< std::pair< int, double > > * iterHistory
Optional iteration history sink.
Definition ISolver.H:77
double omega
Relaxation coefficient (Gauss-Seidel only).
Definition ISolver.H:74

References SolverContext::delta, SolverContext::iterHistory, SolverContext::maxIter, SolverContext::N, SolverContext::observer, SolverContext::omega, SolverContext::P, SolverContext::Q, run(), SolverContext::tolerance, SolverContext::type_bus, SolverContext::V, and SolverContext::Y.

Here is the call graph for this function:

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