flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
wo2_reference.py
Go to the documentation of this file.
1"""WO-2 reference dump (doc/vof_sharp_viscous_stress.md §10 WO-2): the 2-D harness values the 3-D
2extrusion test (`tests/kokkos/test_sharp_viscous.cpp`) must reproduce to 1e-12.
3
4The oracle is mac2d with the production configuration and the §5.7 rule: scheme 'sharp',
5SHARP_BASE 'facef', FCORR 'fit', TAU_RULE 'mixed-avg'. Per case the file lists the plane, the mixed
6cells (C, both midsection fractions, the fitted tau and D_nn evaluated on the exact face averages,
7whether mac2d fitted the cell, i.e. it is in-domain), every node with a mixed cell among its four (the two face
8fractions and the two link fractions), and the exact face-averaged velocities within 3 cells of a
9mixed cell.
10
11 python wo2_reference.py ../../kokkos/sharp_viscous_mac2d.txt
12"""
13import sys
14
15import numpy as np
16
17import mac2d as M
18
19M.SHARP_BASE, M.FCORR, M.TAU_RULE = "facef", "fit", "mixed-avg"
20
21N = 16
22CASES = [(kind, ang, off, ratio) for kind in ("poiseuille", "general") for ang in (11.25, 22.5, 33.75)
23 for off, ratio in ((0.37, 0.01), (0.37, 1000.0))] + [("poiseuille", 45.0, 0.0, 0.01)]
24
25
26def dump(out):
27 lines = ["NCASES %d" % len(CASES)]
28 for kind, ang, off, ratio in CASES:
29 c = M.Case(N, ang, off, ratio, 1.0, kind)
30 M.build(c, "sharp", "fit")
31 L = M.build.last
32 C, mixed, te, de, xall, m = L["C"], L["mixed"], L["tauexpr"], L["dnnexpr"], L["xall"], L["mac"]
33 h = c.h
34 lines.append("CASE %d %.17g %.17g %.17g %.17g %.17g %.17g %.17g %.17g %.17g %d" % (
35 N, c.n[0], c.n[1], c.t[0], c.t[1], c.c[0], c.c[1], c.s, c.muA, c.muB, kind == "general"))
36 cells = [(i, j) for i in range(-1, N + 1) for j in range(-1, N + 1) if mixed[i + 1, j + 1]]
37 rows = []
38 for (i, j) in cells:
39 xc, yc = (i + 0.5) * h, (j + 0.5) * h
40 cbu = c.frac_line(xc, yc, np.array([0.0, 1.0]), "box")
41 cbv = c.frac_line(xc, yc, np.array([1.0, 0.0]), "box")
42 tau = sum(v * xall[k] for k, v in te[(i, j)].items()) if (i, j) in te else 0.0
43 dnn = sum(v * xall[k] for k, v in de[(i, j)].items()) if (i, j) in de else 0.0
44 rows.append("%d %d %.17g %.17g %.17g %d %.17g %.17g" % (i, j, C[i + 1, j + 1], cbu, cbv,
45 (i, j) in te, tau, dnn))
46 lines.append("NCELL %d" % len(rows))
47 lines += rows
48 mx = lambda i, j: 0 <= i <= N - 1 and 0 <= j <= N - 1 and mixed[i + 1, j + 1]
49 rows = []
50 for i in range(0, N + 1):
51 for j in range(0, N + 1):
52 if not any(mx(i - di, j - dj) for di in (0, 1) for dj in (0, 1)):
53 continue
54 fu = c.frac_line(i * h, j * h, np.array([1.0, 0.0]), "box")
55 fv = c.frac_line(i * h, j * h, np.array([0.0, 1.0]), "box")
56 thy = c.frac_line(i * h, j * h, np.array([0.0, 1.0]), "hat")
57 thx = c.frac_line(i * h, j * h, np.array([1.0, 0.0]), "hat")
58 rows.append("%d %d %.17g %.17g %.17g %.17g" % (i, j, fu, fv, thy, thx))
59 lines.append("NNODE %d" % len(rows))
60 lines += rows
61 near = lambda i, j: any(abs(i - p) <= 3 and abs(j - q) <= 3 for (p, q) in cells)
62 ru = ["%d %d %.17g" % (i, j, xall[m.iu(i, j)]) for i in range(N + 1) for j in range(-1, N + 1)
63 if near(i, j)]
64 rv = ["%d %d %.17g" % (i, j, xall[m.iv(i, j)]) for i in range(-1, N + 1) for j in range(N + 1)
65 if near(i, j)]
66 lines.append("NU %d" % len(ru))
67 lines += ru
68 lines.append("NV %d" % len(rv))
69 lines += rv
70 open(out, "w").write("\n".join(lines) + "\n")
71 print("wrote %d cases to %s" % (len(CASES), out))
72
73
74if __name__ == "__main__":
75 dump(sys.argv[1])