Debian Codegraph @

examples/simulations/heatTransfer/read/PrintDataStep.h

raw
1 /*
2 * SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef PRINTDATASTEP_H_
8 #define PRINTDATASTEP_H_
9
10 #include <cstdint>
11 #include <fstream>
12 #include <iomanip>
13 #include <iostream>
14 #include <string>
15
16 template <class T>
17 void printDataStep(double *xy, T *size, T *offset, int rank, int step)
18 {
19 std::ofstream myfile;
20 std::string filename = "data." + std::to_string(rank);
21 if (step == 0)
22 {
23 myfile.open(filename);
24 }
25 else
26 {
27 myfile.open(filename, std::ios::app);
28 }
29 double *data = xy;
30 uint64_t nelems = size[0] * size[1];
31 myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1] << " offsets=" << offset[0]
32 << ":" << offset[1] << " step=" << step << std::endl;
33
34 myfile << " time row columns " << offset[1] << "..." << offset[1] + size[1] - 1
35 << std::endl;
36 myfile << " ";
37 for (int j = 0; j < size[1]; j++)
38 {
39 myfile << std::setw(9) << offset[1] + j;
40 }
41 myfile << std::endl;
42 myfile << "------------------------------------------------------------"
43 "--\n";
44 for (int i = 0; i < size[0]; i++)
45 {
46 myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
47 for (int j = 0; j < size[1]; j++)
48 {
49 myfile << std::setw(9) << std::setprecision(2) << data[i * size[1] + j];
50 }
51 myfile << std::endl;
52 }
53 data += nelems;
54 myfile.close();
55 }
56
57 #endif /* PRINTDATASTEP_H_ */