27 """Global SDF as a 3-D array sdf[x,y,z]; negative inside the solid walls."""
28 gy = np.arange(ny, dtype=np.float64)
29 sdf = np.empty((nx, ny, nz))
30 sdf[:, :, :] = np.minimum(gy - ylo, yhi - gy)[
None, :,
None]
34def run(N, Solver, rho=1.0, mu=0.1, dt=50.0, F=0.01, max_steps=400):
35 """Solve one channel case at wall-to-wall resolution N; return the pointwise node error vs the parabola."""
38 ylo = round(0.30 * ny) + 0.5
39 yhi = round(0.70 * ny) + 0.5
42 s = Solver(nx, ny, nz)
46 s.set_body_force(F, 0.0, 0.0)
47 s.set_velocity_solver_params(200)
48 s.set_pressure_solver_params(1)
49 s.set_solid(
channel_sdf(nx, ny, nz, ylo, yhi), cutcell_pressure=
False)
52 for it
in range(max_steps):
57 u_now = float(u.max())
58 stop = it > 5
and abs(u_now - prev) < 1e-10 * (abs(u_now) + 1e-12)
60 if s.bcast_from_root(stop):
67 prof = u[nx // 2, :, nz // 2]
68 gy = np.arange(ny, dtype=np.float64)
69 fluid = (gy > ylo) & (gy < yhi)
70 u_ana = (F / (2.0 * mu)) * (gy - ylo) * (yhi - gy)
71 node_err = float(np.max(np.abs(prof[fluid] - u_ana[fluid])))
72 return ny, H, node_err