Demagnetization field
The demagnetization (stray) field is the most computationally expensive part of micromagnetics. MagTense computes it from the fully analytical demagnetization tensor of the cell shape; a rectangular prism for the uniform and unstructured-prism grids, and a tetrahedron for the tetrahedral grid. The accuracy of these tensors is documented in Bjørk, R. and d’Aquino, M.: Accuracy of the analytical demagnetization tensor for various geometries, Journal of Magnetism and Magnetic Materials, 587, 171245, 2023.
The tensor is symmetric, so it is stored as the six components \(K_{xx}, K_{xy}, K_{xz}, K_{yy}, K_{yz}, K_{zz}\), each a dense \(n_\mathrm{tot} \times n_\mathrm{tot}\) matrix in single precision. The memory requirement is therefore approximately \(24\,n_\mathrm{tot}^2\) bytes, which sets the problem size the dense tensor handles; the Matlab interface prints an estimate when the problem struct is created, and the Fast Multipole Method lifts the scaling to \(O(N)\) for larger problems. The saturation magnetization is folded into the tensor when it is built, so a spatially varying \(M_s\) costs nothing extra.
Switching the demagnetization off
Setting useDemag (Matlab setUseDemag, Python usedemag) to False removes the
demagnetization field from the effective field and skips building the tensor
altogether.
Cell-averaged versus point-evaluated tensor
useAvgN (Python useavgn, default on) selects the volume-averaged
prism tensor, i.e. the tensor averaged over the receiving cell rather than
evaluated at its centre. This is the more accurate choice for a prism mesh
and is the default; it uses the averaged prism tile (tile_type = 8).
Some analytical benchmarks are formulated for the tensor evaluated at
the cell centre, and for those useAvgN must be switched off. This includes the
macrogeometry and shape-correction tests.
For the unstructuredPrisms grid the tensor may additionally be averaged
numerically over the receiving cell using N_ave = [nx, ny, nz], which
evaluates the tensor on an nx*ny*nz sub-grid inside each receiving prism
and averages. The default [1 1 1] means no averaging.
Approximating the tensor
The dense tensor may be sparsified, which trades accuracy for memory and speed.
The approximation is selected with setMicroMagDemagApproximation in Matlab
and with demag_approx in Python, and the associated cut-off is
dem_thres.
Name |
Value |
Description |
|---|---|---|
|
1 |
Default. The dense tensor is used as is. |
|
2 |
Every element with \(|K| <\) |
|
4 |
As above, but |
The values 3 (fft_thres) and 5 (fft_threshold_fraction) select
earlier Fourier-space variants of the threshold that are superseded by the
three options above; the solver says so if they are selected.
Adding noise to the demagnetization field
CV (Python cv) adds a normally distributed relative error to the
demagnetization field, with CV being the coefficient of variation, i.e. the
ratio of the standard deviation to the mean. The default of zero disables it.
The draw is controlled by the same random seed as the thermal field, see
Reproducible random numbers.
Storing and reusing the tensor
Because building the tensor can dominate the run time of a short simulation, it can be written to disk and read back:
Matlab |
Python |
Description |
|---|---|---|
|
|
|
|
|
The same encoding for loading a previously stored tensor instead of computing it. |
The Matlab helpers setReturnNFilename and setLoadNFilename set the
filename and the matching length in one call. In Python the filename
constructor argument sets all four fields; its default "t" has length one
and therefore selects the default of computing the tensor internally.
Parallelism and hardware
useCuda(MatlabsetUseCuda, Pythoncuda) evaluates the tensor-vector product on an NVIDIA GPU at every time step. The Python interface checks fornvidia-smiand runs on the CPU instead, with a note, when no GPU is present. In Matlab,setUseCudaalso picks the matching MEX-file.The Fast Multipole Method replaces the dense tensor by an \(O(N)\) evaluation and is described in Demag field - FMM. It is selected with
use_fmmin a build withUSE_FMM3D=1.