Introduction

Modern development of spintronic devices1 requires careful design and a time-consuming fabrication process, a preparation of which is often carried out with the help of simulations. The use of magnetic materials and multilayer structures with certain material parameters enables the creation of a spintronic device with optimal functionality, depending on the application: good memory is characterised by high endurance and energy-efficient write operations2, sensor development usually focuses on high sensitivity and low inherent noise3, and in devices with a high-frequency component, we aim to maximise the quality factor while retaining low energy consumption4. To simulate such a variety of use cases, we need an extensive simulation toolkit. As we climb from the macromagnetic models, steadily increasing the resolution of the phenomena in atomistic simulations, and finally reaching the ab initio simulations, we do so with increasing computational cost. This computational cost is closely correlated with the number and complexity of the simulation parameters and may hamper the speed of prototyping. Consequently, we are facing the dilemma of choosing between a slower, but accurate approach and a faster, but not as precise method.

Micromagnetic packages, such as MuMax35 and OOMMF6, offer a lot of plasticity in modelling magnetic interactions of complex structures while maintaining an acceptable computational cost. On the other side of the spectrum, VASP7 and Quantum Espresso8,9 lead the way as recognised self-consistent solvers. Between them, there are tools for atomistic magnetic simulations such as VAMPIRE10 or Spirit11 that, in addition to dynamics solvers, can also employ Monte Carlo methods for time-independent processes. In the micromagnetic regime, a notable research direction was devoted to creating magnetic tunnel junction (MTJ) behavioural models in Verilog, for example, in the work of R. Garg et al.12 or T. Chen et al.13,14. Such models attempt to capture the electronic nature of spintronics devices, describing them as discrete elements or electronic elements in a circuit, making it easy to prototype devices composed of discrete components.

In this article, we seek to fill a gap in the magnetic simulation hierarchy by providing an open-source, computationally efficient standardised Python package, cmtj, for rapid prototyping, large-scale parameter search, and macrospin simulation of multilayer systems. cmtj is capable of simulating, for example, current-induced magnetisation dynamics calculations originating from spin transfer torque (STT)15,16 such as spin torque oscillator (STO)17, STT-induced magnetisation switching18 or voltage-controlled magnetic anisotropy (VCMA) phenomena19. Some of those motivating examples are shown in Fig. 1. In the text, we first discuss the structure of the simulation in the cmtj and its driver systems. Then we present some of the more advanced simulations where cmtj provides valuable information, showing its ability to verify experimental setups that include, but are not limited to, static and dynamic characteristics of spin valves or magnetic tunnel junctions (MTJ).

Fig. 1: Example trajectories extracted by simulating a single ferromagnetic layer with different parameters and excitations.
figure 1

a Depicts a stable oscillator trajectory under a constant current density. b Demonstrates a trajectory obtained with exciting the magnetisation with VCMA. In c we see a trajectory under a pulse excitation of the Oersted field. Finally, d is a thin, bilayer ferromagnetic system with a low-energy barrier that changes states from parallel to anti-parallel under thermal noise.

Results

Simulation design

