deltaFlow
StaFileWriter.C
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
21#include "StaFileWriter.H"
22
23#include <fstream>
24
25#include <fmt/core.h>
26
27#include "OutputFileCommon.H"
28#include "Version.H"
29
31 const std::string& jobName,
32 const std::string& inputFile,
33 const std::string& solverName,
34 const std::string& formatName,
35 int nBus,
36 int nBranch,
37 int iterations,
38 double finalError,
39 double tolerance,
40 bool converged,
41 double elapsedSec
42) const {
43 std::string staFile = jobName + ".sta";
44 std::ofstream out(staFile);
45 if (!out.is_open()) return false;
46
47 out << fmt::format("deltaFlow v{:<36s}Date {:>14s} Time {:>8s}\n",
49
50 out << " SUMMARY OF JOB INFORMATION:\n";
51 out << fmt::format(" {:>6s} {:>6s} {:>10s} {:>12s} {:>12s} {:>8s}\n",
52 "ITER", "STATUS", "ERROR", "TOLERANCE", "ELAPSED", "RESULT");
53
54 out << fmt::format(" {:>6d} {:>6s} {:>10.3e} {:>12.3e} {:>12.3f} {:>8s}\n",
55 iterations,
56 converged ? "CONV" : "FAIL",
57 finalError,
58 tolerance,
59 elapsedSec,
60 converged ? "OK" : "FAILED");
61
62 out << "\n";
63 if (converged) {
64 out << " THE ANALYSIS HAS COMPLETED SUCCESSFULLY\n";
65 } else {
66 out << " THE ANALYSIS HAS FAILED TO CONVERGE\n";
67 }
68
69 out << "\n";
70 out << "Jobinfo File:\n";
71 out << fmt::format("Inputfile: {}\n", inputFile);
72 out << fmt::format("Solver: {}\n", solverName);
73 out << fmt::format("Format: {}\n", formatName);
74 out << fmt::format("Hostname: {}\n", OutputFileCommon::hostname());
75 out << "\n";
76
77 out << "solver and hardware info\n";
78 out << "------------------------\n";
79 out << fmt::format("version : {}\n", deltaFlow_VERSION);
80 out << fmt::format("compiler : GCC {}\n", gcc_VERSION);
81 out << fmt::format("cmake : {}\n", CMake_VERSION);
82 out << fmt::format("hostname : {}\n", OutputFileCommon::hostname());
83 out << "\n";
84
85 out << "model info\n";
86 out << "----------\n";
87 out << fmt::format(" # of buses : {}\n", nBus);
88 out << fmt::format(" # of branches : {}\n", nBranch);
89 out << "\n";
90
91 out << "run and timing info\n";
92 out << "-------------------\n";
93 out << fmt::format("simulation end : {}\n", OutputFileCommon::timestamp());
94 out << fmt::format("elapsed time : {:.3f} seconds\n", elapsedSec);
95 out << fmt::format("iterations : {}\n", iterations);
96 out << fmt::format("final error : {:.6e}\n", finalError);
97 out << fmt::format("termination status: {}\n", converged ? "normal" : "failed");
98 out << "\n";
99
100 out.close();
101 return true;
102}
Shared helpers (hostname/timestamp, bus-type counting, loss calc) used by the OutputFile writer class...
Writer for the compact status output file (.sta).
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.
std::string timestamp()
Returns the current timestamp string.
std::string hostname()
Returns the current hostname.
std::string dateStr()
Returns the current date string.
std::string timeStr()
Returns the current time string.