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."""
36 s = pf.Solver(N, N, N)
40 s.set_domain_bc(
"-y",
"wall", (0, 0, 0))
41 s.set_domain_bc(
"+y",
"wall", (0, 0, 0))
42 s.set_pressure_geometry(np.full((N, N, N), 10.0, order=
"F"))
43 s.add_scalar(
"T", 0.0,
"koren")
44 X, Y, Z = np.meshgrid(*(np.arange(N) + 0.5,) * 3, indexing=
"ij")
45 s.set_field(
"T", np.asfortranarray(np.exp(-((X - 8) ** 2 + (Y - 5) ** 2 + (Z - 8) ** 2) / 8)))
47 s.diagnostics.set_velocity_solver(solver)
49 s.set_property_model(
"mu",
"linear",
"T", [0.5, -0.4])
50 s.set_property_model(
"force_x",
"linear",
"T", [0.0, -0.02])
65 def check(name, good):
68 print(f
"{name:66s} {'ok' if good else 'FAIL'}")
71 def closure_then_solver():
73 s.diagnostics.set_velocity_solver(
"multigrid")
75 def solver_then_closure():
76 make(
True, solver=
"multigrid")
78 def solver_then_mode():
79 s =
make(
False, solver=
"multigrid")
80 s.diagnostics.set_property_mode(
"variable")
82 def closure_then_raw_setter():
84 s.set_velocity_multigrid(
True)
86 check(
"explicit: mu closure, then set_velocity_solver('multigrid')",
raises(closure_then_solver))
87 check(
"explicit: set_velocity_solver('multigrid'), then mu closure",
raises(solver_then_closure))
88 check(
"explicit: set_velocity_solver('multigrid'), then property mode",
raises(solver_then_mode))
89 check(
"explicit: mu closure, then set_velocity_multigrid(True)",
raises(closure_then_raw_setter))
90 s =
make(
False, solver=
"multigrid")
92 check(
"explicit multigrid at constant mu still runs", s.diagnostics.velocity_multigrid_active())
97 check(
"AUTO, constant mu, kappa 13: V-cycle", c.diagnostics.velocity_multigrid_active())
98 a, g =
make(
True),
make(
True, solver=
"gauss_seidel")
102 check(
"AUTO, variable mu: red-black smoother",
not a.diagnostics.velocity_multigrid_active())
103 same = all(np.array_equal(x, y)
for x, y
in
104 ((a.get_u(), g.get_u()), (a.get_v(), g.get_v()), (a.get_w(), g.get_w()),
105 (a.get_p(), g.get_p())))
106 check(
"AUTO, variable mu == explicit gauss_seidel, bitwise (3 steps)", same)
107 print(
"PASS" if ok
else "FAIL")
108 return 0
if ok
else 1