<jupyter_start><jupyter_text>Dynamics equationThe dynamics of magnetisation field $\mathbf{m}$, without external excitations (e.g. spin-polarised current) is governed by the Landau-Lifshitz-Gilbert (LLG) equation$$\frac{d\mathbf{m}}{dt} = \underbrace{-\gamma_{0}(\mathbf{m} \times \mathbf{H}_\text{eff})}_\text{precession} + \underbrace{\alpha\left(\mathbf{m} \times \frac{d\mathbf{m}}{dt}\right)}_\text{damping},$$where $\gamma_{0} = \mu_{0}\gamma$ is the gyromagnetic ratio, $\alpha$ is the Gilbert damping, and $\mathbf{H}_\text{eff} = -\frac{1}{\mu_{0}M_\text{s}}\frac{\delta w(\mathbf{m})}{\delta \mathbf{m}}$ is the effective field. It consists of two terms: precession and damping. In this tutorial, we will explore some basic properties of this equation to understand how to define it in simulations. MacrospinWe will study the simplest "zero-dimensional" case - macrospin. In the first step, after we import necessary modules and create the mesh which consists of a single discretisation cell.<jupyter_code>import oommfc as mc
import discretisedfield as df
import micromagneticmodel as mm

# Define a macrospin mesh (i.e. one discretisation cell).
p1 = (0, 0, 0)  # first point of the mesh domain (m)
p2 = (1e-9, 1e-9, 1e-9)  # second point of the mesh domain (m)
n = (1, 1, 1)  # discretisation cell size (m)

region = df.Region(p1=p1, p2=p2)
mesh = df.Mesh(region=region, n=n)<jupyter_output><empty_output><jupyter_text>Now, we can create a micromagnetic system object.<jupyter_code>system = mm.System(name='macrospin')<jupyter_output><empty_output><jupyter_text>Let us assume we have a simple Hamiltonian which consists of only Zeeman energy term$$w = -\mu_{0}M_\text{s}\mathbf{m}\cdot\mathbf{H},$$where $M_\text{s}$ is the saturation magnetisation, $\mu_{0}$ is the magnetic constant, and $\mathbf{H}$ is the external magnetic field. We apply the external magnetic field with magnitude $H = 2 \times 10^{6} \,\text{A}\,\text{m}^{-1}$ in the positive $z$ direction.<jupyter_code>H = (0, 0, 2e6)  # external magnetic field (A/m)
system.energy = mm.Zeeman(H=H)<jupyter_output><empty_output><jupyter_text>Dynamics simulationIn the next step we can define the system's dynamics. Let us assume we have $\gamma_{0} = 2.211 \times 10^{5} \,\text{m}\,\text{A}^{-1}\,\text{s}^{-1}$ and $\alpha=0.1$.<jupyter_code>gamma0 = 2.211e5  # gyromagnetic ratio (m/As)
alpha = 0.1  # Gilbert damping

system.dynamics = mm.Precession(gamma0=gamma0) + mm.Damping(alpha=alpha)<jupyter_output><empty_output><jupyter_text>To check what is our dynamics equation:<jupyter_code>system.dynamics<jupyter_output><empty_output><jupyter_text>Before we start running time evolution simulations, we need to initialise the magnetisation. In this case, our magnetisation is pointing in the positive $x$ direction with $M_\text{s} = 8 \times 10^{6} \,\text{A}\,\text{m}^{-1}$. The magnetisation is defined using `Field` class from the `discretisedfield` package we imported earlier.<jupyter_code>initial_m = (1, 0, 0)  # vector in x direction
Ms = 8e6  # magnetisation saturation (A/m)

system.m = df.Field(mesh, dim=3, value=initial_m, norm=Ms)<jupyter_output><empty_output><jupyter_text>Now, we can run the time evolution using `TimeDriver` for $t=0.1 \,\text{ns}$ and save the magnetisation configuration in $n=200$ steps.<jupyter_code>td = mc.TimeDriver()
td.drive(system, t=0.1e-9, n=200)<jupyter_output>Running OOMMF (ExeOOMMFRunner)[2022/02/25 17:52]... (1.5 s)<jupyter_text>Simulation resultsHow different system parameters vary with time, we can inspect by showing the system's datatable.<jupyter_code>system.table.data<jupyter_output><empty_output><jupyter_text>However, in our case it is much more informative if we plot the time evolution of magnetisation $z$ component $m_{z}(t)$.<jupyter_code>system.table.mpl(y=['mz'])<jupyter_output><empty_output><jupyter_text>Similarly, we can plot all three magnetisation components<jupyter_code>system.table.mpl(y=['mx', 'my', 'mz'])<jupyter_output><empty_output><jupyter_text>We can see that after some time the macrospin aligns parallel to the external magnetic field in the $z$ direction. We can also have a look at the dynamics using an interactive plot.  Exercise 1Modify Gilbert damping and set it to $\alpha=0.005$ and see what happens with the dynamics.**Solution**<jupyter_code>system.dynamics.damping.alpha = 0.005
system.m = df.Field(mesh, dim=3, value=initial_m, norm=Ms)

td.drive(system, t=0.1e-9, n=200)

system.table.mpl(y=['mx', 'my', 'mz'])<jupyter_output>Running OOMMF (ExeOOMMFRunner)[2022/02/25 17:52]... (1.3 s)<jupyter_text>Exercise 2Repeat the simulation with $\alpha=0.1$ and $\mathbf{H} = (0, 0, -2\times 10^{6})\,\text{A}\,\text{m}^{-1}$.**Solution**<jupyter_code>system.energy.zeeman.H = (0, 0, -2e6)
system.dynamics.damping.alpha = 0.1
system.m = df.Field(mesh, dim=3, value=initial_m, norm=Ms)

td.drive(system, t=0.1e-9, n=200)

system.table.mpl(y=['mx', 'my', 'mz'])<jupyter_output>Running OOMMF (ExeOOMMFRunner)[2022/02/25 17:52]... (1.6 s)<jupyter_text>Exercise 3Keep using $\alpha=0.1$. Change the field from `H = (0, 0, -2e6)` to `H = (0, -1.41e6, -1.41e6)`, and plot$m_x(t)$, $m_y(t)$ and $m_z(t)$ as above. Can you explain the (initially non-intuitive) output?<jupyter_code>system.energy.zeeman.H = (0, -1.41e6, -1.41e6)

td.drive(system, t=0.1e-9, n=200)

system.table.mpl(y=['mx', 'my', 'mz'])<jupyter_output>Running OOMMF (ExeOOMMFRunner)[2022/02/25 17:52]... (1.4 s)
{'fraction_non_alphanumeric': 0.15323767476085356, 'fraction_numerical': 0.037527593818984545, 'mean_word_length': 5.679361179361179, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '132587', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2057, 'n_tokens_neox': 1926, 'n_words': 536, 'path': 'getting-started/dynamics-equation.ipynb', 'repo_name': 'ubermag/tutorials', 'size': '5436'}