Skip to content

MagneticSimulation/MicroMagnetic.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo

MicroMagnetic.jl

Previous name: JuMag.jl

A Julia package for classical spin dynamics and micromagnetic simulations with GPU support.

Docs latest Docs stable Actions Status codecov DOI

Features

  • Supports classical spin dynamics and micromagnetic simulations.
  • Compatible with CPU and multiple GPU platforms, including NVIDIA, AMD, Intel, and Apple GPUs.
  • Supports both double and single precision.
  • Supports Monte Carlo simulations for atomistic models.
  • Implements the Nudged-Elastic-Band method for energy barrier computations.
  • Supports Spin-transfer torques, including Zhang-Li and Slonczewski models.
  • Incorporates various energy terms and thermal fluctuations.
  • Supports constructive solid geometry.
  • Supports periodic boundary conditions.
  • Easily extensible to add new features.

Website

Access our complete web resources including documentation, tutorials and examples:

Latest Version Stable Version

Mirror Site

GitLab Mirror

QQ group support

We have a QQ group. If you have any questions related to Micromagnetic.jl, please join the QQ group (1065654259).

Installation

Install MicroMagnetic is straightforward as long as Julia (http://julialang.org/downloads/) is installed, and it is equally easy in Windows, Linux and Mac.

In Julia, packages can be easily installed with the Julia package manager. From the Julia REPL, type ] to enter the Pkg REPL mode and run:

pkg> add MicroMagnetic

Or, equivalently:

julia> using Pkg;
julia> Pkg.add("MicroMagnetic")

To install the latest development version:

pkg> add MicroMagnetic#master

To enable GPU support, one has to install one of the following packages:

GPU Manufacturer Julia Package
NVIDIA CUDA.jl
AMD AMDGPU.jl
Intel oneAPI.jl
Apple Metal.jl

For example, we can install CUDA for NVIDIA GPUs:

pkg> add CUDA

Now we will see similar messages if we type using MicroMagnetic

julia> using MicroMagnetic
julia> using CUDA
Precompiling CUDAExt
  1 dependency successfully precompiled in 8 seconds. 383 already precompiled.
[ Info: Switch the backend to CUDA.CUDAKernels.CUDABackend(false, false)

Quick start -- Standard Problem 4

using MicroMagnetic
using CairoMakie

@using_gpu() # Import available GPU packages such as CUDA, AMDGPU, oneAPI, or Metal

mesh = FDMesh(; nx=200, ny=50, nz=1, dx=2.5e-9, dy=2.5e-9, dz=3e-9); # Define the discretization

sim = Sim(mesh; driver="SD", name="std4") #Create a simulation instance
set_Ms(sim, 8e5)        # Set saturation magnetization
add_exch(sim, 1.3e-11)  # Add exchange interaction
add_demag(sim)          # Add demagnetization

init_m0(sim, (1, 0.25, 0.1))  # Initialize magnetization
relax(sim; stopping_dmdt=0.01)  # Stage 1 : relax the system to obtain the "S" state

set_driver(sim; driver="LLG", alpha=0.02, gamma=2.211e5)
add_zeeman(sim, (-24.6mT, 4.3mT, 0))                # Stage 2: Apply external magnetic field
run_sim(sim; steps=100, dt=1e-11, save_m_every=1)   # Run the simulation for 100 steps

ovf2movie("std4_LLG"; output="std4.gif", component='x'); # Generate a movie

std4

Running MicroMagnetic.jl from Python

Thanks to PythonCall.jl, running MicroMagnetic.jl from Python is seamless.

Below is an example setup for Standard Problem #4:

from juliacall import Main as jl
jl.seval("using MicroMagnetic")

# Define simulation parameters
args = {
    "name": "std4",
    "task_s": ["relax", "dynamics"],                   # List of tasks to perform
    "mesh": jl.FDMesh(nx=200, ny=50, nz=1, dx=2.5e-9, dy=2.5e-9, dz=3e-9),  # Julia FDMesh object
    "Ms": 8e5,                                         # Saturation magnetization (A/m)
    "A": 1.3e-11,                                      # Exchange stiffness constant (J/m)
    "demag": True,                                     # Enable demagnetization
    "m0": (1, 0.25, 0.1),                              # Initial magnetization vector
    "alpha": 0.02,                                     # Gilbert damping coefficient
    "steps": 100,                                      # Number of dynamic simulation steps
    "dt": 0.01 * jl.ns,                                # Time step size (0.01 ns)
    "stopping_dmdt": 0.01,                             # Stopping criterion for relaxation
    "dynamic_m_interval": 1,                           # Save magnetization at each step
    "H_s": [(0, 0, 0), (-24.6 * jl.mT, 4.3 * jl.mT, 0)]  # Sequence of applied magnetic fields
}

# Run the simulation
sim = jl.sim_with(**args)

Questions and Contributions

If you have any questions about usage, please join the conversation on our GitHub Discussions page.

We greatly appreciate contributions, feature requests, and suggestions! If you encounter any issues or have ideas for improving MicroMagnetic.jl, feel free to open an issue on our GitHub Issues page.

Citation

If you use MicroMagnetic.jl in your research, please cite the following publication:

@article{Wang_2024,
    doi = {10.1088/1674-1056/ad766f},
    url = {https://dx.doi.org/10.1088/1674-1056/ad766f},
    year = {2024},
    month = {oct},
    publisher = {Chinese Physical Society and IOP Publishing Ltd},
    volume = {33},
    number = {10},
    pages = {107508},
    author = {Weiwei Wang and Boyao Lyu and Lingyao Kong and Hans Fangohr and Haifeng Du},
    title = {MicroMagnetic.jl: A Julia package for micromagnetic and atomistic simulations with GPU support},
    journal = {Chinese Physics B}
}

About

A Julia package for classical spin dynamics and micromagnetic simulations with GPU support.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages