This project is a JavaScript-based tool for visualizing the magnetic field distribution in low-field MRI systems. The repository as born as part of Imaging without Borders (IMAGINE) summer school is a hybrid training initiative of the Consortium for Advancement of MRI Education and Research in Africa (CAMERA)
# Halbach Array Field Simulator
An interactive, browser-based simulator for analysing Halbach cylinder magnet arrays used in low-field MRI systems. The tool computes the magnetic field produced by an arbitrary configuration of permanent-magnet rings, visualises it in real time as 2D field maps and a 3D scene, and reports homogeneity metrics over a cylindrical ROI.
No server, no installation — open the HTML file in any browser.
---
## Background
### Halbach arrays in MRI
Conventional MRI scanners use superconducting solenoids to generate a strong, highly uniform static field **B₀**. A Halbach cylinder is an alternative geometry in which permanent magnets are arranged around a cylindrical bore so that their magnetisation vectors rotate by twice the angular position. This rotation constructively reinforces the field inside the bore while cancelling it almost completely outside — making Halbach arrays a geometry for portable and low-field MRI research.
The figure of merit for MRI is **field homogeneity**: the fractional variation of |**B**| over the imaging volume, expressed in **ppm** (parts per million). Even small ppm variations cause image distortion and chemical-shift artefacts. Placing multiple Halbach rings at optimised axial positions and with varying numbers of magnets per ring is the primary lever to reduce this inhomogeneity.
### Physical model
Each magnet is modelled as a **uniformly-magnetised rectangular cuboid**. The field is computed with the exact closed-form solution derived from the Coulombian model:
```
B(r) = (μ₀/4π) · ∇ × ∫ M × ∇(1/|r−r'|) dV'
```
The implementation follows the **magpylib** analytical formulation for cuboid sources.
For a ring with **N** magnets of remanence polarisation **B_r** at radius **R** and axial position **z**, each magnet is a cube of side **D** rotated so that:
- its centre is at angle `α = 2πi/N` on the ring circle
- its magnetisation vector points at angle `2α` (the Halbach condition)
The total field at a …