28def box(pf, cls, nx, ny, nz, walls):
30 s.set_rho(1.0); s.set_mu(MU); s.set_dt(DT)
31 s.set_advection(
True); s.set_advection_scheme(
"koren")
32 if cls
is pf.SolverColocated:
33 s.set_collocated_scheme(
"gauge-exact")
34 s.set_domain_bc(
"-x",
"inflow", (1.0, 0.0, 0.0))
35 s.set_domain_bc(
"+x",
"outflow")
37 s.set_domain_bc(
"-y",
"wall"); s.set_domain_bc(
"+y",
"wall")
38 s.set_pressure_geometry(np.asfortranarray(np.full((nx, ny, nz), 10.0)))
39 s.set_pressure_pcg(
True, 400, 1e-11)
44 nx, ny, nz = 24, 12, 4
45 s =
box(pf, cls, nx, ny, nz, walls=
True)
48 s.add_scalar(
"c", diffusivity=0.0, scheme=scheme, iters=1)
49 s.set_scalar_bc(
"c",
"-x",
"dirichlet", 1.0)
50 s.set_scalar_bc(
"c",
"+x",
"neumann", 0.0)
51 s.set_field(
"c", np.asfortranarray(np.ones((nx, ny, nz))))
53 c = np.asarray(s.get_field(
"c"))
54 err = float(np.abs(c[: nx - 1] - 1.0).max())
55 assert err <= 1e-10, f
"{cls.__name__}/{scheme}: c = 1 moved by {err:.3e} upstream of the outlet"
61 s =
box(pf, cls, nx, ny, nz, walls=
False)
62 s.add_scalar(
"c", diffusivity=0.0, scheme=scheme, iters=1)
63 s.set_scalar_bc(
"c",
"-x",
"dirichlet", 1.0)
64 s.set_scalar_bc(
"c",
"+x",
"neumann", 0.0)
65 s.set_field(
"c", np.asfortranarray(np.zeros((nx, ny, nz))))
66 for _
in range(steps):
68 c = np.asarray(s.get_field(
"c")).
mean(axis=(1, 2))
71 k = int(np.argmax(c < 0.5))
72 xf = k - 0.5 + (c[k - 1] - 0.5) / (c[k - 1] - c[k]) * 1.0
if k > 0
else 0.0
73 assert abs(inv - t) <= 1e-9, f
"{cls.__name__}/{scheme}: inventory {inv:.12f} != U t = {t}"
74 assert abs(xf - t) <= 1.0, f
"{cls.__name__}/{scheme}: c = 1/2 at x = {xf:.3f}, U t = {t}"
75 return inv - t, xf - t