1 Introduction

The simulation of ferromagnetic composites can play an important role in the development of magnetic materials. A typical approach to describing magnetization dynamics of ferromagnetic materials is using the micromagnetic version of the Landau–Lifshitz equation, which states

$$\begin{aligned} \partial _t \textbf{M} ^\varepsilon = - \textbf{M} ^\varepsilon \times \textbf{H} (\textbf{M} ^\varepsilon ) - \alpha \textbf{M} ^\varepsilon \times \left[ \textbf{M} ^\varepsilon \times \textbf{H} (\textbf{M} ^\varepsilon )\right] , \end{aligned}$$
(1)

where \(\textbf{M} ^\varepsilon \) is the magnetization vector, \(\textbf{H} (\textbf{M} ^\varepsilon )\) the effective field acting on the magnetization and the material constant \(\alpha \) describes the strength of damping. While the effective field contains several important contributions, we here consider a simplified model, only taking into account exchange interaction, and introduce a coefficient \(a^\varepsilon \) describing the material variations in the composite. The parameter \(\varepsilon \ll 1\) represents the scale of these variations. We then have

$$\begin{aligned} \textbf{H} (\textbf{M} ^\varepsilon ) := \varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{M} ^\varepsilon ), \end{aligned}$$

a model that was first described in [1]. Similar models have also recently been used by for example [2] as well as [3] and [4].

For small values of \(\varepsilon \), it becomes computationally very expensive and at some point infeasible to provide proper numerical resolution for a simulation of Eq. (1). Hence we aim to apply numerical homogenization based on the approach of Heterogeneous Multiscale Methods (HMM) to the problem. In this framework, one combines a coarse scale macro problem with a micro problem resolving the relevant fast scales on a small domain in order to obtain an approximation to the effective solution corresponding to the problem.

For a simplified Landau–Lifshitz problem with a highly oscillatory external field and no spatial interaction, a possible HMM setup was introduced in [5] and extended to a non-zero temperature scenario in [6].

For the problem we consider here, Eq. (1), the homogenization error has been analyzed in [7]. There it is also shown that \(\textbf{M} ^\varepsilon \) exhibits fast oscillations in both space and time, where the spatial variations are of order \(\mathcal {O}(\varepsilon )\) while the temporal ones are of order \(\mathcal {O}(\varepsilon ^2)\) and get damped away exponentially with time, depending on the given value of \(\alpha \). In [8] several ways to set up HMM were discussed and the errors introduced in the numerical homogenization process, the so-called upscaling errors, were analyzed. In this paper, we focus on numerical aspects related to the implementation of HMM for Eq. (1). In Sect. 2, we first give an overview of the method and include relevant known results from [7] and [8]. We then discuss some aspects of time integration of the Landau–Lifshitz equation in Sect. 3 and suggest suitable methods for the time stepping in the macro and micro problem, respectively. Section 4 focuses on the HMM micro problem. We study how to choose initial data for the micro problem that is appropriately coupled to the current macro scale solution in Sect. 4.1, before using numerical example problems to investigate several factors that influence the errors introduced in the HMM averaging process in Sect. 4.3. In Sect. 5 we present numerical examples to show that the HMM approach can also be applied to locally-periodic and quasi-periodic problems.

2 Heterogeneous Multiscale Methods

In this section, we introduce the concept of Heterogeneous Multiscale Methods, discuss how we choose to set up a HMM model for the Landau–Lifshitz problem Eq. (1) and give relevant error estimates that were introduced in [7] and [8].

2.1 Problem Description

The specific multiscale problem we consider in this article is to find \(\textbf{M} ^\varepsilon \) that satisfies the nonlinear initial value problem

$$\begin{aligned} \partial _t \textbf{M} ^\varepsilon&= - \textbf{M} ^\varepsilon \times \varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{M} ^\varepsilon ) - \alpha \textbf{M} ^\varepsilon \times \left[ \textbf{M} ^\varepsilon \times \varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{M} ^\varepsilon )\right] , \end{aligned}$$
(2a)
$$\begin{aligned} \textbf{M} ^\varepsilon (x, 0)&= \textbf{M} _{\textrm{init}}(x), \end{aligned}$$
(2b)

with periodic boundary conditions, on a fixed time interval [0, T] and a spatial domain \(\Omega = [0, L]^d\) for some \(L \in \mathbb {R}\) and dimension \(d = 1, 2, 3\). Here \(a^\varepsilon \) is a material coefficient which oscillates with a frequency determined by \(\varepsilon \). We furthermore assume the following.

  1. (A1)

    The material coefficient function \(a^\varepsilon \) is in \(C^\infty (\Omega )\) and bounded by constants \(a_\textrm{min}, a_\textrm{max} > 0\); it holds that \(a_\textrm{min}\le a^\varepsilon (x)\le a_\textrm{max}\) for all \(x \in \Omega \).

  2. (A2)

    The damping coefficient \(\alpha \) and the oscillation period \(\varepsilon \) are small, \(0 < \alpha \le 1\) and \(0< \varepsilon < 1\).

  3. (A3)

    The initial data \(\textbf{M} _\textrm{init}(x)\) is normalized such that \(|\textbf{M} _\textrm{init}(x)|= 1\) for all \(x \in \Omega \), which implies that \(|\textbf{M} ^\varepsilon (x, t)|= 1\) for all \(x \in \Omega \) and \(t \in [0, T]\).

When the material coefficient is periodic, \(a^\varepsilon = a(x/\varepsilon )\) where a(y) is a 1-periodic function and \(\varepsilon = L/\ell \) for some \(\ell \in \mathbb {N}\), one can analytically derive a homogenized problem corresponding to Eq. (2), as shown in [7]. The solution \(\textbf{M} _0\) to this homogenized problem satisfies

$$\begin{aligned} \partial _t \textbf{M} _0&= - \textbf{M} _0 \times \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} _0 \textbf{A} ^H) - \alpha \textbf{M} _0 \times \textbf{M} _0 \times \left[ \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} _0 \textbf{A} ^H)\right] , \end{aligned}$$
(3a)
$$\begin{aligned} \textbf{M} _0(x, 0)&= \textbf{M} _\textrm{init}, \end{aligned}$$
(3b)

where \(\textbf{A} ^H\) is the same homogenized coefficient matrix as for standard elliptic homogenization problems,

$$\begin{aligned} \textbf{A} ^H := \int _{[0,1]^d} a(y) \left( \textbf{I} + (\varvec{\nabla }_y \varvec{\chi })^T \right) dy\,. \end{aligned}$$
(4)

Here \(\varvec{\chi }(y) \in \mathbb {R} ^d\) denotes the so-called cell solution, which satisfies

$$\begin{aligned} \varvec{\nabla }\cdot ( a(y) \varvec{\nabla }\varvec{\chi }(y)) = - \nabla _y a(y) \, \end{aligned}$$
(5)

and is defined to have zero average. In [7], error bounds for the difference between the solutions to Eqs. (2) and (3) are proved under certain regularity assumptions. In particular, we have the following result for periodic problems.

Theorem 1

Given a fixed final time T, assume that \(\textbf{M} ^\varepsilon \in C^1([0, T]; H^{2}(\Omega ))\) is a classical solution to Eq. (2) and that there is a constant K independent of \(\varepsilon \) such that \(\Vert \varvec{\nabla }\textbf{M} ^\varepsilon (\cdot , t)\Vert _{L^\infty } \le K\) for all \(t \in [0, T]\). Suppose that \(\textbf{M} _0 \in C^\infty (0, T; H^{\infty }(\Omega ))\) is a classical solution to Eq. (3) and that the assumptions (A1)–(A3) are satisfied. We then have for \(0 \le t \le T\),

$$\begin{aligned} \Vert \textbf{M} ^\varepsilon (\cdot , t) - \textbf{M} _0(\cdot , t)\Vert _{L^2} \le C \varepsilon \,, \end{aligned}$$
(6)

where the constant C is independent of \(\varepsilon \) and t but depends on K and T.

Note that it is easy to show that \(\Vert \varvec{\nabla }\textbf{M} ^\varepsilon (\cdot , t)\Vert _{L^2} \le K\) independent of \(\varepsilon \), as is for example shown in [7, Appendix B]. Numerically one can check that the same also holds for \(\Vert \varvec{\nabla }\textbf{M} ^\varepsilon (\cdot , t)\Vert _{L^\infty }\) for typical example problems.

2.2 Heterogeneous Multiscale Methods for the Landau–Lifshitz Equation

Heterogeneous Multiscale Methods are a well-established framework for dealing with multiscale problems with scale separation, that involve fast scale oscillations which make it computationally infeasible to properly resolve the problem throughout the whole domain. First introduced by E and Engquist [9], they have since then been applied to problems from many different areas [10, 11].

The general idea of HMM is to approximate the effective solution to the given problem using a coarse scale macro model that is missing some data and is thus incomplete. It is combined with an accurate micro model resolving the fast oscillations in the problem, coupled to the macro solution via the micro initial data. The micro problem is only solved on a small domain around each discrete macro location to keep the computational cost low. The thereby obtained solution is then averaged and provides the information necessary to complete the macro model [9,10,11].

Since HMM approximates the effective solution to a multiscale problem rather than resolving the fast scales, some error is introduced. In case of the Landau–Lifshitz problem Eq. (2) with a periodic material coefficient, the effective solution corresponding to \(\textbf{M} ^\varepsilon \) is \(\textbf{M} _0\) satisfying Eq. (3). It hence follows from Theorem 1 that the \(L^2\)-error between the HMM solution and \(\textbf{M} ^\varepsilon \) in the periodic case is always at least \(\mathcal {O}(\varepsilon )\).

There are several different HMM models one could choose for the problem Eq. (2). Three possibilities are discussed in [8], flux, field and torque model. All three are based on the same micro model, the full Landau–Lifshitz equation Eq. (2) which is solved on a time interval \([0, \eta ]\), where \(\eta \sim \varepsilon ^2\). In [7], it is shown that this is the scale of the fast temporal oscillations in the problem. Hence, the micro model is to find \(\textbf{m} ^\varepsilon (x, t)\) for \(0 \le t \le \eta \) such that

$$\begin{aligned} \partial _t \textbf{m} ^\varepsilon&= - \textbf{m} ^\varepsilon \times \varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{m} ^\varepsilon ) - \alpha \textbf{m} ^\varepsilon \times \left[ \textbf{m} ^\varepsilon \times \varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{m} ^\varepsilon )\right] , \end{aligned}$$
(7a)
$$\begin{aligned} \textbf{m} ^\varepsilon (x, 0)&= \textbf{m} _\textrm{init}(x) = \Pi ^k \textbf{M} (\cdot , t_j). \end{aligned}$$
(7b)

The initial data for the micro problem is based on an interpolation of the current macro state \(\textbf{M} \), here denoted by \(\Pi ^k\), which is explained in more detail in Sect. 4.1. In [8], it is assumed that Eq. (7) holds for \(x \in \Omega \) with periodic boundary conditions to simplify the analysis. In practice, one must only solve Eq. (7) for \(x \in [-\mu ', \mu ']^d\) to keep down the computational cost. Here \(\mu ' \sim \varepsilon \), since this is the scale of the fast spatial oscillations in \(\textbf{m} ^\varepsilon \). To do this, we have to add artificial boundary conditions which introduce some error as discussed in Sects. 4.2 and 4.3.

The three different macro models considered in [8] have the general structure of eqs. (2) and (3) but involve different unknown quantities which have to be obtained by averaging the corresponding data from the micro model Eq. (7). In the field model, we have

$$\begin{aligned} \partial _t \textbf{M}&= - \textbf{M} \times \textbf{H} _\textrm{avg}(x, t; \textbf{M}) - \alpha \textbf{M} \times \left[ \textbf{M} \times \textbf{H} _\textrm{avg}(x, t; \textbf{M})\right] , \end{aligned}$$
(8a)
$$\begin{aligned} \textbf{M} (x, 0)&= \textbf{M} _\textrm{init}, \end{aligned}$$
(8b)

where \(\textbf{H} _\textrm{avg}(x, t; \textbf{M})\) denotes the unknown quantity. In the periodic case, this quantity approximates \(\varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} \textbf{A} ^H)\).

In the flux model, Eq. (8a) is replaced by

