44 : options_(std::move(options)) {}
61 LOG_ERROR(
"No bus or branch data found in '{}'. Check the file exists and is valid.", inputFile);
70 int nSlack = 0, nPV = 0, nPQ = 0;
71 for (
int i = 0; i <
N_; ++i) {
76 LOG_DEBUG(
"Bus types: {} Slack, {} PV, {} PQ", nSlack, nPV, nPQ);
88 for (
int i = 0; i <
N_; ++i) {
105 Eigen::MatrixXd G =
Y_.array().real().matrix();
106 Eigen::MatrixXd B =
Y_.array().imag().matrix();
114 bool Q_lim_status =
true;
116 while (Q_lim_status) {
120 std::vector<int> pq_indices;
121 std::vector<int> pv_indices;
123 for (
int i = 0; i <
N_; ++i) {
124 if (
typeBus_(i) == 3) pq_indices.push_back(i);
125 else if (
typeBus_(i) == 2) pv_indices.push_back(i);
139 ctx.
n_pq =
static_cast<int>(pq_indices.size());
146 bool converged = solverImpl->solve(ctx);
168 Eigen::VectorXcd Vc(
N_);
169 for (
int i = 0; i <
N_; ++i)
170 Vc(i) = std::polar(
V_(i),
delta_(i));
176 for (
int i = 0; i <
N_; ++i) {
178 std::complex<double> Ii =
Y_.row(i) * Vc;
179 std::complex<double> Si = Vc(i) * std::conj(Ii);
180 P_net(i) = Si.real();
181 Q_net(i) = Si.imag();
186 for (
int i = 0; i <
N_; ++i) {
188 std::complex<double> Ii =
Y_.row(i) * Vc;
189 Q_net(i) = -std::imag(std::conj(Vc(i)) * Ii);
193 for (
int i = 0; i <
N_; ++i) {
202 LOG_DEBUG(
"Total real power loss: {:.6f} p.u.", PLoss);
203 LOG_DEBUG(
"Total reactive power loss: {:.6f} p.u.", QLoss);
240 auto startTime = std::chrono::high_resolution_clock::now();
252 auto endTime = std::chrono::high_resolution_clock::now();
253 double elapsedSec = std::chrono::duration<double>(endTime - startTime).count();
260 auto endTime = std::chrono::high_resolution_clock::now();
261 double elapsedSec = std::chrono::duration<double>(endTime - startTime).count();
267 " THE ANALYSIS HAS BEEN COMPLETED SUCCESSFULLY\n");
269 fmt::print(
" Elapsed time : {:.3f} sec\n", elapsedSec);
Declaration of a class for constructing the bus admittance matrix ($$ Y_{bus} $$) in power system ana...
Command-line argument parsing utilities for deltaFlow.
InputFormat
Supported input file formats.
SolverType
Types of solvers supported by deltaFlow.
Writer for the detailed data output file (.dat).
Display and formatting utilities for terminal and file output.
Logger utilities for deltaFlow, providing logging macros and a singleton Logger class.
#define LOG_INFO(msg,...)
Macro for logging an info-level message.
#define LOG_DEBUG(msg,...)
Macro for logging a debug-level message.
#define LOG_ERROR(msg,...)
Macro for logging an error-level message.
Concrete ISolverObserver that reports to the Logger singleton and the terminal progress bar (Dependen...
Writer for the iteration-history message file (.msg).
Writer for the main analysis output file (.out).
Orchestrates a full deltaFlow power-flow analysis run (SRP).
Reactive power limit (Q-limit) checking for PV buses.
Factory for constructing Reader instances from InputFormat, so callers (e.g.
Factory for constructing ISolver instances from SolverType, so callers (e.g.
Writer for the compact status output file (.sta).
void dispBusData(const BusData &busData)
Displays bus data in a human-readable format.
void dispLineFlow(const BusData &busData, const BranchData &branchData, const Eigen::MatrixXcd &Y, double basemva)
Displays the line flow results, including power flow and losses.
bool writeOutputCSV(const BusData &busData)
Writes bus data results to a CSV file.
Output utilities for writing power system analysis results to CSV files.
static Eigen::MatrixXcd build(const BusData &busData, const BranchData &branchData, ISolverObserver *observer=nullptr)
Computes the complex bus admittance matrix ($$ Y_{bus} $$).
Writes the detailed data file (.dat) with full input/output records.
bool write(const std::string &jobName, const std::string &inputFile, const std::string &solverName, const std::string &formatName, const BusData &busData, const BranchData &branchData, const std::vector< std::pair< int, double > > &iterationHistory, int totalIterations, double finalError, double tolerance, bool converged, double elapsedSec, double basemva=100.0) const
Writes the detailed data file (.dat) with full input/output records.
Reports solver progress to the Logger singleton and terminal progress bar.
Writes the message file (.msg) with iteration history.
bool write(const std::string &jobName, const std::string &solverName, const std::vector< std::pair< int, double > > &iterationHistory, double tolerance, bool converged) const
Writes the message file (.msg) with iteration history.
Writes the main output file (.out) with full analysis results.
bool write(const std::string &jobName, const std::string &inputFile, const std::string &solverName, const std::string &formatName, const BusData &busData, const BranchData &branchData, const Eigen::MatrixXcd &Y, int iterations, double finalError, double tolerance, double elapsedSec, double basemva=100.0) const
Writes the main output file (.out) with full analysis results.
std::unique_ptr< Reader > reader_
PowerFlowApplication(PowerFlowOptions options)
Construct the application from already-parsed command-line options.
void loadInput()
Reads and validates the input file via ReaderFactory.
void writeFailureStatus(double elapsedSec) const
Writes only the status file, used on the non-convergence early-exit path.
void finalizeResults()
Recomputes slack/PV bus power injections and updates busData_ post-solve.
void writeOutputs(double elapsedSec) const
Writes all output files (.out, .sta, .dat, .msg) and CSV/terminal display.
int run()
Runs the full analysis pipeline: load input, solve, apply Q-limits, recompute results,...
PowerFlowOptions options_
void solve()
Runs the selected solver, re-running on Q-limit violations.
std::vector< std::pair< int, double > > iterationHistory_
void prepareModel()
Computes Y_bus and sets up the flat-start voltage/angle vectors.
static bool check(const Eigen::VectorXd &V, const Eigen::VectorXd &delta, Eigen::VectorXi &type_bus, const Eigen::MatrixXd &G, const Eigen::MatrixXd &B, BusData &busData, const std::vector< int > &pv_bus_id, int n_bus, ISolverObserver *observer=nullptr)
Checks reactive power limits on PV buses after solver convergence.
static std::unique_ptr< Reader > create(InputFormat format)
Construct a concrete reader for the given input format.
static std::unique_ptr< ISolver > create(SolverType type)
Construct a concrete solver for the given solver type.
Writes the status file (.sta) with a compact solver summary.
bool write(const std::string &jobName, const std::string &inputFile, const std::string &solverName, const std::string &formatName, int nBus, int nBranch, int iterations, double finalError, double tolerance, bool converged, double elapsedSec) const
Writes the status file (.sta) with a compact solver summary.
constexpr fmt::rgb LOGO_COLOR
deltaFlow logo color
Eigen::VectorXi From
From bus indices.
Eigen::VectorXd Ql
Reactive power load [MVAr or p.u.].
Eigen::VectorXi ID
Bus numbers.
Eigen::VectorXd V
Voltage magnitude [p.u.].
Eigen::VectorXd Pg
Active power generation [MW or p.u.].
Eigen::VectorXd delta
Voltage angle [rad or deg].
Eigen::VectorXd Pl
Active power load [MW or p.u.].
Eigen::VectorXd Qg
Reactive power generation [MVAr or p.u.].
Eigen::VectorXi Type
Bus type (1=Slack, 2=PV, 3=PQ)
Plain data holder for parsed command-line options.
std::string inputFile
Path to input file.
std::string jobName
Job name (defaults to input filename)
int maxIterations
Maximum number of iterations ($$ N_{max} $$)
double tolerance
Convergence tolerance ($$ \epsilon $$)
SolverType solverType
Solver type.
InputFormat inputFormat
Input file format.
double relaxation
Relaxation coefficient ($$ \omega $$)
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::MatrixXcd * Y
Bus admittance matrix (used by Gauss-Seidel).
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).
Eigen::VectorXi * type_bus
Bus type vector (1=Slack, 2=PV, 3=PQ).
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).
double omega
Relaxation coefficient (Gauss-Seidel only).
const std::vector< int > * pq_bus_id
0-based PQ bus indices (Newton-Raphson).