# A Compact FEM Implementation for Parabolic Integro-Differential Equations in 2D
## 7 Overview of an Implementation in Matlab
However, and as also explained in Appendix C, we would not have been able to use COMSOL Multiphysics at all in this way if the kernel had not had a separable form, whereas the sets of code presented in this article do not have this limitation. Figure 3: Comparison of the analytical solution with the solution computed by COMSOL Multiphysics with 66,142 elements for \(T=0.1,y=-0.5\). Figure 2: **(a)** The exact solution; **(b)** the backward-Euler FEM solution with the left rectangular quadrature rule applied to approximate the Volterra integral term; **(c)** the backward-Euler FEM solution with the right rectangular quadrature rule applied to approximate the Volterra integral term; **(d)** the Crank–Nicolson FEM solution with the trapezoidal quadrature rule applied to approximate the Volterra integral term. All plots are for \(T=0.1\), and the FEM solutions were computed using P1 elements with \(\tau=0.00125\) and \(h=0.05\). In addition, we define an efficiency factor, \(C_{eff}\), given by \(C_{eff}=t_{unrec}/t_{vec}\), where \(t_{unrec}\) is the runtime of the unvectorized code and \(t_{vec}\) is the runtime of the vectorized code; the results for this are shown in Table 4. From the latter, we observe that refining the mesh increases the efficiency factor \(C_{eff}\). This shows that the relative performance of the vectorized code improves significantly as the number of elements is increased. ## 9 Conclusions

In this paper, we have presented a compact implementation using the finite-element method for solving linear PIDEs in arbitrary 2D geometries, both in terms of sets of pseudocode and in terms of a MATLAB code, which we have made openly available; we note that such a code is not available in other competing FEM software, such as freefem++ or deal.II. In addition, it was found that a vectorized version of the MATLAB code solves the model problem considered around three times more quickly than the unvectorized code on finer meshes. Furthermore, because of the particular form of the kernel in the Volterra integral term, the model problem could be represented in a form that was amenable to solution using the commercial finite-element software COMSOL Multiphysics. For this particular problem, in which the kernel has a separable form, COMSOL Multiphysics slightly outperforms even our vectorized code when using a mesh of around 66,000 elements. Future development of this work would involve extending the sets of code to handle non-linear integral terms [55] and to three dimensions. **Supplementary Materials:** The sets of MATLAB code used to generate the results presented in this paper are available online at [[https://github.com/[PERSON]/efficient-PIDE-2D](https://github.com/[PERSON]/efficient-PIDE-2D)]([https://github.com/[PERSON]/efficient-PIDE-2D](https://github.com/[PERSON]/efficient-PIDE-2D)). **Author Contributions:** Conceptualization, G.M.M.R. ; methodology, G.M.M.R. ; software, G.M.M.R., A.B.S., D.d.O.M. and L.M. ; validation, M.A. and M.V. ; formal analysis, G.M.M.R. ; investigation, all; writing--original draft preparation, G.M.M.R. and M.V. ; writing--review and editing, G.M.M.R. and M.V. ; supervision, G.M.M.R. and M.V. ; project administration, G.M.M.R. and M.V. ; funding acquisition, G.M.M.R. and M.V. All authors have read and agreed to the published version of the manuscript. \begin{table}
\begin{tabular}{c c c c c} \hline \hline \(\mathbf{h}\) & \(\mathbf{N}\) & \(\mathbf{C}_{eff}^{\text{BELR}}\) & \(\mathbf{C}_{eff}^{\text{BERR}}\) & \(\mathbf{C}_{eff}^{\text{CN}}\) \\ \hline
0.2 & 258 & 1.06 & 1.06 & 1.07 \\
0.1 & 978 & 1.22 & 1.23 & 1.27 \\
0.05 & 4086 & 1.91 & 1.82 & 1.97 \\
0.025 & 16,406 & 2.35 & 2.39 & 2.48 \\
0.0125 & 66,142 & 3.01 & 2.95 & 2.98 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: The efficiency factor, \(\mathbf{C}_{eff}\), for different MATLAB-based sets of code and different space meshes with a fixed time step \((\tau=0.00125)\).