$$\begin{aligned} \partial _t \textbf{M}&= - \textbf{M} \times \varvec{\nabla }\cdot \textbf{F} _\textrm{avg}(x, t; \textbf{M}) - \alpha \textbf{M} \times \left[ \textbf{M} \times \varvec{\nabla }\cdot \textbf{F} _\textrm{avg}(x, t; \textbf{M})\right] , \end{aligned}$$
(9)

and in the torque model, we instead have

$$\begin{aligned} \partial _t \textbf{M}&= - \textbf{T} _\textrm{avg}(x, t; \textbf{M}) - \alpha \textbf{M} \times \textbf{T} _\textrm{avg}(x, t; \textbf{M}), \end{aligned}$$
(10)

where in the periodic case, \(\textbf{F} _\textrm{avg}\) and \(\textbf{T} _\textrm{avg}\) are approximations to \(\varvec{\nabla }\textbf{m} \textbf{A} ^H\) and \(\textbf{m} \times \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} \textbf{A} ^H)\), respectively. As shown in [8], the error introduced when approximating the respective quantities by an averaging procedure, the so-called upscaling error, is bounded rather similarly for all three models, with somewhat lower errors in the flux model. This does not give a strong incentive to choose one of the models over the others. In this paper, we therefore focus on the field model for the following reasons, not related to the upscaling error.

First, when choosing the flux model, the components of the flux should be approximated at different grid locations to reduce the approximation error in the divergence that has to be computed on the macro scale, which typically has a rather coarse discretization. This implies that we need to run separate micro problems for each component of the gradient. This is not necessary when using the field model.

Second, it is seen as an important aspect of micromagnetic algorithms that the norm preservation property of the continuous Landau–Lifshitz equation is mimicked by time integrators for the discretized problem. This is usually achieved by making use of the cross product structure in the equation. However, when choosing the torque model Eq. (10), there is no cross product in the first term of the macro model.

The chosen HMM macro model, Eq. (8), is discretized on a coarse grid in space with grid spacing \(\Delta X\) and points \(x_i = x_0 + i \Delta X\), where i is a d-dimensional multi-index ranging from 0 to N in each coordinate direction. The corresponding semi-discrete magnetization values are \(\textbf{M} _i(t) \approx \textbf{M} (x_i, t)\), which satisfy the semi-discrete equation

$$\begin{aligned} \partial _t \textbf{M} _i&= - \textbf{M} _i \times \textbf{H} _\textrm{avg}(x_i, t; {\bar{\textbf{M}}}) - \alpha \textbf{M} _i \times \left[ \textbf{M} _i \times \textbf{H} _\textrm{avg}(x_i, t; {\bar{\textbf{M}}})\right] , \end{aligned}$$
(11a)
$$\begin{aligned} \textbf{M} _i(0)&= \textbf{M} _\textrm{init}(x_i), \end{aligned}$$
(11b)

where \( {\bar{\textbf{M}}}\) denotes the vector containing all the \(\textbf{M} _i\), \(i \in \{0, ..., N\}^d\). The notation \(\textbf{H} _\textrm{avg}(x_i, t; {\bar{\textbf{M}}})\) represents the dependence of \(\textbf{H} _\textrm{avg}\) at location \(x_i\) on several values of the discrete magnetization at time t. To discretize Eq. (11) in time, we introduce \(t_j = t_0 + j \Delta t\), for \(j = 0, ..., M\). The specific form of time discretization of Eq. (11) is discussed in Sect. 3.

2.3 Upscaling

To approximate the unknown quantity \(\textbf{H} _\textrm{avg}\) in Eq. (11) in an efficient way and to control how fast the approximation converges to the corresponding effective quantity, we use averaging involving kernels as introduced in [12, 13].

Definition 1

( [8, 13]) A function K is in the space of smoothing kernels \(\mathbb {K}^{p, q}\) if

  1. 1.

    \(K \in C_c^{q}([-1, 1])\) and \(K^{(q+1)} \in BV(\mathbb {R})\) .

  2. 2.

    K has p vanishing moments,

    $$\begin{aligned}\int _{-1}^1 K(x) x^r dx = {\left\{ \begin{array}{ll} 1\,, &{} r = 0\,,\\ 0\,, &{} 1 \le r \le p\,. \end{array}\right. }\end{aligned}$$

If additionally \(K(x) = 0\) for \(x \le 0\), then \(K \in \mathbb {K}_0^{p, q}\).

We use the conventions that \(K_\mu \) denotes a scaled version of the kernel K,

$$\begin{aligned} K_\mu (x) := {1}/{\mu } K(x/\mu ), \end{aligned}$$

and that in space dimensions with \(d > 1\),

$$\begin{aligned} K(x) := K(x_1) \cdots K(x_d). \end{aligned}$$

For the given problem, we choose a kernel \(K \in \mathbb {K}^{p_x, q_x}\) for the spatial and \(K^0 \in \mathbb {K}^{p_t, q_t}_0\) for the temporal averaging due to the fact that Eq. (7) cannot be solved backward in time. The particular upscaling procedure at time \(t_j\) is then given by

$$\begin{aligned} \textbf{H} _\textrm{avg}(x_i, t_j; {\bar{\textbf{M}}}) = \int _0^\eta \int _{\Omega _\mu } K_\mu (x) K_\eta ^0(t) \varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{m} ^\varepsilon ) dx dt, \end{aligned}$$
(12)

where \(\Omega _\mu := [-\mu , \mu ]^d\) for a parameter \(\mu \sim \varepsilon \) such that \(\mu \le \mu '\), the averaging domain is a subset of the domain that the micro problem is solved on. The micro solution \(\textbf{m} ^\varepsilon \) is obtained solving Eq. (7) on \([-\mu ', \mu ']^d \times [0, \eta ]\), with initial data \(\textbf{m} _\textrm{init}\) based on \({\bar{\textbf{M}}}\) at time \(t_j\) and around the discrete location \(x_i\). A second order central difference scheme in space is usually sufficient to obtain an approximation to \(\textbf{m} ^\varepsilon \) with errors that are low compared to the averaging errors at a relatively low computational cost.

Assuming instead that the micro problem is solved on \(\Omega \times [0, \eta ]\), we have the following estimate for the upscaling error for the case of a periodic material coefficient that is proved in [8].

Theorem 2

Assume that (A1)–(A2) hold and that the micro initial data \(\textbf{m} _\textrm{init}\) is normalized such that it satisfies the condition (A3). Let \(\varepsilon ^2 < \eta \le \varepsilon ^{3/2}\) and suppose that for \(x \in \Omega \) and \(0 \le t \le \eta \), the exact solution to the micro problem Eq. (7) is \(\textbf{m} ^\varepsilon (x, t) \in C^1([0, \eta ]; H^{2}(\Omega ))\) and that there is a constant c independent of \(\varepsilon \) such that \(\Vert \varvec{\nabla }\textbf{m} ^\varepsilon (\cdot , t)\Vert _{L^\infty } \le c\). The solution to the corresponding homogenized problem is \(\textbf{m} _0 \in C^\infty (0, \eta , H^\infty (\Omega ))\).

Moreover, consider averaging kernels \(K \in \mathbb {K}^{p_x, q_x}\) and \(K^0 \in \mathbb {K}^{p_t, q_t}_0\) and let \(\varepsilon< \mu < 1\). Then

$$\begin{aligned}&\left|\textbf{H} _\textrm{avg} - \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} _\textrm{init}(0) \textbf{A} ^H) \right|=: E_\varepsilon + E_\mu + E_\eta , \end{aligned}$$

where the \(\varepsilon \)-dependent error \(E_\varepsilon \) and the averaging-domain size dependent error terms \(E_\mu \) and \(E_\eta \) are bounded as

$$\begin{aligned} E_\varepsilon \le C \varepsilon , ~~ E_\mu \le C \left( \mu ^{p_x +1} + \left( \frac{\varepsilon }{\mu }\right) ^{q_x + 2}\right) ~\text {and} ~ E_\eta \le C \left( \eta ^{p_t + 1} + \frac{1}{{\mu }} \left( \frac{\varepsilon ^2}{ \eta }\right) ^{q_t+1}\right) . \end{aligned}$$
(13)

In all cases, the constant C is independent of \(\varepsilon \), \(\mu \) and \(\eta \) but might depend on K, \(K^0\) and \(\alpha \).

As discussed in [8], for periodic problems we in practice often observe \(E_\varepsilon = \mathcal {O}(\varepsilon ^2)\) rather than the more pessimistic estimate in the theorem.

Two things are important to note here. First, Theorem 2 states that \(\textbf{H} _\textrm{avg}(x_i, t_j; {\bar{\textbf{M}}})\) approximates the solution to the corresponding effective quantity involving the micro scale initial data \(\textbf{m} _\textrm{init}\), not the exact macro solution \(\textbf{M} \). We therefore have to require that

$$\begin{aligned} \partial _x^\beta \textbf{m} _\textrm{init}(0) = \partial _x^\beta \textbf{M} (x_i, t_j) \end{aligned}$$
(14)

for a multi-index \(\beta \) with \(|\beta |= 2\) to get an estimate for the actual upscaling error. Bearing in mind a somewhat more general scenario with non-periodic material coefficient where \(\textbf{A} ^H\) no longer is constant, we subsequently require Eq. (14) to hold for \(|\beta |\le 2\).

Moreover, the quantity that \(\textbf{H} _\textrm{avg}\) in Theorem 2 approximates is independent of \(\alpha \). We can thus choose a different damping parameter in the micro problem than in the macro one to optimize the constants in Eq. (13). Typically, it is favorable to have higher damping in the micro problem Eq. (7), as is discussed in the following sections. This can be seen as an introduction of artificial damping to improve numerical properties as is common in for example hyperbolic problems.

2.4 Example Problems

Throughout this article, we use three different periodic example problems to illustrate the behavior of the different HMM components and numerical methods under discussion, one 1D example and two 2D examples. Further, non-periodic examples are discussed in Sect. 5.

Fig. 1
figure 1

Solution \(\textbf{m} ^\varepsilon \) and corresponding HMM approximation to Eq. (1) with setup (EX1) at time \(T = 0.1\) when \(\varepsilon = 1/200\)

  1. (EX1)

    For the 1D example, the initial data is chosen to be

    $$\begin{aligned} \textbf{M} _\textrm{init}(x) = {\tilde{\textbf{M}}}(x)/|{\tilde{\textbf{M}}}(x)|, \quad {\tilde{\textbf{M}}}(x) = \begin{bmatrix} 0.5+\exp (-0.1\cos (2\pi (x-0.32))) \\ 0.5+\exp (-0.2\cos (2\pi x)) \\ 0.5+\exp (-0.1\cos (2\pi (x-0.75))) \end{bmatrix} \end{aligned}$$

    and the material coefficient we consider is \(a^\varepsilon (x) = a(x/\varepsilon )\) where

    $$\begin{aligned}a(x) = 1 + 0.5\sin (2 \pi x).\end{aligned}$$

    The corresponding homogenized coefficient, which is not used in the HMM approach but as a reference solution, is \(\textbf{A} ^H = \left( \int _0^1 1/a(x) dx \right) ^{-1} \approx 0.866\). In Fig. 1 the solution \(\textbf{M} ^\varepsilon (x, T)\) at \(T = 0.1\) and the corresponding HMM approximation \(\textbf{M} (x, T)\) computed on a grid with \(\Delta X = 1/24\) are shown. Note that the HMM approximation agrees very well with \(\textbf{M} ^\varepsilon \).

  2. (EX2)

    For the first 2D example the initial data is

    $$\begin{aligned} \textbf{m} _\textrm{init}(x)&= {\tilde{\textbf{m}}}(x)/|{\tilde{\textbf{m}}}(x)|, \\ {\tilde{\textbf{m}}}(x)&= \begin{bmatrix} 0.6+\exp (-0.3(\cos (2\pi (x_1-0.25)) + \cos (2\pi (x_2-0.12)))) \\ 0.5+\exp (-0.4(\cos (2\pi x_1) + \cos (2\pi (x_2-0.4)))) \\ 0.4+\exp (-0.2(\cos (2\pi (x_1-0.81)) + \cos (2\pi (x_2 - 0.73)))) \end{bmatrix}, \end{aligned}$$

    which is shown in Fig. 2. The material coefficient is given by

    $$\begin{aligned} a(x)&= 0.5 + (0.5 + 0.25\sin (2 \pi x_1))(0.5 + 0.25\sin (2 \pi x_2)) \\&\qquad + 0.25 (\cos (2 \pi (x_1-x_2)) + \sin (2 \pi x_1)), \end{aligned}$$

    which corresponds to a homogenized coefficient with non-zero off-diagonal elements,

    $$\begin{aligned}\textbf{A} ^H \approx \begin{bmatrix} 0.617&{} 0.026 \\ 0.026&{} 0.715 \end{bmatrix}. \end{aligned}$$

    For this example, \(\textbf{A} ^H\) has to be computed numerically (with high precision).

  3. (EX3)

    The second 2D example has the same initial data as (EX2) but a different material coefficient,

    $$\begin{aligned}a(x) = (1.1 + 0.5\sin (2\pi x_1))(1.1 + 0.5\sin (2 \pi x_2)).\end{aligned}$$

    The corresponding homogenized matrix can be computed analytically [14] and takes the value

    $$\begin{aligned}\textbf{A} ^H = 1.1 \sqrt{1.1^2 - 0.25} \,\textbf{I}.\end{aligned}$$