The core of cmtj is based on the Landau–Lifschitz–Gilbert–Slonczewski (LLGS) macrospin equation implemented in C++, with a simple header-only library interface. If the user wishes to benefit from the provided python interface, the setup involves a standard pip installation process. The scope of the python interface covers all basic functionalities of the C++ core library, exposing the functions using the open-source solution Pybind1120. In addition, the python package offers utility functions that complement frequently used operations such as unit conversions, parallelism, parameter sweep, filtering, energy and resistance calculations, or template procedures for spin-diode ferromagnetic resonance (SD-FMR) or pulse-induced microwave magnetometry (PIMM). The library is composed of a couple of classes, mainly the Junction and Layer classes that define a basic magnetic component in the MTJ simulation and the Driver class that contains definitions of various excitations that influence the magnetisation dynamics of the system. We briefly discuss them in the following paragraphs, but detailed descriptions of key cmtj functionality, as well as implementation details, can be found in the library documentation (https://lemurpwned.github.io/cmtj/).

The input to each simulation is the programmatic description of the system and its dynamic stimuli, which may vary over the simulation runtime. The result of a simulation holds the evolution of the magnetisation vector for each layer at each time step, and if the user chooses so, additional time-dependent metadata such as different flavours of magnetoresistance21 or field contributions. All simulations in cmtj are conceptually divided into three levels of abstraction: single-layer simulations, multilayer simulations, and stacked device simulations. The first of those levels are designed to provide a basic interface of the ferromagnetic (FM) layer, which is represented by a time-dependent magnetisation vector, as dictated by a macrospin model. Layers in cmtj are created using the Layer class, for example:

# define the tensor using cmtj C++ binding class called CVector

demagTensor = [

    CVector(0.0002, 2.7139e-10, 5.9550e-14),

    CVector(2.7139e-10, 0.0001, 1.3250e-14),

    CVector(5.95503e-14, 1.3250e-14, 0.9995)

]

# create a simple layer

free_layer = Layer(

      id="free",

    mag=CVector(0, 0, 1),

    anis=CVector(0, 0., 1),

    Ms=1.6,

    thickness=2e-9,

    cellSurface=surface,

    damping=5e-3,

    demagTensor=demagTensor,

)

which defines a layer that can be later referred to by its ‘free’ id, with perpendicular anisotropy axis, initial magnetisation along the z-axis, magnetisation saturation, Ms, of 1.6 T, the thickness of 2 nm, Gilbert damping constant of αG = 0.005 and a demagnetisation tensor under variable name demagTensor (see the “Methods” section for an explanation how those parameters influence the simulation). Multilayer simulation applications revolve most commonly around simple bilayer structures consisting of heavy metal (HM) and FM layers, or MTJs composed of FM layers, each separated by a thin tunnel barrier (TB). Non-ferromagnetic layers, such as HM, are not simulated in the package, but their inclusion in the experiment has direct consequences in the simulation. For example, between two FM layers separated by TB, there is an interlayer exchange coupling (IEC) that varies with thickness22,23. Similarly, layers can be coupled in the multilayer system via a longer-range dipole interaction. HMs are typically simulated indirectly with the addition of STT or SOT terms24,25. It is also possible to save computing time by including pinned layers, experimentally obtained by the exchange-bias structure enforced by the presence of an antiferromagnet. In such a case, the solver is not run for a pinned/reference layer, but the effects of SOT or STT are still modelled via a constant reference vector.

To create a multilayer device in cmtj, the user needs to create at least one FM layer. Layers are then composed into a single Junction that represents a discrete multilayer system. A two-layer Junction can be defined as follows:

# Create MTJ composed of two FM layers created earlier

# Rap - anti-parallel, Rp - parallel resistance

mtj=Junction([free_layer, reference_layer], Rp=100, Rap=200)

Wrapping multiple layers into a single object provides an additional level of control; for instance, the same magnetic field or excitation may be applied to all members of the Junction with a single function instead of to each layer individually.

For some simulations, two or more junctions can be combined into a Stack of type Parallel or Series, which alters the resistance calculation. However, the main consequence of composing a Stack device is the electrical coupling by a current passing through. The model for this kind of coupling follows the work of Taniguchi et al.26. For a parallel or series stack of two junctions, the current depends on the free magnetisations m and the pinning layers p of the junctions i and i + 1:

$$I(t)={I}_{0}(t)+\chi {I}_{0}(t)({{{{\bf{m}}}}}_{i}\cdot {{{{\bf{p}}}}}_{i}+{{{{\bf{m}}}}}_{i+1}\cdot {{{{\bf{p}}}}}_{i+1})\quad ({{{\rm{series}}}})$$
(1)
$$I(t)={I}_{0}(t)+\chi {I}_{0}(t)({{{{\bf{m}}}}}_{i}\cdot {{{{\bf{p}}}}}_{i}-{{{{\bf{m}}}}}_{i+1}\cdot {{{{\bf{p}}}}}_{i+1})\quad ({{{\rm{parallel}}}})$$
(2)

where I0(t) represents the value of the uncoupled current. The coupling strength χ can be positive or negative, most of the time strictly much <1 in absolute value. Creating a stack is simple; for example, setting a current density of I0 = 60 GA/m2 through the stack with the coupling strength of 0.1 reduces to the following:

# create a parallel connection of junction1 and junction 1

stack=ParallelStack([junction1, junction2])

# set the constant current density fed into the system

stack.setCoupledCurrentDriver(ScalarDriver.getConstantDriver(6e10))

# set coupling strength

stack.setCouplingStrength(0.1)

Excitation drivers

The dynamic pathway to excite any system in cmtj takes place through the driver system. The user can define any excitation in the form of a driver, an adequate Scalar driver, or a vector (Axial) driver. The latter are just compositions of the former along each dimension (the x, y, and z axes independently). Each driver component is calculated at each time step and influences the selected effective field contributions. For instance, one may define a sinusoidal driver and use it as a driving excitation of the anisotropy, leading to stimulation of the VCMA effect:

# Junction called mtj was created earlier

# reference the free layer from ‘mtj` using the Junction interface,

mtj.setLayerAnisotropyDriver("free",

  # arguments for the anisotropy sine driver are:

  # offset (J/m^3), amplitude (J/m^3), frequency (GHz), phase

  ScalarDriver.getSineDriver(

    K1, 1e3, 7e9, 0

  ))

Similarly, an externally applied magnetic field can be added through the AxialDriver class by specifying field contributions along each axis. For example, setting a constant field of 5 kA m−1 along the y-axis can happen by using a simple function call:

# reference all layers in the junction

mtj.setLayerExternalFieldDriver("all",

    AxialDriver(

      NullDriver(), # x, does nothing

      ScalarDriver.getConstantDriver(5e3), # y,

      NullDriver())) # z, does nothing

All mechanisms described in this section offer great flexibility in designing an experiment. Since drivers act as input to a state machine, the simulation may be paused, modified, and resumed without having to restart. The output is saved online in a native Python dictionary object that assumes seamless integration with other common numerical, plotting, or machine-learning packages available in that language.

In the consecutive sections section, we focus on reproducing selected interesting experiments and, where possible, comparing the simulation result with the experimental data and analytical functions. The examples are arranged by the level of complexity, starting from the simplest towards more advanced ones. We decided to showcase the following techniques: standard M(H) and R(H) loops in the section “M(H) and R(H) loops”, magnetoresistance (MR) based SD-FMR and PIMM in the section “Spin valve dynamics”, harmonic Hall voltage detection, an angular variant in the section “Angular harmonic Hall detection”, current-induced magnetisation switching (CIMS) in Sect. “CIMS”, electrical coupling of two MTJs in the section “Electrical coupling”. These examples can be reproduced by running the Jupyter notebooks from the GitHub repository of the cmtj package.

M(H) and R(H) loops

The M(H) and R(H) are the basic magnetic characterisation methods that allow the determination of various material parameters of the multilayer system, such as magnetisation saturation, magnetic anisotropy, or magnetoresistance ratio. The M(H) loop simulates magnetometry measurements, such as a vibrating sample magnetometer (VSM) or magnetooptical Kerr effect (MOKE), whereas the R(H) loops are indispensable in adjusting the magnetoresistance magnitude. By performing angular sweep simulations in different planes, one can also determine a type of magnetoresistance, because anisotropic MR (AMR), anomalous Hall effect MR (AHE), giant MR (GMR)/tunnelling MR (TMR) and spin-Hall MR (SMR) are characterised by different angular dependencies21,27,28. Other magnetoresistance flavours, such as those presented, for example, in the works by Avci et al. and Vélez et al.29,30, may be easily added after the magnetisation dynamics have been computed by cmtj.

In the case of M(H) and R(H) loop simulation, we replicated the experimental method by extending the simulation time and collecting the magnetisation or resistance vector at the steady state for each magnitude of the swept magnetic field. As an example, magnetic-field-dependent simulations of the Co(4 nm)/Ru(0.65 nm)/Co(4 nm) system are presented in Fig. 2a–f. The data for this example come from, yet unpublished, wider research on the Co/Ru/Co trilayers. A similar setup may be found in ref. 31. In the simulations, increasing H along the y direction leads to a scissor-shaped magnetisation vector alignment, which saturates at around 600 kA m−1. This becomes particularly clear in the loop M(H) for my component illustrated in Fig. 2b, with the remaining mx and mz having very small amplitudes. Furthermore, the simulation reveals that, due to antiferromagnetic coupling (AFM), the two layers oscillate in antiphase in a certain region, as depicted in Fig. 3. The experimental points for this sample were collected from SD-FMR measurement, with an external field applied at 45° angle respective to the long axis of the stripe, and an RF signal power of 16 dBm. The DC voltage originating from the mixing between oscillating resistance and the in-phase current was obtained using Hall-bar system by a lock-in amplifier synchronised to an amplitude-modulated RF source.

Fig. 2: Steady-state simulations of the Co/Ru/Co system with the transverse applied field.
figure 2

M(H) ac and R(H) df loops simulated with parameters taken from Supplementary Table 1. The magnetic moment is normalised to unity, whereas the SMR, AMR, and GMR magnitudes are set to −0.24, −0.045, and 2 Ω, respectively (note that my and mz components show very little variation with the applied field).

Fig. 3: Co(4 nm)/Ru(0.65 nm)/Co(4 nm) system with both linear and quadratic components of the IEC.
figure 3

ac magnetisation trajectory components for a Hext = 513 kA m−1, marked with the dashed white line in (d). Colour denotes a layer, blue for the top and red for the bottom layer. c Shows that the mz components of the two layers oscillate in antiphase. d Kittel dispersion relation obtained from PIMM (described in the section “Spin valve dynamics”), with experimental points from SD-FMR (given by blue dots), and phase difference Δϕz between mz components of two layers (solid white line) across the external magnetic field range. The region between approximately −600 and 600 kA m−1, where the optical branch is visible, exhibits antiphase oscillation of mz components. Parameters are taken from Supplementary Table 1.

Spin valve dynamics

A more complex example begins with a study of a CoFe(2.1 nm)/Cu(1.9–2.37 nm)/CoFe(1 nm)/NiFe(5 nm) spin valve sample with variable thickness of the Cu spacer layer. This system exhibits characteristic oscillatory coupling varying with spacer thickness, which is well described in terms of the Rudermann–Kittel–Kasyua–Yosida (RKKY) interaction between the magnetisations of the reference and the free layers32. Resulting GMR, R(θ), is calculated with respect to resistances in parallel (RP) and antiparallel states (RAP):

$$R(\theta )={R}_{{{{\rm{P}}}}}+\frac{1}{2}({R}_{{{{\rm{AP}}}}}-{R}_{{{{\rm{P}}}}})(1-{{{{\bf{m}}}}}_{{{{\rm{free}}}}}\cdot {{{{\bf{m}}}}}_{{{{\rm{reference}}}}})$$
(3)

where θ is the angle between the magnetisation vectors of the free and reference layer, mfree is the magnetisation of the free layer, and mreference is the magnetisation of the reference layer. Using the parameters for the system from the papers32,33, also summarised in Supplementary Table 2, we perform SD-FMR and PIMM simulations.

Experimentally SD-FMR methods involve supplying AC current, IAC, in a given frequency range, typically between 2 and 40 GHz, while sweeping with an external magnetic field. As a result, the DC mixing voltage Vmix arises, which is essentially a function of both the frequency and the magnitude of the external magnetic field34. Thus, SD-FMR allows for the calculation of the ferromagnetic resonance frequency for a given set of system parameters in the form of a Kittel dispersion relation. Furthermore, analysis of the shape of the simulated signal can be used to determine the spin torque values, in the current perpendicular to the plane STT35 and in-plane SOT geometries24. In the simulation setup, a representation of SD-FMR is modelled with a 2D map, where Vmix, the mixing voltage of R(θ) and IAC at a frequency f, is plotted against a range of applied external field, H. For each field and frequency, the IAC time series is multiplied by a magnetoresistance time series and then passed through a low-pass filter. Finally, the mixing voltage is extracted as a means of that signal. The results are presented in Fig. 4 with bright green hollow circles as experimental points for comparison. In simple cases, a known analytical relation, in the form of the Kittel dispersion function36, produces the main resonance mode of the system:

$$f=\frac{{\gamma }_{{\rm {e}}}}{2\pi }\sqrt{B(B+{\mu }_{0}{M}_{{{{\rm{s}}}}})}$$
(4)

where the \(\frac{{\gamma }_{e}}{2\pi }\) factor is ≈ 28,024 MHz T−1, and the B field is composed of an external magnetic field, an interlayer exchange coupling field, and an anisotropy field, respectively: B = μ0(Hext + HIEC + HK) (see the section “Field contributions” for more details on how they are computed macro magnetically). We plot the fit to Eq. (4) in Fig. 4 with the solid turquoise line. In addition to Kittel’s model, we included the free-energy model based on the Smit–Beljers model37 (dashed ivory line), which yields more precise results for a multilayer case. The key effect modelled in Fig. 4a–c is the increase of the zero-field oscillation frequency when the IEC increases with absolute value. In Fig. 4d the simulation captures the shift of the resistance loop at ϕH = 90° and the widening of the resistance curve peak at ϕH = 45° in Fig. 4e, all respectively, for the case where J ≈ 0. In any case, macromagnetic simulation, being a dynamic process, can model the experimental data more accurately for that particular experiment. A further advantage of computing the dynamics is that we obtain the full SD-FMR map, rather than the individual resonance modes, as is the case with the Smit–Beljers model.

Fig. 4: Spin valve simulations of CoFe(2.1 nm)/Cu(1.9–2.37 nm)/CoFe(1 nm)/NiFe(5 nm) sample for three different values of Cu thickness which result in different IEC magnitudes.
figure 4

ac Kittel dispersion relations, with the blue dots marking the experimental data. Resistance loops at ϕH = 90° (d) and at ϕH = 0° (e) applied external magnetic field with ϕ denoting the polar angle. Solid turquoise lines mark the fit to Kittel’s formula, Eq. (4) and ivory dashed line represents simulated data from the free-energy Smit–Beljers model. Discrepancies between Kittel and Smit–Beljers model may come from the fact that the latter is better suited to multilayer systems. Parameters of the system may be found in Supplementary Table 2.

Apart from the SD-FMR method described above, magnetisation dynamics can also be investigated by analysing the magnetisation response to picosecond magnetic field pulses. In the experiment, this time domain method is performed indirectly using PIMM38,39,40. From the simulation perspective, PIMM is simulated as an analysis of the free oscillations induced by a short magnetic field pulse, contrary to the dynamics caused by the alternating signal input, as is the case for the FMR. Specifically, we measure the response to a step excitation of a short-lived (2–3 ps), small-amplitude (usually about 50–100 Oe) Oersted field pulse along the z-axis. This corresponds to the experimental setup where a short DC pulse is injected into the system. If the FFT computation of the pulse response for each value of the applied magnetic field from the sweep is repeated, one can obtain a spectrogram representing the dispersion relation, where each pixel denotes the FFT magnitude for a given frequency and magnetic field. For the spin valve system, multiple PIMM simulations are performed for a range of different IEC values and then overlayed, resulting in Fig. 5a, b. Similarly as in the case of the SD-FMR experiment, when the magnitude of the IEC coupling increases, the resonance curve shifts away from the zero fields.

Fig. 5: PIMM scans of the CoFe(2.1 nm)/Cu(1.9–2.37 nm)/CoFe(1 nm)/NiFe(5 nm) system in the function of IEC constant Jlinear.
figure 5

a spectrum of multiple IEC values in (−1,1 mJ m−2) was combined into a single map. The colour indicates the total frequency amplitude summed over all PIMM simulations. b Illustrates the same PIMM, but with a marked maximum amplitude resonance line for each Jlinear value mapped accordingly to the colour scale. The colour scale attached represents different IEC values, from −1 to 1 mJ m−2. We observe the shift of the resonance curve towards the centre for smaller absolute IEC values. Note that at H = 0 the system still exhibits non-zero oscillation. Parameters used for simulation can be found in Supplementary Table 2. Field applied along at 45° angle between x and y axes.

Angular harmonic Hall voltage detection

There are several experimental methods that lead to the determination of the SOT components: SOT-FMR line41 and line width analysis42, the SOT switching current analysis43, or field-dependent harmonic Hall voltage techniques44. Another approach, less susceptible to various artefacts, such as the anomalous Nernst effect, is called the angular harmonic Hall voltage45. Our model has been thoroughly verified using the field-dependent method46, here we present a simplified angular variation of the harmonic Hall voltage detection. The standard process for obtaining torque amplitudes HDL/FL in the angular variation of harmonic Hall voltage detection follows the model of Avcii et al.47,48:

$${V}_{2\omega }=\left(-\frac{{H}_{{{{\rm{FL}}}}}}{{H}_{{{{\rm{ext}}}}}}{V}_{{{{\rm{P}}}}}\cos 2\phi -\frac{1}{2}\frac{{H}_{{{{\rm{DL}}}}}}{{H}_{{{{\rm{eff}}}}}}{V}_{{{{\rm{A}}}}}+{V}_{{{{\rm{ANE}}}}}\right)\cos \phi$$
(5)

where ϕ is the angle in the plane between the long axis of the Hall bar and magnetisation. The effective field Heff includes the external field Hext and the anisotropy field, HK. VP and VA are the planar and anomalous Hall voltages, respectively. VANE is a contribution of the anomalous Nerst effect. We show the simulation result, along with the experimental results for the corresponding Pt(4.3 nm)/FeCoB(2 nm) sample49, in Fig. 6. Each line is produced by sweeping with the azimuth angle ϕ [−180°, 180°] at the frequency f of the AC current and measuring the second harmonic output in the mixing voltage of the input current (for details of the experimental setup, see ref. 49). The parameters for this system can be found in Supplementary Table 3. The signal consists of one part proportional to the damping-like field with a cos ϕ cos 2ϕ dependence and another, related to the field-like term. The former dominates in small magnetic fields because it is scaled by an external field alone, unlike the latter, which is scaled by the effective field (which also includes anisotropy and demagnetising fields). In Fig. 6, this torque causes an inflexion in the curve at large ϕ angles.

Fig. 6: Second Harmonic Hall voltage detection in angular variation.
figure 6

Hollow dots represent the experiment, solid lines mark the simulation data and a dashed red line denotes the fit to Eq. (5). The y-axis is normalised. Measurement data was collected from Pt(4.3 nm)/FeCoB(2 nm) device, for two example magnitudes of the external magnetic field.

CIMS

Next, we discuss an example of SOT-induced magnetisation switching in the HM/FM bilayer. The experimental data were obtained in the multilayer system: Pt(4 nm)/Co(1 nm)/MgO (A1) from the work of Grochot et al.50. In this case, we reproduce the theoretical switching behaviour of the system using the field-like and damping-like SOT, and magnetic parameters obtained from the experiment. The result is shown in Fig. 7. We approximated the critical current density analytically using a formula from Lee et al.51:

$${j}_{{{{\rm{sw}}}}}\approx \frac{2e{\mu }_{0}{M}_{{{{\rm{s}}}}}{t}_{{{{\rm{FM}}}}}}{\hslash {\theta }_{{{{\rm{SH}}}}}}\left(\frac{{H}_{{{{\rm{K}}}}}}{2}-\frac{{H}_{x}}{\sqrt{2}}\right)$$
(6)

where e is the electron charge, μ0 is the magnetic permeability in a vacuum, Ms is the magnetisation saturation, is the reduced Planck constant, θSH is the effective spin Hall angle, HK is the effective perpendicular anisotropy value, and Hx is the applied field along the x direction.

Fig. 7: Critical switching current densities as a function of external field Hx for Pt(4 nm)/Co(1 nm)/MgO SOT device.
figure 7

Fit to analytical formula is represented as a solid blue line and red dots depict the simulated result.

For simulations, we used the trapezoidal impulse shape, with a rising and falling edge of 1 ns and a flat edge of 3 ns. We also normalised the damping- and field-like torque magnitudes obtained from the experiment by the current density with which they were measured. Under the current density sweep, they will scale proportionally, giving the correct values of HDL and HFL at each step.

Electrical coupling

Using this example, we illustrate how electric coupling can be simulated with cmtj. First, we created two MTJs with slightly different magnetic and resistance parameters, emulating a typical experimental dispersion. Then, using the interface of the Stack class (see the section “Simulation design”), we couple them in a parallel connection, setting the coupling value χ. We sweep the external magnetic field at the azimuthal angle of 5° and measure the frequency response of the stack to constant current density excitation. For larger values of the applied external magnetic field and negative coupling constant χ, we observe how two main resonance lines, each corresponding to a separate MTJ, converge towards a common resonance mode. Ultimately, around 250 kA m−1, the two MTJs desynchronise and their resonance lines separate again. The result of the electric synchronisation of two MTJs is depicted in Fig. 8a, while Fig. 8b and c illustrate a situation with a positive coupling coefficient and coupling disabled, respectively. This example shows that the software presented can also be used in more complex systems, for example, for the analysis of neural computing platforms52. The parameters of the coupled system have been collected in Supplementary Table 4.

Fig. 8: The electric synchronisation of two MTJs.
figure 8

Electric coupling constant was set to χ = −0.12 (a) and χ = 0.1 (b). Solid blue and red lines in (a) indicate the primary resonance modes of individual MTJs from the stack. c Shows the same device with no coupling present.

Discussion

In this article, we presented cmtj, fast modelling software for macrospin simulation of magnetic heterostructures. Its core is grounded in the LLGS equation, and the package is capable of calculating both the static and dynamic characteristics of spintronic devices. However, macrospin simulations are inherently limited in modelling any sort of spin wave or materials with non-uniform magnetisation and therefore are not a suitable method in cases where those effects play a key role. Yet, many experimental setups in electrical detection are, in principle, averaged pictures of reality. For instance, in measurements such as M(H) or R(H), we observe only a mean value of multi-domain behaviour of magnetisation or resistance. Therefore, in such use cases, the use of macrospin modelling can be justified and, as shown in the previous sections, results obtained from cmtj agree well with the experimental data.

The key benefit of using macrospin over micromagnetic frameworks is the speed of computation. Additionally, with the Python bindings cmtj provides, the package can be used directly in common parameter search procedures that involve Bayesian optimisation processes or neural network training. The combination of those two advantages, performance and integration with native Python code, hints at the intended use of cmtj, which lies in large-scale sweeps over multidimensional parameter spaces. Such an application plays an interesting role in understanding how different magnetic parameters influence the dynamics of the spintronic device.

Finally, in the spirit of the modern modular development approach suggested, for example, in refs. 53,54, cmtj expands its usability to connect multiple spintronic structures using the Junction or Stack system. Future extensions based on the modular approach may involve the addition of a separate structure, such as a reservoir, where an array of thin-layer spintronics devices is dynamically coupled through dipole interaction55,56.

Methods

Magnetisation dynamics

The pivotal equation for magnetic macrospin simulations is called Landau–Lifshitz–Gilbert–Slonczewski (LLGS)15,45,57,58,59. In the simulation, we use the numerically solvable LL-form of that equation. A formulation with SOT torques included in the package has the following form:

$$\begin{array}{ll}\frac{{{{\rm{d}}}}{{{\bf{m}}}}}{{{{\rm{dt}}}}}\,=\,\frac{-{\gamma }_{0}}{1+{\alpha }_{{{{\rm{G}}}}}^{2}}[{{{\bf{m}}}}\times {{{{\bf{H}}}}}_{{{{\rm{eff}}}}}+{\alpha }_{{{{\rm{G}}}}}{{{\bf{m}}}}\times {{{\bf{m}}}}\times {{{{\bf{H}}}}}_{{{{\rm{eff}}}}}]+\frac{-{\gamma }_{0}}{1+{\alpha }_{{{{\rm{G}}}}}^{2}}[{{{\bf{m}}}}\times {{{\bf{p}}}}({H}_{{{{\rm{FL}}}}}-{\alpha }_{{{{\rm{G}}}}}{H}_{{{{\rm{DL}}}}})+{{{\bf{m}}}}\times {{{\bf{m}}}}\times {{{\bf{p}}}}({H}_{{{{\rm{DL}}}}}+{\alpha }_{{{{\rm{G}}}}}{H}_{{{{\rm{FL}}}}})]\end{array}$$
(7)

where \({{{\bf{m}}}}=\frac{{{{\bf{M}}}}}{{M}_{{\rm {s}}}}\) is a normalised magnetisation vector, with Ms as the magnetisation saturation, Heff as the effective field, αG as the dimensionless Gilbert damping parameter, p is the polarisation vector, and γ0 is the gyromagnetic factor. Factors HDL and HFL are the so-called damping and field-like torque amplitudes, respectively. Usually, for small values of αG, compared to the torque value, the torque mixing can be omitted in the last two terms in this form of the equation.

For structures where the spin current is injected through HM, the values of the SOT torques are usually taken from the experiment. For example, in the harmonic Hall voltage measurement45, their values can be computed with the following equation:

$${H}_{{{{\rm{DL}}}}}=-\frac{2}{\zeta }\frac{{\rho }_{{{{\rm{L}}}}}\pm 2\kappa {\rho }_{{{{\rm{T}}}}}}{1-4{\kappa }^{2}}$$
(8)

where κ is the ratio of the planar Hall effect and the resistance of the anomalous Hall effect and \({\rho }_{{{{\rm{L}}}}/{{{\rm{T}}}}}=\partial {V}_{2\omega }/\partial {H}_{{{{\rm{ext}}}}}^{{{{\rm{L}}}}/{{{\rm{T}}}}}\) for the longitudinal arrangement L, when an external magnetic field is applied along the length of the sample, and the transverse arrangement T, when the field is applied along the width of the sample. The parameter \(\zeta ={\partial }^{2}{V}_{\omega }/\partial {H}_{{{{\rm{ext}}}}}^{2}\) is obtained by fitting the low-field regime of the first harmonic response, Vω to a quadratic function. Substituting the subscripts L and T produces torque HFL. The voltage in the experiment arises as a response to the low-frequency AC current in longitudinal and transverse arrangements, but in the simulations, we often model it as an Oersted field excitation along the y direction. More details can be found in ref. 46. For simulations more suited to the STT model, we assume the following LL form of the LLGS equation:

$$\begin{array}{rcl}\frac{{{{\rm{d}}}}{{{\bf{m}}}}}{{{{\rm{dt}}}}}&=&\frac{-{\gamma }_{0}}{1+{\alpha }_{{{{\rm{G}}}}}^{2}}[{{{\bf{m}}}}\times {{{{\bf{H}}}}}_{{{{\rm{eff}}}}}+{\alpha }_{{{{\rm{G}}}}}{{{\bf{m}}}}\times {{{\bf{m}}}}\times {{{{\bf{H}}}}}_{{{{\rm{eff}}}}}]+ \frac{-{\gamma }_{0}}{1+{\alpha }_{{{{\rm{G}}}}}^{2}}[{a}_{j}\varepsilon \beta ({{{\bf{m}}}}\times {{{\bf{p}}}})+{a}_{j}\varepsilon ({{{\bf{m}}}}\times {{{\bf{m}}}}\times {{{\bf{p}}}})]\end{array}$$
(9)

with β as the secondary parameter that describes the torque (usually set to 0 or equal to the damping parameter αG). The variable aj is defined in terms of current density j:

$${a}_{j}=\frac{\hslash j}{e{M}_{{{{\rm{s}}}}}{t}_{{{{\rm{FM}}}}}}$$
(10)

where is the reduced Planck constant and e is the electron charge. Furthermore, the variable ε depends on λ, the parameter of the spacer layer derived by Slonczewski, and η, the efficiency of the spin current polarisation (0 ≤ η ≤ 1):

$$\varepsilon =\frac{\eta {\lambda }^{2}}{{\lambda }^{2}+1+({\lambda }^{2}-1){{{\bf{m}}}}\cdot {{{\bf{p}}}}}$$
(11)

Often, λ is set to 1, which consequently removes the dependence of torque magnitudes on mp.

Field contributions

In this section, we describe in detail the methods for computing field contributions. The effective field vector Heff is usually composed of various field contributions that, depending on the context of the simulation, may be added or disabled. cmtj provides a range of such contributions:

$${{{{\bf{H}}}}}_{{{{\rm{eff}}}}}={{{{\bf{H}}}}}_{{{{\rm{ext}}}}}+{{{{\bf{H}}}}}_{{{{\rm{IEC}}}}}+{{{{\bf{H}}}}}_{{{{\rm{Oe}}}}}+{{{{\bf{H}}}}}_{{{{\rm{K}}}}}+{{{{\bf{H}}}}}_{{{{\rm{demag}}}}}+{{{{\bf{H}}}}}_{{{{\rm{dipole}}}}}+{{{{\bf{H}}}}}_{{{{\rm{th}}}}}^{* }+{{{{\bf{H}}}}}_{1/{{{f}}}}^{* }$$
(12)

where each component corresponds, respectively, to the applied external field, interlayer exchange coupling (IEC), Oersted field, anisotropy field, demagnetising, dipole, thermal, and 1/f noise field60 (all expressed in A m−1). Contributions marked with * require a stochastic solver. Each of the contributions that constitute Heff may be varied over time using a driver system, as laid out in the section “Excitation drivers”.

Anisotropy field

In cmtj, the anisotropy contribution has two parameters—the axis a which determines a uniaxial anisotropy vector and the scalar value Ku which determines the amplitude of the anisotropy field. The axis parameter is passed in the layer constructor function. However, the scalar value can be driven dynamically using a Driver mechanism using the Layer or Junction API. The formula we use in cmtj is as follows:

$${{{{\bf{H}}}}}_{{{{\rm{K}}}}}=\frac{2{K}_{{{{\rm{u}}}}}}{{\mu }_{0}{M}_{{{{\rm{s}}}}}}({{{\bf{m}}}}\cdot {{{\bf{a}}}}){{{\bf{a}}}}$$
(13)

Interlayer exchange coupling field

The interlayer exchange coupling governs the RKKY-like interaction between neighbouring FM layers separated by a metallic spacer61. In cmtj we include both linear (Jlinear) and quadratic (Jquad) contributions. The contribution enters the effective field of layer i as a result of the interaction with layer j in the form:

$${{{{\bf{H}}}}}_{{{{\rm{IEC}}}},{{{\rm{i}}}}}=\frac{1}{{\mu }_{0}{M}_{{{{\rm{s}}}}}{t}_{{{{\rm{FM}}}}}}[{J}_{{{{\rm{linear}}}}}{{{{\bf{m}}}}}_{j}+2{J}_{{{{\rm{quad}}}}}({{{{\bf{m}}}}}_{i}\cdot {{{{\bf{m}}}}}_{j}){{{{\bf{m}}}}}_{j}]$$
(14)

If a given FM layer is sandwiched between two other FM layers, then the engine will compute the IEC contribution from the top and bottom layers separately and then add them both to the effective field.

Demagnetisation and dipole fields

The demagnetisation interaction has a source in the geometry of the sample. On the other hand, the dipole interaction is a long-range interaction that originates from coupling with other FM layers. Both demagnetisation and dipole fields can be calculated from the tool linked in the repository cmtj (https://github.com/pawelkulig1/Demagnetization-Tensor-Tool). The tool computes a dipole and demagnetising tensor based on the finite difference method and analytical calculations derived in refs. 62,63,64. These tensors can be set directly in the simulation. Specifically, the demagnetisation tensor is passed through the constructor of a Layer. The dipole is set using setBottomDipoleTensor if the interaction originates from the top layers relative to the current layers or setTopDipoleTensor if the dipole interaction originates from the FM layers underneath. The field contribution of dipole and demagnetisation hence takes the form:

$${{{{\bf{H}}}}}_{{{{\rm{dipole}}}}/{{{\rm{demag}}}}}=-{M}_{{{{\rm{s}}}}}{{{\bf{N}}}}{{{\bf{m}}}}$$
(15)

where N is the dipole or demagnetisation tensor and m is the magnetisation of the current layer (demagnetisation) or the coupled layer (dipole). Often the demagnetisation tensor may be approximated by its diagonal when the off-diagonal terms become negligible compared to the diagonal ones.

Oersted field

The Oersted field is statically modelled in cmtj, which means that users can dynamically change it during simulation, but it is not precomputed based on the input current. Obtaining a value of the Oersted field in an element may be a complicated problem. For simple FM/HM bilayer systems41, the Oersted field can be calculated from a simple relation: HOe = jtHM/2 where tHM is the thickness of the HM. In more involved cases, numerical integration or variations of finite-difference methods are required to obtain a precise result.

1/f field

The amplitude of the noise field 1/f is calculated using a modified Voss–McCartney–Trammel (VMT) algorithm60. Being a stochastic contribution, it has the following form:

$${{{{\bf{H}}}}}_{1/{{{f}}}}=c{\eta }_{{{{\rm{VMT}}}}}{{{\rm{d}}}}{{{{\bf{W}}}}}_{{{{\bf{t}}}}}$$
(16)

where c is the scaling parameter, ηVMT is generated from the VMT algorithm, and dWt is the random unit vector. The user specifies a number of generating sources k, and a Bernoulli distribution bias parameter p. At each generation step, k numbers are drawn from the Bernoulli distribution, each representing a source active in that step. For each unique index, a random float is generated, contributing to the total amplitude of the 1/f noise, ηVMT.

Solver methods

The core solver for most of the systems in cmtj is the Runge–Kutta 4 (RK4) algorithm, as it balances decent convergence with speed. However, if the user specifies a temperature component for the system, cmtj switches to the stochastic solver, using the Euler–Heun or Heun method, and solves the Stratonovich form of the LLG equation65:

$${{{\rm{d}}}}{{{\bf{m}}}}(t)={{{\bf{f}}}}({{{\bf{m}}}}(t),t)\Delta t+{{{\bf{g}}}}({{{\bf{m}}}}(t),t)\circ {{{\rm{d}}}}{{{{\bf{W}}}}}_{{{{\bf{t}}}}}\sqrt{\Delta t}$$
(17)

where the non-stochastic part f(m(t), t) is the LL form of the LLG equation, while the stochastic part, g(m(t), t) contains thermal and other stochastic contributions. Δt is the integration step of the numerical method. For example, in the Langevin thermal field, we have the following:

$${{{\bf{g}}}}({{{{\bf{m}}}}}_{t},t)\circ {{{\rm{d}}}}{{{{\bf{W}}}}}_{{{{\bf{t}}}}}=-\frac{\sigma \gamma }{1+{\alpha }^{2}}[{{{\bf{m}}}}\times {{{\rm{d}}}}{{{{\bf{W}}}}}_{{{{\bf{t}}}}}+\alpha {{{\bf{m}}}}\times ({{{\bf{m}}}}\times {{{\rm{d}}}}{{{{\bf{W}}}}}_{{{{\bf{t}}}}})]$$
(18)

where dWt is the random unit vector whose components are sampled from the normal distribution with zero mean, \({{{\mathcal{N}}}}(0,1)\), σ is the standard deviation of thermal noise66,67. From our experience, an optimal integration time should be of the order of at least a picosecond, or tenths of a picosecond, for either type of solver, which was verified experimentally. In cases involving strong IEC coupling or larger stochastic excitation, even shorter integration times may be required. In cases involving strong IEC coupling or larger stochastic excitation, much lower integration times may be required.

Magnetoresistance

Apart from tunnelling and giant magnetoresistance, which are calculated as per Eq. (3), we also include methods to compute longitudinal Rxx and transverse Rxy magnetoresistance21, expressed in terms of magnetisation vector components:

$${R}_{{{{xx}}}}={R}_{{{{xx0}}}}+\left(\Delta {R}_{{{{\rm{AMR}}}}}{m}_{x}^{2}+\Delta {R}_{{{{\rm{SMR}}}}}{m}_{y}^{2}\right)$$
(19)
$${R}_{{{{xy}}}}={R}_{{{{xy0}}}}+\frac{1}{2}\Delta {R}_{{{{\rm{AHE}}}}}{m}_{z}+\frac{w}{l}(\Delta {R}_{{{{\rm{SMR}}}}}+\Delta {R}_{{{{\rm{AMR}}}}}){m}_{x}{m}_{y}$$
(20)

where w and l are the width and length of the sample. ΔRSMR, ΔRAMR, ΔRAHE are the magnitudes of the spin-Hall, anisotropic, and Anomalous Hall Effect resistances, respectively. Rxx0 and Rxy0 are base longitudinal and transverse resistances.

Benchmarks

The cmtj is meant to run on personal computers as well. In Table 1 we present example execution times for more computationally challenging examples described in the sections “M(H) and R(H) loops, Spin valve dynamics, Angular harmonic Hall voltage detection, CIMS, and Electrical coupling”. The runtimes were recorded on a typical 2020 MacBook Pro with Apple Silicon M1 with 16 GB RAM. In the table, the step column designates the number of RK4 steps. For example, in the spin valve VSD experiment, we scan with a field for every frequency; therefore, the total number of steps is frequency steps × field steps × (simulation time/integration time). The measured times in Table 1 are given for a serial execution of each experiment. However, the cmtj library also includes additional helper functions that allow for easy parallelism, designed for simulations performed across multiple parameter spaces.

Table 1 Example of serial execution times and the number of steps per experiment.