Problems, solvers and one verb

Every run in HARTMAX is three objects and one function. A Problem says what to solve, a Solver says how, and solve(problem, solver=None, output=None, start=None) runs it. An Output writes records, ParaView files, a summary and a log. This page lists what each object holds, so you can build a case no preset covers.

A preset such as duct only fills a Problem. The example below solves one at a set flow rate and differentiates the pressure gradient with respect to the field strength:

import jax
import hartmax

hartmax.configure(dtype="float64")                 # explicit; importing HARTMAX changes no JAX setting
problem = hartmax.duct(20.0, 48, flow_rate=4.0)    # Hartmann duct, mean velocity one
solution = hartmax.solve(problem)
print(solution.flow_rate, solution.pressure_gradient)

gradient = jax.grad(lambda p: hartmax.solve(p).pressure_gradient)(problem)
print(gradient.B.strength)                       # d(pressure gradient) / d(field strength)
4.000000000000002 25.95273925471314
1.0640124579450974

python examples/problem_example.py runs this with the inputs written out. The result reports:

  • its arrays by name (solution.fields, each also an attribute);

  • the drive of a periodic duct (pressure_gradient) and the flux (flow_rate);

  • the kernel’s residual;

  • for an unsteady run, the history.

What a Problem holds

Field

Meaning

grid

A hartmax.grid.Grid; an axis is hartmax.grid.axis(cells, lower, upper) with beta= (tanh), ratio= (geometric), layer_thickness= (wall-resolving) or blend= (the sine blend of Krasnov, Zikanov and Boeck, z = a sin(pi xi/2) + (1 - a) xi).

bc

One entry per axis: "periodic", "wall", or from hartmax.problem Wall(conductance=, conductivity=, thickness=, layers=, temperature=, heat_flux=), Sides(lower, upper) or Open(profile=None) (inflow at the lower x end, free outflow at the upper).

density, viscosity, conductivity

Material properties.

B

From hartmax.fields: Uniform(bx, by, bz), Fringe, Table(path, scale) and Func(fn, params).

forcing, flow_rate

The body force, or the flux that sets the drive of a periodic Stokes duct or the inlet of an Open axis; one of them.

advection, thermal

"off", "central" or "limited" transport; a Thermal(...) adds heat transport.

Each preset has a kernel counterpart for the advanced layer, built from the same code:

Preset

Kernel object

duct

hartmax.core3d.duct_problem, the preset through channel_kernel

fringe_duct

hartmax.axial.fringe_duct, the preset through channel_kernel

hartmax.problem.pipe

hartmax.pipe.pipe_problem; both take the mesh of pipe_grid

hartmax.problem.q2d

hartmax.q2d.make_q2d_case, which the preset calls

channel is a plane channel at constant bulk velocity and half-width one. It takes the bulk Reynolds number re, or R = U0 delta / nu of Boeck, Krasnov and Zienicke, a wall-normal or spanwise field, and the domain of their Table 1 or of Krasnov, Zikanov and Boeck 2011. HARTMAX builds a Hartmann channel, with the field normal to the walls, but solve refuses it, because no kernel imposes the zero net spanwise current it needs.

Solvers

Solver(method=...) takes one of:

method

What it runs

stokes

one certified conjugate-gradient solve

newton

the same with advection on

march

an open duct with advection on, marched to its steady state instead

euler

the projection step as one compiled scan, or with thermal the heat step

ifrk4

the Q2D integrator

rk3

the unsteady step of the three-stage IMEX scheme; with thermal, the flow and heat together, without solid walls, a held flow or an open axis

implicit

named for plan step H2.2; raises until it exists

auto picks euler if you give steps and stokes or newton otherwise. On an open duct with advection it picks march while the Courant step of the inlet flow is at most four damping steps, and newton when the Courant step is longer. hartmax.axial.method_for makes this choice, and Solver().resolve(problem) tells you which method it picked. Both methods reach the same root and derivative to 1e-6.

Three things to know about a Solver:

  • tol is relative to the drive and Solution.residual is the absolute norm, so compare the residual with tol times the drive. A steady solve that misses tol raises.

  • solve applies Solver.dtype, which defaults to "float64". For a float32 run pass Solver(dtype="float32"); hartmax.configure(dtype="float32") alone does not give one.

  • To refine duct, raise cells and cells_in_layer together. With cells_in_layer left at 6 the layers stop improving and the error stalls (Shercliff’s duct at Ha 100: 0.70 % at 48 cells, 0.43 % at 96). Refining both keeps second order.

Derivatives

You can differentiate with respect to:

  • the forcing and the flow_rate;

  • the field amplitude (Uniform.strength, Fringe.strength, Table.scale);

  • the Q2D state and coefficients;

  • a heat source and an initial temperature;

  • the numbers of a conducting Wall: its conductance, or conductivity and thickness, and those of its layers (see differentiation).

HARTMAX computes them through the implicit derivative of the steady solve, at about the cost of one more solve. The grid, boundary kinds, which walls conduct, material properties and scheme names are static, and a traced one raises an error instead of returning a zero. HARTMAX builds the factorizations on the host from the primal values, so differentiate with jax.grad outside jit, or close over the problem and jit the objective.

One limit on an Open axis: the derivative with respect to the field amplitude holds the inlet profile at its solved value. The inlet is the developed flow in the field at the inlet, so it does follow the amplitude, and the derivative leaves that part out. On a short fringe duct (upstream length 2 half-widths, Ha 10) the pressure drop’s derivative is 1.1e-3 below a finite difference of the whole solve, and equal to one with the inlet held to 4e-10. A longer upstream length makes the difference smaller.