25 gy = np.arange(ny, dtype=np.float64)
26 sdf = np.empty((nx, ny, nz))
27 sdf[:, :, :] = np.minimum(gy - ylo, yhi - gy)[
None, :,
None]
31def run(N, ghost, rho=1.0, mu=0.1, dt=50.0, F=0.01, max_steps=400):
34 ylo = round(0.30 * ny) + 0.5
35 yhi = round(0.70 * ny) + 0.5
37 s = flow.Solver(nx, ny, nz)
41 s.set_body_force(F, 0.0, 0.0)
42 s.set_velocity_solver_params(200)
43 s.set_pressure_pcg(
True, 200, 1e-8)
45 s.set_ghost_projection(
True)
46 s.set_solid(
channel_sdf(nx, ny, nz, ylo, yhi), cutcell_pressure=
True)
49 for it
in range(max_steps):
51 u_now = float(s.get_u().max())
52 if it > 5
and abs(u_now - prev) < 1e-10 * (abs(u_now) + 1e-12):
57 prof = u[nx // 2, :, nz // 2]
58 gy = np.arange(ny, dtype=np.float64)
59 fluid = (gy > ylo) & (gy < yhi)
60 u_ana = (F / (2.0 * mu)) * (gy - ylo) * (yhi - gy)
61 err = float(np.max(np.abs(prof[fluid] - u_ana[fluid])))
62 return err, s.max_open_divergence()