| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: Apache-2.0 |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "IO.h" |
| 8 |
|
| 9 |
#include <fstream> |
| 10 |
#include <iomanip> |
| 11 |
#include <iostream> |
| 12 |
|
| 13 |
static std::ofstream of; |
| 14 |
static std::streambuf *buf; |
| 15 |
|
| 16 |
IO::IO(const Settings &s, MPI_Comm comm) |
| 17 |
{ |
| 18 |
m_outputfilename = s.outputfile; |
| 19 |
|
| 20 |
if (m_outputfilename == "cout") |
| 21 |
{ |
| 22 |
buf = std::cout.rdbuf(); |
| 23 |
} |
| 24 |
else |
| 25 |
{ |
| 26 |
m_outputfilename = MakeFilename(s.outputfile, ".txt", s.rank); |
| 27 |
of.open(m_outputfilename); |
| 28 |
buf = of.rdbuf(); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
IO::~IO() |
| 33 |
{ |
| 34 |
if (m_outputfilename != "cout") |
| 35 |
{ |
| 36 |
of.close(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) |
| 41 |
{ |
| 42 |
std::ostream out(buf); |
| 43 |
if (step == 0) |
| 44 |
{ |
| 45 |
out << "rank=" << s.rank << " size=" << s.ndx << "x" << s.ndy << " offsets=" << s.offsx |
| 46 |
<< ":" << s.offsy << " step=" << step << std::endl; |
| 47 |
out << " time row columns " << s.offsy << "..." << s.offsy + s.ndy - 1 << std::endl; |
| 48 |
out << " "; |
| 49 |
for (unsigned int j = 1; j <= s.ndy; ++j) |
| 50 |
{ |
| 51 |
out << std::setw(9) << s.offsy + j - 1; |
| 52 |
} |
| 53 |
out << "\n-------------------------------------------------------------" |
| 54 |
"-\n"; |
| 55 |
} |
| 56 |
else |
| 57 |
{ |
| 58 |
out << std::endl; |
| 59 |
} |
| 60 |
|
| 61 |
out << std::fixed; |
| 62 |
for (unsigned int i = 1; i <= s.ndx; ++i) |
| 63 |
{ |
| 64 |
out << std::setw(5) << step << std::setw(5) << s.offsx + i - 1; |
| 65 |
for (unsigned int j = 1; j <= s.ndy; ++j) |
| 66 |
{ |
| 67 |
out << std::setw(9) << std::setprecision(5) << ht.T(i, j); |
| 68 |
} |
| 69 |
out << std::endl; |
| 70 |
} |
| 71 |
} |