Fig. 2
figure 2

Initial data \(\textbf{M} _\textrm{init}\) for the 2D problems

In all three cases, it holds that \(a^\varepsilon (x) = a(x/\varepsilon )\).

3 Time Stepping for Landau–Lifshitz Problems

A variety of different methods for time integration of the Landau–Lifshitz equation in a finite difference setting are available, as for example discussed in the review articles [15,16,17]. Most of these methods can be characterized as either projection methods or geometric integrators, typically based on the implicit midpoint method. In a projection method, the basic update procedure does not preserve the length of the magnetization vector moments which makes it necessary to project the intermediate result back to the unit sphere at the end of each time step. Commonly used examples for this kind of methods are projection versions of Runge-Kutta methods as well as the Gauss-Seidel projection method [18, 19]. Furthermore, an implicit projection method based on a linear update formula is proposed in [20].

The most common geometric integrator is the implicit midpoint method, which is both norm preserving and in case of no damping, \(\alpha = 0\), also energy conserving [21, 22]. However, since it is computationally rather expensive, several semi-implicit variations have been proposed, in particular SIA and SIB introduced in [23] as well as the midpoint extrapolation method, MPE, [24]. Further geometric integrators are the Cayley transform based approaches discussed in [25, 26].

While there are many methods available for time integration of the Landau–Lifshitz equation, which have advantages in different scenarios, we here have a strong focus on computational cost, especially when considering the micro problem, where the subsequent averaging process reduces the importance of conservation of physical properties. For the HMM macro model, the form of the problem, Eq. (8), prevents the rewriting of the equation as would be necessary for some integrators, for example the method in [20]. In general, the dependence of \(\textbf{H} _\textrm{avg}\) in Eq. (8) on the micro solution makes the use of implicit methods problematic, as is further discussed in Sect. 3.3.

In the following, we focus on several time integration methods that might be suitable for the given setup and then motivate our choice for the macro and micro problem, respectively.

3.1 Description of Selected Methods

The methods we focus on are two projection methods, HeunP and RK4P, as well as the semi-implicit midpoint extrapolation method, MPE, introduced in [24] and MPEA, an adaption of the latter method. We furthermore include the implicit midpoint method in the considerations since it can be seen as a reference method for time integration of the Landau–Lifshitz equation.

In this section, we suppose that we work with a discrete grid in space with locations \(x_i = x_0 + i \Delta x\), where \(i \in \{0, ..., N\}^d\), and consider time points \(t_j = t_0 + j \Delta t\), \(j = 0, ..., M\). We denote by \(\textbf{m} _i^j \in \mathbb {R} ^3\) an approximation to the magnetization at location \(x_i\) and time \(t_j\), \(\textbf{m} _i^j \approx \textbf{m} (x_i, t_j)\). When writing \(\textbf{m} ^j\) we refer to a vector in \(\mathbb {R} ^{3(N+1)^d}\) that contains all \(\textbf{m} _i^j\). In the main part of this section, we do not distinguish between macro and micro problem but focus on the general behavior of the time stepping methods. Thus, \(\textbf{m} \) can denote both a micro or macro solution.

We furthermore use the notation \(\textbf{f} _i(\textbf{m} ^j)\) to denote the value of a function \(\textbf{f} \) at location \(x_i\) which might depend on the values of \(\textbf{m} ^j\) at several space locations. In particular, we write \(\textbf{H} _i(\textbf{m} ^j)\) to denote a discrete approximation to the effective field at \(x_i\). On the macro scale, it thus holds that \(\textbf{H} _i(\textbf{m} ^j) \approx \textbf{H} _\textrm{avg}(x_i, t_j; {\bar{\textbf{M}}})\) or, when considering the corresponding homogenized problem in case of a periodic material coefficient,

$$\begin{aligned}\textbf{H} _i(\textbf{m} ^j) \approx \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} (x_i, t_j) \textbf{A} ^H).\end{aligned}$$

For the micro problem, we have

$$\begin{aligned} \textbf{H} _i(\textbf{m} ^j) \approx \varvec{\nabla }\cdot (a(x_i/\varepsilon ) \varvec{\nabla }\textbf{m} ^\varepsilon (x_i, t_j)).\end{aligned}$$

The particular form of \(\textbf{H} _i(\textbf{m} ^j)\) does not have a major influence on the following discussions if not explicitly stated otherwise.

3.1.1 HeunP and RK4P

HeunP and RK4P are the standard Runge Kutta 2 and Runge Kutta 4 methods with an additional projection back to the unit sphere at the end of every time step. Let \(\textbf{f} (\textbf{m} ^j)\) be the \({ 3(N+1)^d}\)-vector such that

$$\begin{aligned}\textbf{f} _i(\textbf{m} ^j) := - \textbf{m} _i^j \times \textbf{H} _i(\textbf{m} ^j) - \alpha \textbf{m} _i^j \times \left[ \textbf{m} _i^j \times \textbf{H} _i(\textbf{m} ^j)\right] , \qquad i \in \{0, ..., N\}^d.\end{aligned}$$

Then in the Runge-Kutta methods, one computes stage values

$$\begin{aligned} \textbf{k} _1 = \textbf{f} (\textbf{m} ^j), ~~ \textbf{k} _2 = \textbf{f} (\textbf{m} ^j + \tfrac{\Delta t}{2} \textbf{k} _1), ~~ \textbf{k} _3 = \textbf{f} (\textbf{m} ^j + \tfrac{\Delta t}{2} \textbf{k} _2), ~~ \textbf{k} _4 = \textbf{f} (\textbf{m} ^j + \Delta t \textbf{k} _3). \end{aligned}$$

In HeunP (RK2P), the time step update then is given by

$$\begin{aligned} \textbf{m} ^{j+1}_i = {\tilde{\textbf{m}}}_i / |{\tilde{\textbf{m}}}_i|, \qquad \text {where} \qquad {\tilde{\textbf{m}}} = \textbf{m} ^j + \tfrac{\Delta t}{2}(\textbf{k} _1 + \textbf{k} _2), \end{aligned}$$
(15)

and for RK4P,

$$\begin{aligned} \textbf{m} ^{j+1}_i = {\tilde{\textbf{m}}}_i / |{\tilde{\textbf{m}}}_i|, \qquad \text {where} \qquad {\tilde{\textbf{m}}} = \textbf{m} ^j + \tfrac{\Delta t}{6}(\textbf{k} _1 + 2 \textbf{k} _2 + 2 \textbf{k} _3 + \textbf{k} _4). \end{aligned}$$
(16)

HeunP is a second order method and RK4P is fourth order accurate.

3.1.2 Implicit Midpoint

Using the implicit midpoint method, the Landau–Lifshitz equation is discretized as

$$\begin{aligned} \frac{\textbf{m} _i^{j+1} - \textbf{m} _i^j}{\Delta t} = - \frac{\textbf{m} _i^j + \textbf{m} _i^{j+1}}{2} \times \textbf{h} _i\left( \frac{\textbf{m} ^j + \textbf{m} ^{j+1}}{2}\right) , \end{aligned}$$
(17)

where

$$\begin{aligned} \textbf{h} _i(\textbf{m}) := \textbf{H} _i(\textbf{m}) + \alpha \textbf{m} _i \times \textbf{H} _i(\textbf{m}). \end{aligned}$$
(18)

Hence, the values for \(\textbf{m} _i^{j+1}\) are obtained by solving the nonlinear system

$$\begin{aligned} \textbf{m} ^{j+1} = \left( \textbf{I} + \tfrac{\Delta t}{2} \left[ \textbf{h} \left( \tfrac{\textbf{m} ^j + \textbf{m} ^{j+1}}{2}\right) \right] _\times \right) ^{-1} \left( \textbf{I}- \tfrac{\Delta t}{2} \left[ \textbf{h} \left( \tfrac{\textbf{m} ^j + \textbf{m} ^{j+1}}{2}\right) \right] _\times \right) \textbf{m} ^j, \end{aligned}$$
(19)

where \(\left[ \textbf{h} \right] _\times \) is the matrix such that the matrix-vector product \(\left[ \textbf{h} \right] _\times \textbf{m} ^j\) corresponds to taking the cross products \(\textbf{h} _i \times \textbf{m} _i^j\) for all \(i \in \{0, ..., N\}^d\). The implicit midpoint method is norm-conserving and results in a second order accurate approximation.

However, when using Newton’s method to solve the non-linear system Eq. (19), one has to compute the Jacobian of the right-hand side with respect to \(\textbf{m} ^{j+1}\), a sparse, but not (block)-diagonal, \({3(N+1)^d \times 3(N+1)^d}\) matrix and then solve the corresponding linear system in each iteration, which has a rather high computational cost. In case of the HMM macro model, the Jacobian cannot be computed analytically since then \(\textbf{H} _i\) in Eq. (18) is replaced by the averaged quantity \(\textbf{H} _\textrm{avg}(x_i, t_j; \textbf{m})\), with a dependence on \(\textbf{m} \) that is very complicated. A numerical approximation is highly expensive since it means solving \(C N^{2d}\) additional micro problems per time step.

3.1.3 MPE and MPEA

As described in [24], the idea behind the midpoint extrapolation method is to approximate \(\textbf{h} (\frac{\textbf{m} ^j + \textbf{m} ^{j+1}}{2})\) in Eq. (17) using the explicit extrapolation formula

$$\begin{aligned} \textbf{h} \left( \frac{\textbf{m} ^j + \textbf{m} ^{j+1}}{2}\right) \approx \textbf{h} ^{j+1/2} := \tfrac{3}{2} \textbf{h} (\textbf{m} ^j) - \tfrac{1}{2} \textbf{h} (\textbf{m} ^{j-1}). \end{aligned}$$
(20)

The update for \(\textbf{m} _i\) then becomes

$$\begin{aligned} \frac{\textbf{m} _i^{j+1} - \textbf{m} _i^j}{\Delta t} = - \frac{\textbf{m} _i^j + \textbf{m} _i^{j+1}}{2} \times \textbf{h} _i^{j+1/2}. \end{aligned}$$
(21)

The quantity \(\textbf{h} _i^{j+1/2}\) here is independent of \(\textbf{m} ^{j+1}\), which means that the problem decouples into \((N+1)^d\) small \(3\times 3\) systems. Since the first term on the right-hand side still contains \(\textbf{m} _i^{j+1}\), this is considered a semi-implicit method. Just as the implicit midpoint method, MPE is second order accurate. We furthermore propose to use third-order accurate extrapolation,

$$\begin{aligned} \textbf{h} ^{j+1/2} := \frac{23}{12} \textbf{h} (\textbf{m} ^j) - \frac{16}{12} \textbf{h} (\textbf{m} ^{j-1}) + \frac{5}{12} \textbf{h} (\textbf{m} ^{j-2}), \end{aligned}$$
(22)

in Eq. (21), which gives MPEA, the adapted MPE method. As it is based on the implicit midpoint method, MPEA is second order accurate just like MPE, but has better stability properties for low damping, as shown in the next section.

As MPE and MPEA are multi-step methods, values for \(\textbf{m} ^1\) (and \(\textbf{m} ^2\)) are required for startup. These can be obtained using HeunP or RK4P, as suggested in [24].

3.1.4 Comparison of Methods

