deltaFlow
DatFileWriter Class Referencefinal

Writes the detailed data file (.dat) with full input/output records. More...

#include <DatFileWriter.H>

Public Member Functions

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.
 

Detailed Description

Writes the detailed data file (.dat) with full input/output records.

Definition at line 42 of file DatFileWriter.H.

Member Function Documentation

◆ write()

bool DatFileWriter::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.

Parameters
jobNameJob name (used as output filename stem).
inputFilePath to the input data file.
solverNameName of the solver method used.
formatNameName of the input file format.
busDataSolved bus data.
branchDataBranch data.
iterationHistoryVector of (iteration, error) pairs.
totalIterationsTotal number of iterations performed.
finalErrorFinal convergence error.
toleranceConvergence tolerance.
convergedWhether the solver converged.
elapsedSecWall-clock time in seconds.
basemvaSystem base MVA (default: 100).
Returns
true on success, false if file could not be opened.

Definition at line 31 of file DatFileWriter.C.

45 {
46 std::string datFile = jobName + ".dat";
47 std::ofstream out(datFile);
48 if (!out.is_open()) return false;
49
50 int nBus = busData.V.size();
51 int nBranch = branchData.From.size();
52 int W = Display::pageWidth;
53
54 out << Display::fileBanner();
55 out << fmt::format("\n deltaFlow v{:<32s}Date {:>14s} Time {:>8s}\n",
57
58 out << Display::sectionHeader("I N P U T P R O C E S S I N G");
59 out << fmt::format(" Input File : {}\n", inputFile);
60 out << fmt::format(" Input Format : {}\n", formatName);
61
62 auto counts = OutputFileCommon::countBusTypes(busData);
63
64 out << fmt::format(" Number of Buses : {:>6d}\n", nBus);
65 out << fmt::format(" Slack Buses : {:>6d}\n", counts.nSlack);
66 out << fmt::format(" PV Buses : {:>6d}\n", counts.nPV);
67 out << fmt::format(" PQ Buses : {:>6d}\n", counts.nPQ);
68 out << fmt::format(" Number of Branches : {:>6d}\n", nBranch);
69 out << fmt::format(" Base MVA : {:>10.1f}\n", basemva);
70
71 std::string solverBanner;
72 for (const char &c : solverName) {
73 solverBanner += std::toupper(c);
74 solverBanner += ' ';
75 }
76 out << Display::sectionHeader(solverBanner + " S O L V E R E X E C U T I O N");
77 out << fmt::format(" Method : {}\n", solverName);
78 out << fmt::format(" Max Iterations : {:>6d}\n", static_cast<int>(iterationHistory.size()) > 0 ?
79 static_cast<int>(iterationHistory.back().first) : totalIterations);
80 out << fmt::format(" Convergence Tol. : {:.6e}\n", tolerance);
81 out << "\n";
82
83 out << fmt::format(" {:>6s} {:>16s} {:>12s} {:>8s}\n",
84 "Iter", "Max Mismatch", "Tolerance", "Status");
85 out << " " << std::string(W - 4, '-') << "\n";
86
87 for (const auto& [iter, error] : iterationHistory) {
88 std::string status;
89 if (error < tolerance)
90 status = "CONV";
91 else
92 status = "----";
93 out << fmt::format(" {:>6d} {:>16.6e} {:>12.6e} {:>8s}\n",
94 iter, error, tolerance, status);
95 }
96
97 out << " " << std::string(W - 4, '-') << "\n";
98 out << "\n";
99
100 if (converged) {
101 out << fmt::format(" {} CONVERGED after {} iterations.\n", solverName, totalIterations);
102 out << fmt::format(" Final max mismatch = {:.6e}\n", finalError);
103 } else {
104 out << fmt::format(" *** WARNING: {} DID NOT CONVERGE after {} iterations.\n", solverName, totalIterations);
105 out << fmt::format(" Final max mismatch = {:.6e}\n", finalError);
106 }
107
108 out << Display::sectionHeader("B U S D A T A R E S U L T S");
109 out << fmt::format(" {:>4s} {:>9s} {:>9s} {:>10s} {:>10s} {:>10s} {:>10s} {:>10s}\n",
110 "Bus", "Voltage", "Angle", "Load", "Load", "Gen", "Gen", "Injected");
111 out << fmt::format(" {:>4s} {:>9s} {:>9s} {:>10s} {:>10s} {:>10s} {:>10s} {:>10s}\n",
112 "No.", "Mag.", "Degree", "MW", "Mvar", "MW", "Mvar", "Mvar");
113 out << " " << std::string(W - 4, '=') << "\n";
114
115 for (int i = 0; i < nBus; ++i) {
116 double injectedMvar = busData.Qg(i) - busData.Ql(i);
117 out << fmt::format(" {:>4d} {:>9.4f} {:>9.4f} {:>10.4f} {:>10.4f} {:>10.4f} {:>10.4f} {:>10.4f}\n",
118 i + 1, busData.V(i), busData.delta(i),
119 busData.Pl(i), busData.Ql(i), busData.Pg(i), busData.Qg(i), injectedMvar);
120 }
121
122 out << " " << std::string(W - 4, '=') << "\n";
123
124 auto totals = OutputFileCommon::computeBusTotals(busData);
125
126 out << fmt::format(" Total{:>27.4f} {:>10.4f} {:>10.4f} {:>10.4f} {:>10.4f}\n",
127 totals.totalPl, totals.totalQl, totals.totalPg, totals.totalQg, totals.totalInjected);
128
129 out << "\n\n";
130 out << " JOB TIME SUMMARY\n";
131 out << fmt::format(" TOTAL CPU TIME (SEC) = {:>12.5f}\n", elapsedSec);
132 out << fmt::format(" WALLCLOCK TIME (SEC) = {:>12d}\n", static_cast<int>(std::round(elapsedSec)));
133 out << "\n";
134
135 out << Display::sectionHeader("A N A L Y S I S C O M P L E T E");
136 if (converged) {
137 out << Display::center("THE ANALYSIS HAS BEEN COMPLETED SUCCESSFULLY") << "\n";
138 } else {
139 out << Display::center("*** THE ANALYSIS HAS NOT CONVERGED ***") << "\n";
140 }
141 out << "\n";
142
143 out.close();
144 return true;
145}
std::string center(const std::string &text)
Returns a centered string within the page width.
Definition Display.H:91
constexpr int pageWidth
Standard output page width.
Definition Display.H:51
std::string sectionHeader(const std::string &title)
Returns a section header for output files.
Definition Display.H:226
std::string fileBanner()
Returns a full plain-text banner for output/log files.
Definition Display.H:217
std::string dateStr()
Returns the current date string.
BusTotals computeBusTotals(const BusData &busData)
Computes total load/gen/injected Mvar across all buses.
std::string timeStr()
Returns the current time string.
BusTypeCounts countBusTypes(const BusData &busData)
Counts buses by type (1=Slack, 2=PV, else PQ).
Eigen::VectorXi From
From bus indices.
Definition Data.H:84
Eigen::VectorXd Ql
Reactive power load [MVAr or p.u.].
Definition Data.H:65
Eigen::VectorXd V
Voltage magnitude [p.u.].
Definition Data.H:60
Eigen::VectorXd Pg
Active power generation [MW or p.u.].
Definition Data.H:62
Eigen::VectorXd delta
Voltage angle [rad or deg].
Definition Data.H:61
Eigen::VectorXd Pl
Active power load [MW or p.u.].
Definition Data.H:64
Eigen::VectorXd Qg
Reactive power generation [MVAr or p.u.].
Definition Data.H:63

References Display::center(), OutputFileCommon::computeBusTotals(), OutputFileCommon::countBusTypes(), OutputFileCommon::dateStr(), BusData::delta, Display::fileBanner(), BranchData::From, Display::pageWidth, BusData::Pg, BusData::Pl, BusData::Qg, BusData::Ql, Display::sectionHeader(), OutputFileCommon::timeStr(), and BusData::V.

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

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