Motivation
The effective macrospin model in Adams et al., Phys. Rev. B 110, 054415 (2024), provides two useful dynamics test cases:
- an exact analytical trajectory for $k_4=0$;
- a perturbative physics-regression test for small $k_4\neq0$.
The first case enables a strict pointwise comparison with the numerical trajectory. The second checks whether the expected weak nutational mode, frequency ratio, and amplitudes are reproduced.
$$\mathcal{H}
=
-k_2 m_z^2
+
k_4
\left(
m_x^4+m_y^4+m_z^4
\right).$$
This model provides two useful test scenarios:
- an exact analytical test for $k_4=0$;
- an approximate physics-regression test for small $k_4\neq0$.
The first case allows a strict pointwise comparison with an exact trajectory. The second case tests whether the expected weak nutational mode is reproduced.
Model
The normalised magnetisation is parametrised as
$$\mathbf{m}
=
\begin{bmatrix}
\sin\theta\cos\phi\\\
\sin\theta\sin\phi\\\
\cos\theta
\end{bmatrix}.$$
The undamped dynamics are governed by
$$\frac{d\mathbf{m}}{d\tau}
=
\mathbf{m}\times\mathbf{b}_{\mathrm{eff}},$$
with
$$\mathbf{b}_{\mathrm{eff}}
=
2k_2m_z\mathbf{e}_z
-
4k_4
\left(
m_x^3\mathbf{e}_x
+
m_y^3\mathbf{e}_y
+
m_z^3\mathbf{e}_z
\right).$$
Exact test for $k_4=0$
For $k_4=0$, the polar angle remains constant,
$$\theta(\tau)=\theta_0,$$
while the azimuthal angle evolves linearly,
$$\phi(\tau)
=
\phi_0-\nu_{p,0}\tau,$$
with
$$\nu_{p,0}
=
2k_2\cos\theta_0.$$
The exact trajectory is therefore
$$\mathbf{m}(\tau)
=
\begin{bmatrix}
\sin\theta_0\cos\left(\phi_0-\nu_{p,0}\tau\right)\\\
\sin\theta_0\sin\left(\phi_0-\nu_{p,0}\tau\right)\\\
\cos\theta_0
\end{bmatrix}.$$
A possible analytical reference implementation is
import numpy as np
def exact_uniaxial_trajectory(tau, theta0, phi0, k2):
"""Return the exact undamped trajectory for k4 = 0."""
tau = np.asarray(tau, dtype=float)
nu_p = 2.0 * k2 * np.cos(theta0)
phi = phi0 - nu_p * tau
return np.column_stack(
(
np.sin(theta0) * np.cos(phi),
np.sin(theta0) * np.sin(phi),
np.full_like(tau, np.cos(theta0)),
)
)
The normalised simulated magnetisation can then be compared directly with the analytical trajectory:
m_exact = exact_uniaxial_trajectory(
tau=times,
theta0=theta0,
phi0=phi0,
k2=k2,
)
np.testing.assert_allclose(
m_simulated,
m_exact,
rtol=...,
atol=...,
)
This exact case tests:
- conservation of the polar angle;
- the sign of the azimuthal motion;
- the precession frequency;
- and conservation of the magnetisation norm.
Approximate test for small $k_4$
For small but finite $k_4$, the dynamics contain a weak nutational modulation.
The approximate precession and nutation frequencies are
$$\nu_p
=
\cos\theta_0
\left[
2k_2+
\left(
3-7\cos^2\theta_0
\right)k_4
\right],$$
and
$$\nu_c=4\nu_p.$$
The corresponding amplitudes are
$$a_\theta
=
\frac{k_4\sin^3\theta_0}{4\nu_p},$$
and
$$a_\phi
=
\frac{k_4\cos\theta_0\sin^2\theta_0}{4\nu_p}
=
a_\theta\cot\theta_0.$$
The approximate angular trajectory is
$$\theta(\tau)
\approx
\theta_0
+
a_\theta
\left[
\cos(4\phi_0)
-
\cos\left(4\phi_0-4\nu_p\tau\right)
\right],$$
and
$$\phi(\tau)
\approx
\phi_0-\nu_p\tau
+
a_\phi
\left[
\sin\left(4\phi_0-4\nu_p\tau\right)
-
\sin(4\phi_0)
\right].$$
Because this result is perturbative, it should not be used as a strict pointwise equality test. Instead, the numerical trajectory can be analysed to extract:
- the dominant precession frequency;
- the nutation frequency;
- the polar nutation amplitude;
- and the azimuthal modulation amplitude.
Possible assertions are
assert np.isclose(
nu_p_simulated,
nu_p_analytical,
rtol=...,
)
assert np.isclose(
nu_c_simulated / nu_p_simulated,
4.0,
rtol=...,
)
assert np.isclose(
a_theta_simulated,
a_theta_analytical,
rtol=...,
)
assert np.isclose(
a_phi_simulated,
a_phi_analytical,
rtol=...,
)
The tolerances should account for both the perturbative approximation error and the numerical integration error.
Suggested test hierarchy
-
$k_4=0$: exact pointwise trajectory comparison;
- small $k_4$: comparison of the precession frequency;
- small $k_4$: verification of $\nu_c/\nu_p\approx4$;
- small $k_4$: comparison of the nutation amplitudes.
The $k_4=0$ case provides a strict solver test, whereas the finite-$k_4$ case provides a nontrivial physics-regression test.
Expected value
These tests would validate:
- undamped anisotropy-driven precession;
- the implementation of uniaxial anisotropy;
- the implementation of cubic anisotropy;
- the sign and magnitude of the precession frequency;
- the emergence of the weak nutational mode;
- and the characteristic relation $\nu_c\approx4\nu_p$.
Motivation
The effective macrospin model in Adams et al., Phys. Rev. B 110, 054415 (2024), provides two useful dynamics test cases:
The first case enables a strict pointwise comparison with the numerical trajectory. The second checks whether the expected weak nutational mode, frequency ratio, and amplitudes are reproduced.
This model provides two useful test scenarios:
The first case allows a strict pointwise comparison with an exact trajectory. The second case tests whether the expected weak nutational mode is reproduced.
Model
The normalised magnetisation is parametrised as
The undamped dynamics are governed by
with
Exact test for$k_4=0$
For$k_4=0$ , the polar angle remains constant,
while the azimuthal angle evolves linearly,
with
The exact trajectory is therefore
A possible analytical reference implementation is
The normalised simulated magnetisation can then be compared directly with the analytical trajectory:
This exact case tests:
Approximate test for small$k_4$
For small but finite$k_4$ , the dynamics contain a weak nutational modulation.
The approximate precession and nutation frequencies are
and
The corresponding amplitudes are
and
The approximate angular trajectory is
and
Because this result is perturbative, it should not be used as a strict pointwise equality test. Instead, the numerical trajectory can be analysed to extract:
Possible assertions are
The tolerances should account for both the perturbative approximation error and the numerical integration error.
Suggested test hierarchy
The$k_4=0$ case provides a strict solver test, whereas the finite-$k_4$ case provides a nontrivial physics-regression test.
Expected value
These tests would validate: