deltaFlow
NewtonRaphson Class Referencefinal

Newton-Raphson power flow solver implementing the ISolver interface. More...

#include <NewtonRaphson.H>

Inheritance diagram for NewtonRaphson:
Collaboration diagram for NewtonRaphson:

Public Member Functions

bool solve (SolverContext &ctx) override
 Run the Newton-Raphson 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::MatrixXd &G, const Eigen::MatrixXd &B, const Eigen::VectorXd &Ps, const Eigen::VectorXd &Qs, Eigen::VectorXd &V, Eigen::VectorXd &delta, int n_bus, int n_pq, const std::vector< int > &pq_bus_id, int maxIter=1024, double tolerance=1E-8, std::vector< std::pair< int, double > > *iterHistory=nullptr, ISolverObserver *observer=nullptr)
 Solves the power flow equations using the Newton-Raphson iterative method.
 

Detailed Description

Newton-Raphson power flow solver implementing the ISolver interface.

Takes G, B matrices, scheduled power, initial voltage/angle guesses, and bus classification. It modifies V and delta in-place.

Definition at line 96 of file NewtonRaphson.H.

Member Function Documentation

◆ name()

const char * NewtonRaphson::name ( ) const
inlineoverridevirtual

Human-readable solver name (e.g.

for logging/output).

Implements ISolver.

Definition at line 105 of file NewtonRaphson.H.

105{ return "Newton-Raphson"; }

◆ run()

bool NewtonRaphson::run ( const Eigen::MatrixXd &  G,
const Eigen::MatrixXd &  B,
const Eigen::VectorXd &  Ps,
const Eigen::VectorXd &  Qs,
Eigen::VectorXd &  V,
Eigen::VectorXd &  delta,
int  n_bus,
int  n_pq,
const std::vector< int > &  pq_bus_id,
int  maxIter = 1024,
double  tolerance = 1E-8,
std::vector< std::pair< int, double > > *  iterHistory = nullptr,
ISolverObserver observer = nullptr 
)
static

Solves the power flow equations using the Newton-Raphson iterative method.

Parameters
GConductance matrix (real part of $$ Y_{bus} $$).
BSusceptance matrix (imaginary part of $$ Y_{bus} $$).
PsScheduled active power injections (Pg - Pl) [p.u.].
QsScheduled reactive power injections (Qg - Ql) [p.u.].
V(in/out) Voltage magnitudes [p.u.].
delta(in/out) Voltage angles [rad].
n_busTotal number of buses.
n_pqNumber of PQ buses.
pq_bus_id0-based indices of PQ buses.
maxIterMaximum number of iterations (default: 1024).
toleranceConvergence tolerance for power mismatches (default: $$ 1 \times 10^{-8} $$).
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 converged, false otherwise.

Definition at line 55 of file NewtonRaphson.C.

