# Accelerating Electromagnetic Field Simulations Based on Memory-Optimized CPML-FDTD with OpenACC
## 2 Propagation Equations and Algorithm  
The governing equations for the electric transverse mode (TE) in the absence of sources, are:  
\[\frac{\partial E_{z}}{\partial t} =\frac{1}{\varepsilon}\bigg{[}\frac{\partial H_{y}}{\partial x}- \frac{\partial H_{x}}{\partial y}-\sigma E_{z}\bigg{]}, \tag{1}\] \[\frac{\partial H_{y}}{\partial t} =\frac{1}{\mu}\frac{\partial E_{z}}{\partial x},\] (2) \[\frac{\partial H_{x}}{\partial t} =-\frac{1}{\mu}\frac{\partial E_{z}}{\partial y}. \tag{3}\]  
Equations (1)-(3) are set in finite differences over a staggered cell mesh (see Figure 1) as follows. At time \(n+1/2\), \(\partial_{t}E_{z}\), \(\partial_{x}H_{y}\) and \(\partial_{y}H_{x}\) take the following form:  
\[\frac{\partial E_{z}}{\partial t}\bigg{|}_{i,j}^{n+1/2} \approx\frac{\bigg{(}E_{z\;(i,j)}^{n+1}-E_{z\;(i,j)}^{n}\bigg{)}}{ \Delta t}, \tag{4}\] \[\frac{\partial H_{y}}{\partial x}\bigg{|}_{i,j}^{n+1/2} \approx\frac{\bigg{(}H_{y\;(i,j+1/2)}^{n+1/2}-H_{y\;(i,j-1/2)}^{n +1/2}\bigg{)}}{\Delta x},\] (5) \[\frac{\partial H_{x}}{\partial y}\bigg{|}_{i,j}^{n+1/2} \approx\frac{\bigg{(}H_{x\;(i+1/2,j)}^{n+1/2}-H_{x\;(i-1/2,j)}^{n +1/2}\bigg{)}}{\Delta y}. \tag{6}\]  
Figure 1: Mesh used in the algorithm and notation.  
Replacing these approximations, (4)-(6), in Equation (1), it yields:  
\[E_{z\;(i,j)}^{n+1}=E_{z\;(i,j)}^{n}\frac{\left(1-\frac{\Delta t\sigma _{(ij)}}{2t_{(i,j)}}\right)}{\left(1+\frac{\Delta t\sigma_{(ij,j)}}{2t_{(i,j)}} \right)}+ \tag{7}\] \[\frac{\Delta t}{\epsilon_{(i,j)}\left(1+\frac{\Delta t\sigma_{(ij )}}{2t_{(i,j)}}\right)}\frac{\left(H_{y\;(i,j+1/2)}^{n+1/2}-H_{y\;(i,j-1/2)}^{ n+1/2}\right)}{\Delta x}\] \[-\frac{\Delta t}{\epsilon_{(i,j)}\left(1+\frac{\Delta t\sigma_{( ij)}}{2t_{(i,j)}}\right)}\frac{\left(H_{x\;(i+1/2,j)}^{n+1/2}-H_{x\;(i-1/2,j)}^{ n+1/2}\right)}{\Delta y}\]  
Similarly, approximating \(\partial_{t}H_{y}\) and \(\partial_{x}E_{z}\) in Equation (2) as  
\[\frac{\partial H_{y}}{\partial t}\bigg{|}_{i,j+1/2}^{n} \approx\frac{\left(H_{y\;(i,j+1/2)}^{n+1/2}-H_{y\;(i,j+1/2)}^{n-1 /2}\right)}{\Delta t}, \tag{8}\] \[\frac{\partial E_{z}}{\partial x}\bigg{|}_{i,j}^{n} \approx\frac{E_{z\;(i,j+1)}^{n}-E_{z\;(i,j)}^{n}}{\Delta x}. \tag{9}\]  
it takes the form  
\[H_{y\;(i,j+\frac{1}{2})}^{n+1/2}=H_{y\;(i,j+\frac{1}{2})}^{n-1/2} \frac{\left(1-\frac{\Delta t\sigma_{(ij+1/2)}}{2t_{(i,j+1/2)}}\right)}{\left(1 +\frac{\Delta t\sigma_{(ij+1/2)}}{2t_{(i,j+1/2)}}\right)}+ \tag{10}\] \[\frac{\Delta t}{\mu\left(1+\frac{\sigma_{(ij+1/2)}\Delta t}{2t_{ (i,j+1/2)}}\right)}\left(\frac{E_{z\;(i,j+1)}^{n}-E_{z\;(i,j)}^{n}}{\Delta x}\right)\]  
By approximating \(\partial_{t}H_{x}\) y \(\partial_{t}E_{z}\) in Equation (3) as  
\[\frac{\partial H_{x}}{\partial t}\bigg{|}_{i+1/2,j}^{n} \approx\frac{\left(H_{x\;(i+\frac{1}{2},j)}^{n+1/2}-H_{x\;(i+ \frac{1}{2},j)}^{n-1/2}\right)}{\Delta t} \tag{11}\] \[\frac{\partial E_{z}}{\partial x}\bigg{|}_{i,j}^{n} \approx\frac{E_{z\;(i+1,j)}^{n}-E_{z\;(i,j)}^{n}}{\Delta x}. \tag{12}\]  
it takes the form  
\[H_{x\;(i+\frac{1}{2},j)}^{n+1/2}=H_{x\;(i+\frac{1}{2},j)}^{n-1/2} \frac{\left(1-\frac{\Delta t\sigma_{(i+1/2,j)}}{2t_{(i+1/2,j)}}\right)}{\left(1 +\frac{\Delta t\sigma_{(i+1/2,j)}}{2t_{(i+1/2,j)}}\right)}+ \tag{13}\] \[\frac{\Delta t}{\mu\left(1+\frac{\sigma_{(i+1/2)}\Delta t}{2t_{ (i,j+1/2,j)}}\right)}\frac{E_{z\;(i+1,j)}^{n}-E_{z\;(i-1,j)}^{n}}{\Delta y}\]