The Fortran code is compiled and wrapped to a module that can be directly called from Python.
The tool f2py
of the NumPy package is used to wrap the interface file MagTense/python/src/magtense/lib/FortranToPythonIO.f90
.
-
Python >= 3.9
-
Intel® C++ Compiler and Intel® Fortran Compiler
-
[Linux] Prepare your terminal, so that ifort compiler can be found:
. /opt/intel/oneapi/setvars.sh
-
[Windows] Activation via VS Code extension for Intel® oneAPI Toolkits
-
-
Required python packages
Find available
${CUDA_LABEL}
here. HINT: Usenvcc --version
ornvidia-smi
to detect the correct CUDA version for your system.conda install -y numpy matplotlib conda install -y -c "nvidia/label/cuda-${CUDA_LABEL}" cuda-nvcc libcusparse-dev libcublas-dev cuda-cudart-dev libnvjitlink-dev conda install -y -c intel mkl-static
-
[ Linux ]
conda install -y -c intel intel-fortran-rt
-
[ Windows / MacOS ] Installation of Make utility
conda install -y -c conda-forge make
-
-
Additional python packages to run data creation scripts
conda install -y h5py tqdm
Create an importable Python module from Fortran source code.
For MacOS ARM architectures, currently only magnetostatics with the gfortran compiler is supported.
Navigate to folder MagTense/python/src/magtense/lib/
, run make
, and install the package:
cd MagTense/python/src/magtense/lib/
make
cd MagTense/python/
python -m pip install -e .
This feature is currently only supported for soft magnetic tiles (type=2).
In iterate_magnetization(), an arbitrary number of state functions (M-H-curves) can be defined:
mu_r = 100
datapath = f'./magtense/mat/Fe_mur_{mu_r}_Ms_2_1.csv'
...
data_statefcn = numpy.genfromtxt(datapath, delimiter=';')
n_statefcn = 1
Here, three sample M-H-curves for Fe with different relative permeabilities and a saturation magnetization of 2.1 T are stored as CSV-files. The data format is as follows:
0; Temp0; Temp1; ...
H0-field; M0@Temp0; M0@Temp1;...
H1-field; M1@Temp0; M1@Temp1;...
.
.
H100-field; M100@Temp0; M100@Temp1; ...
.
With only one state function given, the same M-H-curve applies to all tiles of type 2.
When the soft tiles differ in their M-H-curves, multiple state function can be combined. In order to match a specific M-H-curve with the corresponding tile, the variable stfcn_index can be set.
Distribution on Anaconda
conda install -y anaconda-client conda-build
# Add nvidia channel to find CUDA and intel libraries
# conda config --show channels
conda config --env --append channels nvidia/label/cuda-12.2.2
conda config --env --append channels intel
# On Windows
# conda config --env --append channels conda-forge
# Quick fix for error of nvcc during build on Windows
# conda install -y -c nvidia/label/cuda-12.2.2 cuda-nvcc
# cd MagTense/source/MagTenseFortranCuda/cuda/
# nvcc -c MagTenseCudaBlas.cu -o MagTenseCudaBlas.o
# Version numbers have to be set in advance in pyproject.toml
cd MagTense/python/
python scripts/dist_conda.py
Distribution on PyPI
Libraries have to be pre-build for now, and should be located in MagTense/python/compiled_libs
.
# Required python packages for distribution
python -m pip install build
conda install -y twine
cd MagTense/python/
python scripts/dist_pypi.py
# Upload to pypi.org
# twine upload --repository testpypi dist/*
twine upload dist/*