61 Kokkos::View<int*, CCMem> idMap,
int rank = 0) {
63 if (level <= 0 ||
nRows <= 0)
65 const auto h_cell = Kokkos::create_mirror_view_and_copy(
66 Kokkos::HostSpace(), Kokkos::subview(ov.cell, Kokkos::make_pair(0,
nRows)));
67 const auto h_rho = Kokkos::create_mirror_view_and_copy(
68 Kokkos::HostSpace(), Kokkos::subview(ov.rescale, Kokkos::make_pair(0,
nRows)));
69 const auto h_cpl = Kokkos::create_mirror_view_and_copy(
70 Kokkos::HostSpace(), Kokkos::subview(ov.coupled, Kokkos::make_pair(0,
nRows)));
71 const auto sub6 = Kokkos::make_pair(0, 6 *
nRows);
73 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Kokkos::subview(ov.state,
sub6));
75 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Kokkos::subview(ov.th,
sub6));
77 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Kokkos::subview(ov.wm_n1,
sub6));
79 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Kokkos::subview(ov.wm_n2,
sub6));
81 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Kokkos::subview(ov.w_n1,
sub6));
83 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), Kokkos::subview(ov.w_n2,
sub6));
84 const auto h_id = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), idMap);
86 const char*
stName[5] = {
"COUPLED",
"QUAD",
"LIN",
"BC_ONLY",
"EXPLICIT"};
87 long stCount[5] = {0, 0, 0, 0, 0};
90 long rhoDec[7] = {0, 0, 0, 0, 0, 0, 0};
91 long wDec[8] = {0, 0, 0, 0, 0, 0, 0, 0};
93 double rhoMin = 1.0,
wMax = 0.0;
96 for (
int s = 0; s <
nRows; ++s) {
99 const float rho =
h_rho(s);
100 rhoMin = rho < rhoMin ? rho : rhoMin;
101 int d = rho >= 1.0f ? 6 : (int)std::floor(std::log10((
double)rho)) + 6;
102 rhoDec[d < 0 ? 0 : (d > 6 ? 6 : d)]++;
104 for (
int k = 0; k < 6; ++k) {
107 const float th =
h_th(s * 6 + k);
111 if (th <= (
float)(1e-4 * 1.0000001))
115 const float a1 = std::fabs(
h_wm1(s * 6 + k)), a2 = std::fabs(
h_wm2(s * 6 + k));
118 const float b1 = std::fabs(
h_w1(s * 6 + k)),
b2 = std::fabs(
h_w2(s * 6 + k));
125 int wd =
mw <= 1.0f ? 0 : (int)std::floor(std::log10((
double)
mw));
133 long mmDec[6] = {0, 0, 0, 0, 0, 0};
135 auto rhoAt = [&](
int x,
int y,
int z) ->
float {
141 const int s =
h_id(c);
142 return s >= 0 ?
h_rho(s) : 1.0f;
145 for (
int s = 0; s <
nRows; ++s) {
147 const int x = c %
nn.x, y = (c /
nn.x) %
nn.y, z = c / (
nn.x *
nn.y);
148 const double lr = std::log10((
double)
h_rho(s));
150 const int off[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
151 for (
auto& o : off) {
152 const double d = std::fabs(lr - std::log10((
double)
rhoAt(x + o[0], y + o[1], z + o[2])));
153 worst = d > worst ? d : worst;
158 mmDec[b < 0 ? 0 : (b > 5 ? 5 : b)]++;
161 std::printf(
"[gp] rank %d overlay census: %d rows of %ld inner cells (%.2f %%), %ld decoupled\n",
163 std::printf(
"[gp] face states:");
164 for (
int i = 0; i < 5; ++i)
166 std::printf(
"\n[gp] theta: EXTENDED(1,2)=%ld clamped-low(1e-4)=%ld clamped-high(2)=%ld\n",
169 "[gp] rho decades [1e-5,1e-4)=%ld [1e-4,1e-3)=%ld [1e-3,1e-2)=%ld "
170 "[1e-2,1e-1)=%ld [1e-1,1)=%ld ==1:%ld min=%.3e\n",
172 std::printf(
"[gp] max|w| decades");
173 for (
int i = 0; i < 8; ++i)
174 std::printf(
" 1e%d:%ld", i,
wDec[i]);
175 std::printf(
" max=%.3e\n",
wMax);
176 std::printf(
"[gp] neighbour rho mismatch |log10| bins");
177 for (
int i = 0; i < 6; ++i)
178 std::printf(
" %d:%ld", i,
mmDec[i]);
179 std::printf(
" max=%.2f decades\n",
mmMax);
182 std::vector<int>
ord((std::size_t)
nRows);
183 for (
int i = 0; i <
nRows; ++i)
184 ord[(std::size_t)i] = i;
186 std::partial_sort(
ord.begin(),
ord.begin() + show,
ord.end(),
187 [&](
int a,
int b) { return h_rho(a) < h_rho(b); });
188 std::printf(
"[gp] worst %d rows by rho:\n", show);
189 for (
int i = 0; i < show; ++i) {
190 const int s =
ord[(std::size_t)i];
192 std::printf(
"[gp] (%4d,%4d,%4d) rho=%.4e maxw=%.3e mism=%.2f |", c %
nn.x,
195 for (
int k = 0; k < 6; ++k)
196 std::printf(
" %s(th=%.3e,wm=%.3e/%.3e)",
stName[
h_st(s * 6 + k)],
h_th(s * 6 + k),
204 const char*
fenv = std::getenv(
"PECLET_FLOW_GP_DEBUG_FILE");
205 std::string path =
fenv ? std::string(
fenv) : std::string(
"gp_rows");
206 path +=
"_rank" + std::to_string(rank) +
".bin";
207 std::FILE* f = std::fopen(path.c_str(),
"wb");
209 std::printf(
"[gp] COULD NOT OPEN %s for the per-row dump\n", path.c_str());
212 for (
int s = 0; s <
nRows; ++s) {
215 const float rho =
h_rho(s);
219 for (
int k = 0; k < 6; ++k) {
220 st[k] =
h_st(s * 6 + k);
221 th[k] =
h_th(s * 6 + k);
228 std::fwrite(&rho,
sizeof(
float), 1, f);
230 std::fwrite(st,
sizeof(
int8_t), 6, f);
231 std::fwrite(th,
sizeof(
float), 6, f);
232 std::fwrite(
wm1,
sizeof(
float), 6, f);
233 std::fwrite(
wm2,
sizeof(
float), 6, f);
234 std::fwrite(
w1,
sizeof(
float), 6, f);
235 std::fwrite(
w2,
sizeof(
float), 6, f);
238 std::printf(
"[gp] per-row dump -> %s (%d records)\n", path.c_str(),
nRows);