deltaFlow
MsgFileWriter.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 "MsgFileWriter.H"
22
23#include <fstream>
24
25#include <fmt/core.h>
26
27#include "Display.H"
28#include "OutputFileCommon.H"
29#include "Version.H"
30
32 const std::string& jobName,
33 const std::string& solverName,
34 const std::vector<std::pair<int, double>>& iterationHistory,
35 double tolerance,
36 bool converged
37) const {
38 std::string msgFile = jobName + ".msg";
39 std::ofstream out(msgFile);
40 if (!out.is_open()) return false;
41
42 out << Display::fileBanner();
43
44 out << fmt::format("\n deltaFlow v{:<32s}Date {:>14s} Time {:>8s}\n",
46 out << "\n";
47
48 out << Display::sectionHeader("I T E R A T I O N H I S T O R Y");
49
50 out << fmt::format(" {:>6s} {:>16s} {:>12s} {:>8s}\n",
51 "Iter", "Max Mismatch", "Tolerance", "Status");
52 out << " " << std::string(Display::pageWidth - 4, '-') << "\n";
53
54 for (const auto& [iter, error] : iterationHistory) {
55 std::string status = (error < tolerance) ? "CONV" : "";
56 out << fmt::format(" {:>6d} {:>16.6e} {:>12.6e} {:>8s}\n",
57 iter, error, tolerance, status);
58 }
59
60 out << " " << std::string(Display::pageWidth - 4, '-') << "\n";
61 out << "\n";
62
63 if (converged) {
64 out << " " << solverName << " CONVERGED\n";
65 } else {
66 out << " *** WARNING: " << solverName << " DID NOT CONVERGE\n";
67 }
68
69 out << "\n";
70 out.close();
71 return true;
72}
Display and formatting utilities for terminal and file output.
Writer for the iteration-history message file (.msg).
Shared helpers (hostname/timestamp, bus-type counting, loss calc) used by the OutputFile writer class...
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.
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.
std::string timeStr()
Returns the current time string.