deltaFlow
ISolver.H
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Saud Zahir
3 *
4 * This file is part of deltaFlow.
5 *
6 * deltaFlow is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * deltaFlow is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with deltaFlow. If not, see
18 * <https://www.gnu.org/licenses/>.
19 */
20
35#ifndef ISOLVER_H
36#define ISOLVER_H
37
38#include <Eigen/Dense>
39#include <utility>
40#include <vector>
41
50 // Common admittance representation.
51 const Eigen::MatrixXcd* Y = nullptr;
52 const Eigen::MatrixXd* G = nullptr;
53 const Eigen::MatrixXd* B = nullptr;
54
55 // State (in/out).
56 Eigen::VectorXd* V = nullptr;
57 Eigen::VectorXd* delta = nullptr;
58
59 // Bus classification.
60 Eigen::VectorXi* type_bus = nullptr;
61 const std::vector<int>* pq_bus_id = nullptr;
62
63 // Scheduled power injections.
64 const Eigen::VectorXd* P = nullptr;
65 const Eigen::VectorXd* Q = nullptr;
66
67 // Sizes.
68 int N = 0;
69 int n_pq = 0;
70
71 // Solver tuning.
72 int maxIter = 1024;
73 double tolerance = 1E-8;
74 double omega = 1.0;
75
76 // Diagnostics.
77 std::vector<std::pair<int, double>>* iterHistory = nullptr;
78 class ISolverObserver* observer = nullptr;
79};
80
94 public:
95 virtual ~ISolverObserver() = default;
96
98 virtual void onIteration(const char* solverName, int iter, int maxIter, double error, double tolerance) = 0;
99
101 virtual void onFinished(const char* solverName, bool converged, int iter, int maxIter, double error, double tolerance) = 0;
102
104 virtual void onMessage(const char* solverName, const char* message) = 0;
105};
106
115class ISolver {
116 public:
117 virtual ~ISolver() = default;
118
124 virtual bool solve(SolverContext& ctx) = 0;
125
129 virtual const char* name() const = 0;
130};
131
132#endif
Common interface for power-flow solvers.
Definition ISolver.H:115
virtual bool solve(SolverContext &ctx)=0
Run the power-flow solver using the given context.
virtual ~ISolver()=default
virtual const char * name() const =0
Human-readable solver name (e.g.
Sink for solver progress/diagnostics (Dependency Inversion / SRP).
Definition ISolver.H:93
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.
virtual ~ISolverObserver()=default
Shared input/output parameters for power-flow solvers.
Definition ISolver.H:49
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
const Eigen::MatrixXd * G
Conductance matrix (used by Newton-Raphson).
Definition ISolver.H:52
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
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
double omega
Relaxation coefficient (Gauss-Seidel only).
Definition ISolver.H:74
const std::vector< int > * pq_bus_id
0-based PQ bus indices (Newton-Raphson).
Definition ISolver.H:61