44 cs = np.array([0.25 * N, 0.75 * N])
45 xs = np.arange(N) + 0.5
46 X, Y, Z = np.meshgrid(xs, xs, xs, indexing=
"ij")
47 best = np.full((N, N, N), 1e30)
51 dx = X - sx; dx -= N * np.round(dx / N)
52 dy = Y - sy; dy -= N * np.round(dy / N)
53 dz = Z - sz; dz -= N * np.round(dz / N)
54 best = np.minimum(best, np.sqrt(dx * dx + dy * dy + dz * dz) - R)
55 return np.asfortranarray(best)
60 off = (np.arange(sub) + 0.5) / sub
65 X, Y, Z = np.meshgrid(np.arange(n[0]) + ox, np.arange(n[1]) + oy,
66 np.arange(n[2]) + oz, indexing=
"ij")
67 out += ((X - c[0]) ** 2 + (Y - c[1]) ** 2 + (Z - c[2]) ** 2 <= R * R)
68 return np.asfortranarray(out / sub ** 3)
73 s.set_rho(1.0); s.set_mu(0.1); s.set_dt(60.0); s.set_body_force((1e-3, 0.0, 0.0))
74 s.set_advection(
False)
75 s.diagnostics.set_velocity_solver_params(80)
76 s.set_pressure_multigrid(
True, 3)
77 s.set_pressure_pcg(
True, 200, 1e-9)
78 if scheme
is not None:
79 s.set_collocated_scheme(scheme)
81 for _
in range(steps):
107 """A divergence-free (to O(h^2)) cell-centred Taylor-Green pair: a non-trivial advecting
108 field with no body force, so the hash reflects the advection + projection only."""
111 X, Y = np.meshgrid(ix, ix, indexing=
"ij")
112 u = np.repeat((U0 * np.sin(k * X) * np.cos(k * Y))[:, :,
None], nz, axis=2)
113 v = np.repeat((-U0 * np.cos(k * X) * np.sin(k * Y))[:, :,
None], nz, axis=2)
114 return (np.asfortranarray(u), np.asfortranarray(v),
115 np.asfortranarray(np.zeros((N, N, nz))))
119 """Collocated + advection, triply periodic: hasBc_ false, so advection is EXPLICIT (Koren in
120 the RHS) and the advecting velocity is the projected face field of the previous step."""
122 s = pf.SolverColocated(N, N, nz)
123 s.set_rho(1.0); s.set_mu(0.05); s.set_dt(0.5)
124 s.set_advection(
True); s.set_advection_scheme(
"koren")
125 s.diagnostics.set_velocity_solver_params(80)
126 s.set_pressure_pcg(
True, 200, 1e-9)
127 s.set_solid(np.asfortranarray(np.full((N, N, nz), 1e3)), cutcell_pressure=
True)
135 """Collocated + advection + domain BCs: hasBc_ true, so implicitAdv() holds and the IMPLICIT
136 FOU operator (buildAdvStencil) plus the explicit (SOU - FOU) deferred correction both read
137 the advecting velocity -- they must read the SAME one."""
138 nx, ny, nz = 24, 12, 8
139 s = pf.SolverColocated(nx, ny, nz)
140 s.set_rho(1.0); s.set_mu(0.05); s.set_dt(0.5)
141 s.set_advection(
True); s.set_advection_scheme(
"koren")
142 s.set_domain_bc(
"-x",
"inflow", (1.0, 0.0, 0.0))
143 s.set_domain_bc(
"+x",
"outflow")
144 s.set_domain_bc(
"-y",
"wall"); s.set_domain_bc(
"+y",
"wall")
145 s.set_pressure_geometry(np.asfortranarray(np.full((nx, ny, nz), 10.0)))
146 s.set_pressure_pcg(
True, 200, 1e-9)
170 s.set_advection(
False)
171 s.set_rho(1.0); s.set_mu(0.1)
172 s.set_pressure_geometry(np.asfortranarray(np.full((n, n, n), 10.0)))
173 s.set_pressure_pcg(
True, 500, 1e-12)
175 s.set_vof(
sphere_fractions((n, n, n), R, (n / 2 + 0.13, n / 2 + 0.27, n / 2 + 0.11)))
176 s.set_property_model(
"rho",
"linear",
"C", [1.0, 0.0])
177 s.set_surface_tension(1.0)
178 s.set_dt(0.25 * s.capillary_dt())
185 """Collocated variable-rho (V8) VoF drop at ratio 1000 under a constant curvature (an exact
186 equilibrium), the balanced-force projection ON (its V8 default) and the single-rank MG-PCG: the
187 one path where the resident PCG stops on the caller's stop reference (WO-X1, setStopReference)."""
189 s = pf.SolverColocated(n, n, n)
190 s.set_advection(
False)
191 s.set_rho(1000.0); s.set_mu(0.1); s.set_dt(1.0)
192 s.set_pressure_geometry(np.asfortranarray(np.full((n, n, n), 10.0)))
194 s.set_vof(
sphere_fractions((n, n, n), R, (n / 2 + 0.13, n / 2 + 0.27, n / 2 + 0.11)))
195 s.set_property_model(
"rho",
"linear",
"C", [1.0, 999.0])
196 s.set_surface_tension(1.0)
197 s.diagnostics.set_vof_kappa_constant(1.0 / R)
198 s.set_dt(0.5 * s.capillary_dt())
199 s.set_balanced_force_projection(
True)
200 s.set_pressure_pcg(
True, 500, 1e-10)
210 s.set_advection(
False)
211 s.set_rho(1.0); s.set_mu(0.05); s.set_dt(8.0)
212 s.set_implicit_advection(
True); s.diagnostics.set_outer_iterations(2)
213 for f
in (
"-x",
"+x",
"-y",
"+y"):
214 s.set_domain_bc(f,
"wall", (0.0, 0.0, 0.0))
215 s.set_pressure_geometry(np.asfortranarray(np.full((N, N, nz), 10.0)))
217 s.add_scalar(
"T", diffusivity=alpha, scheme=
"koren", iters=50)
218 s.set_scalar_bc(
"T",
"-x",
"dirichlet", 1.0); s.set_scalar_bc(
"T",
"+x",
"dirichlet", 0.0)
219 s.set_scalar_bc(
"T",
"-y",
"neumann", 0.0); s.set_scalar_bc(
"T",
"+y",
"neumann", 0.0)
220 coeff = 1e4 * 0.05 ** 2 / (0.71 * N ** 3)
221 s.set_property_model(
"force_y",
"boussinesq",
"T", [1.0, coeff, 1.0, 0.5])
223 T0 = np.repeat((1.0 - (x + 0.5) / N)[:,
None,
None], N, 1).repeat(nz, 2)
224 s.set_field(
"T", np.asfortranarray(T0.astype(np.float64)))
233 s.set_rho(1.0); s.set_mu(1.0); s.set_dt(0.5)
234 s.set_advection(
False)
235 s.set_pressure_geometry(np.asfortranarray(np.full((N, N, N), 10.0)))
237 s.set_porous_continuity(
True)
238 s.set_field(
"eps", np.asfortranarray(np.full((N, N, N), 0.6)))
239 s.set_field(
"drag_beta", np.asfortranarray(np.full((N, N, N), 4.0)))
240 s.diagnostics.exchange_field(
"eps"); s.diagnostics.exchange_field(
"drag_beta")
242 s.set_body_force((0.0, 0.0, 0.2))
251 s.set_rho(1.0); s.set_mu(0.1); s.set_dt(2.0); s.set_body_force((1e-3, 0.0, 0.0))
252 s.set_advection(
False)
253 s.set_pressure_pcg(
True, 200, 1e-9)
254 node_ints = np.array([1, -1, -1], dtype=np.int32)
255 node_reals = np.zeros(16); node_reals[0] = 3.0; node_reals[14] = 1.0; node_reals[15] = 1.0
256 ii = np.array([[0, -1]], dtype=np.int32)
257 ir = np.zeros((1, 18)); ir[0, 0:3] = (N / 2, N / 2, N / 2); ir[0, 6] = 1.0; ir[0, 7] = 1.0
258 s.set_scene(node_ints, node_reals, ii.ravel(), ir.ravel(), periodic=
True)
259 s.set_instance_transform(0, [N / 2, N / 2, N / 2], [0.0, 0.0, 0.0, 1.0])
260 s.set_instance_motion(0, lin_vel=[0.02, 0.0, 0.0], ang_vel=[0.0, 0.0, 0.005])
261 s.set_solid_from_scene(
True)
264 s.set_instance_transform(0, [N / 2 + 0.1, N / 2, N / 2], [0.0, 0.0, 0.0, 1.0])
288 from mpi4py
import MPI
289 comm = MPI.COMM_WORLD
292 origin, bsize = pf.mpi_block(N, N, N)
293 ox, oy, oz = origin; lnx, lny, lnz = bsize
294 lsdf = np.asfortranarray(gsdf[ox:ox + lnx, oy:oy + lny, oz:oz + lnz])
297 s.set_rho(1.0); s.set_mu(0.1); s.set_dt(60.0); s.set_body_force((1e-3, 0.0, 0.0))
298 s.set_advection(
False)
299 s.diagnostics.set_velocity_solver_params(80)
300 s.set_pressure_multigrid(
True, 3)
301 s.set_pressure_pcg(
True, 200, 1e-9)
302 s.set_solid(lsdf, cutcell_pressure=
True)
305 loc = {k: np.ascontiguousarray(v, dtype=np.float64)
for k, v
in fields(s).items()}
306 allf = comm.gather(loc, root=0)
307 if comm.Get_rank() == 0:
308 d = {k: np.concatenate([np.asarray(r[k]).ravel()
for r
in allf])
for k
in loc}
309 report(f
"mpi_np{comm.Get_size()}", d)