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 |
|---|---|
|
A |
|
One entry per axis: |
|
Material properties. |
|
From |
|
The body force, or the flux that sets the drive of a periodic Stokes duct or the inlet of an |
|
|
Each preset has a kernel counterpart for the advanced layer, built from the same code:
Preset |
Kernel object |
|---|---|
|
|
|
|
|
|
|
|
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:
|
What it runs |
|---|---|
|
one certified conjugate-gradient solve |
|
the same with advection on |
|
an open duct with advection on, marched to its steady state instead |
|
the projection step as one compiled scan, or with |
|
the Q2D integrator |
|
the unsteady step of the three-stage IMEX scheme; with |
|
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:
tolis relative to the drive andSolution.residualis the absolute norm, so compare the residual withtoltimes the drive. A steady solve that missestolraises.solveappliesSolver.dtype, which defaults to"float64". For a float32 run passSolver(dtype="float32");hartmax.configure(dtype="float32")alone does not give one.To refine
duct, raisecellsandcells_in_layertogether. Withcells_in_layerleft 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
forcingand theflow_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.