# A Compact FEM Implementation for Parabolic Integro-Differential Equations in 2D
## 7 Overview of an Implementation in Matlab
*d31(:,1))\)
10:\(A\leftarrow\)StiffAssemb(\(n4e,nC,area4,d21,d31,nE\))
11:\(B\leftarrow\)MassAssemb(\(nC,n4e^{T},\frac{1}{4}*area4\))
12:\(U(:,1)\leftarrow\)U0(\(c4n\))
13:for\(j\gets 2\) to \((N+1)\),do
14:\(U(:,j)\leftarrow\)solvECN(\(c4n,n4e,dir,dt,FN,A,B,n,U,c1,d21,d31,area4\))
15:endfor
16:return\(U\)
17:endprocedure
18:proceduresolveCN(\(c4n,n4e,dir,dt,FN,A,B,n,U,c1,d21,d31,area4\))
19:\(r\leftarrow\)NROW(\(c4n\))
20:\(fsT_{1}\leftarrow\)f(\(c1+\frac{d21+d31}{2}\,(n-1)*dt\))
21:\(fsT_{2}\leftarrow\)f(\(c1+\frac{d21^{3}d31}{3},(n-2)*dt\))
22:\(fsT_{mid}\gets 0.5*(fsT_{1}T_{1}+fsT_{2})\)
23:\(L\leftarrow\)remat(\(dt.*area4.*fsT_{mid}. *\frac{1}{12},3,1\))
24:\(b\leftarrow\)accumarray(\(n4e(:),L,[\,7\,1]\))
25:\(Int\leftarrow\frac{1}{8}*dt^{2}*A*U(:,1)*(2*\textsc{intgral}((n-1.5)*dt,0)\)
26:\(\textsc{in}\)\(n>2\),then
27:\(Int\leftarrow\frac{1}{2}*dt^{2}*A*U(:,1)*\textsc{intgral}((n-1.5)*dt,0)\)\(+\frac{1}{8}*dt^{2}*A*U(:,n-1)*\textsc{intgral}((n-1.5)*dt,(n-1.5)*dt)\)\(6*\textsc{intgral}((n-1.5)*dt,(n-2)*dt))\)
28:for\(j\gets 2\) to \((n-2)\),do
29:\(Int\gets Int+dt^{2}*A*U(:,j)*\textsc{intgral}((n-1.5)*dt,(j-1)*dt)\)
30:endfor
31:endif
32:\(b\gets b+(B-\frac{dt}{2}*A)*U(:,n-1)+Int\)
33:\(u\leftarrow\)SPARSE(\(r,1\))
34:\(u_{d}\leftarrow\)UNIQUE(\(dir\))
35:\(u(u_{d})\leftarrow\)UD(\(c4n(u_{d}:),(n-1)*dt\))
36:\(b\gets b-\left(\frac{dt}{2}-\frac{dt^{2}}{8}*\textsc{intgral}((n-1.5)*dt,( n-1)*dt)\right)*A+B\)*u\)
37:\(M_{1}\leftarrow\left(\frac{dt}{2}-\frac{dt^{2}}{8}*\textsc{intgral}((n-1.5)*dt,( n-1)*dt)\right)*A(FN,FN)+B(FN,FN)\)
38:\(u(FN)\leftarrow\)INV(\(M_{1}\))*\(b(FN)\)
39:\(solCN\gets u\)
40:return\(solCN\)
41:endprocedure
```

**Algorithm A6** Crank-Nicolson scheme with the trapezoidal rule. ## Appendix C Solution Using COMSOL Multiphysics

The fact that (26) is separable in \(t\) and \(s\) implies that the problem can be reformulated as a hyperbolic initial boundary value problem defined by the so-called telegraph equation [53]. In particular, on using (4) and setting \(B\left(t,s\right)=B_{0}\left(t\right)B_{1}\left(s\right),\) Equation (1) becomes

\[\frac{\partial u}{\partial t}=\frac{\partial^{2}u}{\partial x^{2}}+\frac{ \partial^{2}u}{\partial y^{2}}-B_{0}\left(t\right)\phi+f, \tag{27}\]

where

\[\phi=\int_{0}^{t}B_{1}\left(s\right)\left\{\frac{\partial^{2}u}{\partial x^{2} }+\frac{\partial^{2}u}{\partial y^{2}}\right\}\mathrm{d}s, \tag{28}\]

which differentiates with respect to \(t\) and using (27) gives

\[\frac{\partial\phi}{\partial t}=B_{1}\left(t\right)\left(\frac{\partial u}{ \partial t}+B_{0}\left(t\right)\phi-f\right). \tag{29}\]

Thus, the system to solve is (27) and (29), subject to

\[u(\mathbf{x},t) =g(\mathbf{x}),\quad(\mathbf{x},t)\in\partial\Omega\times[0,T], \tag{30}\] \[u(\mathbf{x},0) =u_{0}(\mathbf{x}),\quad\mathbf{x}\in\Omega,\] (31) \[\phi(\mathbf{x},0) =0,\quad\mathbf{x}\in\Omega. \tag{32}\]

This is then a relatively straightforward task in COMSOL Multiphysics, which can be carried out from the graphical user interface; in particular, PDE General Form and Weak Form (subdomain) modules are used for Equations (27) and (29), respectively. Moreover, we are able to ensure a fair comparison with the results of the other sets of code by importing into COMSOL Multiphysics the same meshes as were used for the earlier computations and using the same time step (0.025); in addition, for the time-stepping, we used the generalized-\(\alpha\) method [56; 57]. On the other hand, if \(B\left(t,s\right)\) is not separable, e.g., \(B(t,s)=\exp(-\pi^{2}(t-s)^{2})\) instead of (26), it is not possible to have a formulation that does not retain an integral sign and we have not, at this point, found a simple way to solve this problem, although it would no doubt require coupling COMSOL Multiphysics to a MATLAB script. ## References

* [PERSON] and [PERSON] (1968) [PERSON]; [PERSON] A general theory of heat conduction with finite wave speeds. _Arch. Ration. Mech. Anal._**1968**, 31, 113-126. [CrossRef]
* [PERSON] and [PERSON] (1989) [PERSON]; [PERSON] Heat waves. _Rev. Mod. Phys._**1989**, 61, 41-73.