Installation
MagTense consists of a Fortran core with a Matlab MEX interface and a Python interface. Neither interface requires building anything from source: prebuilt MEX-files are attached to every release, and the Python interface is available as a wheel on PyPI.
MagTense is tested on Linux and on Windows 11. macOS is not supported at the moment.
Python
Installing the Python package
Requires Python \(\geq\) 3.12 - wheels are published for Python 3.12, 3.13 and 3.14:
pip install magtense
The wheel ships the compiled Fortran core together with the Intel MKL and Intel Fortran runtime it needs, so no compiler is required.
For GPU support, the CUDA runtime libraries have to be present as well:
pip install nvidia-cuda-runtime nvidia-cublas nvidia-cusparse nvidia-nvjitlink
Usage
The magnetostatic framework lives in magtense.magstatics and the
micromagnetic framework in magtense.micromag:
from magtense.magstatics import Tiles, run_simulation
from magtense.micromag import MicromagProblem
Examples for both are in python/examples.
Matlab
Prerequisites
Matlab \(\geq\) 2023a
An installation of the CUDA toolkit, if the CUDA-enabled MEX-files are to be used
MagTense is directly usable in Matlab by downloading the already compiled
MEX-files, which are
provided for both Windows and Linux. Add the folder holding the MEX-files and
the matlab/util folder to the Matlab path:
addpath('MagTense/matlab/MEX_files');
addpath('MagTense/matlab/util');
The MEX-files are
MEX-file |
Purpose |
|---|---|
|
Micromagnetic solver, CUDA-enabled |
|
Micromagnetic solver without CUDA |
|
Iterate the magnetization of soft magnetic tiles |
|
H-field from a set of tiles |
|
Demagnetization tensor of a single tile |
|
Magnetic force on a tile |
Examples are in matlab/examples.
Building from source
Building is only necessary in order to modify the Fortran core, or to enable an optional component that the prebuilt binaries do not carry. The optional components are selected with make flags:
Flag |
Effect |
|---|---|
|
GPU acceleration of the demagnetization field through CUDA. |
|
The CVODE time integrator from SUNDIALS, see ODE solver settings. |
|
The FMM demagnetization path, see Demag field - FMM. |
|
Compile the Fortran objects needed by the Matlab MEX-files. |
A typical Linux build of the Python module with everything enabled is
conda env create -n magtense-env -f python/.build/env-313-linux.yml
conda activate magtense-env
make python USE_CUDA=1 USE_CVODE=1 USE_MATLAB=0 USE_FMM3D=0
python -m pip install -e ./python
The environment files come in one variant per Python version and platform,
env-312, env-313 and env-314 times -linux and -win.
The full, up-to-date build instructions - including the Conda environment
files, the CVODE and CUDA prerequisites, the Windows toolchain and the
Visual Studio solution MagTense.sln - are kept next to the code, since they
change with the compiler versions:
Python: python/README.md
Matlab: matlab/README.md
The GitHub workflow files are always a working reference, since they are what builds and tests every commit.
For Matlab, the Fortran objects are built first and the MEX-files are then produced from Matlab itself with buildMagTenseMEX.m:
mex -setup FORTRAN
buildMagTenseMEX('USE_RELEASE', true, 'USE_CUDA', true, 'USE_CVODE', false)