flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
vofmom_probe.cpp
Go to the documentation of this file.
1// Q6 diagnosis (case A, bubble_column_perf/validation/Q6_DIAG.md): replay ONE momentum-consistent
2// VoF advection (vof::MomentumConsistentAdvector, rung V2b) on a solver state dumped by
3// probe_vofmom_rho.py and write the half-shifted colour C^e — the density rho^e of the control
4// volume that carried the momentum — which the Python API does not expose. The advected velocity
5// and the new colour are written too, so the replay is checked against the solver's own
6// (diagnostics.vof_advected_velocity, get_vof) before C^e is trusted.
7//
8// usage: vofmom_probe DIR
9// in : DIR/meta.txt "n dth step rho_g rho_l wisp_eps cfl_limit muscl"
10// DIR/{C,u,v,w}.bin n^3 doubles, x fastest; u, v, w in the SOLVER's low-face convention
11// (u[i] is the -x face of cell i), velocities and dth = dt/h in consistent units
12// out: DIR/{Ce0,Ce1,Ce2}_seed.bin C^e at the START of the advection (clipped from C^n planes)
13// DIR/{Ce0,Ce1,Ce2}.bin C^e after the advection, solver indexing (CV_c(i) = u_c(i))
14// DIR/{ua0,ua1,ua2}.bin, DIR/Cnew.bin
15#include <cstdio>
16#include <fstream>
17#include <Kokkos_Core.hpp>
18#include <stdexcept>
19#include <string>
20#include <vector>
21
22#include "vof/colour_field.hpp"
24
25namespace {
29namespace vf = peclet::flow::vof;
30
31std::vector<double> readBin(const std::string& p, long len) {
32 std::vector<double> v(len);
33 std::ifstream f(p, std::ios::binary);
34 if (!f.read(reinterpret_cast<char*>(v.data()), len * static_cast<long>(sizeof(double))))
35 throw std::runtime_error("short read: " + p);
36 return v;
37}
38
39void writeBin(const std::string& p, const std::vector<double>& v) {
40 std::ofstream f(p, std::ios::binary);
41 f.write(reinterpret_cast<const char*>(v.data()), static_cast<long>(v.size() * sizeof(double)));
42}
43
44// Inner cell (x,y,z) of the extended block <- src[(x+sx)%n, (y+sy)%n, (z+sz)%n].
45void putInner(SField dst, I3 e, int g, int n, const std::vector<double>& src, int sx, int sy,
46 int sz) {
47 auto h = Kokkos::create_mirror_view(dst);
48 Kokkos::deep_copy(h, dst);
49 for (int z = 0; z < n; ++z)
50 for (int y = 0; y < n; ++y)
51 for (int x = 0; x < n; ++x)
52 h(L3(g + x, g + y, g + z, e)) =
53 src[((x + sx) % n) + n * (((y + sy) % n) + n * ((z + sz) % n))];
54 Kokkos::deep_copy(dst, h);
55}
56
57std::vector<double> getInner(SField src, I3 e, int g, int n) {
58 auto h = Kokkos::create_mirror_view(src);
59 Kokkos::deep_copy(h, src);
60 std::vector<double> v(static_cast<long>(n) * n * n);
61 for (int z = 0; z < n; ++z)
62 for (int y = 0; y < n; ++y)
63 for (int x = 0; x < n; ++x)
64 v[x + n * (y + n * z)] = h(L3(g + x, g + y, g + z, e));
65 return v;
66}
67} // namespace
68
69int main(int argc, char** argv) {
70 if (argc != 2) {
71 std::fprintf(stderr, "usage: vofmom_probe DIR\n");
72 return 2;
73 }
74 const std::string dir = argv[1];
75 Kokkos::initialize(argc, argv);
76 {
77 int n = 0, muscl = 0;
78 long step = 0;
79 double dth = 0, rg = 0, rl = 0, weps = 0, cfl = 0;
80 {
81 std::ifstream m(dir + "/meta.txt");
82 if (!(m >> n >> dth >> step >> rg >> rl >> weps >> cfl >> muscl))
83 throw std::runtime_error("bad meta.txt");
84 }
85 const long len = static_cast<long>(n) * n * n;
86 vf::WyAdvector w;
87 w.init(n, n, n, 1.0, 3); // h = 1, as the solver (cell units); dth carries dt/h
88 w.cflLimit = cfl;
89 w.interfaceLocalCfl = true;
90 w.wispEps = weps;
91 const I3 e = w.extent();
92 const int g = w.ghost();
93 w.exchange = [e, g](SField f) { vf::periodicFill(f, e, g, true, true, true); };
94
95 putInner(w.colour(), e, g, n, readBin(dir + "/C.bin", len), 0, 0, 0);
96 const char* vn[3] = {"/u.bin", "/v.bin", "/w.bin"};
97 for (int d = 0; d < 3; ++d) // u_advector(i) = u_solver(i + s_d) (vof/colour_field.hpp)
98 putInner(w.faceVel(d), e, g, n, readBin(dir + vn[d], len), d == 0, d == 1, d == 2);
99 w.exchange(w.colour());
100 for (int d = 0; d < 3; ++d)
101 w.exchange(w.faceVel(d));
102
103 vf::MomentumConsistentAdvector mom;
104 mom.init(w, rg, rl);
105 mom.momentumScheme = muscl != 0 ? vf::MomentumScheme::MusclMixed : vf::MomentumScheme::Upwind;
106 // The seed C^e, exactly as advect() builds it (planes of C^n).
107 w.reconstruct();
108 mom.buildShiftedColour(w);
109 for (int c = 0; c < 3; ++c)
110 writeBin(dir + "/Ce" + std::to_string(c) + "_seed.bin",
111 getInner(mom.shiftedColour(c), e, g, n));
112
113 mom.advect(w, dth, step); // dt in cell units = dt/h, as the solver passes dt_ with h = 1
114 for (int c = 0; c < 3; ++c) {
115 writeBin(dir + "/Ce" + std::to_string(c) + ".bin", getInner(mom.shiftedColour(c), e, g, n));
116 writeBin(dir + "/ua" + std::to_string(c) + ".bin",
117 getInner(mom.advectedVelocity(c), e, g, n));
118 }
119 writeBin(dir + "/Cnew.bin", getInner(w.colour(), e, g, n));
120 const auto dg = mom.diagnostics();
121 std::printf(
122 "VOFMOM_PROBE n=%d step=%ld floored=%ld clamped=%ld minRhoC=%.6e sumM0=%.17g "
123 "sumM=%.17g\n",
124 n, step, dg.floored, mom.clampedFluxes(), dg.minRhoC, dg.sumM0[0], dg.sumM[0]);
125 }
126 Kokkos::finalize();
127 return 0;
128}
flow — VoF rung V2a (WO-J): the bridge between the solver's G = 2 block and the colour field's own g ...
flow — VoF rung V2b (WO-K): momentum-consistent transport of rho^c u_c on the half-shifted (MAC) mome...
y
Definition cmp.py:24
Kokkos::View< double *, SMem > SField
long L3(int x, int y, int z, I3 e)
Kokkos::View< double *, SMem > SField
long L3(int x, int y, int z, I3 e)