Metadata-Version: 2.4
Name: hartmax
Version: 2.0.0
Summary: JAX-native inductionless MHD toolkit for research, benchmarking, and differentiable simulation
Author: Rogerio Jorge
License-Expression: MIT
Project-URL: Homepage, https://github.com/uwplasma/HARTMAX
Project-URL: Documentation, https://hartmax.readthedocs.io/
Project-URL: Issues, https://github.com/uwplasma/HARTMAX/issues
Project-URL: Source, https://github.com/uwplasma/HARTMAX
Keywords: magnetohydrodynamics,liquid-metal,jax,differentiable-simulation
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: <3.14,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: filelock
Requires-Dist: jax>=0.7.2
Requires-Dist: numpy
Requires-Dist: solvax<1,>=0.36.2
Provides-Extra: dev
Requires-Dist: matplotlib; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pytest-timeout; extra == "dev"
Requires-Dist: pytest-xdist; extra == "dev"
Requires-Dist: ruff<1,>=0.16; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: myst-parser; extra == "docs"
Requires-Dist: furo; extra == "docs"
Requires-Dist: sphinx-copybutton; extra == "docs"
Requires-Dist: sphinx-design; extra == "docs"
Provides-Extra: release
Requires-Dist: build; extra == "release"
Requires-Dist: twine; extra == "release"
Provides-Extra: visualization
Requires-Dist: matplotlib; extra == "visualization"
Dynamic: license-file

# HARTMAX

[![PyPI version](https://img.shields.io/pypi/v/hartmax.svg)](https://pypi.org/project/hartmax/)
[![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue.svg)](pyproject.toml)
[![License](https://img.shields.io/github/license/uwplasma/HARTMAX)](LICENSE)
[![CI](https://img.shields.io/github/actions/workflow/status/uwplasma/HARTMAX/ci.yml?branch=main&label=ci)](https://github.com/uwplasma/HARTMAX/actions/workflows/ci.yml)
[![Docs](https://img.shields.io/readthedocs/hartmax/latest?label=docs)](https://hartmax.readthedocs.io/)

**Differentiable liquid-metal MHD in JAX, for the ducts of fusion blankets.**

HARTMAX solves liquid metal flowing through strong magnetic fields. It handles ducts and pipes with insulating or
conducting walls, three-dimensional ducts leaving a magnet, heat transfer through steel walls, and
quasi-two-dimensional vortex dynamics. Every result is differentiable end to end, so a design study can take
gradients through the solve. It runs on a CPU or a GPU, and [SOLVAX](https://github.com/uwplasma/SOLVAX) supplies
the solvers and implicit derivatives.

![Hunt duct side-layer jets from Ha 20 to 1000](docs/_static/hunt_side_layers.webp)

## Install and run

HARTMAX needs Python 3.11, 3.12 or 3.13. It was called LMhdX until 2.0: `pip install hartmax` replaces
`pip install lmhdx`, and the [migration guide](https://hartmax.readthedocs.io/en/latest/reference/migration.html)
lists what changed. The 1.x releases stay on PyPI as `lmhdx`.

```console
pip install hartmax            # JAX runs on the CPU; for a GPU follow the JAX installation guide
hartmax examples/hartmann_case.toml
```

The same case from Python:

```python
import hartmax

solution = hartmax.solve(hartmax.duct(100.0, 48, wall_conductance=0.027))
print(float(solution.velocity[0].data.max()))
```

`solve` takes a `Problem` and a `Solver`, and a TOML file builds the same objects. The
[first run](https://hartmax.readthedocs.io/en/latest/getting_started/first_run.html) walks through it and checks the
answer against the exact profile.

## What it does

- **Fully developed ducts and pipes,** with thin or resolved conducting walls and wall stacks, and meshes chosen from
  the layer thicknesses `a/Ha` and `a/√Ha` rather than from a cell count.
- **Steady states as roots.** The steady solve is a differentiable root found by conjugate gradients or
  Newton-Krylov, not a march in time.
- **Three-dimensional and open ducts,** with an inlet and an outlet through a field that varies along them, with or
  without inertia (`method="auto"` picks Newton or marching the Runge-Kutta step).
- **Runs in time,** by `Solver(method="euler" | "rk3", dt=, steps=)`. An `Output` writes records, ParaView files and
  a summary, and a later run restarts from them bit for bit.
- **Heat transfer,** with conduction through solid walls, Joule heat and Boussinesq buoyancy.
- **Quasi-two-dimensional flow** with Hartmann-layer friction, by a spectral time step.

## Validation

![Hartmann layers, flow-rate error and mesh convergence](docs/_static/validation_ladder.webp)

HARTMAX is checked against exact solutions, independent spectral references, experiments and other codes, and its
adjoints against finite differences. The [validation record](https://hartmax.readthedocs.io/en/latest/validation/index.html)
gives every result with its gate, what is still at the research stage, and the measured speed on a CPU and a GPU.

## Examples

| Command | Physics |
|---|---|
| `hartmax examples/hartmann_case.toml` | Hartmann duct from a TOML file |
| `hartmax examples/heated_duct.toml` | heated duct with buoyancy |
| `python examples/hunt_example.py` | conducting walls, side-layer jets |
| `python examples/fringe_duct_example.py` | duct leaving a magnet, its drop and the drop's field derivative |
| `python examples/open_duct_inertia_example.py` | inertial share of the fringe drop |
| `python examples/q2d_turbulence_demo.py` | Q2D vorticity evolution and energy decay |
| `python examples/duct_design_law.py` | optimum aspect ratio of an insulated duct |

[`examples/catalog.toml`](examples/catalog.toml) lists each example's parameters and evidence status, and
`python scripts/make_showcase_figures.py` regenerates the figures.

## Documentation

The [documentation](https://hartmax.readthedocs.io/) has
[getting started](https://hartmax.readthedocs.io/en/latest/getting_started/install.html) guides, step-by-step
[tutorials](https://hartmax.readthedocs.io/en/latest/tutorials/fully_developed.html), the
[equations and numerical methods](https://hartmax.readthedocs.io/en/latest/physics/numerics.html), the
[validation](https://hartmax.readthedocs.io/en/latest/validation/index.html) record and the
[API reference](https://hartmax.readthedocs.io/en/latest/reference/api.html).

## Citing

If you use HARTMAX in published work, cite the release you used and the benchmark sources your case relies on.
[CITATION.cff](CITATION.cff) holds the details, GitHub's "Cite this repository" button exports them, and the
[references page](https://hartmax.readthedocs.io/en/latest/reference/bibliography.html) has a BibTeX entry.

## Contributing

Install for development with `pip install -e ".[dev,docs]"`, then run the tests for your changes with
`python scripts/run_full_test_suite.py --changed-from HEAD`. [CONTRIBUTING.md](CONTRIBUTING.md) describes the
workflow, and the [plan](plan.md) shows what is in progress. Questions and bug reports go to the
[issue tracker](https://github.com/uwplasma/HARTMAX/issues). The code was LMX before 1.5 and LMhdX from 1.5
to 1.12; `import lmhdx` and `import lmx` are now `import hartmax`.
