flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
setsolid_bench.py
Go to the documentation of this file.
1"""set_solid cost: sampled-array vs scene path, and the per-call breakdown that Layer 3's
2incremental-rebuild decision needs. Also the per-step moving-geometry cost TODAY."""
3import numpy as np, time, sys
4from peclet import flow as sdflow
5
6N = int(sys.argv[1]) if len(sys.argv) > 1 else 64
7R = 0.18 * N
8CEN = [(0.25*N,0.25*N,0.25*N),(0.75*N,0.75*N,0.25*N),(0.75*N,0.25*N,0.75*N),(0.25*N,0.75*N,0.75*N)]
9KN_R, KI_I, KI_R = 16, 2, 17
10node_ints = np.array([1,-1,-1], dtype=np.int32)
11node_reals = np.zeros(KN_R); node_reals[0]=R; node_reals[14]=1.0; node_reals[15]=1.0
12bi = np.zeros((4,KI_I),dtype=np.int32); br = np.zeros((4,KI_R))
13for m,(cx,cy,cz) in enumerate(CEN):
14 bi[m]=(0,-1); br[m,0:3]=(cx-0.5,cy-0.5,cz-0.5); br[m,6]=1.0; br[m,7]=1.0
15
16g = np.arange(N)+0.5
17X,Y,Z = np.meshgrid(g,g,g,indexing="ij")
18ref = np.full((N,N,N),1e30)
19for (cx,cy,cz) in CEN:
20 dx=np.abs(X-cx); dx=np.minimum(dx,N-dx); dy=np.abs(Y-cy); dy=np.minimum(dy,N-dy)
21 dz=np.abs(Z-cz); dz=np.minimum(dz,N-dz)
22 ref=np.minimum(ref,np.sqrt(dx*dx+dy*dy+dz*dz)-R)
23refF = np.asfortranarray(ref)
24
25s = sdflow.Solver(N,N,N)
26s.set_rho(1.0); s.set_mu(1.0); s.set_dt(50.0)
27s.set_scene(node_ints,node_reals,bi.ravel(),br.ravel(),periodic=True)
28s.set_solid_from_scene(True) # warm-up (allocations, MG first build)
29for name, fn in [("set_solid(array) incl. numpy-free upload", lambda: s.set_solid(refF, cutcell_pressure=True)),
30 ("set_solid_from_scene FULL (pressure on) ", lambda: s.set_solid_from_scene(True)),
31 ("set_solid_from_scene MOMENTUM-ONLY ", lambda: s.set_solid_from_scene(False))]:
32 ts=[]
33 for _ in range(5):
34 t0=time.time(); fn(); ts.append(time.time()-t0)
35 ts=sorted(ts)
36 print(" N=%d %-42s median %.1f ms (min %.1f)" % (N, name, 1e3*ts[2], 1e3*ts[0]))
37print(" -> a moving body today costs the full set_solid_from_scene per step")