69 {
70 // Compute initial mismatch
71 Eigen::VectorXd P(n_bus), Q(n_bus);
72 Eigen::VectorXd mismatch = PowerMismatch::compute(Ps, Qs, G, B, V, delta, n_bus, pq_bus_id, P, Q);
73
74 double error = mismatch.cwiseAbs().maxCoeff();
75 int iter = 0;
76
77 if (iterHistory) {
78 iterHistory->clear();
79 iterHistory->emplace_back(0, error);
80 }
81
82 while (error >= tolerance) {
83 if (iter >= maxIter) {
84 if (observer) observer->onFinished("Newton-Raphson", false, iter, maxIter, error, tolerance);
85 return false;
86 }
87 iter++;
88
89 // Build Jacobian
90 Eigen::MatrixXd J = Jacobian::compute(V, delta, n_bus, n_pq, pq_bus_id, G, B, P, Q);
91
92 // Solve J * correction = mismatch
93 Eigen::VectorXd correction = J.colPivHouseholderQr().solve(mismatch);
94
95 // Update delta for non-slack buses (indices 1..N-1)
96 for (int i = 1; i < n_bus; ++i) {
97 delta(i) += correction(i - 1);
98 }
99
100 // Update V for PQ buses only
101 for (int k = 0; k < n_pq; ++k) {
102 V(pq_bus_id[k]) += correction(n_bus - 1 + k);
103 }
104
105 // Recompute mismatch
106 mismatch = PowerMismatch::compute(Ps, Qs, G, B, V, delta, n_bus, pq_bus_id, P, Q);
107
108 error = mismatch.cwiseAbs().maxCoeff();
109 if (iterHistory) iterHistory->emplace_back(iter, error);
110 if (observer) observer->onIteration("Newton-Raphson", iter, maxIter, error, tolerance);
111 }
112
113 if (observer) observer->onFinished("Newton-Raphson", true, iter, maxIter, error, tolerance);
114 return true;
115}
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).
static Eigen::MatrixXd compute(const Eigen::VectorXd &V, const Eigen::VectorXd &delta, int n_bus, int n_pq, const std::vector< int > &pq_bus_id, const Eigen::MatrixXd &G, const Eigen::MatrixXd &B, const Eigen::VectorXd &P, const Eigen::VectorXd &Q)
Computes the Jacobian matrix for the Newton-Raphson power flow solver.
Definition Jacobian.C:30
static Eigen::VectorXd compute(const Eigen::VectorXd &Ps, const Eigen::VectorXd &Qs, const Eigen::MatrixXd &G, const Eigen::MatrixXd &B, const Eigen::VectorXd &V, const Eigen::VectorXd &delta, int n_bus, const std::vector< int > &pq_bus_id, Eigen::VectorXd &P, Eigen::VectorXd &Q)
Computes the power mismatch vector for use in Newton-Raphson iterations.

References PowerMismatch::compute(), Jacobian::compute(), ISolverObserver::onFinished(), and ISolverObserver::onIteration().

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

◆ solve()

bool NewtonRaphson::solve ( SolverContext ctx)
overridevirtual

Run the Newton-Raphson 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 37 of file NewtonRaphson.C.

37 {
38 return NewtonRaphson::run(
39 *ctx.G,
40 *ctx.B,
41 *ctx.P,
42 *ctx.Q,
43 *ctx.V,
44 *ctx.delta,
45 ctx.N,
46 ctx.n_pq,
47 *ctx.pq_bus_id,
48 ctx.maxIter,
49 ctx.tolerance,
50 ctx.iterHistory,
51 ctx.observer
52 );
53}
static bool run(const Eigen::MatrixXd &G, const Eigen::MatrixXd &B, const Eigen::VectorXd &Ps, const Eigen::VectorXd &Qs, Eigen::VectorXd &V, Eigen::VectorXd &delta, int n_bus, int n_pq, const std::vector< int > &pq_bus_id, int maxIter=1024, double tolerance=1E-8, std::vector< std::pair< int, double > > *iterHistory=nullptr, ISolverObserver *observer=nullptr)
Solves the power flow equations using the Newton-Raphson iterative method.
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::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
const Eigen::MatrixXd * G
Conductance matrix (used by Newton-Raphson).
Definition ISolver.H:52
class ISolverObserver * observer
Optional injected progress/log observer (DIP); nullptr = silent.
Definition ISolver.H:78
const Eigen::MatrixXd * B
Susceptance matrix (used by Newton-Raphson).
Definition ISolver.H:53
std::vector< std::pair< int, double > > * iterHistory
Optional iteration history sink.
Definition ISolver.H:77
int n_pq
Number of PQ buses (Newton-Raphson).
Definition ISolver.H:69
const std::vector< int > * pq_bus_id
0-based PQ bus indices (Newton-Raphson).
Definition ISolver.H:61

References SolverContext::B, SolverContext::delta, SolverContext::G, SolverContext::iterHistory, SolverContext::maxIter, SolverContext::N, SolverContext::n_pq, SolverContext::observer, SolverContext::P, SolverContext::pq_bus_id, SolverContext::Q, run(), SolverContext::tolerance, and SolverContext::V.

Here is the call graph for this function:

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