24 d = np.maximum(G.dwall, 1e-3 * h)
if SURR ==
"centroid" else 0.7 * h
25 wc = np.where(cells, G.Aw / (h * h * (d + (0
if np.isinf(k)
else 1 / k))), 0)
26 S, _ = assemble_fv(G, G.ax, G.ay, cells, wall_coef=wc)
31 L = sp.tril(A, 0).tocsc(); U = A - sp.tril(A, 0)
32 u = np.zeros_like(b); r0 = np.linalg.norm(b)
35 u = spla.spsolve_triangular(L, b - U @ u, lower=
True)
36 hist.append(np.linalg.norm(b - A @ u) / r0)
37 if not np.isfinite(hist[-1])
or hist[-1] > 1e8:
43 G =
Geo(ND, (0.31, 0.62))
44 A, M = build(G, k, fc=
False, wall=
"probe0.7")
48 idt = 1.0 / (dtn * h2)
49 A = A + sp.diags(M * idt); S = S + sp.diags(M * idt)
50 A = A.tocsr(); S = S.tocsc()
51 rng = np.random.default_rng(0)
52 b = M * (1 + 0.1 * rng.standard_normal(A.shape[0]))
56 P = spla.LinearOperator(A.shape, matvec=lu.solve)
58 v = rng.standard_normal(A.shape[0])
60 w = v - lu.solve(A @ v); nv = np.linalg.norm(w); v = w / nv
62 for name, fn
in ((
"BiCGStab", spla.bicgstab), (
"GMRES20",
lambda A_, b_, **kw: spla.gmres(A_, b_, restart=20, callback_type=
'legacy', **kw))):
66 x, info = fn(A, b, M=P, rtol=1e-10, maxiter=500, callback=cb)
67 out[name] = (cnt[0], info, np.linalg.norm(b - A @ x) / np.linalg.norm(b))
70 out[
"min_kappa"] = G.kap[cells].min()