flow
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
embed_flatwall_guard.py
Go to the documentation of this file.
1"""Guard: a FLAT (grid-aligned normal) channel wall at a FRACTIONAL y position -> genuine axis-aligned
2cut cells (fractional openness), driven Poiseuille, periodic box + cut-cell pressure. The embed wall
3gradient (mode 5) must reproduce the analytic parabola as well as mode 0 (for an axis-aligned normal
4the true-normal reconstruction is a pure 1-D quadratic along y = exact for the quadratic profile).
5Confirms mode 5 does not degrade the flat-wall case that modes 0-3 nail."""
6import os, sys
7sys.path.insert(0, os.path.abspath("build_cuda2"))
8import numpy as np
9from peclet import flow
10
11def run(N, mode, mu=0.1, F=0.01, dt=50.0, max_steps=1500):
12 nx, nz = 8, 8; ny = N
13 ylo = 0.3 * ny + 0.137 # fractional -> real cut cells (axis-aligned normal)
14 yhi = 0.7 * ny - 0.137
15 H = yhi - ylo
16 gy = np.arange(ny, dtype=np.float64) + 0.5 # cell centres
17 sdf = np.minimum(gy - ylo, yhi - gy)[None, :, None] * np.ones((nx, ny, nz))
18 lv = max(2, int(np.log2(N)) - 1)
19 s = flow.SolverColocated(nx, ny, nz)
20 s.set_rho(1.0); s.set_mu(mu); s.set_dt(dt); s.set_body_force(F, 0, 0); s.set_advection(False)
21 s.set_velocity_solver_params(200); s.set_pressure_multigrid(True, levels=lv)
22 s.set_pressure_pcg(True, 400, 1e-11); s.set_face_interp(mode)
23 s.set_solid(sdf, cutcell_pressure=True, pressure_coarse="rediscretized")
24 prev = 0.0
25 for it in range(max_steps):
26 s.step(); u = float(s.get_u().max())
27 if it > 10 and abs(u - prev) < 1e-9 * (abs(u) + 1e-30): break
28 prev = u
29 U_sim = float(s.get_u().max()); U_ana = F * H * H / (8.0 * mu)
30 return H, U_sim, U_ana, 100 * abs(U_sim - U_ana) / U_ana
31
32print("Flat-wall (fractional, axis-aligned cut cells) Poiseuille: mode 0 vs mode 6 (embed)")
33print(f"{'N':>4} | {'mode0 err%':>11} | {'mode6 err%':>11}")
34for N in (32, 48, 64):
35 _, _, _, e0 = run(N, 0)
36 _, _, _, e6 = run(N, 6)
37 print(f"{N:>4} | {e0:>+11.5f} | {e6:>+11.5f}", flush=True)
run(N, mode, mu=0.1, F=0.01, dt=50.0, max_steps=1500)