34def make(pf, cls, u_in, low, blk, dist):
38 s.init_mpi(NX, NY, NZ)
39 s.set_rho(1.0); s.set_mu(MU); s.set_dt(DT)
40 s.set_advection(
True); s.set_advection_scheme(
"koren")
41 if cls
is pf.SolverColocated:
42 s.set_collocated_scheme(
"gauge-exact")
44 s.set_domain_bc(
"-x",
"inflow", (u_in, 0.0, 0.0)); s.set_domain_bc(
"+x",
"outflow")
46 s.set_domain_bc(
"-x",
"outflow"); s.set_domain_bc(
"+x",
"inflow", (u_in, 0.0, 0.0))
47 s.set_domain_bc(
"-y",
"wall"); s.set_domain_bc(
"+y",
"wall")
48 s.set_pressure_geometry(np.asfortranarray(np.full((lx, ly, lz), 10.0)))
49 s.set_pressure_pcg(
True, 400, 1e-11)
54 """The three cases on one block; returns {name: local array} (census: the per-step series)."""
56 for cls
in (pf.SolverColocated,
pf.Solver):
58 s =
make(pf, cls, 1.0,
"inflow", blk, dist)
61 s.add_scalar(
"c", diffusivity=0.0, scheme=
"koren", iters=1)
62 s.set_scalar_bc(
"c",
"-x",
"dirichlet", 1.0); s.set_scalar_bc(
"c",
"+x",
"neumann", 0.0)
63 s.set_field(
"c", np.asfortranarray(np.ones(blk[3:])))
66 res[n +
"_A_c"] = np.array(s.get_field(
"c"), dtype=np.float64)
67 res[n +
"_A_u"] = np.array(s.get_u(), dtype=np.float64)
68 s =
make(pf, cls, -1.0,
"inflow", blk, dist)
72 cen.append(s.diagnostics.outflow_backflow()[
"max_reverse"])
73 res[n +
"_B_census"] = np.array(cen)
74 s =
make(pf, cls, -1.0,
"outflow", blk, dist)
77 res[n +
"_C_u"] = np.array(s.get_u(), dtype=np.float64)
84 from mpi4py
import MPI
85 except ImportError
as e:
88 if not hasattr(pf,
"mpi_block"):
89 print(
"SKIP: peclet.flow built without PECLET_FLOW_MPI")
93 print(
"SKIP: run under mpirun with np >= 2")
95 (ox, oy, oz), (lx, ly, lz) = pf.mpi_block(NX, NY, NZ)
96 blk = (ox, oy, oz, lx, ly, lz)
97 xsplit = comm.allreduce(int((oy, oz, ly, lz) == (0, 0, NY, NZ)), op=MPI.MIN)
98 owners = comm.allreduce(int(ox + lx == NX), op=MPI.SUM)
101 parts = comm.gather((blk, local), root=0)
104 ref =
run_cases(pf, (0, 0, 0, NX, NY, NZ),
False)
106 assert xsplit == 1
and owners == 1, (
107 f
"np {comm.size}: the decomposition is not an x-only split with one owner of +x "
108 f
"(xsplit {xsplit}, owners {owners})")
109 line = [f
"np {comm.size}"]
110 for k
in sorted(ref):
111 if k.endswith(
"census"):
112 d = float(np.abs(parts[0][1][k] - ref[k]).max())
114 g = np.zeros_like(ref[k])
115 for (bx, by, bz, bl, bm, bn), p
in parts:
116 g[bx:bx + bl, by:by + bm, bz:bz + bn] = p[k]
117 d = float(np.abs(g - ref[k]).max())
118 if k.endswith(
"_A_c"):
119 cdev = float(np.abs(g - 1.0).max())
120 assert cdev <= TOL_C, f
"{k}: distributed c = 1 moved by {cdev:.3e}"
121 line.append(f
"{k} {d:.1e}")
122 assert d <= TOL_SERIAL, f
"{k}: distributed vs serial {d:.3e} > {TOL_SERIAL:.0e}"
123 for n
in (
"SolverColocated",
"Solver"):
124 cdev = float(np.abs(ref[n +
"_A_c"] - 1.0).max())
125 assert cdev <= TOL_C, f
"{n}_A_c: serial c = 1 moved by {cdev:.3e}"
126 print(
" " +
" ".join(line))
127 except AssertionError
as e:
130 ok = comm.bcast(ok, root=0)
134 print(
"OK: the high-side face plane is kept on its owning rank only; distributed == serial")