# An Efficient and Accurate Adaptive Time-Stepping Method for the Landau-Lifshitz Equation
## 2 Numerical Method
### Adaptive Time-Stepping Algorithm  
Now, we present the adaptive time-stepping method. We set a maximum displacement of the numerical solution within a single time step by a tolerance \(tol\). Multiplying both sides of Equation (16) by \(\Delta t^{n+1}\), we obtain  
\[\mathbf{m}_{i}^{n+1}-\mathbf{m}_{i}^{n}=\Delta t^{n+1}\big{(}-\mathbf{m}_{i}^ {n}\times\Delta_{h}\mathbf{m}_{i}^{n}+\mathbf{f}_{i}^{n}\big{)},\ \ 1\leq i\leq N_{x}. \tag{3}\]  
A maximum norm is defined as follows:  
\[\lVert\mathbf{m}\rVert_{\infty}=\max_{1\leq i\leq N_{x}}|\mathbf{m}_{i}|. \tag{4}\]  
Then, from Equation (3), we require that the following condition be satisfied:  
\[\lVert\mathbf{m}^{n+1}-\mathbf{m}^{n}\rVert_{\infty}=\Delta t^{n+1}\rVert- \mathbf{m}^{n}\times\Delta_{h}\mathbf{m}^{n}+\mathbf{f}^{n}\rVert_{\infty} \leq tol. \tag{5}\]  
In this study, we use the maximum norm instead of the \(l^{2}\)-norm, which measures the average, because the maximum norm is more effective for assessing the largest individual component in a vector and ensures that no single variable dominates the vector's magnitude. From Equation (5), we have the constraint of the time step sizes:  
\[\Delta t^{n+1}\leq\frac{tol}{\lVert-\mathbf{m}^{n}\times\Delta_{h}\mathbf{m}^ {n}+\mathbf{f}^{n}\rVert_{\infty}}. \tag{6}\]  
Then, we use  
\[\Delta t^{n+1}=\text{min}\biggl{(}\frac{tol}{\lVert-\mathbf{m}^{n}\times\Delta _{h}\mathbf{m}^{n}+\mathbf{f}^{n}\rVert_{\infty}},\ \Delta t_{\text{max}}\biggr{)}, \tag{7}\]where \(\Delta t_{\max}\) is a given maximum time step size that guarantees stability. From Equation (3), we have the next time solution:  
\[\mathbf{m}_{i}^{n+1}=\mathbf{m}_{i}^{n}+\Delta t^{n+1}\big{(}-\mathbf{m}_{i}^{n} \times\Delta_{h}\mathbf{m}_{i}^{n}+\mathbf{f}_{i}^{n}\big{)},\ \ 1\leq i\leq N_{x}. \tag{8}\]  
However, generally, \(|\mathbf{m}_{i}^{n+1}|\
eq 1\) for some \(i\). We normalize it as  
\[\mathbf{m}_{i}^{n+1}=\frac{\mathbf{m}_{i}^{n+1}}{|\mathbf{m}_{i}^{n+1}|},\ \ 1 \leq i\leq N_{x}. \tag{9}\]  
Repeat this process while \(t^{n}+\Delta t^{n+1}\leq T\) to calculate the numerical approach of \(\mathbf{m}(x,T)\). When determining adaptive time steps, \(t^{n+1}\) can exceed the desired final time. In order to avoid such circumstance, if \(t^{n+1}=t^{n}+\Delta t^{n+1}>T\), then set \(\Delta t^{n+1}=T-t^{n}\). We present a detailed numerical algorithm for each step of the proposed method in Algorithm 1. ```
INPUT endpoints \(L_{x},R_{x}\); number of grid points \(N_{x}\); initial condition; final time \(T\);  tolerance tol; maximum time step size \(\Delta t_{\max}\); forcing term \((f_{u},f_{v},f_{w})\). OUTPUT approximation of \(\mathbf{m}(x,T)=(u(x,T),v(x,T),w(x,T))\). Step 1 Initialization  Set \(h=\left(R_{x}-L_{x}\right)/N_{x}\) and \(t=0\)  For \(i=1,\ldots,N_{x}\) do \(x_{i}=L_{x}+(i-0.5)h\) \(u_{i}^{0}=u_{0}(x_{i}),\quad v_{i}^{0}=v_{0}(x_{i}),\quad w_{i}^{0}=w_{0}(x_{i})\) Step 2 While (\(t<T\)), do Steps 3-7. Step 3 For \(i=1,\ldots,N_{x}\) do \(\Delta_{h}u_{i}^{n}=(u_{i+1}^{n}-2u_{i}^{n}+u_{i-1}^{n})/h^{2}\); \(\Delta_{h}v_{i}^{n}=(v_{i+1}^{n}-2v_{i}^{n}+v_{i-1}^{n})/h^{2}\); \(\Delta_{h}w_{i}^{n}=(w_{i+1}^{n}-2w_{i}^{n}+w_{i-1}^{n})/h^{2}\). Use periodic boundary condition Step 4 Set \(s_{u,i}^{n}=w_{i}^{n}\Delta_{h}v_{i}^{n}-v_{i}^{n}\Delta_{h}w_{i}^{n}+f_{u,i}^ {n}\); \(s_{v,i}^{n}=u_{i}^{n}\Delta_{h}w_{i}^{n}-w_{i}^{n}\Delta_{h}u_{i}^{n}+f_{v,i}^ {n}\); \(s_{v,i}^{n}=v_{i}^{n}\Delta_{h}u_{i}^{n}-w_{i}^{n}\Delta_{h}v_{i}^{n}+f_{w,i}^ {n}\); Step 5 Set \(dis=\max\limits_{1\leq i\leq N_{x}}|(s_{u,i}^{n},\ s_{v,i}^{n},\ s_{w,i}^{n})|\); \(\Delta t=\min(0.99\,tol/dis,\Delta t_{\max})\). If \(t+\Delta t>T\), then \(\Delta t=T-t\). Step 6 Set \(u_{i}^{*}=u_{i}^{n}+\Delta t\,s_{i}^{n}\) \(v_{i}^{t}=v_{i}^{t}+\Delta t\,s_{i}^{n}\) \(w_{i}^{t}=w_{i}^{n}+\Delta t\,s_{i}^{n}\) \(s_{v,i}^{n}=v_{i}^{n}+\Delta t\,s_{w,i}^{n}\); Step 7 Set \(u_{i}^{n+1}=u_{i}^{*}/|(u_{i}^{*},\,v_{i}^{*},\ w_{i}^{*})|\) \(v_{i}^{n+1}=v_{i}^{*}/|(u_{i}^{*},\,v_{i}^{*},\ w_{i}^{*})|\) \(w_{i}^{n+1}=w_{i}^{*}/|(u_{i}^{*},\,v_{i}^{*},\ w_{i}^{*})|\). \(t=t+\Delta t\).