58 off = (np.arange(sub) + 0.5) / sub
59 g = (np.arange(n)[:,
None] + off[
None, :]).ravel()
60 out = np.zeros((n, n, n))
61 lo, hi = int(math.floor(c - r)) - 1, int(math.ceil(c + r)) + 1
62 for k
in range(max(lo, 0), min(hi, n)):
64 X, Y, Z = np.meshgrid(g, g, zs, indexing=
"ij")
65 ins = ((X - c) ** 2 + (Y - c) ** 2 + (Z - c) ** 2 < r * r).astype(np.float64)
66 out[:, :, k] = ins.reshape(n, sub, n, sub, sub).
mean(axis=(1, 3, 4))
67 return np.asfortranarray(out)
71 """Cell fractions of the half-space nrm.(x - x0) < 0, x in cells, sub^3 samples."""
72 off = (np.arange(sub) + 0.5) / sub
73 g = (np.arange(n)[:,
None] + off[
None, :]).ravel()
74 out = np.zeros((n, n, n))
76 X, Y, Z = np.meshgrid(g, g, k + off, indexing=
"ij")
77 ins = (nrm[0] * (X - x0[0]) + nrm[1] * (Y - x0[1]) + nrm[2] * (Z - x0[2]) < 0).astype(np.float64)
78 out[:, :, k] = ins.reshape(n, sub, n, sub, sub).
mean(axis=(1, 3, 4))
79 return np.asfortranarray(out)
89 from mpi4py
import MPI
90 if MPI.COMM_WORLD.Get_size() > 1:
94 n = round(4 * a.dh)
if a.case ==
"p1" else a.n
96 org, siz = (0, 0, 0), (n, n, n)
98 org, siz = pf.mpi_block(n, n, n)
99 sl = tuple(
slice(o, o + m)
for o, m
in zip(org, siz))
102 AR, BO, RR, MR = 29.9, 2.0, 1e-3, 1e-2
103 D, RHO_L, G = 1.0e-3, 1000.0, 9.81
105 MU_L = math.sqrt(RHO_L * (RHO_L - RHO_G) * G * D ** 3) / AR
106 MU_G = MU_L
if a.mu_uniform
else MR * MU_L
107 SIGMA = (RHO_L - RHO_G) * G * D ** 2 / BO
110 s =
pf.Solver(siz, extent=(L, L, L))
if comm
is None else \
111 pf.Solver(siz, extent=(L, L, L), global_cells=(n, n, n))
116 s.set_pressure_geometry(np.full(siz, 1.0, order=
"F"))
118 s.set_property_model(
"rho",
"linear",
"C", [RHO_L, RHO_G - RHO_L])
119 s.set_property_model(
"mu",
"linear",
"C", [MU_L, MU_G - MU_L])
120 s.set_advection(
True)
121 s.set_surface_tension(SIGMA)
122 s.set_pressure_pcg(
True, 800, 1e-8)
124 s.set_vof(np.asfortranarray(Cg[sl]))
125 s.enable_vof_momentum(RHO_L, RHO_G)
126 alpha = float(np.mean(Cg))
127 rho_av = RHO_L + (RHO_G - RHO_L) * alpha
128 s.set_property_model(
"force_x",
"linear",
"C", [-(RHO_L - rho_av) * G, -(RHO_G - RHO_L) * G])
129 s.set_superficial_velocity(
True,
"x", 0.0)
132 MU_HI, MU_LO = 1.0, (1.0
if a.mu_uniform
else 1e-2)
133 s =
pf.Solver(siz, extent=(L, L, L))
if comm
is None else \
134 pf.Solver(siz, extent=(L, L, L), global_cells=(n, n, n))
137 for f
in (
"-x",
"+x",
"-y",
"+y",
"-z",
"+z"):
138 s.set_domain_bc(f,
"wall")
141 s.set_pressure_geometry(np.full(siz, 1.0, order=
"F"))
143 b, g = math.radians(22.5), math.radians(22.5)
144 nrm = (math.cos(b) * math.cos(g), math.cos(b) * math.sin(g), math.sin(b))
145 x0 = [0.5 * n + 0.3 * c
for c
in nrm]
147 s.set_property_model(
"mu",
"linear",
"C", [MU_HI, MU_LO - MU_HI])
148 s.set_advection(
False)
149 s.set_body_force((-0.1 * math.sin(g), 0.1 * math.cos(g), 0.0))
150 s.set_pressure_pcg(
True, 800, 1e-10)
152 s.set_surface_tension(a.sigma)
153 if a.mode ==
"sharp" or hasattr(s,
"set_vof_viscous_interface"):
154 s.set_vof_viscous_interface(a.mode)
155 cen = {
"band_cells": 0,
"virtual_cells": 0,
"film_cells": 0,
"fit_fallbacks": 0}
157 for _
in range(a.steps):
159 lm = s.vof_step_limits()
160 s.set_dt(0.25 * min(lm[
"cfl_dt"], lm[
"capillary_dt"]))
162 s.set_dt(100.0 * h * h / MU_HI)
164 if hasattr(s.diagnostics,
"vof_viscous_interface_census"):
165 c = s.diagnostics.vof_viscous_interface_census()
168 tie_read(s, tie, comm)
171 cen[k] = comm.allreduce(cen[k])
172 loc = {
"C": s.get_vof(),
"u": s.get_u(),
"v": s.get_v(),
"w": s.get_w(),
"p": s.get_field(
"p")}
174 parts = comm.gather((sl, loc), root=0)
175 if comm.Get_rank() != 0:
177 glob = {k: np.zeros((n, n, n), order=
"F")
for k
in loc}
178 for psl, pl
in parts:
182 np.savez(a.out, **loc)
183 hs = hashlib.sha256(b
"".join(np.ascontiguousarray(loc[k]).tobytes()
for k
in sorted(loc))).hexdigest()[:16]
184 npr = 1
if comm
is None else comm.Get_size()
185 print(f
"GSV56 case={a.case} mode={a.mode} mu_uniform={a.mu_uniform} np={npr} steps={a.steps} "
186 f
"census/step band={cen['band_cells'] / a.steps:.1f} virt={cen['virtual_cells'] / a.steps:.1f} "
187 f
"film={cen['film_cells'] / a.steps:.1f} fallbacks={cen['fit_fallbacks']} {tie_str(tie)} "
188 f
"max|u|={float(np.max(np.abs(loc['u']))):.6e} sha={hs}")