25 R = (3 * phi / (4 * np.pi)) ** (1 / 3) * N
26 g = np.arange(N) + 0.5
27 X, Y, Z = np.meshgrid(g, g, g, indexing=
"ij")
28 d =
lambda A, c: A - c * N - N * np.round((A - c * N) / N)
29 return np.sqrt(d(X, .5) ** 2 + d(Y, .5) ** 2 + d(Z, .5) ** 2) - R, R
32def drag(N, scheme, mu=0.1, F=1e-3, dt=80.0, warm_tol=1e-7, tail=40, max_steps=4000):
34 s = flow.SolverColocated(N, N, N)
35 s.set_rho(1.0); s.set_mu(mu); s.set_dt(dt)
36 s.set_body_force(F, 0, 0); s.set_advection(
False)
37 s.set_velocity_solver_params(150)
38 s.set_pressure_multigrid(
True, max(2, int(np.log2(N)) - 1))
39 s.set_pressure_pcg(
True, 200, 1e-8)
40 s.set_collocated_scheme(scheme)
41 s.set_solid(sdf, cutcell_pressure=
True, pressure_coarse=
"rediscretized")
42 prev, warm, um, pit, t0 = 0.0,
None, [], [], time.time()
43 for it
in range(max_steps):
45 um.append(float(s.get_u().mean())); pit.append(int(s.last_pressure_iterations()))
48 if it > 10
and abs(um[-1] - prev) < warm_tol * (abs(um[-1]) + 1e-30):
51 elif it - warm >= tail:
53 umean = float(np.mean(um[-tail:]))
54 K = F * N ** 3 / (6 * np.pi * mu * R * umean)
55 return K, 100 * (K - K_ZH) / K_ZH, float(np.mean(pit[-tail:])), it + 1, time.time() - t0