33def make(variable_mu, solver=None, dt=2.0):
34 """Walled box, a transported scalar T driving the body force (and mu(T) when variable_mu).
35 dt = 2, mu = 0.5: kappa = 1 + 12 * 1.0 = 13 -> AUTO picks the V-cycle at constant mu."""
37 s.set_advection(
False)
41 s.set_domain_bc(
"-y",
"wall", (0, 0, 0))
42 s.set_domain_bc(
"+y",
"wall", (0, 0, 0))
43 s.set_pressure_geometry(np.full((N, N, N), 10.0, order=
"F"))
44 s.add_scalar(
"T", 0.0,
"koren")
45 X, Y, Z = np.meshgrid(*(np.arange(N) + 0.5,) * 3, indexing=
"ij")
46 s.set_field(
"T", np.asfortranarray(np.exp(-((X - 8) ** 2 + (Y - 5) ** 2 + (Z - 8) ** 2) / 8)))
48 s.diagnostics.set_velocity_solver(solver)
50 s.set_property_model(
"mu",
"linear",
"T", [0.5, -0.4])
51 s.set_property_model(
"force_x",
"linear",
"T", [0.0, -0.02])
66 def check(name, good):
69 print(f
"{name:66s} {'ok' if good else 'FAIL'}")
72 def closure_then_solver():
74 s.diagnostics.set_velocity_solver(
"multigrid")
76 def solver_then_closure():
77 make(
True, solver=
"multigrid")
79 def solver_then_mode():
80 s =
make(
False, solver=
"multigrid")
81 s.diagnostics.set_property_mode(
"variable")
83 def closure_then_raw_setter():
85 s.set_velocity_multigrid(
True)
87 check(
"explicit: mu closure, then set_velocity_solver('multigrid')",
raises(closure_then_solver))
88 check(
"explicit: set_velocity_solver('multigrid'), then mu closure",
raises(solver_then_closure))
89 check(
"explicit: set_velocity_solver('multigrid'), then property mode",
raises(solver_then_mode))
90 check(
"explicit: mu closure, then set_velocity_multigrid(True)",
raises(closure_then_raw_setter))
91 s =
make(
False, solver=
"multigrid")
93 check(
"explicit multigrid at constant mu still runs", s.diagnostics.velocity_multigrid_active())
98 check(
"AUTO, constant mu, kappa 13: V-cycle", c.diagnostics.velocity_multigrid_active())
99 a, g =
make(
True),
make(
True, solver=
"gauss_seidel")
103 check(
"AUTO, variable mu: red-black smoother",
not a.diagnostics.velocity_multigrid_active())
104 same = all(np.array_equal(x, y)
for x, y
in
105 ((a.get_u(), g.get_u()), (a.get_v(), g.get_v()), (a.get_w(), g.get_w()),
106 (a.get_p(), g.get_p())))
107 check(
"AUTO, variable mu == explicit gauss_seidel, bitwise (3 steps)", same)
108 print(
"PASS" if ok
else "FAIL")
109 return 0
if ok
else 1