flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
test_open_face_plane.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""Gate: the HIGH-side domain face of a MAC face field survives the ghost fills (both grids).
3
4Why this test exists. That face is the first GHOST index along its axis, and the ghost fill wraps
5every axis periodically, so it came back carrying the LOW boundary's plane -- the inlet on the
6outlet (doc/uf_outlet_fix.md). Nothing registered could see it: momentum reads the outlet through
7openFaceView, the state hashes record cell fields only, and max_open_divergence reads the
8zero-gradient view. The readers that DID see it were the scalar transport, the backflow census
9and, at a high-side INFLOW face, collocated momentum.
10
11Checks, in the order they would fail:
12 1. census == required: on a channel driven backwards (fluid enters through the +x outflow face),
13 outflow_backflow() reads the raw outlet plane; its max_reverse must equal max(-u_out) of the
14 flux that closes the last cell's divergence (built from the inner faces), at every step, to
15 1e-9 (the reconstruction differences O(1) faces at the pressure tolerance; broken: O(1));
16 2. a c == 1 scalar (D = 0, first-order upwind) stays 1 in the OUTLET column after one step;
17 3. staggered: max_open_divergence_projected stays at round-off after that scalar step (the
18 scalar's fill used to overwrite C[0].u's corrected outlet face in place: 0.785);
19 4. a HIGH-side inflow (+x inflow, -x outflow): the collocated inlet-adjacent centreline velocity
20 agrees with the staggered one (1.7e-3 fixed; 3.6e-2 when it read the outlet's plane);
21 5. checks 1 and 2 again on the collocated grid with VoF enabled (the bubble-column
22 configuration): the VoF bridge fills uf_ IN PLACE between the projection and the scalars and
23 the census, so it must keep the plane too (flow 17d6a8e; reverted, both checks fail).
24
25Run: OMP_NUM_THREADS=4 OMP_PROC_BIND=false PYTHONPATH=<build> \
26 python tests/python/test_open_face_plane.py
27Exit 0 pass, 1 fail, 77 skipped (no module).
28"""
29import sys
30
31import numpy as np
32
33NX, NY, NZ = 24, 12, 4
34MU, DT = 0.1, 0.5
35
36
37def channel(pf, cls, u_in, low="inflow", nx=NX, ny=NY, vof=False):
38 s = cls(nx, ny, NZ)
39 s.set_rho(1.0); s.set_mu(MU); s.set_dt(DT)
40 s.set_advection(True); s.set_advection_scheme("koren")
41 if cls is pf.SolverColocated:
42 s.set_collocated_scheme("gauge-exact")
43 if low == "inflow":
44 s.set_domain_bc("-x", "inflow", (u_in, 0.0, 0.0))
45 s.set_domain_bc("+x", "outflow")
46 else:
47 s.set_domain_bc("-x", "outflow")
48 s.set_domain_bc("+x", "inflow", (u_in, 0.0, 0.0))
49 s.set_domain_bc("-y", "wall"); s.set_domain_bc("+y", "wall")
50 s.set_pressure_geometry(np.asfortranarray(np.full((nx, ny, NZ), 10.0)))
51 s.set_pressure_pcg(True, 400, 1e-11)
52 if vof:
53 # One phase everywhere (C = 0, no property model): the flow is unchanged, but every step
54 # now runs the VoF bridge between the projection and the readers of the face plane.
55 s.enable_vof()
56 s.set_vof(np.zeros((nx, ny, NZ), order="F"))
57 return s
58
59
61 """The +x outlet flux that closes the last cell's discrete divergence (cell units)."""
62 uf, vf, wf = (np.asarray(s.get_uf()), np.asarray(s.get_vf()), np.asarray(s.get_wf()))
63 i = NX - 1
64 vtop = np.zeros((NY, NZ)); vtop[:-1] = vf[i, 1:, :] # +y wall face = 0
65 wtop = np.roll(wf[i], -1, axis=1) # z periodic
66 return uf[i] - (vtop - vf[i]) - (wtop - wf[i])
67
68
69def check_census(pf, cls, vof=False):
70 s = channel(pf, cls, -1.0, vof=vof)
71 worst = 0.0
72 for _ in range(20):
73 s.step()
74 ob = s.diagnostics.outflow_backflow()
75 req = required_outlet(s)
76 worst = max(worst, abs(ob["max_reverse"] - (-req).max()))
77 assert ob["reversed_faces"] == ob["outlet_faces"] == NY * NZ, ob
78 assert worst <= 1e-9, f"{cls.__name__}{' +VoF' * vof}: census vs required outlet flux {worst:.3e}"
79 return worst
80
81
82def check_scalar_outlet(pf, cls, vof=False):
83 s = channel(pf, cls, 1.0, vof=vof)
84 for _ in range(30):
85 s.step()
86 s.add_scalar("c", diffusivity=0.0, scheme="fou", iters=1)
87 s.set_scalar_bc("c", "-x", "dirichlet", 1.0)
88 s.set_scalar_bc("c", "+x", "neumann", 0.0)
89 s.set_field("c", np.asfortranarray(np.ones((NX, NY, NZ))))
90 s.step()
91 c = np.asarray(s.get_field("c"))
92 out = float(np.abs(c[NX - 1] - 1.0).max())
93 assert out <= 1e-10, f"{cls.__name__}{' +VoF' * vof}: c = 1 outlet column moved by {out:.3e}"
94 div = float(s.max_open_divergence_projected())
95 if cls is pf.Solver:
96 assert div <= 1e-12, f"staggered max_open_divergence_projected {div:.3e} after a scalar step"
97 return out, div
98
99
101 nx, ny = 48, 16
102 u = {}
103 for cls in (pf.SolverColocated, pf.Solver):
104 s = channel(pf, cls, -1.0, low="outflow", nx=nx, ny=ny)
105 for _ in range(100):
106 s.step()
107 u[cls] = float(np.asarray(s.get_u())[nx - 1, ny // 2, 0])
108 d = abs(u[pf.SolverColocated] - u[pf.Solver])
109 assert d < 1e-2, (f"high-side inflow: collocated inlet-cell u {u[pf.SolverColocated]:.5f} vs "
110 f"staggered {u[pf.Solver]:.5f}")
111 return d
112
113
114def main():
115 try:
116 import peclet.flow as pf
117 except ImportError:
118 print("SKIP: peclet.flow not importable (set PYTHONPATH to the build tree)")
119 return 77
120 try:
121 for cls in (pf.SolverColocated, pf.Solver):
122 w = check_census(pf, cls)
123 out, div = check_scalar_outlet(pf, cls)
124 print(f" {cls.__name__:16s} census-required {w:.2e} outlet |c-1| {out:.2e} "
125 f"div_projected {div:.2e}")
126 d = check_high_inflow(pf)
127 print(f" high-side inflow: |u_colo - u_stag| at the inlet cell {d:.2e}")
128 w = check_census(pf, pf.SolverColocated, vof=True)
129 out, _ = check_scalar_outlet(pf, pf.SolverColocated, vof=True)
130 print(f" SolverColocated +VoF census-required {w:.2e} outlet |c-1| {out:.2e}")
131 except AssertionError as e:
132 print(f"FAIL: {e}")
133 return 1
134 print("OK: high-side face planes survive the ghost fills")
135 return 0
136
137
138if __name__ == "__main__":
139 sys.exit(main())
channel(pf, cls, u_in, low="inflow", nx=NX, ny=NY, vof=False)
check_scalar_outlet(pf, cls, vof=False)
check_census(pf, cls, vof=False)