56 const Eigen::MatrixXd& G,
57 const Eigen::MatrixXd& B,
58 const Eigen::VectorXd& Ps,
59 const Eigen::VectorXd& Qs,
61 Eigen::VectorXd& delta,
64 const std::vector<int>& pq_bus_id,
67 std::vector<std::pair<int, double>>* iterHistory,
71 Eigen::VectorXd P(n_bus), Q(n_bus);
74 double error = mismatch.cwiseAbs().maxCoeff();
79 iterHistory->emplace_back(0, error);
82 while (error >= tolerance) {
83 if (iter >= maxIter) {
84 if (observer) observer->
onFinished(
"Newton-Raphson",
false, iter, maxIter, error, tolerance);
90 Eigen::MatrixXd J =
Jacobian::compute(V, delta, n_bus, n_pq, pq_bus_id, G, B, P, Q);
93 Eigen::VectorXd correction = J.colPivHouseholderQr().solve(mismatch);
96 for (
int i = 1; i < n_bus; ++i) {
97 delta(i) += correction(i - 1);
101 for (
int k = 0; k < n_pq; ++k) {
102 V(pq_bus_id[k]) += correction(n_bus - 1 + k);
108 error = mismatch.cwiseAbs().maxCoeff();
109 if (iterHistory) iterHistory->emplace_back(iter, error);
110 if (observer) observer->
onIteration(
"Newton-Raphson", iter, maxIter, error, tolerance);
113 if (observer) observer->
onFinished(
"Newton-Raphson",
true, iter, maxIter, error, tolerance);
Data structures and utility functions for reading and displaying bus and branch data in power system ...
Jacobian matrix computation for Newton-Raphson power flow analysis.
Declaration of the Newton-Raphson load flow solver for power system analysis.
Power mismatch computation for Newton-Raphson power flow analysis.
Utility functions and helpers for deltaFlow.
Sink for solver progress/diagnostics (Dependency Inversion / SRP).
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.
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.
bool solve(SolverContext &ctx) override
Run the Newton-Raphson solver using the given context.
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.
Shared input/output parameters for power-flow solvers.
const Eigen::VectorXd * Q
Scheduled reactive power injections (Qg - Ql).
double tolerance
Convergence tolerance.
Eigen::VectorXd * V
Voltage magnitudes [p.u.].
const Eigen::VectorXd * P
Scheduled active power injections (Pg - Pl).
int maxIter
Maximum number of iterations.
int N
Total number of buses.
Eigen::VectorXd * delta
Voltage angles [rad].
const Eigen::MatrixXd * G
Conductance matrix (used by Newton-Raphson).
class ISolverObserver * observer
Optional injected progress/log observer (DIP); nullptr = silent.
const Eigen::MatrixXd * B
Susceptance matrix (used by Newton-Raphson).
std::vector< std::pair< int, double > > * iterHistory
Optional iteration history sink.
int n_pq
Number of PQ buses (Newton-Raphson).
const std::vector< int > * pq_bus_id
0-based PQ bus indices (Newton-Raphson).