# Accelerating Electromagnetic Field Simulations Based on Memory-Optimized CPML-FDTD with OpenACC
## 2 Propagation Equations and Algorithm
#### CPML ABC Formulation  
According to [31], the convolutional term \(\Psi\) the CPML ABC is likely to be obtained as a time recursion, being able to update the \(F\) (\(H\) or \(E\)) field memory variable in the \(x\) or \(y\) direction, for each time-step \(n\), as  
\[\Psi_{x}^{n}(F)=b_{x}\Psi_{x}^{n-1}(F)+a_{x}(\partial F)^{n-1} \tag{14}\]  
This formulation is suitable to be implemented within an FDTD code, just substituting the spatial derivative \(\partial x\), with \(\frac{1}{k}\partial x+\Psi\); the time evolution of \(\Psi\) is that of the other variables. For example, the equation for \(\partial_{x}H_{y}\) adding the CPML is expanded as:  
\[\Psi\Big{(}\partial_{x}H_{y}|_{(i,j)}^{n+1/2}\Big{)} =b_{x}(i)\Psi\Big{(}\partial_{x}H_{y}|_{(i,j)}^{n+1/2}\Big{)} \tag{15}\] \[+a_{x}(i)\Big{(}\partial_{x}H_{y}|_{(i,j)}^{n+1/2}\Big{)}.\]  
The arrays \(k_{x}\), \(b_{x}\) y \(a_{x}\) are calculated, inside the absorption region, as:  
\[k_{x}(q)=1+(k_{max}-1.0)x(q)_{\text{norm}}^{m}, \tag{16}\]  
where \(x(q)_{\text{norm}}=\frac{T_{h}-q\Delta x}{T_{h}}\), and \(T_{h}\) is the CPML thickness, where \(q=0,1,2...N\), and \(N\) is the number of points in the absorbing region. One must note that \(b_{x}=0\), \(c_{x}=0\) and \(k_{x}=1\) within the physical domain; within the CPML:  
\[b_{x}(q)=e^{-\left(\frac{\sigma_{x}(q)}{k_{x}(q)a_{x}(q)}\right)}\Big{(}\frac {\Delta t}{\varepsilon_{0}}\Big{)} \tag{17}\]  
\[a_{x}(q)=\frac{\sigma_{x}(q)(b_{x}(q)-1)}{\sigma_{x}(q)k_{x}(q)+k_{x}(q)^{2}a _{x}(q)} \tag{18}\]  
where \(\sigma_{x}(q)=\sigma_{\text{max}}x(q)_{\text{norm}}^{m}\) y \(a_{x}(q)=a_{\text{max}}(1.0-x(q)_{\text{norm}})^{ma}\).  
The vectors \(k_{x_{h}}\), \(b_{x_{h}}\) and \(a_{x_{h}}\) have to be interpolated in the points \(j+\
icefrac{{1}}{{2}}\), while the vectors \(k_{y_{h}}\), \(b_{y_{h}}\) y \(a_{y_{h}}\) in the points \(i+\
icefrac{{1}}{{2}}\).  
Equations (7), (10) and (13) are observed in what follows, featuring the CPML:  
\[E_{z\;(i,j)}^{n+1}=E_{z\;(i,j)}^{n}\frac{\left(1-\frac{\Delta t \sigma_{(i,j)}}{2\varepsilon_{(i,j)}}\right)}{\left(1+\frac{\Delta t\sigma_{ z}\;(i,j)}{2\varepsilon_{(i,j)}}\right)}+\] (19) \[\frac{\Delta t}{\varepsilon_{(i,j)}\Big{(}1+\frac{\Delta t \sigma_{(i,j)}}{2\varepsilon_{(i,j)}}\Big{)}}\frac  
\[\begin{split} H_{y\;(i,j+\frac{1}{2})}^{n+\
icefrac{{1}}{{2}}}=H_{y\;( i,j+\frac{1}{2})}^{n-\
icefrac{{1}}{{2}}}\frac{\left(1-\frac{\Lambda\epsilon\iota_{(i,j+1/2)}}{2 \mu_{(i,j+1/2)}}\right)}{\left(1+\frac{\Lambda\epsilon\iota_{(i,j+1/2)}}{2\mu_ {(i,j+1/2)}}\right)}+\\ \frac{\Lambda t}{\mu\left(1+\frac{\epsilon\left(i,j+1/2\right)^{ \Lambda t}}{2\mu_{(i,j+1/2)}}\right)}\frac{1}{k_{\mathrm{x}_{\mathrm{h}}}(i) }\left(\frac{E_{i(j,i+1)}^{\mathrm{x}_{\mathrm{h}}}-E_{i(j,i)}^{\mathrm{x}_{ \mathrm{h}}}}{\Delta x}\right)+\\ \Psi\Big{(}\partial_{x}E_{z}|_{(i,j+1/2)}^{n}\Big{)}.\end{split} \tag{20}\]  
\[\begin{split} H_{x(i+\frac{1}{2},i)}^{n+\
icefrac{{1}}{{2}}}=H_{ x(i+\frac{1}{2},i)}^{n-\
icefrac{{1}}{{2}}}\frac{\left(1-\frac{\Lambda\iota_{(i +1/2)}}{2\mu_{(i,j+1/2)}}\right)}{\left(1+\frac{\Lambda\iota_{(i+1/2)}}{2\mu_ {(i+1/2)}}\right)}+\\ \frac{\Lambda t}{\mu\left(1+\frac{\epsilon\left(i+1/2\right)^{ \Lambda t}}{2\mu_{(i+1/2)}}\right)}\frac{1}{k_{y_{\mathrm{h}}}(j)}\left(\frac{E _{z(i+1)}^{\mathrm{x}_{\mathrm{h}}}-E_{z(i-1,i)}^{\mathrm{x}_{\mathrm{h}}}}{ \Delta y}\right)+\\ \Psi\Big{(}\partial_{y}E_{z}|_{(i+\
icefrac{{1}}{{2}},j)}^{n} \Big{)}\end{split} \tag{21}\]