In Fig. 3, the error with respect to a reference solution \(\textbf{m} _\textrm{ref}\) is shown for all the considered (semi-)explicit methods and two example problems, a 1D problem and a 2D problem. Both example problems are homogenized problems on a rather coarse spatial discretization grid such as we might have in the HMM macro problem. For the 1D problem, the implicit midpoint method is also included for reference.

Fig. 3
figure 3

Comparison of \(L^2\)-error in different time stepping methods when varying the time step size \(\Delta t\) given a fixed spatial discretization with \(\Delta x = 1/50\) and damping parameter \(\alpha = 0.01\). The dotted vertical line corresponds to \(\Delta t = (\Delta x)^2\) in each case

For small time step sizes, one can observe the expected convergence rates for HeunP, RK4P and MPE. For MPEA, we observe third order convergence in the 1D problem, while in the 2D case, we have second order convergence for small \(\Delta t\). Overall, MPEA results in lower errors compared to HeunP, MPE and the implicit midpoint method. RK4P is most accurate.

3.2 Stability of the Time Stepping Methods

It is well known that in explicit time stepping methods for the Landau–Lifshitz equation, the choice of time step size \(\Delta t\) given \(\Delta x\) in space is severely constrained by numerical stability, see for example [17, 18]. Note that due to the norm preservation property of the considered methods, the solutions cannot grow arbitrarily as unstable solutions often do in other applications. However, when taking too large time steps, explicit time integration will typically result in solutions that oscillate rapidly and do not represent the intended solution in any way. Following standard practice in the field, we refer to this behavior as instability in this section. This stability limit is seen clearly for all methods expect IMP in Fig. 3.

In numerical experiments, we observe that in order to obtain stable solutions, the time step size \(\Delta t\) has to be chosen proportional to \(\Delta x^2\) for all of the considered methods, both explicit and semi-explicit. This is exemplified in Fig. 4 for (EX1) with \(\alpha = 0.01\).

Fig. 4
figure 4

Empirically found maximum value of \(\Delta t\) that still results in a stable solution for varying values of \(\Delta x\) in (EX1), homogenized, with \(\alpha = 0.01\)

To get a better understanding of stability, consider a semi-discrete form of the Landau–Lifshitz equation in one dimension with a constant material coefficient, equal to one. This can be written as

$$\begin{aligned} \partial _t \textbf{m} = \textbf{f} _\alpha (\textbf{m}), \qquad \textbf{f} _\alpha (\textbf{m}) = - \textbf{m} \times {D} \textbf{m}- \alpha \textbf{m} \times \left[ \textbf{m} \times {D} \textbf{m} \right] = -B(\textbf{m})D\textbf{m}, \end{aligned}$$
(23)

where \(\textbf{m} \in \mathbb {R} ^{3N}\) contains the vectors \(\{\textbf{m} _i\}\), D is the discrete Laplacian and \(B(\textbf{m})\) is a block diagonal skew-symmetric matrix with eigenvalues \(\{0,\ +i-\alpha ,\ -i-\alpha \}\) that comes from the cross products. If \(\{\textbf{m} _i\}\) samples a smooth function, the Jacobian of \(\textbf{f} _\alpha (\textbf{m})\) can be approximated as

$$\begin{aligned} \nabla _\textbf{m} \textbf{f} _\alpha (\textbf{m})=-\nabla _\textbf{m} B(\textbf{m})D\textbf{m} \approx -B(\textbf{m})D. \end{aligned}$$

Still assuming smoothness, one can subsequently deduce [27] that the eigenvalues of the Jacobian are approximately given as the eigenvalues \(\omega \) of \(-D\) multiplied by the eigenvalues of \(B(\textbf{m})\), namely

$$\begin{aligned} \lambda _+\approx (i-\alpha )\omega , \qquad \lambda _-\approx (-i-\alpha )\omega , \qquad \lambda _0\approx 0. \end{aligned}$$

The eigenvalues of \(-D\), the negative discrete Laplacian, are real, positive and bounded by \(O(\Delta x^{-2})\). Consequently, the eigenvalues of the Jacobian \(\nabla _\textbf{m} \textbf{f} _\alpha (\textbf{m})\) will lie along the lines \(s(\pm i-\alpha )\) for real \(s\in [0,O(\Delta x^{-2})\)] in the complex plane. This is illustrated in Fig. 5a where we have plotted the eigenvalues of \(\nabla _\textbf{m} \textbf{f} _\alpha (\textbf{m})\), scaled by \(\Delta x^2\), for several values of \(\alpha \). One can observe that given \(\alpha = 0\), the eigenvalues are purely imaginary. As \(\alpha \) increases, the real parts of the eigenvalues decrease correspondingly.

For the Landau–Lifshitz equation Eq. (2) with a material coefficient as well as the homogenized equation Eq. (3), the eigenvalues of the corresponding Jacobians get a different scaling based on the material coefficient but their general behavior is not affected. We hence conjecture that it is necessary that

$$\begin{aligned} \frac{\Delta t}{(\Delta x)^2} \le C_{\textrm{stab}, \alpha }, \end{aligned}$$
(24)

where \(C_{\textrm{stab}, \alpha }\) is a constant depending on the chosen integrator, the damping parameter \(\alpha \) and the material coefficient. Based on several numerical examples, we observe for the latter dependence that

$$\begin{aligned}C_{\textrm{stab}, \alpha } \lesssim C_\mathrm {\alpha } {\left\{ \begin{array}{ll} (\max _{y \in Y} |a(y)|)^{-1}, &{} \text {original problem}, \\ (\max _{i,j} |\textbf{A} ^H_{ij}|)^{-1}, &{} \text {homogenized problem}, \end{array}\right. } \end{aligned}$$

where \(C_\mathrm {\alpha }\) denotes further dependence on \(\alpha \) and the integrator.

3.2.1 Stability Regions of Related Methods

In order to better understand the stability behavior of the considered time integrators, it is beneficial to study the stability regions of some well-known, related methods. For HeunP and RK4P, we regard the corresponding integrators without projection. We observe a very similar stability behavior when using Heun and RK4 to solve the problems considered in Figs. 3 and 4.

To get some intuition about MPE and MPEA, we start by considering the problem

$$\begin{aligned} \partial _t \textbf{m} = - \textbf{n} \times \textbf{H} (\textbf{m}) - \alpha \textbf{n} \times \left[ \textbf{m} \times \textbf{H} (\textbf{m})\right] = - \textbf{n} \times \textbf{h} (\textbf{m}) , \end{aligned}$$
(25)

where \(\textbf{n} \) is a given vector function, constant in time, with \(|\textbf{n} |= 1\). This corresponds to replacing the first \(\textbf{m} \) in each term on the right-hand side in Eq. (2) by a constant approximation. For this problem, time stepping according to the MPE update Eq. (21) results in

$$\begin{aligned} \frac{\textbf{m} _i^{j+1} - \textbf{m} _i^j}{\Delta t} = - \textbf{n} _i \times \textbf{h} _i^{j+1/2} = - \frac{3}{2} \left( \textbf{n} _i \times \textbf{h} _i(\textbf{m} ^j)\right) + \frac{1}{2} \left( \textbf{n} _i \times \textbf{h} _i(\textbf{m} ^{j-1})\right) . \end{aligned}$$
(26)

This is the same update scheme as one gets when applying the Adams–Bashforth 2 (AB2) method to Eq. (25). In the same way, MPEA and AB3 are connected. Furthermore, note that the term that was replaced by \(\textbf{n} \) in Eq. (2) to obtain Eq. (25) is the one that is treated implicitly in the semi-implicit methods MPE and MPEA. We hence expect that studying the stability of AB2 and AB3 can give an indication of what to expect for MPE and MPEA. This is backed up by the fact that the stability properties observed for MPE and MPEA in Figs. 3 and 4 are closely matched when using AB2 and AB3, respectively, to solve the respective problems.

When comparing the stability regions of RK4, Heun, AB2 and AB3 as shown in Fig. 5b, one clearly sees that the Runge-Kutta methods have larger stability regions than the multi-step methods. RK4’s stability region is largest and contains part of the imaginary axis, while the one for Heun is only close to the imaginary axis in a shorter interval.

Fig. 5
figure 5

Eigenvalues of Jacobian \(\nabla \textbf{f} _\alpha (\textbf{m})\) and stability regions of methods related to the considered time integrators

AB2 and AB3 have stability regions with a similar extent in the imaginary direction, but while AB3’s contains part of the imaginary axis, AB2’s does not. On the other hand, the stability region of AB2 is wider in the real direction.

Consider now again the example problems shown in Fig. 3 where \(\alpha =0.01\), which implies that the eigenvalues of the corresponding Jacobian are rather close to the imaginary axis. Based on Fig. 5b we therefore expect the methods with related stability areas which include parts of the imaginary axis, RK4P and MPEA, to require fewer time steps than HeunP and MPE. This matches with the observed stability behavior in Fig. 3.

3.2.2 Influence of \(\alpha \)

To further investigate the influence of \(\alpha \) on \(C_\mathrm {stab, \alpha }\), this factor is shown in Fig. 6 for varying \(\alpha \), both for the considered methods HeunP, RK4P, MPE and MPEA and the discussed related methods, Heun, RK4, AB2 and AB3. The behavior of \(C_\mathrm {stab, \alpha }\) is almost the same for the actual and the related methods.

As expected, we observe that \(C_\mathrm {stab, \alpha }\) for low \(\alpha \)-values is constant for MPEA and RK4P, with related stability regions that include the imaginary axis, while for HeunP and MPE, lower \(\alpha \) results in lower \(C_\mathrm {stab, \alpha }\). When increasing \(\alpha \), the eigenvalues of \(\varvec{\nabla }_m \textbf{f} _\alpha \) as defined in Eq. (23) get larger real parts and the stability regions’ extent in the real direction becomes more important. For RK4P and MPEA, this means that for \(\alpha \gtrsim 0.2\), \(C_\mathrm {stab, \alpha }\) decreases as \(\alpha \) increases. For HeunP and MPE, the highest \(C_\mathrm {stab, \alpha }\) is obtained at \(\alpha \approx 0.5\). For higher \(\alpha \), the required \(C_\mathrm {stab, \alpha }\) decreases as \(\alpha \) increases. Overall, MPEA requires the lowest \(C_{\textrm{stab}, \alpha }\) for high \(\alpha \), which agrees with the fact that the related stability region is shortest in the real direction. The highest \(C_{\textrm{stab}, \alpha }\) is still the one for RK4P, in accordance with the stability region considerations.

Fig. 6
figure 6

Dependence of \(C_{\textrm{stab}, \alpha }\) on \(\alpha \), for actual and related time integrators. Based on the homogenized solution to (EX2)

However, HeunP is a two-stage method and each RK4P step consists of four stages, while MPE and MPEA are multi-step methods that only require computation of one new stage per time step. In general, each step of HeunP/RK4P thus has roughly two/four times the computational cost as a MPE or MPEA step. To take this into account, we compare the total number of computations for each method by considering the factor \(s/C_{\textrm{stab}, \alpha }\), where s denotes the number of stages in the method. This is shown in Fig. 7.

Fig. 7
figure 7

Left: Dependence of \(C_{\textrm{stab}, \alpha }\) on \(\alpha \), based on the homogenized solution to (EX2). Right: corresponding scaling of computational cost

We hence draw the following conclusion.

  • For \(\alpha < 0.1\), RK4 and MPEA result in approximately the same computational cost, independent of the specific value of \(\alpha \), while MPE and HeunP require significantly more computations.

  • For high (artificial) damping, the situation changes and HeunP has the lowest computational cost of the considered time integrators.

3.3 Macro Time stepping

On the HMM macro scale, the given spatial discretization is in general rather coarse, containing only relatively few grid points, and we are interested in longer final times. Therefore, an implicit method such as IMP might seem suitable here. However, the resulting computational cost is higher than with an explicit method since we cannot compute the required Jacobian analytically as discussed in Sect. 3.1.

When considering which (semi)-explicit method is most suitable, we have to consider the value of the damping constant \(\alpha \). According to for example [28, 29], the value of \(\alpha \) is less than 0.1 or even 0.01 for typical metallic materials such as Fe, Co and Ni, and could be one or two orders smaller for ferromagnetic oxides or garnets. On the macro scale, we hence typically reckon with \(\alpha \) between \(10^{-1}\) and \(10^{-4}\). This also matches with the \(\alpha \)-values typically used in the literature, see for instance [15, 18, 30] and [24]. For this range of \(\alpha \), we conclude based on the discussion in Sect. 3.2 that RK4P and MPEA are preferred for time integration on the macro scale. These are also the methods which give the most accurate solutions as, for example, shown in Fig. 3.

For the overall error on the macro scale in the periodic case, we expect that

$$\begin{aligned} \Vert \textbf{M} ^\varepsilon - \textbf{M} _0\Vert&\le C \left( \varepsilon + (\Delta t)^{k} + (\Delta X)^\ell + e_\textrm{HMM}\right) \nonumber \\&\le C \left( \varepsilon + (\Delta X)^{\min (2k, \ell )} + e_\textrm{HMM}\right) , \end{aligned}$$
(27)

where the factor \(\varepsilon \) follows from Theorem 1 and k is the order of accuracy of the time integrator. Moreover, \(\ell \) is the order of accuracy of the spatial approximation to the effective field on the macro scale and \(e_\textrm{HMM}\) is an additional error due to the fact that we approximate this effective field by \(\textbf{H} _\textrm{avg}\) in the upscaling procedure.

Because of the time step restriction required for stability in explicit and semi-explicit methods, Eq. (24), it is desirable to have relatively large \(\Delta x\) to reduce computational cost. We therefore propose to use a higher order method in space, ideally \(\ell = 2k\).

We hence have two possible choices. One can either use the fourth order accurate RK4P in combination with an eighth order approximation in space to get a macro scheme with very high order of accuracy regarding space and time discretization. However, to get the full effect of this, \(\textbf{H} _\textrm{avg}\) has to be approximated very precisely such that also \(e_\textrm{HMM}\) is low, see also Sect. 4.5, which in turn can result in rather high computational cost. Alternatively, one can apply the second order MPEA and a spatial approximation such that \(\ell = 4\) which results in fourth order accuracy of the space and time discretization. Since MPEA also has the advantage that it is a geometric integrator and norm preserving without projection, this is what we propose to use.

3.4 Micro Time Stepping

When considering the micro problem, there are two important differences compared to the macro problem. First, the fast oscillations in the solution \(\textbf{m} ^\varepsilon \) are on different scales in time and space. The time scale we are interested in is \(\mathcal {O}(\varepsilon ^2)\) while the spatial scale is \(\mathcal {O}(\varepsilon )\). Therefore a time step size proportional to \((\Delta x)^2\) is suitable to obtain a proper resolution of the fast oscillations in time. Second, as discussed Sect. 2.3, we can choose the damping parameter \(\alpha \) for the micro problem to optimize convergence of the upscaling errors. As shown in Sect. 4, it is typically advantageous to use artificial damping and set \(\alpha \) close to one, considerably higher than in the macro problem.

The order of accuracy of the time integrator is not an important factor, since already for a second order accurate integrator, the time integration error usually is significantly lower than the space discretization error due to the given time step restriction. As the micro problem is posed on a relatively short time interval and the solution then is averaged in the upscaling process, inherent norm preservation that geometric integrators have is not an important factor here either. The considerations in Sect. 3.2 thus imply that the optimal strategy with respect to computational cost is to use HeunP for time integration when \(\alpha > 0.2\) is chosen in the micro problem.

4 Micro Problem Setup

In this section, we investigate how different aspects of the micro problem influence the upscaling error as well as the overall macro solution. In particular, the choice of initial data and the size of the computational and averaging domain in space and time are important. Consider the periodic case, \(a^\varepsilon (x) = a(x/\varepsilon )\). Then it holds for the error in the HMM approximation to the effective field that

$$\begin{aligned} E_\textrm{approx}&:= \left|\textbf{H} _\textrm{avg} - \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} _0(x_i, t_j) \textbf{A} ^H)\right|\nonumber \\ {}&\le \left|\textbf{H} _\textrm{avg} - \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} _\textrm{init}(0) \textbf{A} ^H)\right|\nonumber \\ {}&\qquad + \left|\varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} _\textrm{init}(0) \textbf{A} ^H) - \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} _0(x_i, t_j) \textbf{A} ^H)\right|\nonumber \\ {}&=: E_\textrm{avg} + E_\textrm{disc}. \end{aligned}$$
(28)

