83 const int e[3] = {ln[0] + 2 *
G, ln[1] + 2 *
G, ln[2] + 2 *
G};
84 const long n = (long)e[0] * e[1] * e[2];
85 std::vector<double> col((
long)ln[0] * ln[1] * ln[2]);
86 for (
int z = 0; z < ln[2]; ++z)
87 for (
int y = 0; y < ln[1]; ++y)
88 for (
int x = 0; x < ln[0]; ++x)
89 col[x + (
long)ln[0] * (y + (long)ln[1] * z)] =
colourValue(o[0] + x, o[1] + y, o[2] + z);
91 s.setPropertyModel(
"mu", ClosureKind::LinearMix,
"C",
"", {1.0, 1e-2 - 1.0});
92 s.setViscousStress(
"full");
93 s.setVofViscousInterface(
"sharp");
95 s.resolveSharpViscous();
96 s.sharpViscousGeometry();
97 const auto st = s.sharpViscousState();
98 for (
int c = 0; c < 3; ++c) {
99 auto h = Kokkos::create_mirror_view(st.old[c]);
100 for (
int z = 0; z < e[2]; ++z)
101 for (
int y = 0; y < e[1]; ++y)
102 for (
int x = 0; x < e[0]; ++x) {
104 x >=
G && x < e[0] -
G && y >=
G && y < e[1] -
G && z >=
G && z < e[2] -
G;
105 h((
long)x + (
long)y * e[0] + (
long)z * e[0] * e[1]) =
106 inner ? 2.0 *
urand(1 + c, o[0] + x -
G, o[1] + y -
G, o[2] + z -
G) - 1.0
107 : std::numeric_limits<double>::quiet_NaN();
109 Kokkos::deep_copy(st.old[c], h);
111 s.fullStressPrelude();
115 const auto sv2 = s.sharpViscousState();
116 std::vector<std::vector<double>> cols;
118 auto cl = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), sv2.cls);
119 auto fb = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), sv2.fb);
120 std::vector<double> a(n), b(n);
121 for (
long i = 0; i < n; ++i) {
129 auto h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), f);
130 cols.emplace_back(h.data(), h.data() + n);
132 for (
int a = 0; a < 3; ++a)
136 Kokkos::deep_copy(rs, 1.0);
139 for (
int c = 0; c < 3; ++c) {
143 peclet::flow::ibmBuildDiffusionVar(B[0], B[1], B[2], B[3], B[4], B[5], B[6], e[0], e[1], e[2],
150 for (
int c = 0; c < 3; ++c) {
160 CCField em(
"sv_mpi_edges", 18 * n);
162 Kokkos::parallel_for(
163 "sv_mpi_edges", Kokkos::RangePolicy<peclet::flow::CCExec>(0, n), KOKKOS_LAMBDA(
long i) {
164 const int z = (int)(i / g.st[2]), rr = (int)(i - z * g.st[2]), y = rr / (int)g.st[1],
165 x = rr - y * (
int)g.st[1];
167 x >=
G && y >=
G && z >=
G && x < g.e[0] -
G && y < g.e[1] -
G && z < g.e[2] -
G;
168 const int k[3] = {x, y, z};
169 for (
int ac = 0; ac < 3; ++ac) {
170 const int a = (ac == 2) ? 1 : 0, c = (ac == 0) ? 1 : 2;
171 double r6[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
172 if (in && g.edgeFaceFraction(k, a, c, a, r6[0])) {
173 g.edgeFaceFraction(k, a, c, c, r6[1]);
174 g.edgeLinkFractions(k, a, c, r6[2], r6[3]);
175 r6[4] = g.edgeTraction(k, a, c, a, t);
176 r6[5] = g.edgeTraction(k, a, c, c, t);
178 for (
int q = 0; q < 6; ++q)
179 em((
long)(6 * ac + q) * n + i) = r6[q];
183 auto h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), em);
184 for (
int q = 0; q < 18; ++q)
185 cols.emplace_back(h.data() + (
long)q * n, h.data() + (
long)(q + 1) * n);
187 std::vector<double> out;
188 out.reserve((
long)
kVals * ln[0] * ln[1] * ln[2]);
189 for (
const auto& f : cols)
190 for (
int z =
G; z < e[2] -
G; ++z)
191 for (
int y =
G; y < e[1] -
G; ++y)
192 for (
int x =
G; x < e[0] -
G; ++x)
193 out.push_back(f[(
long)x + (
long)y * e[0] + (
long)z * e[0] * e[1]]);
204int main(
int argc,
char** argv) {
205 MPI_Init(&argc, &argv);
206 Kokkos::initialize(argc, argv);
209 int rank = 0, size = 1;
210 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
211 MPI_Comm_size(MPI_COMM_WORLD, &size);
212 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
213 const int gn[3] = {
NX,
NY,
NZ};
215 for (
int a = 0; a < 3; ++a) {
217 for (
const auto& sz : dec.sizes())
218 cut = cut || ((int)sz[a] != gn[a]);
221 const int needCut = (size >= 4) ? 2 : (size >= 2 ? 1 : 0);
223 std::printf(
"SHARP_VISCOUS_MPI np=%d grid %dx%dx%d, %d cut axes (need >= %d)\n", size,
NX,
NY,
227 auto blk = dec.block(rank);
228 const int o[3] = {(int)blk.origin[0], (
int)blk.origin[1], (int)blk.origin[2]};
229 const int ln[3] = {(int)blk.size[0], (
int)blk.size[1], (int)blk.size[2]};
232 double vcen[3] = {
NX / 2,
NY / 2, 0};
233 for (
int a = 0; a < 3; ++a) {
235 for (
int r = 0; r < size; ++r) {
236 const int org = (int)dec.block(r).origin[a];
237 if (org > 0 && org < cut)
244 std::printf(
" vertex sphere centre (%g, %g, %g), radius 3.4\n", vcen[0], vcen[1], vcen[2]);
245 for (
int pass = 0; pass < 3; ++pass) {
246 const bool walls = (pass == 1);
248 for (
int a = 0; a < 3; ++a)
252 std::vector<double> mine;
256 s.initMpi(dec, MPI_COMM_WORLD);
259 std::vector<int> counts(size), displs(size);
261 for (
int r = 0; r < size; ++r) {
262 const auto b = dec.block(r);
263 counts[r] =
kVals * (int)(b.size[0] * b.size[1] * b.size[2]);
264 displs[r] = (int)total;
267 std::vector<double> all(rank == 0 ? total : 0);
268 MPI_Gatherv(mine.data(), (
int)mine.size(), MPI_DOUBLE, all.data(), counts.data(),
269 displs.data(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
271 const int zo[3] = {0, 0, 0}, gl[3] = {
NX,
NY,
NZ};
274 const std::vector<double> want =
evalSharp(ref, zo, gl);
275 const long tied = ref.vofViscousInterfaceCensus().tied;
276 long bad = 0, nonfinite = 0, band = 0, fallbacks = 0, rhsNz = 0;
277 const long NN = (long)
NX *
NY *
NZ;
278 for (
int r = 0; r < size; ++r) {
279 const auto b = dec.block(r);
280 const int bs[3] = {(int)b.size[0], (
int)b.size[1], (int)b.size[2]};
281 const long bn = (long)bs[0] * bs[1] * bs[2];
282 for (
int f = 0; f <
kVals; ++f)
283 for (
int z = 0; z < bs[2]; ++z)
284 for (
int y = 0; y < bs[1]; ++y)
285 for (
int x = 0; x < bs[0]; ++x) {
287 all[displs[r] + f * bn + x + (long)bs[0] * (y + (
long)bs[1] * z)];
289 ((int)b.origin[0] + x) +
290 (
long)
NX * (((int)b.origin[1] + y) + (long)
NY * ((int)b.origin[2] + z));
291 const double w = want[(long)f * NN + gi];
292 if (std::memcmp(&got, &w,
sizeof(
double)) != 0)
294 if (!std::isfinite(got))
296 if (f == 0 && got != 0.0)
298 if (f == 1 && got != 0.0)
300 if (f >=
kVals - 3 && got != 0.0)
304 const bool ok = bad == 0 && nonfinite == 0 && band > 100 && fallbacks == 0 && rhsNz > 0 &&
305 (pass != 2 || tied > 0);
307 " %-9s %ld/%ld bitwise mismatches vs np 1, %ld non-finite, %ld band cells, "
308 "%ld fallbacks, %ld nonzero RHS, %ld tied edges %s\n",
309 pass == 2 ?
"vertex" : (walls ?
"y walls" :
"periodic"), bad, total, nonfinite, band,
310 fallbacks, rhsNz, tied, ok ?
"PASS" :
"FAIL");
317 MPI_Allreduce(&fail, &gfail, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
void addSharpViscousRhs(int c, CCField bb, CCConst rs, const CCConst(&v)[3], const SharpGeom &gg, const CCConst(&tau)[3], CCConst dnn, int g, double wc, bool skipLoC, SvList list, long nl)
The explicit band terms of the u_c rows over the inner cells [g, e−g)³ (§5.4): the τ-terms of the fou...
void ibmBuildDiffusionVar(MV AC, MV AW, MV AE, MV AS, MV AN, MV AB, MV AT, int ex, int ey, int ez, int g, FaceProps fp, double wx=1.0, double wy=1.0, double wz=1.0)
void addFullStressRhs(int c, CCField bb, CCConst rs, const CCConst(&v)[3], FaceProps fp, C3 e, int g, double wc, bool skipLoC, const RegConst(®)[3]={RegConst(), RegConst(), RegConst()})
Add rs_c · T_c(uⁿ) to the momentum RHS bb of component c over the inner cells [g, e−g)³.