Code verification

Verification asks whether HARTMAX solves its equations correctly. As the mesh refines, the error against a known solution must fall at the scheme’s design order. Validation, on the other pages, asks whether those equations describe the flow.

This page checks the time step, hartmax.thermal.build_thermal_step, against solutions that share none of its operators: a manufactured solution for each term and for all of them at once, and the exact decay of a vortex between insulating Hartmann walls. Every term converges at second order in space. The step is first order in time, and with the explicit Lorentz force its time error does not grow with the field.

Run it

This runs one term, conduction, on two meshes in about 4 s on a laptop CPU:

import numpy as np

from validation.verification import manufactured_run

coarse, fine = (manufactured_run("conduction", cells)["rms"]["T"] for cells in (16, 32))
print(f"RMS error {coarse:.2e} on 16 cells, {fine:.2e} on 32: order {np.log2(coarse / fine):.2f}")
# RMS error 1.29e-03 on 16 cells, 3.51e-04 on 32: order 1.88

validation/verification.py holds every case (TERMS, vortex_decay). tests/test_steady.py runs each term on 16 and 32 cells, the coupled case in space and in time, and the vortex’s decay. Three single terms run on every pull request and the rest on the slow tier.

Each term on its own

Method.

  • Each manufactured solution is a smooth velocity, temperature and, where tested, pressure.

  • Its source is the residual of the continuous equations at the step’s old time. Only the term under test is on, besides the time derivative and incompressibility.

  • The meshes have \(N\) = 8, 16, 32 and 64 cells along \(x\) and \(z\) (128 for the cases with two cells along \(y\)), and half as many along \(y\).

  • The time step falls as \(h^2\) from 0.01 at \(N=8\), so that a first-order time error falls with the mesh too.

  • The errors, exact less computed, are measured at \(t=0.2\) on every velocity face or cell, in \(L_\infty\) and RMS.

The field lies along \(y\). A flow invariant along it has the electromotive force \(B\nabla\psi\), which the potential \(B\psi\) cancels, so it carries no current. A flow with no vorticity along it carries \(\sigma\mathbf u\times\mathbf B\). Both vanish with their normal derivatives at the walls \(z=\pm1\), so the potential and current are exact, conducting walls included.

The observed orders on the finest pair of meshes (the tests hold the orders between 16 and 32 cells):

Term

Tested

Field

\(L_\infty\)

\(L_2\)

Momentum advection

\((\mathbf u\cdot\nabla)\mathbf u\), limited, triply periodic

\(u_x\)

1.76

2.07

Viscous diffusion

\(\nu\nabla^2\mathbf u\), no-slip walls

\(u_x\)

1.85

1.96

Pressure gradient

\(-\nabla p/\rho\), a manufactured pressure

\(p\)

1.96

2.00

Lorentz force, balanced part

\(\mathbf j=\sigma(-\nabla\phi+\mathbf u\times\mathbf B)=\mathbf 0\)

\(u_x\)

1.93

1.99

Lorentz force, damped part

\(\mathbf j\times\mathbf B/\rho=-(\sigma B^2/\rho)\,\mathbf u_\perp\)

\(u_x\)

1.98

1.98

Lorentz force with conducting walls

\(\nabla\cdot(\sigma\nabla\phi)=\nabla\cdot(\sigma\,\mathbf u\times\mathbf B)\)

\(u_x\)

1.93

1.94

Buoyancy

\(-\beta\,(T-T_{\mathrm r})\,\mathbf g\), the exact velocity zero

\(u_z\)

1.99

1.99

Heat conduction

\(\kappa\nabla^2T\), isothermal walls

\(T\)

1.84

1.97

Heat advection

\(\mathbf u\cdot\nabla T\), van Leer, triply periodic

\(T\)

1.36

2.08

Joule heating

\(\lvert\mathbf j\rvert^2/(\sigma\rho c_p)\) of a held flow

\(T\)

1.93

1.99

Conjugate conduction

\(\nabla\cdot(k\nabla T)\), \([T]=[k\,\partial_zT]=0\) at the walls

\(T\)

1.94

2.00

All terms together

conducting walls

\(u_x\)

1.93

2.01

  • Every term converges at second order in RMS. Heat advection’s \(L_\infty\) order of 1.36 comes from the van Leer limiter, which clips extrema.

  • The conjugate case has walls 0.25 thick, with four times the fluid’s conductivity and twice its heat capacity. Its errors include the wall cells.

In time, with the field on

The coupled case in time. On 32 cells to \(t=1\), the differences between successive halvings of \(\Delta t\) fall at first order.

  • With the explicit Lorentz force, their constant on \(u_x\) does not grow with the field. It is 2.20 with no field, 2.14 at \(\sigma B^2/\rho=10\) and 2.12 at 30.

  • Under the implicit damping shift it is 3.6 and 7.7, which is the shift’s transient error (What the shift costs a transient).

  • At a small step, the shift’s error is the floor at which spatial refinement stops.

Braking by Hartmann walls. A vortex invariant along the field, between the insulating walls the field crosses, is braked by their Hartmann layers. validation.shercliff.vortex_decay_rate solves its decay exactly by Chebyshev collocation. validation.verification.vortex_decay runs it at Ha 20 with 48 cells across, 12 in each layer:

  • Along the vortex’s wavelength, the braking is weak by 7.6, 2.2 and 0.9 % on 8, 16 and 32 cells. That is second order, about \(0.48\sin^2(\pi/n)\) on \(n\) cells, above a floor of 0.4 % from the cells across.

  • The cause is averaging. The step averages the electromotive force onto the current’s faces, and the current back onto the velocity’s. Each average multiplies a wave by \(\cos(k\Delta x/2)\). Case 2’s rolls have 7 to 8 cells a wavelength.

The same vortex between Case 2’s steel walls needs a Hartmann channel with conducting walls, which HARTMAX refuses until plan row H2.9. It returns with that work.

Manufactured solutions elsewhere

Other parts of HARTMAX have their own, on the pages of the code they check:

Sources

  • J. Sommeria and R. Moreau, J. Fluid Mech. 118 (1982) 507–518.

  • C. J. Roy, J. Comput. Phys. 205 (2005) 131–156 (order-of-accuracy verification with manufactured solutions).