flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
uf_outlet_diag.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""Diagnosis probe (branch uf-outlet-diag): does the collocated projected face field uf_ carry, on
3the OUTLET face plane, the flux the projection solved for?
4
5The outlet face (index nx along x) is a ghost index of uf_, so get_uf() cannot read it. A passive
6scalar c == 1 with zero diffusivity and first-order upwind reads it exactly: in the last column
7 c_new = 1 - dt * (U_out_raw - U_out_required) (cell units, h = 1)
8where U_out_required closes the last cell's discrete divergence from the inner faces get_uf/vf/wf
9return. Every other cell changes by dt * div(face field), i.e. by the projection residual.
10
11Run: OMP_NUM_THREADS=4 OMP_PROC_BIND=false PYTHONPATH=build_host python tests/study/uf_outlet_diag.py
12"""
13import sys
14
15import numpy as np
16
17import peclet.flow as pf
18
19NX, NY, NZ = 48, 16, 4
20U_IN, MU, DT = 1.0, 0.1, 0.5
21
22
23def channel(cls, scheme=None, steps=200):
24 s = cls(NX, NY, NZ)
25 s.set_rho(1.0); s.set_mu(MU); s.set_dt(DT)
26 s.set_advection(True); s.set_advection_scheme("koren")
27 if scheme is not None:
28 s.set_collocated_scheme(scheme)
29 s.set_domain_bc("-x", "inflow", (U_IN, 0.0, 0.0))
30 s.set_domain_bc("+x", "outflow")
31 s.set_domain_bc("-y", "wall"); s.set_domain_bc("+y", "wall")
32 s.set_pressure_geometry(np.asfortranarray(np.full((NX, NY, NZ), 10.0)))
33 s.set_pressure_pcg(True, 400, 1e-11)
34 for _ in range(steps):
35 s.step()
36 return s
37
38
40 """Outlet flux that closes the last cell's divergence, from the inner faces."""
41 uf, vf, wf = (np.asarray(s.get_uf()), np.asarray(s.get_vf()), np.asarray(s.get_wf()))
42 i = NX - 1
43 vtop = np.zeros((NY, NZ)); vtop[:-1] = vf[i, 1:, :] # +y wall face = 0
44 wtop = np.roll(wf[i], -1, axis=1) # z periodic
45 return uf[i] - (vtop - vf[i]) - (wtop - wf[i]), uf[0]
46
47
48def probe(name, s):
49 req_before, uin = required_outlet(s)
50 s.add_scalar("c", diffusivity=0.0, scheme="fou", iters=1)
51 s.set_scalar_bc("c", "-x", "dirichlet", 1.0)
52 s.set_scalar_bc("c", "+x", "neumann", 0.0)
53 s.set_field("c", np.asfortranarray(np.ones((NX, NY, NZ))))
54 u_last = np.asarray(s.get_u())[NX - 1].copy()
55 s.step() # the scalar rides the face field of THIS step's projection
56 c = np.asarray(s.get_field("c"))
57 req, uin = required_outlet(s)
58 mism = (1.0 - c[NX - 1]) / DT # = U_out_raw - U_out_required
59 raw = req + mism
60 j = slice(None)
61 print(f"--- {name}")
62 print(f" inner columns: max|c-1| = {np.abs(c[:NX - 1] - 1).max():.3e} "
63 f"max_open_divergence_projected = {s.max_open_divergence_projected():.3e}")
64 d = np.abs(c[:NX - 1] - 1); loc = np.unravel_index(np.argmax(d), d.shape)
65 print(f" inner max at {loc}, c there {c[loc]:.4f}; per-column max|c-1| cols 0,1,2,NX-3,NX-2: "
66 + " ".join(f"{v:.1e}" for v in d.max(axis=(1, 2))[[0, 1, 2, NX - 3, NX - 2]]))
67 print(f" outlet column: min c = {c[NX-1].min():.4f} max c = {c[NX-1].max():.4f}")
68 print(f" mass: inflow sum uf[0] = {uin.sum():.6f} required outflow = {req.sum():.6f} "
69 f"raw outflow = {raw.sum():.6f} (per-z-slice: in {uin.sum()/NZ:.4f}, raw {raw.sum()/NZ:.4f})")
70 k = 0
71 print(" y | u_in face | u_last cell | required out | raw out (from c) | raw - u_in_face")
72 for y in range(NY):
73 print(f" {y:2d} | {uin[y,k]: .5f} | {u_last[y,k]: .5f} | {req[y,k]: .6f} | {raw[y,k]: .6f} |"
74 f" {raw[y,k]-uin[y,k]: .3e}")
75 return c, req, raw
76
77
78if __name__ == "__main__":
79 which = sys.argv[1:] or ["colo-default", "colo-gauge-exact", "colo-embed", "staggered"]
80 steps = 200
81 for w in which:
82 if w == "staggered":
83 s = channel(pf.Solver, steps=steps)
84 elif w == "colo-default":
85 s = channel(pf.SolverColocated, steps=steps)
86 else:
87 s = channel(pf.SolverColocated, scheme=w.split("colo-")[1], steps=steps)
88 probe(w, s)
channel(cls, scheme=None, steps=200)
static std::vector< double > slice(const std::vector< double > &g, int ox, int oy, int oz, int lnx, int lny, int lnz)