flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
test_vof_momentum_scheme_names.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""Gate: diagnostics.set_vof_momentum_scheme(name) / vof_momentum_scheme() (flow
3doc/vof_momentum_second_order.md §7, WO-2).
4
5Checks, on a solver with enable_vof_momentum (no step is taken):
6 1. the default is 'muscl_phase' (since 2026-10-31; note §12);
7 2. every name ('upwind', 'muscl_mixed', 'muscl_mixed_capped', 'muscl_phase') round-trips through
8 the getter;
9 3. an unknown name raises ValueError and leaves the selection unchanged;
10 4. the former spelling set_vof_momentum_muscl(True / False) selects 'muscl_mixed' / 'upwind';
11 5. vof_momentum_diagnostics() carries 'capped'.
12
13Run: OMP_NUM_THREADS=4 OMP_PROC_BIND=false PYTHONPATH=<build> \
14 python tests/python/test_vof_momentum_scheme_names.py
15Exit 0 pass, 1 fail, 77 skipped (no module).
16"""
17import sys
18
19import numpy as np
20
21NAMES = ("upwind", "muscl_mixed", "muscl_mixed_capped", "muscl_phase")
22
23
24def main():
25 try:
26 import peclet.flow as pf
27 except ImportError as e:
28 print(f"SKIP: peclet.flow not importable ({e})")
29 return 77
30 n = 8
31 s = pf.Solver(n, n, n)
32 s.set_rho(10.0)
33 s.set_dt(0.2)
34 s.set_pressure_geometry(np.full((n, n, n), 1.0, order="F"))
35 s.enable_vof()
36 s.set_vof(np.zeros((n, n, n), order="F"))
37 s.set_property_model("rho", "linear", "C", [1.0, 9.0])
38 s.enable_vof_momentum(1.0, 10.0)
39 d = s.diagnostics
40 fails = []
41 if d.vof_momentum_scheme() != "muscl_phase":
42 fails.append(f"default is {d.vof_momentum_scheme()!r}, not 'muscl_phase'")
43 for name in NAMES:
44 d.set_vof_momentum_scheme(name)
45 got = d.vof_momentum_scheme()
46 print(f"set {name!r} -> {got!r}")
47 if got != name:
48 fails.append(f"{name!r} round-trips to {got!r}")
49 try:
50 d.set_vof_momentum_scheme("bogus")
51 fails.append("'bogus' did not raise")
52 except ValueError as e:
53 print(f"'bogus' -> ValueError: {e}")
54 if d.vof_momentum_scheme() != NAMES[-1]:
55 fails.append("a rejected name changed the selection")
56 for on, want in ((True, "muscl_mixed"), (False, "upwind")):
57 d.set_vof_momentum_muscl(on)
58 got = d.vof_momentum_scheme()
59 print(f"set_vof_momentum_muscl({on}) -> {got!r}")
60 if got != want:
61 fails.append(f"set_vof_momentum_muscl({on}) gives {got!r}, not {want!r}")
62 if "capped" not in d.vof_momentum_diagnostics():
63 fails.append("vof_momentum_diagnostics() has no 'capped'")
64 for f in fails:
65 print("FAIL:", f)
66 print("PASS" if not fails else "FAIL")
67 return 1 if fails else 0
68
69
70if __name__ == "__main__":
71 sys.exit(main())