OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
show.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
36#ifndef PFC_UTILS_SHOW
37#define PFC_UTILS_SHOW
38
39#include "typename.hpp"
40#include <array>
41#include <complex>
42#include <iomanip>
43#include <iostream>
44#include <vector>
45
46namespace pfc {
47namespace utils {
48
49template <typename T>
50void show(const std::vector<T> &data, const std::array<int, 3> &size,
51 const std::array<int, 3> &offsets) {
52 std::cout << size[0] << "×" << size[1] << "×" << size[2] << " Array<3, "
53 << pfc::TypeName<T>::get() << ">:" << std::endl;
54 for (int k = 0; k < size[2]; ++k) {
55 std::cout << "[:, :, " << offsets[2] + k << "] = " << std::endl;
56 for (int i = 0; i < size[0]; ++i) {
57 for (int j = 0; j < size[1]; ++j) {
58 int idx = k * size[0] * size[1] + j * size[0] + i;
59 std::cout << std::setw(9) << std::setprecision(6) << std::fixed << data[idx]
60 << " ";
61 }
62 std::cout << std::endl;
63 }
64 std::cout << std::endl;
65 }
66}
67
68template <typename T>
69void show(const std::vector<T> &data, const std::array<int, 2> &size,
70 [[maybe_unused]] const std::array<int, 2> &offsets) {
71 std::cout << size[0] << "×" << size[1] << " Array<2, " << pfc::TypeName<T>::get()
72 << ">:" << std::endl;
73 for (int i = 0; i < size[0]; ++i) {
74 for (int j = 0; j < size[1]; ++j) {
75 size_t idx = j * size[0] + i;
76 std::cout << std::setw(9) << std::setprecision(6) << std::fixed << data[idx]
77 << " ";
78 }
79 std::cout << std::endl;
80 }
81}
82
83} // namespace utils
84} // namespace pfc
85
86#endif
Definition typename.hpp:48
Get human-readable type names at runtime.