61def run(n, ratio, ja, x0p=0.10, xep=0.25, alpha_l=1.0, cfl=0.2, fo=0.5, nt=4,
62 kratio=None, rcpratio=None, consistent=True, plane=True, quad=False, muscl=False,
63 verbose=True, energy_order=1, deposit=None, mu_ratio=None, stress=None):
64 """One resolution. The PHYSICAL problem is fixed (domain length 1, alpha_l = 1, the vapour
65 layer growing from x0p to xep of the domain) and only h = 1/n changes. `nt` is the transverse
66 extent: the problem is 1-D so 4 is enough physically, but it decides how far the pressure
67 multigrid can coarsen (see the findings)."""
71 t0 = (x0p / (2 * b)) ** 2 / alpha_l
72 te = (xep / (2 * b)) ** 2 / alpha_l
76 rho_l, rho_v = 1.0, rr
78 k_l = al * rho_l * cpl
80 rcp_v = rcp_l / (rcpratio
if rcpratio
else ratio)
81 k_v = k_l / (kratio
if kratio
else ratio)
83 h_lv = rho_l * cpl * dT / (rho_v * ja)
89 s.set_advection(
False)
90 s.set_domain_bc(
"-x",
"wall")
91 s.set_domain_bc(
"+x",
"outflow")
92 s.set_pressure_geometry(np.full((n, ny, nz), 1.0, order=
"F"))
94 c = np.zeros((n, ny, nz), order=
"F")
96 c[i, :, :] = min(1.0, max(0.0, (i + 1) - X0))
98 s.set_property_model(
"rho",
"linear",
"C", [rho_v, rho_l - rho_v])
99 if mu_ratio
is not None:
100 s.set_property_model(
"mu",
"linear",
"C", [1e-3 * mu_ratio, 1e-3 * (1.0 - mu_ratio)])
101 if stress
is not None:
102 s.set_viscous_stress(stress)
103 s.set_pressure_fcg(
True, 4000, 1e-10)
106 t = np.zeros((n, ny, nz), order=
"F")
110 sv = x / (2 * math.sqrt(alpha_l * t0)) - b * (1.0 - rr)
111 t[i, :, :] = dT - dT * math.erfc(sv) / math.erfc(b * rr)
119 sv = 1.0 / (2 * math.sqrt(alpha_l * tt)) - b * (1.0 - rr)
120 return dT - dT * math.erfc(sv) / math.erfc(b * rr)
122 s.add_scalar(
"T", al,
"koren", 60)
123 s.set_scalar_bc(
"T",
"-x",
"dirichlet", 0.0)
124 s.set_scalar_bc(
"T",
"+x",
"dirichlet", farT(t0))
126 s.enable_phase_change(rho_v, rho_l, h_lv)
127 s.set_phase_change_thermal(
True,
"T", 0.0, k_v, k_l, 0.0)
128 s.diagnostics.set_phase_change_plane_dirichlet(plane)
129 s.diagnostics.set_phase_change_quadratic_fit(quad)
131 s.set_phase_change_energy(
True, rcp_v, rcp_l)
132 s.diagnostics.set_phase_change_energy_muscl(muscl)
134 if energy_order != 1:
135 s.diagnostics.set_phase_change_energy_order(energy_order)
136 if deposit
is not None:
137 s.diagnostics.set_phase_change_deposit_fallback(bool(deposit))
140 Xdot = b * math.sqrt(alpha_l / t0) * n
141 ul = Xdot * (1.0 - rr)
142 u = np.zeros((n, ny, nz), order=
"F")
143 u[int(X0) + 2:, :, :] = ul
149 tcur, nsteps, itmax, capped = t0, 0, 0, 0
151 Xd = b * math.sqrt(alpha_l / tcur) * n
152 dt = min(cfl / max(Xd * (1.0 - rr), 1e-30), fo / al)
153 dt = min(dt, (te - tcur))
155 s.set_scalar_bc(
"T",
"+x",
"dirichlet", farT(tcur + dt))
159 it = s.diagnostics.last_pressure_iterations()
160 itmax = max(itmax, it)
163 layer = n - s.get_vof().sum() / (ny * nz)
164 exact = 2 * b * math.sqrt(alpha_l * te) * n
165 d = s.diagnostics.phase_change_diagnostics()
167 tnum = s.get_field(
"T")[:, 0, 0]
171 xg = 2 * b * math.sqrt(alpha_l * te)
173 sv = x / (2 * math.sqrt(alpha_l * te)) - b * (1.0 - rr)
174 ex = dT - dT * math.erfc(sv) / math.erfc(b * rr)
175 terr = max(terr, abs(tnum[i] - ex))
178 print(f
" N = {n:4d} steps {nsteps:5d} b {b:.6f} layer {layer:9.5f} cells "
179 f
"(exact {exact:9.5f}) rel {100*(layer-exact)/exact:+8.4f} %")
180 print(f
" |T - T_exact|_inf over the liquid = {terr:.4e} ({100*terr/dT:.3f} % of "
181 f
"dT, {tn} cells) C in [{d['min_C']:.2e}, {d['max_C']:.6f}]")
182 print(f
" pressure iters max {itmax}/4000 (capped steps {capped}), "
183 f
"band_div {d['band_div']:.3e}, T in [{d['T_min']:.4e}, {d['T_max']:.6f}], "
184 f
"unresolved {d['unresolved']:.1e}, fallback {d['fallback_cells']}")
185 return abs((layer - exact) / exact), terr / dT, capped, itmax
189 ap = argparse.ArgumentParser()
190 ap.add_argument(
"--ratio", type=float, default=10.0)
191 ap.add_argument(
"--ja", type=float, default=1.0)
192 ap.add_argument(
"--ns", type=str, default=
"64,128,256")
193 ap.add_argument(
"--kratio", type=float, default=
None)
194 ap.add_argument(
"--rcpratio", type=float, default=
None)
195 ap.add_argument(
"--no-consistent", action=
"store_true")
196 ap.add_argument(
"--no-plane", action=
"store_true")
197 ap.add_argument(
"--no-quad", action=
"store_true")
198 ap.add_argument(
"--fo", type=float, default=0.5)
199 ap.add_argument(
"--muscl", action=
"store_true")
200 ap.add_argument(
"--nt", type=int, default=4)
201 ap.add_argument(
"--mu-ratio", type=float, default=
None)
202 ap.add_argument(
"--viscous-stress", type=str, default=
None)
203 ap.add_argument(
"--energy-order", type=int, default=1,
204 help=
"WO-P3g: 2 = the second-order interfacial energy operator")
205 ap.add_argument(
"--deposit-fallback", type=int, default=
None,
206 help=
"WO-P3f open item 6: the 5^3 divergence-source deposit fallback")
208 ns = [int(x)
for x
in a.ns.split(
",")]
209 print(f
"P2 sucking interface: rho_l/rho_v = {a.ratio:g}, Ja = {a.ja:g}, "
210 f
"k ratio {a.kratio or a.ratio:g}, rho*c_p ratio {a.rcpratio or a.ratio:g}, "
211 f
"consistent energy {not a.no_consistent}, plane Dirichlet {not a.no_plane}, "
212 f
"quadratic fit {not a.no_quad}, Fo {a.fo:g}, WO-P3g energy order {a.energy_order}, "
213 f
"deposit fallback {a.deposit_fallback}, mu ratio {a.mu_ratio}, viscous stress "
214 f
"{a.viscous_stress or 'solver default'}")
217 e, te_, capped, itmax =
run(n, a.ratio, a.ja, kratio=a.kratio, rcpratio=a.rcpratio,
218 consistent=
not a.no_consistent, plane=
not a.no_plane,
219 quad=
not a.no_quad, fo=a.fo, muscl=a.muscl, nt=a.nt,
220 energy_order=a.energy_order, deposit=a.deposit_fallback,
221 mu_ratio=a.mu_ratio, stress=a.viscous_stress)
225 print(f
" *** {capped} CAPPED pressure solves at N = {n}: rule 3b, run INVALID")
226 for x, y, na, nb
in zip(errs[:-1], errs[1:], ns[:-1], ns[1:]):
227 print(f
" observed order {na} -> {nb}: {math.log2(x/y):.3f}")
229 print(f
" observed order {ns[0]} -> {ns[-1]} (fit): "
230 f
"{math.log2(errs[0]/errs[-1])/math.log2(ns[-1]/ns[0]):.3f}")
231 print(f
" GATE: order >= 1.4 and |T - T_exact| <= 1 % of dT at N = {ns[-1]} "
232 f
"(got {100*terrs[-1]:.3f} %)")
run(n, ratio, ja, x0p=0.10, xep=0.25, alpha_l=1.0, cfl=0.2, fo=0.5, nt=4, kratio=None, rcpratio=None, consistent=True, plane=True, quad=False, muscl=False, verbose=True, energy_order=1, deposit=None, mu_ratio=None, stress=None)