The discretization error \(E_\textrm{disc}\) is determined by the choice of initial data \(\textbf{m} _\textrm{init}\) to the micro problem and is analyzed in the next section, Sect. 4.1.

Given that we have initial data with \(|\textbf{m} _\textrm{init}|= 1\) and an exact solution to the micro problem on the whole domain, the averaging error \(E_\textrm{avg}\) can be bounded using Theorem 2. When solving the micro problem numerically and only on a subdomain \([-\mu ', \mu ']^d\), additional errors are introduced. We can split \(E_\textrm{avg}\) as

$$\begin{aligned} E_\textrm{avg} = E_\varepsilon + E_\mu + E_\eta + E_{\mu '} + E_\textrm{num}, \end{aligned}$$
(29)

where \(E_\varepsilon , E_\mu \) and \(E_\eta \) are as in Theorem 2. They depend on \(\varepsilon \) and the parameters \(\mu \) and \(\eta \), which determine the size of the micro problem averaging domains in space and time. Moreover, the choice of averaging kernels, K and \(K^0\), influences these errors. How to specifically choose these parameters is discussed in Sect. 4.3. The term \(E_{\mu '}\) comprises errors due to the micro problem boundary conditions, as explained in Sect. 4.2, and \(E_\textrm{num}\) errors due to the numerical discretization of the micro problem, which is done using a standard second order finite difference approximation to \(\varvec{\nabla }\cdot (a^\varepsilon \varvec{\nabla }\textbf{m} ^\varepsilon )\) and HeunP for time integration.

4.1 Initial Data

We first consider how to choose the initial data \(\textbf{m} _\textrm{init}\) to a micro problem based on the current macro state, obtained according to Eq. (11). We here suppose that the current given discrete magnetization values match with the (exact) macro solution at time \(t = t_j\), \(\textbf{M} _i = \textbf{M} (x_i, t_j)\). For the discretization of \(\textbf{M} \), the same setup as described in Sect. 2.2 for the HMM macro model is considered.

The initial data \(\textbf{m} _\textrm{init}\) for the micro problem should satisfy two conditions.

  1. 1.

    It should be normalized, \(|\textbf{m} _\textrm{init}(x)|= 1\) for all \(x \in [-\mu ', \mu ']^d\), to satisfy the conditions necessary for Theorem 2, which we use to bound \(E_\textrm{avg}\).

  2. 2.

    The initial data should be consistent with the current macro solution in the sense that given a multi-index \(\beta \) with \(|\beta |\le 2\),

    $$\begin{aligned} \left|\partial _x^\beta \textbf{m} _\textrm{init}(0) - \partial _x^\beta \textbf{M} (x_k, t_j)\right|= \mathcal {O}((\Delta X)^\ell ). \end{aligned}$$
    (30)

    Then the discretization error in Eq. (28) is \(E_\textrm{disc} = \mathcal {O}((\Delta X)^\ell )\). As described in Eq. (27) in Sect. 3.3, when using a kth order explicit time stepping method, it is ideal in terms of order of accuracy to choose \(\ell = 2k\).

In order to get initial data satisfying the requirements, an approach based on polynomial interpolation is applied. We use \(p^{[n]}(x)\) to denote an interpolating polynomial of order n, and let \(\textbf{P} _{[n]}(x) = \left[ p_1^{[n]}, p_2^{[n]}, p_3^{[n]}\right] ^T\), a vector containing an independent polynomial for each component in \(\textbf{M} \), such that

$$\begin{aligned}\textbf{P} _{[n]}(x_i) = \textbf{M} _{i}, \quad i = 0, \ldots , n.\end{aligned}$$

When \(d > 1\), we apply one-dimensional interpolation in one space dimension after the other. For matters of simplicity, we regard a 1D problem in the following analytical error estimates. Due to the tensor product extension, the considerations generalize directly to higher dimensions.

Without loss of generality, we henceforth assume that we want to find initial data for the micro problem associated with the macro grid point at location \(x_{k}\) based on 2k-th order polynomial interpolation. This implies that the macro grid points involved in the process are \(x_j\), \(j = 0, ..., 2k\).

According to standard theory, it holds for the interpolation errors that given \(0 \le i \le 2k\) and \(\textbf{M} \in C^{(2k+1)}([x_0, x_{2k}])\),

$$\begin{aligned} \sup _{x \in [x_0, x_{2k}]} |\textbf{P} _{[2k]}^{(i)}(x) - \textbf{M} ^{(i)}(x, t_j)|\le C (\Delta X)^{2k+1-i}. \end{aligned}$$
(31)

Furthermore, it is well known that given a 2k-th degree interpolating polynomial, it holds that

$$\begin{aligned} \textbf{P} _{[2k]}'(x_k) = D_{[2k]} \textbf{M} (x_k, t_j), \qquad \textbf{P} _{[2k]}''(x_k) = D_{[2k]}^2 \textbf{M} ({x_k}, t_j), \end{aligned}$$

where \(D_{[2k]}\) and \(D^2_{[2k]}\) denote the 2k-th order standard central finite difference approximations to the first and second derivative, see for example [31]. As a direct consequence, we have in the grid point \(x_k\),

$$\begin{aligned} |\textbf{M} '(x_k, t_j) - \textbf{P} _{[2k]}'(x_k)|\le C (\Delta X)^{2k}, \qquad |\textbf{M} ''(x_k, t_j) - \textbf{P} _{[2k]}''(x_k)|\le C (\Delta X)^{2k}. \end{aligned}$$
(32)

Note that this gives a better bound for the error in the second derivative in the point \(x_k\) than Eq. (31), valid on the whole interval \([x_0, x_{2k}]\). The bounds in Eq. (32) show that we have the required consistency, Eq. (30), between macro and micro derivatives when directly using \(\textbf{P} _k(x)\) to obtain the initial data for the micro problem. However, the disadvantage of this approach is that the polynomial vector \(\textbf{P} _k\) is not normalized. For the deviation of its length from one, it holds by Eq. (31) that

$$\begin{aligned}\left||\textbf{P} _{[2k]}|- 1\right|= \left||\textbf{P} _{[2k]}|- |\textbf{M} |\right|\le |\textbf{P} _{[2k]} - \textbf{M} |\le C (\Delta X)^{2k+1}.\end{aligned}$$

Consider instead a normalized function \(\textbf{Y} (x)\) for which \(|\textbf{Y} (x)|= 1\). Then the derivative \(\textbf{Y} '\) is orthogonal to \(\textbf{Y} \) as it holds that

$$\begin{aligned}\textbf{Y} '(x)\cdot \textbf{Y} (x) = \frac{1}{2} \frac{d}{dx} |\textbf{Y} (x)|^2 = 0.\end{aligned}$$

In particular, this shows that \(\textbf{M} ' \cdot \textbf{M} = 0\). However, in general,

$$\begin{aligned}\textbf{M} (x_k, t_j) \cdot D_{[2k]} \textbf{M} (x_k, t_j) = \textbf{P} _{[2k]}(x_k) \cdot \textbf{P} _{[2k]}'(x_k) \ne 0.\end{aligned}$$

Hence there is no normalized interpolating function \(\textbf{Y} \) such that \(\textbf{Y} '(x_\textrm{k})\) becomes a standard linear 2k-th order central difference approximation, \(D_{[2k]}\). In the following, we consider the normalized interpolating function \(\textbf{Q} _{[n]}(x)\) defined as

$$\begin{aligned} \textbf{Q} _{[n]}(x) := \textbf{P} _{[n]}(x) / |\textbf{P} _{[n]}(x)|\,, \end{aligned}$$
(33)

and show that it satisfies the consistency requirement Eq. (30).

Lemma 1

In one space dimension, the normalized function \(\textbf{Q} _{[2k]}\) satisfies Eq. (30) with \(\ell = 2k\).

Proof

As \(\left|\textbf{P} _{[2k]}(x_i)\right|= |\textbf{M} _i|= 1\) in the grid points \(x_i\), where \(i = 0, ..., 2k\), it follows directly that \(\textbf{Q} _{[2k]}(x_i) = \textbf{M} _i\) for \(i = 0, ... , 2k\), the normalized function still interpolates the given points.

For the first derivative of \(\textbf{Q} _{[2k]}\), it holds that

$$\begin{aligned} \begin{aligned} \textbf{Q} _{[2k]}'&= \frac{d}{dx} \left( \textbf{P} _{[2k]} / |\textbf{P} _{[2k]}|\right) = \textbf{P} _{[2k]}' / |\textbf{P} _{[2k]}|- (\textbf{P} _{[2k]}^T \textbf{P} _{[2k]}') \textbf{P} _{[2k]} /|\textbf{P} _{[2k]}|^3 \,, \end{aligned} \end{aligned}$$

which, together with the fact that \(\textbf{P} _{[2k]}(x_i) = \textbf{M} _i\) for \(i = 0, .., 2k\), implies that

$$\begin{aligned} \textbf{Q} _{[2k]}'(x_i) = (\textbf{I}- \textbf{M} _i \textbf{M} _i^T) \textbf{P} _{[2k]}'(x_i). \end{aligned}$$
(34)

In particular, it holds due to orthogonality that

$$\begin{aligned} \left|\textbf{Q} _{[2k]}'(x_i) - \textbf{M} '(x_i)\right|&= \left|(\textbf{I}- \textbf{M} _i \textbf{M} _i^T) \left( \textbf{P} _{[2k]}'(x_i) - \textbf{M} '(x_i)\right) \right|\\&\le C |\textbf{P} _{[2k]}'(x_i) - \textbf{M} '(x_i)|\le C (\Delta X)^{2k}, \end{aligned}$$

hence \(\textbf{Q} _{[2k]}'(x_k)\) is a 2k-th order approximation to the derivative of \(\textbf{M} \) in \(x_k\). For the second derivative of \(\textbf{Q} _{[n]}\), it holds in general that

$$\begin{aligned} \textbf{Q} _{[n]}'' \!=\! \frac{\textbf{P} _{[n]}''}{|\textbf{P} _{[n]}|} \!-\! 2 \frac{(\textbf{P} _{[n]}\cdot \textbf{P} _{[n]}')\textbf{P} _{[n]}'}{|\textbf{P} _{[n]}|^3} \!+\! 3 \frac{(\textbf{P} _{[n]} \cdot \textbf{P} _{[n]}')^2 \textbf{P} _{[n]}}{|\textbf{P} _{[n]}|^5} \!-\! \frac{(|\textbf{P} _{[n]}'|^2 \!+\! \textbf{P} _{[n]}'' \cdot \textbf{P} _{[n]}) \textbf{P} _{[n]}}{|\textbf{P} _{[n]}|^3}, \end{aligned}$$
(35)

where we can rewrite

$$\begin{aligned} |\textbf{P} _{[n]}'|^2 + \textbf{P} _{[n]}'' \cdot \textbf{P} _{[n]} = (\textbf{P} _{[n]}- \textbf{M}) \cdot \textbf{P} _{[n]}'' + (\textbf{P} _{[n]}' - \textbf{M} ') \cdot (\textbf{M} ' + \textbf{P} _{[n]}') + (\textbf{P} _{[n]}'' - \textbf{M} '') \cdot \textbf{M},\end{aligned}$$

For a 2k-th order interpolating polynomial, we hence have in the grid point \(x_k\) that

$$\begin{aligned}&\left|\left( |\textbf{P} _{[2k]}'(x_k)|^2 + \textbf{P} _{[2k]}''(x_k) \cdot \textbf{P} _{[2k]}(x_k)\right) \textbf{P} _{2k}(x_k)\right|\\&\le \left|(\textbf{P} _{[2k]}'(x_k) - \textbf{M} '(x_k)) \cdot (\textbf{M} '(x_k) + \textbf{P} _{[2k]}'(x_k)) + (\textbf{P} _{[2k]}''(x_k) - \textbf{M} ''(x_k)) \cdot \textbf{M} (x_k)\right|\\& \le C \left( \left|(\textbf{P} _{[2k]}'(x_k) - \textbf{M} '(x_k)) \right|+ \left|\textbf{P} _{[2k]}''(x_k) - \textbf{M} ''(x_k))\right|\right) \le C (\Delta X)^{2k}, \end{aligned}$$

where we used Eq. (32) in the last step. Moreover, it holds due to orthogonality and Eq. (32) that

$$\begin{aligned} |\textbf{P} _{[2k]}(x_k) \cdot \textbf{P} _{[2k]}'(x_k)|&= |\textbf{M} _k \cdot (\textbf{P} _{[2k]}'(x_k) - \textbf{M} '(x_k))|\\&\le |\textbf{P} _{[2k]}'(x_k) - \textbf{M} '(x_k)|\le C (\Delta X)^{2k}. \end{aligned}$$

It therefore follows that

$$\begin{aligned}&|\textbf{Q} _{[2k]}''(x_k) - \textbf{P} _{[2k]}''(x_k)|\\&\le 2\left|(\textbf{P} _{[2k]}(x_k) \cdot \textbf{P} _{[2k]}'(x_k)) \textbf{P} _{[2k]}'(x_k) \right|+ 3 \left|\left( \textbf{P} _{[2k]}(x_k) \cdot \textbf{P} _{[2k]}'(x_k)\right) ^2 \textbf{P} _{[2k]}(x_k) \right|\\ {}&+ \left|\left( |\textbf{P} _{[2k]}'(x_k)|^2 + \textbf{P} _{[2k]}''(x_k) \cdot \textbf{P} _{[2k]}(x_k)\right) \textbf{P} _{2k}(x_k)\right|\le C (\Delta X)^{2k}, \end{aligned}$$

which by Eq. (32) implies that \(\textbf{Q} _k''(x_k)\) is a 2k-th order approximation to \(\textbf{M} ''\) (but not a standard linear central finite difference approximation). \(\square \)

We can conclude that when using either \(\textbf{P} _{[2k]}\) or \(\textbf{Q} _{[2k]}\) to obtain initial data \(\textbf{m} _\textrm{init}\) for the HMM micro problem, then \(\partial _{xx} \textbf{m} _\textrm{init}(0)\) is a 2k-th order approximation to \(\partial _{xx} \textbf{M} (x_k, t_j)\), where \(x_k\) is the grid point in the middle of the interpolation stencil. Similarly, in two space dimensions, \(\partial _{xy} \textbf{m} _\textrm{init}(0)\) and \(\partial _{yy} \textbf{m} _\textrm{init}(0)\) are 2k-th order approximations to \(\partial _{xy} \textbf{M} (x_k, t_j)\) and \(\partial _{yy} \textbf{M} (x_k, t_j)\). Thus, the discretization error, which corresponds to the interpolation error, is

$$\begin{aligned} E_\textrm{disc} = \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} _\textrm{init}(0) \textbf{A} ^H) - \varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} (x_k, t_j) \textbf{A} ^H) = C (\Delta X)^{2k}. \end{aligned}$$
(36)

Both \(\textbf{P} _{[2k]}\) and \(\textbf{Q} _{[2k]}\) hence satisfy the consistency requirement Eq. (30) for the initial data. However, only \(\textbf{Q} _{[2k]}\) is normalized, therefore this is what we choose subsequently. Typically, the difference between the approximations is only rather small, though, as shown in the following numerical example.

4.1.1 Numerical Example

As an example, consider the initial data for a micro problem on a 2D domain of size \(10 \varepsilon \) in each space dimension, obtained by interpolation from the macro initial data of (EX2) and (EX3).

We first investigate the maximal deviation of the length of \(\textbf{m} _\textrm{init}\) from one when using \(\textbf{P} _{[2]}\) and \(\textbf{P} _{[4]}\) to obtain the initial data. In Fig. 8, this error is shown for varying \(\Delta X\) and different values of \(\varepsilon \).

Fig. 8
figure 8

Maximum norm deviation in polynomial interpolation initial data \(\textbf{P} _{[2]}\) (left) and \(\textbf{P} _{[4]}\) (right) from one given a micro domain size of \(10\varepsilon \), for several values of \(\varepsilon \). 2D problem with macro initial data as in (EX3) and (EX2). Only values where \(2k \Delta X > 10\varepsilon \) are plotted to avoid extrapolation

One can observe that the deviation decreases as the macro step size \(\Delta X\) decreases. Moreover, especially for high \(\Delta X\) values, smaller \(\varepsilon \) result in smaller deviations. This is due to the fact that a smaller \(\varepsilon \) corresponds to a smaller micro domain, around \(x_k\). The maximum possible norm deviation is only attained further away from \(x_k\). In the limit, as \(\varepsilon \rightarrow 0\), the norm deviation vanishes.

Next, we examine the difference between \(\textbf{P} _{[2k]}\) and \(\textbf{Q} _{[2k]}\) and the order of accuracy of the resulting approximations to \(\varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} \textbf{A} ^H)\). In the left subplot in Fig. 9, the error \(E_\textrm{disc}\) is shown for several values of \(\Delta X\) and for second and fourth order interpolation. The expected convergence rates of \((\Delta X)^{2k}\) can be observed for both approximations, based on \(\textbf{P} _\mathrm {[2k]}\) and \(\textbf{Q} _\mathrm {[2k]}\).

Fig. 9
figure 9

Interpolation error \(E_\textrm{disc}\) with and without normalization, i.e. using \(\textbf{Q} _{[2k]}\) and \(\textbf{P} _{[2k]}\), when varying macro grid spacing \(\Delta X\). 2nd and 4th order interpolation. Left: norm of the error between approximated and actual effective field for (EX2). Right: z-component only

In the right subplot, only the difference between the z-components of \(\varvec{\nabla }\cdot (\varvec{\nabla }\textbf{m} _\textrm{init} \textbf{A} ^H)\) and \(\varvec{\nabla }\cdot (\varvec{\nabla }\textbf{M} \textbf{A} ^H)\) is considered to emphasize the fact that while \(\textbf{P} _{[2k]}\) and \(\textbf{Q} _{[2k]}\) result in approximations of the same order of accuracy, they do not give the same approximation.

4.2 Boundary Conditions

In this section, the issue of boundary conditions for the HMM micro problem is discussed. In the case of a periodic material coefficient, as considered for the estimate in Theorem 2, the micro problem would ideally be solved on the whole domain \(\Omega \) with periodic boundary conditions, even though the resulting solution is only averaged over a small domain \([-\mu , \mu ]^d\). This is not a reasonable choice in practice, since the related computational cost is too high. We therefore have to restrict the size of the computational domain for the micro problem and complete it with boundary conditions. Every choice of boundary conditions introduces some error inside the domain in comparison to the whole domain solution since it is not possible to exactly match both “incoming” and “outgoing” dynamics. In Fig. 10, the effect of boundary conditions in comparison to the solution on a much larger domain is illustrated for one example 1D micro problem with the setup (EX1). The solution in the micro domain as well as the errors due to two kinds of boundary conditions are plotted: assuming periodicity of \(\textbf{m} ^\varepsilon - \textbf{m} _\textrm{init}\) (middle) and homogeneous Dirichlet boundary conditions for \(\textbf{m} ^\varepsilon - \textbf{m} _\textrm{init}\) (right).

Fig. 10
figure 10

Example (EX1) with \(\alpha = 0.01\), comparison of solution on micro domain \([-\mu ', \mu ']\), where \(\mu ' = 5\varepsilon \) and \(\varepsilon = 2\,\times \,10^{-3}\), to solution on a 10 times larger domain. Left: x component of the expected solution, middle: error with periodic boundary conditions for \(\textbf{m} ^\varepsilon - \textbf{m} _\textrm{init}\), right: error with Dirichlet boundary condition

In both cases, one can observe errors propagating into the domain from both boundaries as time increases, even though the amplitude of the errors is influenced by the type of condition. Since we cannot remove this problem even when considering more involved boundary conditions, we choose to solve the micro problem on a domain \([-\mu ', \mu ']^d\), for some \(\mu ' \ge \mu \), with Dirichlet boundary conditions and only average over \([-\mu , \mu ]^d\). The size of the domain extension \(\mu ' - \mu \) together with the time parameter \(\eta \) determine how large the boundary error \(E_{\mu '}\) in Eq. (29) becomes. For larger values of \(\eta \), we expect a larger \(\mu ' - \mu \) to be required to obtain \(E_{\mu }\) below a given threshold, since given a longer final time the errors can propagate further into the domain. This is investigated in more detail in the next section.

4.3 Size of Micro Domain

Here, we investigate how to choose the size of the micro problem domain. There are three important parameters that have to be set, \(\mu \) and \(\eta \) as in Theorem 2, which determine the size of the averaging domain in space and time, as well as the outer box size \(\mu '\). Note that the optimal choice of all three parameters is dependent on the given initial data and the material coefficient.

To determine the influence of the respective parameters, we consider the example (EX2), with a periodic material coefficient, and investigate for one micro problem the error \(E_\textrm{avg}\) as given in Eq. (29). Throughout this section, we consider averaging kernels \(K, K^0\) with \(p_x = p_t = 3\) and \(q_x = q_t = 7\), based on the experiments in [8]. Typically, \(\varepsilon = 1/400\) is used, which results in a value of \(E_\varepsilon \) that is relatively low compared to other contributions to \(E_\textrm{avg}\). Moreover, we assume that \(E_\textrm{num}\) is small compared to the other error terms and can be neglected. In practice, we here use at least 40 discretization points per \(\varepsilon \) to achieve this.

4.3.1 Averaging Domain Size, \(\mu \)

To begin with, we choose a large value for the computational domain \(\mu '\), so that

$$\begin{aligned}E_\textrm{avg} \approx E_\varepsilon + E_\eta + E_\mu .\end{aligned}$$

We then vary the averaging parameter \(\mu \), which affects the error contribution \(E_{\mu }\), that satisfies Eq. (13), repeated here for convenience,

$$\begin{aligned} E_\mu \le C \left( \mu ^{p_x+1} + \left( \frac{\varepsilon }{\mu }\right) ^{q_x+2}\right) . \end{aligned}$$
(37)

Based on the considerations in [8] and Theorem 2, we expect that \(\mu \) should be chosen to be a multiple of \(\varepsilon \), which is the scale of the fast spatial oscillations in the problem. With the given averaging kernel, the first term on the right-hand side in Eq. (37) then is small in comparison to the other error contributions and the second term dominates \(E_\mu \).

In Fig. 11, the development of \(E_\textrm{avg}\) when increasing \(\mu \) for (EX2) is shown for several values of \(\eta \) and \(\alpha \). One can observe that as \(\mu \) is increased, the error decreases rapidly from high initial levels. This is due to the contribution \(C \left( \frac{\varepsilon }{\mu }\right) ^{q_x+2}\) to \(E_\mu \). Once \(\mu \) becomes sufficiently large, in this example around \(\mu \approx 3.5\varepsilon \), the error does not change significantly anymore but stays at a constant level, depending on \(\eta \) and \(\alpha \). Here \(E_\mu \) no longer dominates the error, which will instead be determined by \(E_\eta \) and \(E_\varepsilon \). One can observe that longer times \(\eta \) result in lower overall errors. Furthermore, the errors in the high damping case, \(\alpha = 1\), are considerably lower than with \(\alpha = 0.1\) or \(\alpha = 0.01\). However, note that the required value of \(\mu \) until the errors no longer decrease is independent of both \(\alpha \) and \(\eta \). In the subsequent investigations, we therefore choose a fixed value of \(\mu \) which is slightly above this number, thus making sure that \(E_\mu \) does not significantly influence the overall error observed there.

Fig. 11
figure 11

(EX2): Influence of spatial averaging size \(\mu \) on the overall error in one micro problem for several values of \(\eta \) and \(\alpha \) when \(\varepsilon = 1/400\). Kernel parameters \(p_x = p_t = 3\) and \(q_x = q_t = 7\). The outer box size \(\mu '\) is chosen sufficiently large to not significantly influence the results

4.3.2 Full Domain Size, \(\mu '\)

Next, we study the effect of the size of the computational domain, which is determined by \(\mu '\), on the error \(E_\textrm{avg}\). We here choose \(\mu \) large enough so that

$$\begin{aligned}E_\textrm{avg} \approx E_\varepsilon + E_\eta + E_{\mu '}.\end{aligned}$$

We consider the same choices of \(\alpha \) and \(\eta \)-values as in the previous example, and vary \(\mu '\) to investigate \(E_{\mu '}\). Note that in contrast to the other error terms, we do not have a model for \(E_{\mu '}\). As shown in Fig. 12, a value of \(\mu '\) that is only slightly larger than \(\mu \) gives a high error, which decreases as \(\mu '\) is increased, until the same error levels as in Fig. 11, determined by \(E_\eta \) and \(E_\varepsilon \), are reached.

Fig. 12
figure 12

(EX2): Influence of the extension of the computational domain, \([-\mu ', \mu ']^d\) beyond the averaging domain, \([-\mu , \mu ]^d\), on the overall averaging error \(E_\textrm{avg}\) in one micro problem for several values of \(\eta \) and \(\alpha \). Here \(\mu = 3.9 \varepsilon \) and \(\varepsilon = 1/400\)

The longer the time interval \(\eta \) considered, the larger the domain has to be chosen to reduce the boundary error \(E_{\mu '}\) such that it no longer dominates \(E_\textrm{avg}\). This is due to the fact that the boundary error propagates further into the domain the longer time passes. We can furthermore observe that larger \(\alpha \) results in somewhat faster convergence of the error for higher values of \(\eta \).

4.3.3 Length of Time Interval \(\eta \)

Finally, we consider the influence of \(\eta \) and the corresponding error contribution \(E_\eta \) to the averaging error \(E_\textrm{avg}\) as given in Eq. (29). Based on Theorem 2, we have

$$\begin{aligned} E_\eta \le C_\mu \left( \eta ^{p_t+1} + \left( \frac{\varepsilon ^2}{\eta }\right) ^{q_t +1}\right) , \end{aligned}$$
(38)

repeated here for convenience. We consider \(\eta \sim \varepsilon ^2\). With the given choice of averaging kernel, with \(p_t = 3\), the first term in Eq. (38) is small compared to the second one. We choose the parameters \(\mu \) and \(\mu '\) such that

$$\begin{aligned}E_\textrm{avg} \approx E_\varepsilon + E_\eta \end{aligned}$$

and vary \(\eta \). In Fig. 13a, one can then observe that higher values of \(\eta \) result in lower errors, since the second term on the right hand side in Eq. (38) decreases as \(\eta \) increases. This matches with the error behavior depicted in Figs. 11 and 12. Figure 13a furthermore shows that the error eventually saturates at a certain level, corresponding to \(E_\varepsilon \). Comparing the errors for \(\alpha = 1\) with \(\varepsilon = 1/200\) and \(\varepsilon = 1/400\), one finds that the respective \(E_\varepsilon \) differ by a factor of approximately four, which indicates that \(E_\varepsilon \le C \varepsilon ^2\) here, as was previously observed in [8]. The different cases of \(\alpha \) considered in Fig. 13a have a similar overall behavior of the error, but for high damping, \(\alpha = 1\), the development happens for considerably lower values of \(\eta \) than in the other cases. Moreover, in case of \(\alpha = 0.01\), we observe some oscillations as the error decreases.

Fig. 13
figure 13

(EX2): Influence of the time averaging length \(\eta \) on the overall error in one micro problem. Here \(\mu = 3.9 \varepsilon \) and \(\mu '\) is chosen sufficiently big to not significantly change the results. Kernel parameters \(p_t = 3\) and \(q_t = 7\)

In Fig. 13b, we further investigate the influence of the damping parameter on the time \(\eta \) it takes for the averaging error \(E_\textrm{avg}\) to fall below certain given thresholds. One can clearly observe that high damping reduces the required time to reach all three considered error levels. This indicates that the introduction of artificial damping in the micro problem can help to significantly reduce computational cost, since a shorter final time also implies a smaller computational domain as explained in the previous section. However, since \(\alpha \gg 1\) results in a seriously increased number of time steps necessary to get a stable solution, as discussed in Sect. 3.2, we conclude that choosing \(\alpha \) around one is most favorable. Note that as discussed in Sect. 2.3 in connection with Theorem 2, it is proved for periodic material coefficients that choosing a higher value of \(\alpha \) does not change the quantity \(\textbf{H} _\textrm{avg}\) which is approximated in the upscaling process.

4.3.4 Example (EX3)

To support the considerations regarding the choice of micro parameters, we furthermore study the Landau–Lifshitz problem Eq. (2) with the setup (EX3). In (EX3) the material coefficient has a higher average and higher maximum value than in (EX2). This results in a higher “speed” of the dynamics. In Fig. 14, the influence of \(\mu \), \(\mu '\), \(\eta \) and \(\alpha \), respectively, on the averaging error \(E_\textrm{avg}\) are shown for this example.

Fig. 14
figure 14

(EX3): Influence of micro domain parameters on error \(E_\textrm{avg}\). Parameters not explicitly given are chosen to not influence \(E_\textrm{avg}\) significantly. Moreover, \(\varepsilon = 1/400\), and \(\alpha = 1\) in (a)–(c)

Qualitatively, the results for (EX3) are the same as (EX2), but some details differ. A notable difference between the examples (EX2) and (EX3) is that the time \(\eta \) required for saturation of the errors is considerably shorter in (EX3), as can be observed when comparing Figs. 14c to 13a. An explanation for this is that due to the faster dynamics in (EX3), comparable effects are achieved at shorter times. The ratio between the times \(\eta \) it takes in (EX2) and (EX3), respectively, to reach the level where the error no longer changes matches approximately with the ratio of the maxima of the material coefficients.

Moreover, a slightly larger \(\mu \) is required to reach the level where the errors saturate in (EX3). The (EX3) saturation errors for a specific value of \(\eta \) are lower, though, due to the fact that the error decreases faster with \(\eta \) as discussed previously.

When it comes to the full size of the domain required for the boundary error to not influence the overall error in a significant way, one can observe somewhat larger required value of \(\mu '\) in (EX3) when comparing Figs. 12 to 14b. This is partly due to the fact that the overall error for a given \(\eta \) is lower in (EX3). Moreover, due to the faster dynamics, the errors at time \(\eta \) have propagated further into the domain. As a result, the computational domain has to be chosen approximately the same size in (EX2) and (EX3) to obtain a certain error level, even though the required \(\eta \) is smaller in (EX3).

4.4 Computational Cost

The computational cost per micro problem is a major factor for an efficient HMM implementation. Given a spatial discretization with a certain number of grid points, K, per wave length \(\varepsilon \), that is a micro grid spacing \(\delta x = \varepsilon /K\), we have in total \(N^d = \left( 2 K \mu '/\varepsilon \right) ^d\) micro grid points. The time step size for the micro time integration has to be chosen as \(\delta t \le C_\mathrm {stab, \alpha } \delta x^2\), hence the number of time steps becomes \(M \ge C_\mathrm {stab, \alpha }^{-1} K^2 \eta / \varepsilon ^2\). It then holds for the computational cost per micro problem that

$$\begin{aligned} \mathrm {micro~cost} \sim M N^d \sim \frac{1}{C_{stab, \alpha _\textrm{micro}}} \frac{\eta }{\varepsilon ^2} \left( \frac{\mu '}{\varepsilon }\right) ^d K^{2+d}. \end{aligned}$$
(39)

It is important to note that due to the choice of parameters \(\mu ' \sim \varepsilon \) and \(\eta \sim \varepsilon ^2\), the computational cost per micro problem is independent of \(\varepsilon \). This makes it possible to use HMM also for problems where the computational cost of other approaches, resolving the fast oscillations, becomes tremendously high.

In general, choosing higher values for \(\eta , \mu '\) or K results in higher computational cost per micro problem. We therefore aim to choose these values as low as possible without negatively affecting the overall error. For the numerical examples shown in Sect. 5, we find that selecting \(K \approx 10\) gives a reasonable compromise between accuracy and computational cost. The overall cost is determined by the cost per micro problem and the choice of the macro discretization size \(\Delta X\),

$$\begin{aligned}\textrm{cost} \sim \frac{1}{C_\textrm{stab},{\alpha }_\textrm{macro}} (\Delta X)^{-(2+d)} \mathrm {micro~cost}.\end{aligned}$$

This shows the importance of choosing \(\Delta X\) relatively large, wherefore it is advantageous that the overall method proposed based on MPEA is fourth order accurate, as discussed in Sect. 3.3. Since all the HMM micro problems are independent of each other, it is moreover very simple to parallelize their computations. This can be an effective way to reduce the overall run time of the method.

4.5 Choice of Overall Setup

We now aim to give an overview of the overall choice of HMM setup, based on the discussions in Sects. 3 and 4.1 to 4.3. Furthermore, we study the resulting errors.

To begin with, we discuss the overall setup for the micro problem.

According to Eq. (28), the approximation error in \(\textbf{H} _\textrm{avg}\) is

$$\begin{aligned}E_\textrm{approx} = E_\textrm{avg} + E_\textrm{disc},\end{aligned}$$

where \(E_\textrm{disc}\) is determined by the macro discretization size \(\Delta X\) as given in Eq. (36). For a given \(\Delta X\), we therefore aim to choose the parameters \(\mu , \mu '\) and \(\eta \) so that \(E_\textrm{avg}\) matches \(E_\textrm{disc}\). Further reducing \(E_\textrm{avg}\) only increases the computational cost per micro problem without significantly improving the overall error.

In Table 1, we hence suggest choices for \(\eta \) and \(\mu '\) in the example setups (EX2) and (EX3) with \(\Delta X = 1/(12\cdot 2^i)\), \(i = 0, 1, 2\), such that \(E_\textrm{avg}\) is slightly below the corresponding values for \(E_\textrm{disc}\) when using fourth order interpolation. The averaging parameter \(\mu \) is fixed to a value such that \(E_\mu \) does not significantly increase \(E_\textrm{avg}\) but not much higher. This helps to reduce the number of parameters to vary. Moreover, choosing lower \(\mu \) results in a rather steep increase of \(E_\textrm{avg}\) in comparison to how much the computational cost is reduced.

Note that the specific values of the discretization error depend on the given macro solution and macro location. In this example, we consider the macro initial data and the micro problem solved to obtain \(\textbf{H} _\textrm{avg}\) at macro location (0, 0). We furthermore choose \(\alpha = 1\) here to make it simple to compare the suggestions to the values shown in Figs. 11,  12 and 13a as well as Fig. 14. The optimal choice for \(\alpha \) would be slightly higher.

Table 1 Example micro problem setups with \(\alpha = 1\), where \(\mu = 3.9\varepsilon \) for (EX2) and \(\mu = 4.2\varepsilon \) for (EX3)

Based on the values in Table 1, one can conclude that the required sizes of the computational domains are very similar between the considered examples. When scaled by the maximum of the respective material coefficients, also the suggested final times are comparable.

Next, we further test the influence of the micro domain setup and corresponding \(E_\textrm{avg}\) on the overall error. For this purpose, we consider (EX2)on a unit square domain with periodic boundary condition, \(\alpha = 0.01\) in the original problem and a final time \(T = 0.1\). We use artificial damping and set \(\alpha = 1.2\) in the micro problem. As in the previous examples, we choose averaging kernel parameters \(p_x = p_t = 3\) and \(q_x = q_t = 7\) and let \(\varepsilon = 1/400\). We again fix \(\mu = 3.9 \varepsilon \), and use HeunP as the micro solver as proposed in Sect. 3. . We then run HMM with MPEA for the macro time stepping to approximate the homogenized reference solution \(\textbf{M} _0\) at time T for varying \(\Delta X\).

Four different combinations of \(\eta \) and \(\mu '\) are used for the micro problem, referred to as (s1)-(s4). The resulting \(L^2\)-norms of the errors \(\textbf{M} _0 - \textbf{M} \) are shown in Fig. 15, together with the error one obtains when using the average \(a_\textrm{avg}\) of the material coefficient \(a^\varepsilon \) to approximate \(\textbf{A} ^H\) when solving Eq. (3). Using \(a_\textrm{avg}\) can be seen as a naive approach to dealing with the fast oscillations in the material coefficient. It does in general not result in good approximations. The corresponding error is included here to give a baseline for the relevance of the HMM solutions.

We find that with the micro problem setup (s1), corresponding to a rather high averaging error, HMM results in a solution that is only slightly better than the one that is obtained using the average of the material coefficient. However, when applying setups with lower averaging errors, lower overall errors are achieved. In particular, with (s4), the setup with the lowest considered averaging error, the overall error in Fig. 15 is determined by the error \(E_\textrm{disc}\), proportional to \((\Delta X)^4\) since fourth order interpolation is used to obtain the initial data for the micro problems. For the other two setups, (s2) and (s3), the overall errors saturate at levels somewhat lower than the respective values of \(E_\textrm{avg}\), corresponding to \(e_\textrm{HMM}\) in Eq. (27). Note that this saturation occurs for relatively high values of \(\Delta X\).

For matters of completeness, in Fig. 16, also the \(H^1\)-norm of the error in the HMM solution compared to the homogenized solution \(\textbf{M} _0\) is shown for the same setups as in Fig. 15. The observed errors behave very similar to the \(L^2\)-case. Note, though, that the \(H^1\)-norm of the homogenization error, \(\Vert \textbf{M} ^\varepsilon - \textbf{M} _0\Vert _{H^1}\), is only known to be bounded [7], it is in general not small, in contrast to \(\Vert \textbf{M} ^\varepsilon - \textbf{M} _0\Vert _{L^2}\) which is \(\mathcal {O}(\varepsilon )\).

Fig. 15
figure 15

\(L^2\)-norm of difference between HMM solution \(\textbf{M} \) and homogenized reference solution \(\textbf{M} _0\) at time \(T = 0.1\) for (EX2)

Fig. 16
figure 16

\(H^1\)-norm of difference between HMM solution \(\textbf{M} \) and homogenized reference solution \(\textbf{M} _0\) at time \(T = 0.1\) for (EX2)

5 Further Numerical Examples

To conclude this article, we consider several numerical examples with material coefficients that are not fully periodic. Those cases are not covered by the theorems in Sect. 2, however, the HMM approach still results in good approximations. In the 2D examples, we again include the solution obtained when using a (local) average of the material coefficient as an approximation to the effective coefficient to stress the relevance of the HMM solutions. As for the periodic examples, we use artificial damping in the micro problem.

5.1 Locally Periodic 1D Example

We first consider a one-dimensional example with material coefficient

$$\begin{aligned} a^\varepsilon (x) = 1.1 + \tfrac{1}{4}\sin (2 \pi x + 1.1) + \tfrac{1}{2}\sin (2 \pi x/\varepsilon ). \end{aligned}$$
(40)

This coefficient is locally periodic. We consider Eq. (2) with this coefficient and \(\varepsilon = 1/400\), \(\alpha = 0.01\) on the unit interval with periodic boundary conditions. A comparison between the solution \(\textbf{M} ^\varepsilon \) at time \(T = 0.1\), obtained using a direct numerical simulation resolving the \(\varepsilon \)-scale, and corresponding HMM approximation on a coarse grid with \(\Delta X = 1/25\) is shown in Fig. 17. Here the HMM parameters are chosen to be \(\mu = 3.9 \varepsilon \), \(\mu ' = 8 \varepsilon \) and \(\eta = 0.9 \varepsilon ^2\). Artificial damping with \(\alpha = 1.2\) is used for the micro problem. The averaging kernel parameters are again \(p_x = p_t = 3\) and \(q_x = q_t = 7\).

Fig. 17
figure 17

HMM solution to Eq. (2) with \(a^\varepsilon \) as in Eq. (40) with \(\varepsilon = 1/400\) and corresponding \(\textbf{M} ^\varepsilon \) obtained using direct simulation resolving \(\varepsilon \), at \(T = 0.1\)

For the direct simulation, we use \(\Delta x = 1/6000\), which corresponds to 15 grid points per \(\varepsilon \), and MPEA for time integration.

One can clearly observe that the HMM solution is very close to the solution obtained with a direct simulation resolving \(\varepsilon \). The corresponding discrete \(L^2\) norm of the error is approximately \(\Vert \textbf{M} _0 - \textbf{M} _\textrm{HMM}\Vert _{L^2} \approx 10^{-4}\). Moreover, note that in this example the computation time for HMM is about 20 secondsFootnote 1, while the direct simulation takes almost two hours.

5.2 Quasi-Periodic 2D Example

Next, Eq. (2) is solved in two space dimensions and with material coefficient

$$\begin{aligned} a^\varepsilon (x) = (1 + 0.25\sin (2\pi x_1/\varepsilon ))(1 + 0.25\sin (2\pi x_2/\varepsilon ) + 0.25\sin (2\pi r x_2/\varepsilon )), \end{aligned}$$
(41)

where \(r = 1.41\) as an approximation to \(\sqrt{2}\). This coefficient is periodic in \(x_1\)-direction but not in \(x_2\)-direction. If we choose \(\varepsilon = 0.01\), though, it is periodic also in \(x_2\) direction over the whole domain \([0, 1]^2\) but not on the micro domains. The initial data is set as in (EX2).

To make direct numerical simulation feasible, we consider the case \(\varepsilon = 0.01\) and set \(\Delta x = 1/1500\) in the direct simulation. For HMM, the micro problem parameters are chosen to be \(\mu = 6.5\varepsilon \), \(\eta = 0.7\varepsilon ^2\) and \(\mu ' = 9.25\varepsilon \). We use again averaging kernels with \(p_x = p_t = 3\) and \(q_x = q_t = 7\) as well as artificial damping with \(\alpha = 1.2\) in the micro problem. On the macro scale, \(\Delta X = 1/16\) and \(\alpha = 0.01\). The final time is set to \(T = 0.2\).

In Fig. 18a, the x-components of \(\textbf{M} ^\varepsilon \), obtained using a direct simulation resolving \(\varepsilon \) and a HMM solution to Eq. (2) with material coefficient Eq. (41) are shown. Moreover, the solution obtained when simply using the average of \(a^\varepsilon (x)\) as an approximation is included. One can observe that the HMM solution captures the characteristics of the overall solution well, while the approach with an averaged coefficient does not. To further stress this, cross sections of the respective solutions at \(x_1 = 0.5\) and \(x_2=0.5\) are shown in Fig. 18b.

Fig. 18
figure 18

Quasi-periodic example, with \(\varepsilon = 0.01\), \(T = 0.2\) and \(\alpha = 0.01\)

Despite the choice of a rather high \(\varepsilon \)-value, \(\varepsilon = 0.01\), the direct simulation of this problem took about 5 days. In comparison, the computational time of HMM was about 4 ho,Footnote 2 which is independent of \(\varepsilon \).

5.3 Locally Periodic 2D Example

Finally, we consider a locally periodic 2D example with material coefficient

$$\begin{aligned} a^\varepsilon (x) = 0.25 \exp \left( -\cos (2\pi (x_1+x_2)/\varepsilon ) + \sin (2\pi x_1/\varepsilon )\cos (2\pi x_2)\right) . \end{aligned}$$
(42)

In this example, we set \(\alpha = 0.1\) and choose a final time \(T = 0.05\).

The HMM parameters are set to \(\mu = 5 \varepsilon \), \(\mu ' = 9.75\varepsilon \) and \(\eta = 1.6 \varepsilon ^2\). Note that the average and maximum of this coefficient is lower than for the previously considered ones, hence a longer time \(\eta \) is chosen. Again \(\alpha = 1.2\) in the micro problem. Initial data and averaging parameters are set as in the previous example. Direct simulation solution \(\textbf{M} ^\varepsilon \), HMM approximation and a solution based on local averages of \(a^\varepsilon \) are shown in Fig. 19. Also for this problem HMM captures the characteristics of the solution well. The discrete \(L^2\) norm of the error with the chosen micro setup is approximately \(5\,\times \,10^{-3}\). In contrast, the averaging based solution does not capture the correct characteristics.

Fig. 19
figure 19

Locally periodic example, with \(\varepsilon = 0.01\), \(T = 0.05\) and \(\alpha = 0.1\)

6 Conclusion and Future Work

In this paper, we presented a heterogeneous multiscale method for the Landau–Lifshitz equation with highly oscillatory material coefficient in a periodic setting. A simplified setup, only taking into account the so-called exchange interaction was considered. We showed convergence of relevant errors for periodic material coefficients and obtain solutions which capture the correct characteristics for more general cases. To get a more physically realistic setting, the model should be extended to also include anisotropy, external field and demagnetization. Furthermore, additional boundary conditions should be studied. In particular, in physics and materials science it is common to consider homogeneous Neumann boundary conditions. A step in this direction is taken in [32], where a finite element method for a similar Landau–Lifshitz problem in a somewhat more realistic setting is discussed.

Furthermore, in [33], a basis-representation technique which drastically reduces the number of micro problems that have to be solved in HMM was introduced for linear PDEs. It would be very interesting to investigate whether those ideas can be extended to the non-linear problem considered here. This would be very beneficial for the HMM scheme discussed in this paper.