flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
probe_translate.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""Case A G5 diagnosis, step 2: the a-priori translation test (doc/full_viscous_stress.md ยง2.4).
3
4A two-phase field translating rigidly, u = U everywhere, with the case-A density and viscosity
5jumps (ratios 0.1), g = 0, triply periodic, is an exact solution of the two-phase Navier-Stokes
6equations without surface tension: every force vanishes and the interface is carried by U.
7A momentum form passes if it keeps u = U to rounding. With sigma != 0 (the case-A sigma, i.e. Bo 2
8at the case-A g) the exact solution is still u = U (a translating sphere at rest in its own frame,
9Laplace pressure inside), and |u - U| measures the spurious currents.
10
11Forms: 'vel' = the velocity form (the case-A default), 'vel-adv' = the velocity form with
12set_advection(True), 'mom' = enable_vof_momentum (conservative rho u transport, single VoF).
13The structured VoF is used throughout (enable_vof_momentum refuses the block container) except
14'vel-blk' / 'vel-adv-blk' = the case-A block container + block CSF.
15set_superficial_velocity(True, 'x', U) as in case A; a = shift/dt reported in units of g = 9.81.
16
17Usage: OMP_NUM_THREADS=4 OMP_PROC_BIND=false PYTHONPATH=<build> \\
18 python tests/study/case_a/probe_translate.py --n 32 --steps 200 [--sigma]
19Prints one line per (form, stress).
20"""
21
22import argparse
23import os
24import sys
25
26import numpy as np
27
28sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
29import run_case_a as ca
30
31U0 = (0.07, 0.035, 0.0175) # m/s; the case-A rise velocity is ~0.07 m/s
32
33
34def build(n, form, stress, sigma):
35 L = ca.L_OVER_D * ca.D
36 s = ca.pf.Solver((n, n, n), extent=(L, L, L))
37 s.set_rho(ca.RHO_L)
38 s.set_mu(ca.MU_L)
39 s.set_pressure_geometry(np.full((n,) * 3, 1.0, order="F"))
40 s.enable_vof()
41 s.set_vof(np.zeros((n,) * 3, order="F"))
42 s.set_property_model("rho", "linear", "C", [ca.RHO_L, ca.RHO_G - ca.RHO_L])
43 s.set_property_model("mu", "linear", "C", [ca.MU_L, ca.MU_G - ca.MU_L])
44 s.set_viscous_stress(stress)
45 if "adv" in form:
46 s.set_advection(True)
47 if sigma:
48 s.set_surface_tension(ca.SIGMA)
49 s.set_pressure_pcg(True, 800, 1e-8)
50 h = L / n
51 if form.endswith("blk"):
52 s.enable_vof_blocks([(0.5 * L / h,) * 3 + (0.5 * ca.D / h,)])
53 if sigma:
54 s.enable_vof_block_csf()
55 else:
56 s.set_vof(ca.sphere_fractions(n, 0.5 * L / h, 0.5 * ca.D / h))
57 if form == "mom":
58 s.enable_vof_momentum(ca.RHO_G, ca.RHO_L)
59 # pin the time reference (the first set_dt) BEFORE set_velocity and the first
60 # vof_step_limits: before it, velocities go in and come out unscaled (case A starts at rest
61 # and never met this)
62 s.set_dt(0.05 * h / U0[0])
63 for c in range(3):
64 s.set_velocity(c, np.full((n,) * 3, U0[c], order="F"))
65 s.set_superficial_velocity(True, "x", U0[0])
66 s.update_properties()
67 return s
68
69
70def run(n, form, stress, sigma, steps):
71 s = build(n, form, stress, sigma)
72 emax, acc = 0.0, []
73 Cin = np.array(s.get_vof())
74 C0 = Cin.sum()
75 for k in range(steps):
76 L_ = s.vof_step_limits()
77 dt = 0.25 * min(L_["cfl_dt"], L_["capillary_dt"])
78 s.set_dt(dt)
79 s.step()
80 e = max(
81 float(np.max(np.abs(np.array(g()) - U0[c])))
82 for c, g in enumerate((s.get_u, s.get_v, s.get_w))
83 )
84 emax = max(emax, e)
85 acc.append(s.diagnostics.last_superficial_velocity_shift() / dt / ca.G)
86 Cend = np.array(s.get_vof())
87 vol = Cend.sum() / C0 - 1.0
88 moved = float(np.abs(Cend - Cin).max()) # O(1) when the interface moved
89 acc = np.array(acc)
90 return (
91 f"TRANSLATE n={n} sigma={'case' if sigma else 0} form={form} stress={stress} "
92 f"steps={steps} max|u-U|/U={emax / U0[0]:.3e} final|u-U|/U={e / U0[0]:.3e} "
93 f"a/g(mean last half)={acc[len(acc) // 2 :].mean():+.3e} a/g(max abs)={np.abs(acc).max():.3e} "
94 f"vol_err={vol:.1e} max|C-C0|={moved:.2f}"
95 )
96
97
98def main():
99 p = argparse.ArgumentParser()
100 p.add_argument("--n", type=int, default=32)
101 p.add_argument("--steps", type=int, default=200)
102 p.add_argument("--sigma", action="store_true")
103 p.add_argument("--forms", default="vel,vel-adv,mom,vel-blk")
104 a = p.parse_args()
105 for form in a.forms.split(","):
106 for stress in ("laplacian", "full"):
107 print(run(a.n, form, stress, a.sigma, a.steps), flush=True)
108
109
110if __name__ == "__main__":
111 main()
build(n, form, stress, sigma)
run(n, form, stress, sigma, steps)