Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* IO_ADIOS2.cpp
*
* Created on: Feb 2017
* Author: Norbert Podhorszki
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include "IO.h"
static std::ofstream of;
static std::streambuf *buf;
IO::IO( std::string output_basename, MPI_Comm comm )
{
m_outputfilename = output_basename;
if (m_outputfilename == "cout")
{
buf = std::cout.rdbuf();
}
else
{
int rank;
MPI_Comm_rank( comm, &rank );
std::string rs = std::to_string(rank);
of.open(output_basename + rs + ".txt");
buf = of.rdbuf();
}
}
IO::~IO()
{
if (m_outputfilename != "cout")
{
of.close();
}
}
void IO::write( int step, std::shared_ptr<HeatTransfer> ht, std::shared_ptr<Settings> s, MPI_Comm comm)
{
std::ostream out(buf);
if( step == 1)
{
out << "rank=" << s->rank
<< " size=" << s->ndx << "x" << s->ndy
<< " offsets=" << s->offsx << ":" << s->offsy
<< " step=" << step << std::endl;
out << " time row columns " << s->offsy << "..." << s->offsy+s->ndy-1 << std::endl;
out << " ";
for (int j = 1; j <= s->ndy; ++j) {
out << std::setw(9) << s->offsy+j-1;
}
out << "\n--------------------------------------------------------------\n";
}
else
{
out << std::endl;
}
for (int i = 1; i <= s->ndx; ++i)
{
out << std::setw(5) << step << std::setw(5) << s->offsx+i-1;
for (int j = 1; j <= s->ndy; ++j)
{
out << std::setw(9) << ht->T(i,j);
}
out << std::endl;
}
}