{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "19a77cf6",
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"\n",
"import numpy as np\n",
"from numpy.linalg import norm\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "979a4680",
"metadata": {},
"source": [
"(theory)=\n",
"\n",
"# Theory\n",
"\n",
"Please see our paper for details about the magnetic model implemented by flatspin:\n",
"\n",
"[Jensen et al. \"flatspin: A Large-Scale Artificial Spin Ice Simulator\"]\n",
"\n",
"A short summary is provided below, as well as some additional practical information.\n",
"\n",
"## Magnets as dipoles\n",
"\n",
":::{figure} _static/dipoles.svg\n",
":alt: dipoles\n",
":::\n",
"\n",
"As illustrated in the above figure, magnets are modelled as magnetic dipoles with *binary* magnetization, i.e., macro spins:\n",
"\n",
"$$\n",
"s_i \\in \\{-1, +1\\}\n",
"$$\n",
"\n",
"Each magnetic dipole has an associated position $\\vec{r}_i$ and rotation $\\theta_i$.\n",
"Using reduced units, the magnetization vector of a single magnet can be expressed as\n",
"\n",
"$$\n",
"\\vec{m}_i=s_i \\vec{\\hat{m}}_i\n",
"$$\n",
"\n",
"where $\\vec{\\hat{m}}_i$ is the unit vector along $\\vec{m}_i$.\n",
"\n",
"## Magnetic Fields and Temperature\n",
"\n",
"External fields and temperature are modeled as a combination of effective magnetic fields.\n",
"The total field, $\\vec{h}_i$, affecting each magnet $i$ is the sum of three components:\n",
"\n",
"$$\n",
"\\vec{h}_i = \\vec{h}_{dip}^{(i)} + \\vec{h}_{ext}^{(i)} + \\vec{h}_{th}^{(i)}\n",
"$$\n",
"\n",
"where $\\vec{h}_\\text{dip}^{(i)}$ is the local magnetic field from neighboring magnets (magnetic dipole-dipole interactions), $\\vec{h}_\\text{ext}^{(i)}$ is a global or local external field, and $\\vec{h}_\\text{th}^{(i)}$ is a random magnetic field representing thermal fluctuations in each magnetic element.\n",
"\n",
"## Magnetic dipole-dipole interactions\n",
"\n",
"Spins are coupled through [dipole-dipole interactions](https://en.wikipedia.org/wiki/Magnetic_dipole%E2%80%93dipole_interaction).\n",
"Each spin, $i$, is subject to a magnetic field from all neighboring spins, $j\\neq i$, given by\n",
"\n",
"$$\n",
"\\vec{h}_\\text{dip}^{(i)} = \\alpha \\sum_{j \\ne i}\\frac{3\\vec{r}_{ij}(\\vec{m}_j \\cdot \\vec{r}_{ij})}{|\\vec{r}_{ij}|^5} - \\frac{\\vec{m}_j}{|\\vec{r}_{ij}|^3},\n",
"$$\n",
"\n",
"where $\\vec{r}_{ij}=\\vec{p}_i-\\vec{p}_j$ is the distance vector from spin $i$ to $j$ and $\\alpha$ scales the dipolar coupling strength between spins.\n",
"The coupling strength $\\alpha$ is given by $\\alpha = \\frac{\\mu_0 M}{4\\pi a^3}$, where $a$ is the lattice spacing, $M$ is the net magnetic moment of a single magnet, and $\\mu_0$ is the vacuum permeability.\n",
"The distance $\\vec{r}_{ij}$ is given in reduced units of the lattice spacing.\n",
"The size of the neighborhood is user-configurable and defined in units of the lattice spacing.\n",
"\n",
"## External field\n",
"\n",
"Applying an external magnetic field is the primary mechanism for altering the state of an ASI in a controlled manner.\n",
"The external field can either be set locally on a per-spin basis, $\\vec{h}_\\text{ext}^{(i)}$, globally for the entire system, $\\vec{h}_\\text{ext}$, or as a spatial vector field, $\\vec{h}_\\text{ext}(\\vec{r})$.\n",
"\n",
"Time-dependent external fields are supported, i.e., $\\vec{h}_\\text{ext}$ is a discrete time series of either local, global or spatial fields.\n",
"A variety of time-dependent external fields are provided, including sinusoidal, sawtooth and rotational fields.\n",
"More complex field-protocols can be generated, e.g., for annealing purposes or probing dynamic response.\n",
"\n",
"## Thermal field\n",
"\n",
"Thermal fluctuations are modelled as an additional local field, $\\vec{h}_\\text{th}^{(i)}$, applied to each magnet individually.\n",
"\n",
"The magnitude of the thermal fields, $\\vec{h}_\\text{th}^{(i)}$, is sampled from a Poisson distribution given by the CDF,\n",
"\n",
"$$\n",
"P(X \\leq \\Delta h) = \\exp(-f\\Delta t)\n",
"$$\n",
"\n",
"where $\\Delta h$ is the smallest additional field required for switching, $\\Delta t$ is the experimental time interval, and $f$ is the characteristic switching rate given by the Arrhenius-NĂ©el equation,\n",
"\n",
"$$\n",
"f = f_0 \\exp\\left(-\\frac{\\Delta E}{k_\\text{B}T}\\right)\n",
" = f_0 \\exp\\left(-\\frac{\\Delta h M_\\text{th}}{k_\\text{B}T}\\right),\n",
"$$\n",
"\n",
"where $f_0$ is the attempt frequency and $\\Delta E$ is the energy barrier for switching.\n",
"The energy barrier corresponds to the additional Zeeman energy required for magnetization reversal, i.e., $\\Delta E = \\Delta h M_\\text{th}$, where $M_\\text{th}$ is the thermal nucleation moment.\n",
"\n",
"The direction of the thermal vector fields is chosen to take the path of least resistance, i.e., the switching direction with the minimum energy.\n",
"In other words, the thermal fields point towards the shortest distance out of the switching astroid.\n",
"\n",
"It is important to note that flatspin does not account for the temperature dependence of the material parameters.\n",
"If these parameters are expected to vary significantly in the temperature range of interest, e.g., $M_\\text{th}$, this has to be explicitly accounted for by the user.\n",
"\n",
"## Switching\n",
"\n",
"Magnetization reversal, or *switching*, may take place when a magnet is subjected to a magnetic field or high temperature.\n",
"If the field is sufficiently strong (stronger than some critical field) and directed so that the projection onto $\\vec{m}_i$ is in the opposite direction to $\\vec{m}_i$, the magnetization $\\vec{m}_i$ will switch direction.\n",
"\n",
"The critical field strength is referred to as the coercive field $\\vec{h}_\\text{c}$, which depends on the angle between the applied field $\\vec{h}_i$ and $\\vec{m}_i$.\n",
"The external field can be decomposed into two components, $\\vec{h}_\\parallel$ and $\\vec{h}_\\perp$, corresponding to the field component parallel and perpendicular to the easy axis, respectively.\n",
"We denote the coercive field strength along the hard axis as $h_k$.\n",
"\n",
"flatspin uses a generalized Stoner-Wohlfarth (SW) switching model to allow an asymmetry between easy and hard axes.\n",
"The critical field is described by the equation:\n",
"\n",
"$$\n",
"\\left(\\frac{h_{\\parallel}}{b h_k}\\right)^{2/\\gamma} + \\left(\\frac{h_{\\perp}}{c h_k}\\right)^{2/\\beta} = 1\n",
"$$\n",
"\n",
"$b$, $c$, $\\beta$ and $\\gamma$ are parameters which adjust the shape of the switching astroid: $b$ and $c$ define the height and width, respectively, while $\\beta$ and $\\gamma$ adjust the curvature of the astroid at the easy and hard axis, respectively.\n",
"With $b = c = 1$ and $\\beta = \\gamma = 3$, the classical Stoner-Wohlfarth astroid is obtained (valid for elliptical magnets).\n",
"The plot below illustrates how the parameters affect the shape of the switching astroid:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3e459b4",
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [],
"source": [
"def GSW(h_par, h_perp, b=1, c=1, beta=3, gamma=3):\n",
" \"\"\" Generalized Stoner-Wohlfarth astroid \"\"\"\n",
" sw = b*(1 - ((h_perp/c)**2)**(1/beta))**(gamma/2)\n",
" sw[h_par<0] *= -1\n",
" return sw\n",
"\n",
"def plot_GSW(b=1, c=1, beta=3, gamma=3, ax=None, **kwargs):\n",
" thetas = np.linspace(0, 2*np.pi, 3601)\n",
"\n",
" h_perp = c * np.cos(thetas)\n",
" h_par = b * np.sin(thetas)\n",
"\n",
" kwargs.setdefault(\"label\", rf\"$b={b:g}, c={c:g}, \\beta={beta:g}, \\gamma={gamma:g}$\")\n",
"\n",
" if ax is None:\n",
" ax = plt.gca()\n",
" ax.plot(h_perp, GSW(h_par, h_perp, b, c, beta, gamma), **kwargs)\n",
"\n",
"plot_GSW(label=\"Stoner-Wohlfarth\")\n",
"plot_GSW(b=0.5)\n",
"plot_GSW(b=0.5, beta=1.5)\n",
"plt.xlabel('$h_\\perp / h_k$')\n",
"plt.ylabel('$h_\\parallel / h_k$')\n",
"plt.axis('square')\n",
"plt.legend(loc='upper left', bbox_to_anchor=(1.0, 1.0));"
]
},
{
"cell_type": "markdown",
"id": "1cceb617",
"metadata": {},
"source": [
"In flatspin, the generalized SW model is used as the switching criteria, i.e., a spin may flip if the left hand side of the above equation is greater than one.\n",
"Additionaly, the projection of $\\vec{h}_\\text{i}$ onto $\\vec{m}_i$ must be in the opposite direction of $\\vec{m}_i$:\n",
"\n",
"$$\n",
"\\vec{h}_i \\cdot \\vec{m}_i < 0.\n",
"$$\n",
"\n",
"## Imperfections and disorder\n",
"\n",
"Variations in each magnet are modelled as a disorder in the coercive fields.\n",
"A user-defined parameter, $k_\\text{disorder}$, defines the distribution of coercive fields, i.e., $h_{k}^{(i)}$ is sampled from a normal distribution $\\mathcal{N}(h_{k}, \\sigma)$, where $\\sigma = k_\\text{disorder} \\cdot h_k$.\n",
"\n",
"## Dynamics\n",
"\n",
"flatspin employs deterministic single spin flip dynamics.\n",
"At each simulation step, we calculate the total magnetic field, $\\vec{h}_i$, acting on each spin.\n",
"Next, we determine which spins *may* flip according to the switching criteria above.\n",
"Finally we flip the spin where $\\vec{h}_i$ is the furthest outside its switching astroid, i.e., where the left hand side of the SW equation is greatest.\n",
"Ties are broken in a deterministic, arbitrary manner, although with non-zero disorder such occurrences are rare.\n",
"The above process is repeated until there are no more flippable spins.\n",
"\n",
"This relaxation process is performed with constant external and thermal fields.\n",
"To advance the simulation, the fields are updated and relaxation is performed again.\n",
"**Hence a simulation run consists of a sequence of field updates and relaxation processes.**\n",
"\n",
"## Geometries\n",
"\n",
"The particular spatial arrangement of the magnets is referred to as the *geometry*.\n",
"flatspin includes the most commonly used ASI geometries: square, kagome, pinwheel and ising.\n",
"\n",
"flatspin can be used to model any two-dimensional ASI comprised of identical elements.\n",
"New geometries can easily be added by extending the model with a new set of positions $\\vec{r}_i$ and rotations $\\theta_i$.\n",
"\n",
"## Parameter and variable listing\n",
"\n",
"The following table lists model parameters with their equivalents in the Python code:\n",
"\n",
"| Parameter | Python parameter | Description |\n",
"| ------------------- | ---------------- | ------------------------------------------ |\n",
"| $\\alpha$ | `alpha` | Dipolar coupling strength |\n",
"| $h_k$ | `hc` | Mean coercive field (along hard axis) |\n",
"| $k_\\text{disorder}$ | `disorder` | Disorder in coercive fields |\n",
"| $b$ | `sw_b` | Height of switching astroid (easy axis) |\n",
"| $c$ | `sw_c` | Width of switching astroid (hard axis) |\n",
"| $\\beta$ | `sw_beta` | Curvature of switching astroid (easy axis) |\n",
"| $\\gamma$ | `sw_gamma` | Curvature of switching astroid (hard axis) |\n",
"| $T$ | `temperature` | Temperature |\n",
"| $\\Delta t$ | `therm_timescale`| Thermal time scale (seconds per timestep) |\n",
"| $M_\\text{th}$ | `m_therm` | Thermal nucleation moment |\n",
"| $f_0$ | `attempt_freq` | Attempt frequency |\n",
"\n",
"Additional parameters in the Python code include:\n",
"\n",
"| Python parameter | Description |\n",
"| ------------------- | ------------------------------------------------------------- |\n",
"| `size` | Size of ASI (geometry specific) |\n",
"| `lattice_spacing` | Spacing between each spin (in reduced units) |\n",
"| `neighbor_distance` | Neighborhood to consider when calculating dipole interactions |\n",
"\n",
"The following table lists model variables with their equivalents in the Python code:\n",
"\n",
"| Variable | Python name | Description |\n",
"| --------------------- | ------------------ | --------------------------------------- |\n",
"| $s_i$ | `spin[i]` | Magnet spin |\n",
"| $\\vec{r}_i$ | `pos[i]` | Magnet position |\n",
"| $\\theta_i$ | `angle[i]` | Magnet angle |\n",
"| $\\vec{m}_i$ | `vectors[i]` | Magnet magnetization |\n",
"| $h_k^{(i)}$ | `hc[i]` | Magnet coercive field (along hard axis) |\n",
"| $\\vec{h}_i$ | `total_field(i)` | Total magnetic field |\n",
"| $\\vec{h}_{dip}^{(i)}$ | `dipolar_field(i)` | Magnetic field from neighboring magnets |\n",
"| $\\vec{h}_{ext}^{(i)}$ | `h_ext[i]` | External magnetic field |\n",
"| $\\vec{h}_{th}^{(i)}$ | `h_therm[i]` | Thermal field |\n",
"\n",
"## Choosing parameters\n",
"\n",
"Here we give some advice on how to set some of the parameters.\n",
"\n",
"### Coupling parameters $\\alpha$ and lattice spacing\n",
"\n",
"Although `alpha` defines the lattice spacing between magnets, it is also possible to change the lattice spacing via the `lattice_spacing` parameter.\n",
"This has the effect of scaling the magnetic coupling as if changing lattice spacing directly.\n",
"A neat trick is to calculate `alpha` based on a lattice spacing of 1 nm, set `lattice_spacing=L` to obtain an effective lattice spacing of `L` nm.\n",
"Hence `lattice_spacing` allows setting the lattice spacing directly, e.g., for sweeps, as opposed to indirectly through `alpha`.\n",
"\n",
"### Note on units\n",
"\n",
"The physical unit of the $\\vec{h}$-field in flatspin is Tesla $\\mathrm{[T]}$.\n",
"While the $\\vec{H}$-field is typically described in units of $\\mathrm{[Am^{-1}]}$, the fields in flatspin are exclusively external to the magnets.\n",
"In other words, the $\\vec{h}$-field is equivalent to a $\\vec{B}$-field in the absence of material magnetization, i.e., $\\vec{h} = \\mu_0 \\vec{H}$. \n",
"Correspondingly, the magnetic moments $M$ and $M_\\text{th}$ have units $\\mathrm{[Am^2]}$.\n",
"\n",
"### Switching parameters $h_k$, $b$, $c$, $\\beta$ and $\\gamma$\n",
"\n",
"These parameters define the switching characteristic of the magnets.\n",
"They can be estimated from micromagnetic simulations of a single magnet, when subject to a gradually increasing external field at different angles.\n",
"\n",
"Here we provide a list some example magnet sizes corresponding switching parameters:\n",
"\n",
"| Magnet shape | Magnet size | $h_k$ | $b$ | $c$ | $\\beta$ | $\\gamma$ |\n",
"| ------------ | ------------- | ----- | ---- | --- | ------- | -------- |\n",
"| Elliptical | 220x80x10 nm | 0.2 | 0.77 | 1.0 | 2.2 | 4.2 |\n",
"| Stadium | 220x80x25 nm | 0.2 | 0.38 | 1.0 | 1.3 | 3.6 |\n",
"| Stadium | 220x80x20 nm | 0.2 | 0.41 | 1.0 | 1.5 | 3.9 |\n",
"| Stadium | 470x170x10 nm | 0.14 | 0.28 | 1.0 | 4.8 | 3.0 |\n",
"\n",
"[jensen et al. \"flatspin: a large-scale artificial spin ice simulator\"]: https://arxiv.org/abs/2002.11401"
]
}
],
"metadata": {
"jupytext": {
"formats": "md:myst",
"text_representation": {
"extension": ".md",
"format_name": "myst",
"format_version": 0.13,
"jupytext_version": "1.11.5"
}
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"source_map": [
15,
23,
136,
164
]
},
"nbformat": 4,
"nbformat_minor": 5
}