43def make(cls, N, variable, dt, drag=False):
48 s.set_advection(
False)
49 s.set_pressure_pcg(
True, 400, 1e-13)
50 s.diagnostics.set_velocity_solver_params(400, 1e-12, 2)
51 s.set_pressure_geometry(np.asfortranarray(np.full((N, N, NZ), 10.0)))
53 s.diagnostics.set_density_mode(
"variable")
67 for _
in range(max_steps):
69 u = np.array(s.get_u())
70 if prev
is not None and np.max(np.abs(u - prev)) <= tol * max(np.max(np.abs(u)), 1e-300):
73 return np.array(s.get_u()), np.array(s.get_v())
99 """Relative misfit of the recovered placed force against (cell value, face mean)."""
100 u, v, k, fx, fy =
tg_case(cls, N, variable)
101 lam_h = 8.0 * np.sin(0.5 * k) ** 2
102 rec_x, rec_y = MU * lam_h * u, MU * lam_h * v
103 face_x = 0.5 * (fx + np.roll(fx, 1, axis=0))
104 face_y = 0.5 * (fy + np.roll(fy, 1, axis=1))
105 scale = np.max(np.abs(fx))
108 return max(np.max(np.abs(rec_x - cx)), np.max(np.abs(rec_y - cy))) / scale
110 return mis(fx, fy), mis(face_x, face_y)
114 """Max error of the steady velocity vs the continuum solution at the velocity's location."""
115 u, v, k, _, _ =
tg_case(cls, N, variable, A)
116 i = np.arange(N, dtype=np.float64)
117 off = 0.0
if cls
is pf.Solver
else 0.5
118 xu, yc = np.meshgrid(i + off, i + 0.5, indexing=
"ij")
119 xc, yv = np.meshgrid(i + 0.5, i + off, indexing=
"ij")
120 amp = A / (MU * 2.0 * k * k)
121 ue = amp * np.sin(k * xu) * np.cos(k * yc)
122 ve = -amp * np.cos(k * xc) * np.sin(k * yv)
123 return max(np.max(np.abs(u[:, :, 0] - ue)), np.max(np.abs(v[:, :, 0] - ve))) / amp
128 xc = np.arange(N) + 0.5
129 X, Y = np.meshgrid(xc, xc, indexing=
"ij")
132 beta = np.repeat((2.0 + np.sin(k * X) * np.cos(k * Y))[:, :,
None], NZ, 2)
133 s =
make(cls, N, variable, dt=1.0, drag=
True)
136 set_cell(s,
"force_y", np.zeros_like(beta))
137 set_cell(s,
"force_z", np.zeros_like(beta))
139 return max(np.max(np.abs(u - U0)), np.max(np.abs(v))) / U0