flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
periodic_image_gate.py
Go to the documentation of this file.
1"""Periodic images are a UNION -- the oversized-leaf trap, gated.
2
3A container wall built as slab-minus-cavity in a periodic box: if the slab is wider than the box,
4its periodic images overlap and refill the cavity wherever a neighbouring image's slab covers it
5(the query takes the min over images). set_solid_from_scene must (a) DETECT it exactly --
6periodic_image_overlap_cells() > 0 plus a stderr warning -- for a 0.7 L slab, and (b) report 0
7for a slab of half the box plus the wall thickness, whose cavity must then be the full 53 cells.
8
9Usage: PYTHONPATH=<flow build> python periodic_image_gate.py
10"""
11import numpy as np
12from peclet import flow as sdflow
13from peclet import geom
14
15L, NY, U = 64, 32, 0.02
16KI_I, KI_R = 2, 17
17OFF, WX = 0.3, 5.335
18HW = (L - 2 * WX) / 2
19x0 = 0.5 * L + OFF
20
21
22def cavity_width(slab_half):
23 b = geom.SceneBuilder()
24 slab = b.add_leaf("box", [slab_half, NY * 2.0, slab_half])
25 cav = b.add_leaf("box", [HW, NY * 2.0, HW])
26 node = b.add_difference(slab, cav)
27 ni, nr, _, _ = b.encode()
28 ii = np.zeros((1, KI_I), dtype=np.int32); ir = np.zeros((1, KI_R))
29 ii[0] = (node, -1); ir[0, 0:3] = (x0, 0.5 * NY, x0); ir[0, 6] = 1.0; ir[0, 7] = 1.0
30 s = sdflow.Solver(L, NY, L)
31 s.set_rho(1.0); s.set_mu(0.1); s.set_dt(1.0)
32 s.set_scene(np.asarray(ni, np.int32), np.asarray(nr, float), ii.ravel(), ir.ravel(),
33 periodic=True)
34 s.set_solid_from_scene(True)
35 s.set_velocity(1, np.full((L, NY, L), U, dtype=np.float64, order="F"))
36 v = np.asarray(s.get_v()).reshape((L, NY, L), order="F")
37 cols = np.where((np.abs(v) > 0).sum(axis=(1, 2)) > 0.5 * NY * L)[0]
38 return len(cols), s.periodic_image_overlap_cells()
39
40
41ok = True
42for tag, half, want_overlap, want_w in (("0.70 L slab (WIDER than the box)", 0.70 * L, True, 38),
43 ("L/2 + 1 slab (half box + wall)", L / 2 + 1.0, False, 53)):
44 w, n = cavity_width(half)
45 good = (n > 0) == want_overlap and w == want_w
46 ok &= good
47 print(" %-34s cavity %2d cols (expect %2d) overlap cells %7d %s"
48 % (tag, w, want_w, n, "ok" if good else "FAIL"))
49print("PERIODIC-IMAGE GATE %s" % ("PASS" if ok else "FAIL"))