121def couette(full, dt, N=32, steps=4000, tol=1e-9):
123 mu1, mu2, U = 1.0, 0.1, 1.0
128 s.set_domain_bc(
"-y",
"wall", (0.0, 0.0, 0.0))
129 s.set_domain_bc(
"+y",
"inflow", (U, 0.0, 0.0))
130 s.set_pressure_geometry(
F(np.full((N, N, nz), 10.0)))
132 muy = np.where(y < N // 2, mu1, mu2).astype(np.float64)
134 s.set_field(
"mu",
F(np.repeat(muy[
None, :,
None], N, 0).repeat(nz, 2)))
135 s.diagnostics.set_property_mode(
"variable",
False)
137 s.set_viscous_stress(
"full")
138 prev, conv =
None, -1
139 for it
in range(steps):
142 u = np.array(s.get_u())
144 if prev
is not None and np.abs(u - prev).max() / (um + 1e-30) < tol:
148 u = np.array(s.get_u())[N // 2, :, 0]
149 ui = U * mu2 / (mu1 + mu2)
151 exact = np.where(yc < 0.5, ui * yc / 0.5, ui + (U - ui) * (yc - 0.5) / 0.5)
152 return np.max(np.abs(u - exact)) / U, conv
177 lambda: pf.SolverColocated(8, 8, 8).set_viscous_stress(
"full"))
180 def var_solver(harmonic=False, porous=False):
185 s.set_pressure_geometry(
F(np.full((8, 8, 8), 10.0)))
187 mu = np.full((8, 8, 8), 0.1)
188 mu[2:5, 2:5, 2:5] = 1.0
189 s.set_field(
"mu",
F(mu))
190 s.diagnostics.set_property_mode(
"variable", harmonic)
192 s.set_porous_continuity(
True)
193 s.set_viscous_stress(
"full")
196 msgs[
"harmonic at step"] =
expect_raise(
lambda: var_solver(harmonic=
True).step())
197 msgs[
"porous at step"] =
expect_raise(
lambda: var_solver(porous=
True).step())
198 ok_laplacian =
expect_raise(
lambda: pf.SolverColocated(8, 8, 8).set_viscous_stress(
"laplacian"))
199 for k, m
in msgs.items():
200 verdict(f
"refuse: {k}", m
is not None, m
or "did NOT raise")
201 verdict(
"refuse: collocated 'laplacian' accepted", ok_laplacian
is None, ok_laplacian
or "ok")
214 c[k] = f * r ** (k - d)
217 A = np.array([row(R, 0), row(R, 1), row(R, 2), row(R2, 0), row(R2, 1), row(R2, 2)])
218 b = np.array([U0, dH, 0.0, 0.0, 0.0, 0.0])
219 return np.linalg.solve(A, b)
224 R, R2 = 0.25 * L, 0.45 * L
225 mu_out, mu_in = 1.0, ratio
226 a =
quintic(R, R2, U0, (U0 / R) * (1.0 + 2.0 * mu_in / mu_out))
229 out = np.zeros_like(r)
230 for k
in range(d, 6):
234 out += a[k] * f * r ** (k - d)
238 return np.where(r <= R, U0 * (r / R) ** 3, np.where(r < R2, H(r), 0.0))
241 inner = -mu_in * 8.0 * U0 * r / R ** 3
242 rr = np.maximum(r, 1e-300)
243 outer = -mu_out * (H(r, 2) + H(r, 1) / rr - H(r) / rr ** 2)
244 return np.where(r <= R, inner, np.where(r < R2, outer, 0.0))
246 return R, R2, mu_in, mu_out, u_theta, f_theta
249def rotcore(N, ratio, full, D=10.0, U0=1e-3, max_steps=200000, tol=1e-12, nz=4, init=None):
250 R, _R2, mu_in, mu_out, u_theta, f_theta =
rotcore_exact(N, ratio, U0)
252 i = np.arange(N, dtype=np.float64)
254 sub = (np.arange(8) + 0.5) / 8.0
255 xs = (i[:,
None] + sub[
None, :]).ravel()
256 XS, YS = np.meshgrid(xs, xs, indexing=
"ij")
257 inside = (np.hypot(XS - c0, YS - c0) < R).astype(np.float64)
258 C = inside.reshape(N, 8, N, 8).
mean(axis=(1, 3))
259 mu = mu_in * C + mu_out * (1.0 - C)
260 rep =
lambda a:
F(np.repeat(a[:, :,
None], nz, axis=2))
262 Xc, Yc = np.meshgrid(i + 0.5, i + 0.5, indexing=
"ij")
263 rc = np.hypot(Xc - c0, Yc - c0)
265 with np.errstate(invalid=
"ignore", divide=
"ignore"):
266 sn, cs = np.where(rc > 0, (Yc - c0) / rc, 0.0), np.where(rc > 0, (Xc - c0) / rc, 0.0)
267 fx, fy = -ft * sn, ft * cs
269 Xu, Yu = np.meshgrid(i, i + 0.5, indexing=
"ij")
270 Xv, Yv = np.meshgrid(i + 0.5, i, indexing=
"ij")
271 ru, rv = np.hypot(Xu - c0, Yu - c0), np.hypot(Xv - c0, Yv - c0)
272 ue = -u_theta(ru) * (Yu - c0) / np.maximum(ru, 1e-300)
273 ve = u_theta(rv) * (Xv - c0) / np.maximum(rv, 1e-300)
277 s.set_dt(D / min(mu_in, mu_out))
278 s.set_advection(
False)
279 s.set_pressure_pcg(
True, 400, 1e-13)
280 s.diagnostics.set_velocity_solver_params(400, 1e-12, 2)
281 s.set_pressure_geometry(
F(np.full((N, N, nz), 10.0)))
282 s.enable_cell_force()
283 s.diagnostics.set_property_mode(
"variable",
False)
284 s.set_field(
"mu", rep(mu))
285 s.diagnostics.set_property_mode(
"variable",
False)
287 s.set_viscous_stress(
"full")
288 for nm, a
in ((
"force_x", rep(fx)), (
"force_y", rep(fy)), (
"force_z", rep(0 * fx))):
290 s.diagnostics.exchange_field(nm)
292 s.set_velocity(0, rep(ue))
293 s.set_velocity(1, rep(ve))
296 s.set_velocity(k,
F(init[k]))
297 prev = np.array(s.get_u())
299 for steps
in range(1, max_steps + 1):
301 u = np.array(s.get_u())
302 du = np.abs(u - prev).max()
305 hist.append(np.abs(u).max())
308 u, v = np.array(s.get_u())[:, :, 0], np.array(s.get_v())[:, :, 0]
309 e = max(np.abs(u - ue).max(), np.abs(v - ve).max()) / U0
310 return e, steps, du / U0, hist, s