Next Article in Journal
A Multiobjective Large Neighborhood Search Metaheuristic for the Vehicle Routing Problem with Time Windows
Previous Article in Journal
The Online Reservation Problem
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A Compact FEM Implementation for Parabolic Integro-Differential Equations in 2D

by
Gujji Murali Mohan Reddy
1,
Alan B. Seitenfuss
2,†,
Débora de Oliveira Medeiros
2,†,
Luca Meacci
2,†,
Milton Assunção
2,† and
Michael Vynnycky
3,4,*
1
Department of Mathematics, Birla Institute of Technology & Science, Pilani, Hyderabad Campus, Telangana 500078, India
2
Department of Applied Mathematics and Statistics, Institute of Mathematical and Computer Sciences, University of São Paulo at São Carlos, P.O. Box 668, São Carlos 13560-970, São Paulo, Brazil
3
Division of Processes, Department of Materials Science and Technology, KTH Royal Institute of Technology, Brinellvägen 23, 100 44 Stockholm, Sweden
4
Department of Mathematics and Statistics, University of Limerick, Limerick V94 T9PX, Ireland
*
Author to whom correspondence should be addressed.
These authors contributed equally to this work.
Algorithms 2020, 13(10), 242; https://doi.org/10.3390/a13100242
Submission received: 27 August 2020 / Revised: 17 September 2020 / Accepted: 18 September 2020 / Published: 24 September 2020
(This article belongs to the Section Algorithms for Multidisciplinary Applications)

Abstract

:
Although two-dimensional (2D) parabolic integro-differential equations (PIDEs) arise in many physical contexts, there is no generally available software that is able to solve them numerically. To remedy this situation, in this article, we provide a compact implementation for solving 2D PIDEs using the finite element method (FEM) on unstructured grids. Piecewise linear finite element spaces on triangles are used for the space discretization, whereas the time discretization is based on the backward-Euler and the Crank–Nicolson methods. The quadrature rules for discretizing the Volterra integral term are chosen so as to be consistent with the time-stepping schemes; a more efficient version of the implementation that uses a vectorization technique in the assembly process is also presented. The compactness of the approach is demonstrated using the software Matrix Laboratory (MATLAB). The efficiency is demonstrated via a numerical example on an L-shaped domain, for which a comparison is possible against the commercially available finite element software COMSOL Multiphysics. Moreover, further consideration indicates that COMSOL Multiphysics cannot be directly applied to 2D PIDEs containing more complex kernels in the Volterra integral term, whereas our method can. Consequently, the subroutines we present constitute a valuable open and validated resource for solving more general 2D PIDEs.

1. Introduction

Parabolic integro-differential equations (PIDEs) arise in various physical contexts, such as heat conduction in materials with memory [1,2,3], the compression of poro-viscoelastic media [4], nuclear reactor dynamics [5], epidemic phenomena in biology [6] and drug absorption/release [7,8]. Existing and unique results from such kinds of problems can be found in [9,10,11,12].
Inevitably, such equations have to be solved numerically and various approaches have been developed for this, such as spectral methods, spline and collocation, the method of lines and finite-element methods [13,14,15,16,17,18,19,20,21]. Amongst these, one of the most attractive is arguably the finite-element method (FEM), since it can be applied to irregularly-shaped domains in higher dimensions; moreover, convergence (both a priori and a posteriori) analysis for such problems is already well-established, and for this one may refer to [9,10,12,22,23,24,25,26,27,28]. As regards existing software platforms which could be used for a finite-element implementation without having to resort to lengthy programming from first principles, the main choices are freefem++ [29], deal.II [30], iFEM [31], FEniCS [32], DUNE [33], FEATool [34], MATLAB’s Partial Differential Equation Toolbox [35] and COMSOL Multiphysics [36]; however, it is not immediately obvious how to solve PIDEs with any of these. This is perhaps surprising in the case of MATLAB, which has become increasingly popular in recent years for the numerical solutions of various partial differential equations (PDEs) in structural mechanics and heat transfer [37,38,39,40,41,42,43,44,45,46,47], and has proven to be an excellent tool for academic education in general [40].
Against that background, the purpose of this article is to provide a compact formulation for solving PIDEs in two spatial dimensions (2D) using FEM on unstructured grids (we made the resulting software, which we programmed in MATLAB, openly available). This is done by extending the already available FEM formulations for PDEs [40,43,44,48,49] to PIDEs. In particular, we:
  • Use piecewise linear finite element spaces on triangles for the space discretization;
  • Vase the time discretizations on the backward-Euler and the Crank–Nicolson methods;
  • Choose the quadrature rules for discretizing the Volterra integral term so as to be consistent with the time-stepping schemes.
In addition, we demonstrate that for PDEs, vectorization techniques can be used to speed up the sets of code for PIDEs. Importantly, these sets of code can be easily extended to more complex geometries, and to PIDEs with different kernels in the Volterra integral term. A comparison with results obtained using COMSOL Multiphysics for a test example shows that our method is competitive. Moreover, further consideration indicates that COMSOL Multiphysics cannot be directly applied to 2D PIDEs containing more complex kernels in the Volterra integral term, whereas our method can.
The rest of the paper is organized as follows. The model problem and its weak formulation are described in Section 2. The discretization is sketched in Section 3. The data representation of the triangulation is described in Section 4, together with the discrete space. The assembly of the stiffness matrix, mass matrix and load vector are presented in Section 5. Improved pseudo-codes using vectorization is presented in Section 6, and an implementation in MATLAB is discussed in Section 7. In Section 8, a comparison of the results obtained using the different sets of code is presented; results obtained using COMSOL Multiphysics are also compared. Conclusions are drawn in Section 9.

2. Model Problem and Weak Formulation

Given a Lebesgue measurable set Ω , we denote by L p ( Ω ) , 1 p the Lebesgue spaces. When  p = 2 , the space L 2 ( Ω ) is equipped with an inner product · , · . For an integer m > 0 , we use the standard notation for Sobolev spaces W m , p ( ω ) with 1 p . When p = 2 , we denote W m , 2 ( Ω ) by H m ( Ω ) . The function space H 0 1 ( Ω ) consists of elements from H 1 ( Ω ) that vanish on the boundary of Ω , where the boundary values are to be interpreted in the sense of a trace.
Consider the following initial-boundary value problem for a linear PIDE of the form
u t ( x , t ) + A u ( x , t ) = 0 t B ( t , s ) u ( x , s ) d s + f ( x , t ) , ( x , t ) Ω × ( 0 , T ] ,
u ( x , t ) = 0 , ( x , t ) Ω × [ 0 , T ] ,
u ( x , 0 ) = u 0 ( x ) , x Ω .
Here, 0 < T < and Ω R 2 is a bounded Lipschitz domain with boundary Ω . Further, A u ( x , t ) = Δ u ( x , t ) and
B ( t , s ) u ( x , s ) = · ( B ( t , s ) u ( x , s ) ) ,
where Δ denotes the Laplacian and ∇ denotes the spatial gradient. We assume that the coefficient matrix B ( t , s ) = { b i j ( x ; t , s ) } is 2 × 2 in L ( Ω ) 2 × 2 . If we assume the initial function u 0 ( x ) to be in H 2 ( Ω ) H 0 1 ( Ω ) , the source term f ( x , t ) to be in L 2 ( 0 ; T ; L 2 ( Ω ) ) and
max Ω ¯ × { 0 s t T } | x b i , j ( x ; t , s ) | < ,
then the problem (1) admits a unique solution
u L 2 ( 0 , T ; H 2 ( Ω ) H 0 1 ( Ω ) ) H 1 ( 0 , T ; L 2 ( Ω ) ) .
The existence results are discussed in detail in Chapter 2 of [9]. For regularity and stability results of such problems, please refer to [10,28].
Let a ( · , · ) : H 0 1 ( Ω ) × H 0 1 ( Ω ) R be the bilinear form corresponding to the operator A defined by
a ( ϕ , ψ ) : = ϕ , ψ ϕ , ψ H 0 1 ( Ω ) .
Similarly, let b ( t , s ; · , · ) be the bilinear form corresponding to the operator B ( t , s ) defined on H 0 1 ( Ω ) × H 0 1 ( Ω ) by
b ( t , s ; ϕ ( s ) , ψ ) : = B ( t , s ) ϕ ( s ) , ψ ϕ ( s ) , ψ H 0 1 ( Ω ) .
Then, the weak formulation of the problem (1) may be stated as follows: find u : [ 0 , T ] H 0 1 ( Ω ) such that, for all t ( 0 , T ] ,
Ω u t ϕ d x + a ( u , ϕ ) = 0 t b ( t , s ; u ( s ) , ϕ ) d s + Ω f ϕ d x ϕ H 0 1 ( Ω ) , u ( · , 0 ) = u 0 .

3. Galerkin Discretizations

Let T denote a regular partition of the domain Ω R 2 into disjoint triangles K of diameter h K such that:
  • K i T K i ¯ = Ω ¯ , and any pair of triangles intersect along a complete edge, at a vertex, or not at all;
  • No vertex of any triangle lies on the interior of a side of another triangle.
Let V be the finite element space defined by
V : = H 0 1 ( Ω ) { ϕ C ( Ω ¯ ) : ϕ | K P 1 K T h } ,
where P 1 is the space of polynomials in d variables of degree at most 1.
With N = { z 1 , , z M } as the set of nodes of T , we consider the nodal basis B = { ϕ 1 , , ϕ M } , where the hat function ϕ l P 1 is characterized by ϕ l ( z k ) = δ k l , where δ k l is the Kronecker delta.
Let 0 = t 0 < t 1 < < t N = T be a partition of [ 0 , T ] with τ n : = t n t n 1 . Set f n ( · ) = f ( · , t n ) for t = t n , n [ 0 , 1 , , N ] . Now, for  n = 1 , 2 , , N , we define
v n : = v n v n 1 τ n , t n 1 / 2 : = t n + t n 1 2 and v n 1 / 2 : = v n + v n 1 2 .
In this article, we consider uniform time steps, i.e.,  τ = τ 1 = = τ N .

3.1. Backward-Euler Scheme

Let I h be the Lagrange interpolant corresponding to V . Then, the fully discrete backward-Euler scheme may be stated as follows: given U 0 , where U 0 = I h u 0 , find U n V , n [ 1 : N ] such that
Ω U n ϕ d x + a ( U n , ϕ ) = σ n ( b ( t n ; U , ϕ ) ) + Ω f n ϕ d x , ϕ V ,
where
σ n ( b ( t n ; v , ϕ ) ) = j = 0 n 1 τ j + 1 B ( t n , t j ) v ( t j ) , ϕ ,
if the left rectangular rule is used to discretize the integral term, or 
σ n ( b ( t n ; v , ϕ ) ) = j = 1 n τ j B ( t n , t j ) v ( t j ) , ϕ ,
if the right rectangular rule is used. In any case, both are consistent with the backward-Euler scheme and the order of accuracy is same.
The discrete problem (6) becomes: find U n = j = 1 M u ( z j , t n ) ϕ j ( x ) R m such that
( M + τ A ) U n = M U n 1 + τ 2 A ( B ( t n , t 0 ) U 0 + + B ( t n , t n 1 ) U n 1 ) + τ b n ,
where the mass matrix M , the stiffness matrix A and the load vector b n are given by
M = { M i , j } = Ω ϕ j ϕ i d x ,
A = { A i , j } = Ω ϕ j · ϕ i d x ,
b n = { b i n } = Ω f n ϕ i d x ,
respectively.

3.2. Crank–Nicolson Scheme

We now state the Crank–Nicolson scheme as follows: given U 0 , where U 0 = I h u 0 , find U n V , n [ 1 : N ] such that
Ω U n ϕ d x + a ( U n 1 / 2 , ϕ ) = σ n ( b ( t n 1 / 2 ; U , ϕ ) ) + Ω f n 1 / 2 ϕ d x ϕ V ,
where
σ n ( b ( t n 1 / 2 ; v , ϕ ) ) : = j = 0 n 2 τ j + 1 2 B ( t n 1 / 2 , t j ) v j + B ( t n 1 / 2 , t j + 1 ) v j + 1 , ϕ
+ τ n 4 B ( t n 1 / 2 , t n 1 ) v n 1 + B ( t n 1 / 2 , t n 1 / 2 ) v n 1 / 2 , ϕ .
Here, the trapezoidal rule is used to discretize the integral term in order to be consistent with the Crank–Nicolson scheme.
Using (13), we obtain the following matrix equation for the Crank–Nicolson scheme:
( M + τ 2 A τ 2 8 B ( t 1 2 , t 1 ) A ) U 1 = ( M τ 2 A ) U 0 + 3 τ 2 8 B ( t 1 2 , t 0 ) A U 0 + τ b ^ 1 , ( M + τ 2 A τ 2 8 B ( t n 1 / 2 , t n ) A ) U n = ( M τ 2 A ) U n 1 + τ b ^ n + τ 2 2 A B ( t n 1 / 2 , t 0 ) U 0 + 2 i = 1 n 2 B ( t n 1 / 2 , t i ) U i + 7 τ 2 8 B ( t n 1 / 2 , t n 1 ) A U n 1 ,
for n > 1 and where M is the mass matrix, A is the stiffness matrix and b ^ n is the load vector:
b ^ n = { b i } = Ω f n + f n 1 2 ϕ i d x .

3.3. Remark on More General Boundary Conditions

Problems involving more general boundary conditions can also be addressed in a similar manner. Suppose that the domain boundary is split into two components Γ D and Γ N such that Γ D Γ N = Ω and Γ D Γ N = , assuming that Γ D is closed and has a nonzero measure. For sufficiently regular Neumann boundary data g N , consider a problem posed with mixed-type boundary conditions:
u t ( x , t ) + A u ( x , t ) = 0 t B ( t , s ) u ( x , s ) d s + f ( x , t ) , ( x , t ) Ω × ( 0 , T ] , u ( x , t ) = g ( x ) , ( x , t ) Γ D × [ 0 , T ] , u n ( x , t ) = g N ( x ) , ( x , t ) Γ N × [ 0 , T ] , u ( x , 0 ) = u 0 ( x ) , x Ω .
We assume there is a function u D ( x , t ) H 1 ( Ω ) for t [ 0 , T ] such that u D ( x , t ) = g ( x ) for x Ω , t [ 0 , T ] . Then, the weak form of this problem reads: find u = w + u D : [ 0 , T ] H g , Γ D 1 ( Ω ) , w H 0 , Γ D 1 ( Ω ) such that
Ω w t ϕ d x + a ( w , ϕ ) = Ω u D t ϕ d x + 0 t b ( t , s ; w ( s ) , ϕ ) d s a ( u D , ϕ ) + 0 t b ( t , s ; u D ( s ) , ϕ ) d s + Ω f ϕ d x + Γ N g N ϕ d S 0 t Γ N B ( t , s ) g N ( s ) ϕ d S d s ϕ H 0 1 ( Ω ) , t ( 0 , T ] , u ( · , 0 ) = u 0 ,
where
H g , Γ D 1 ( Ω ) : = { w H 1 ( Ω ) : w = g on Γ D }
and
H 0 , Γ D 1 ( Ω ) : = { w H 1 ( Ω ) : w = 0 on Γ D } .

4. Data Representation

To fix ideas ahead of benchmark computations, consider the L-shaped domain Ω = [ 1 , 1 ] 2 [ 1 , 0 ] × [ 0 , 1 ] with a closed polygonal boundary Γ = Γ D , as shown in Figure 1, where nodes are represented as blue squares and the exterior continuous line represents the boundary with Dirichlet boundary condition Γ D ; this domain was chosen as it is often used for benchmarking FEM computations [41,44,50,51].
In order to represent the relationship between node and spatial coordinates, and between elements and nodes, it is necessary to define arrays that store this information. Thus, we define the array c4n, which represents the node-coordinate relation, and the array n4e, which represents the element-node relation to generate the domain; these are given in Table 1. In addition, the Dirichlet boundary conditions are represented by a data structure dir which contains nodal information; this is also given in Table 1. The first columns of the arrays c4n, n4e and dir represent the node number, element number and edge number, respectively.

5. Assembly

In this section, we assemble the stiffness matrix, the mass matrix, the load vector and the initial and boundary conditions. The assembly is standard and builds on the ideas for PDEs presented in [40,44]; however, we include it here for completeness, ensuring that the standard routines and the non-standard ones related to PIDEs are available in one location. In what follows, we take x = ( x , y ) and let ( x 1 , y 1 ) , ( x 2 , y 2 ) and ( x 3 , y 3 ) be the vertices of an element K and ϕ 1 , ϕ 2 and ϕ 3 the corresponding local basis functions in V . The sets of code which make use of the subroutines presented in this section are given in Appendix A.
For the sets of pseudocode that follow, we first need to establish a common notation; this is given in Table 2.

5.1. Assembling the Stiffness Matrix

Since
ϕ j ( x k , y k ) = δ j k , j , k = 1 , 2 , 3 ,
a simple calculation reveals
ϕ j ( x , y ) = det 1 x y 1 x j + 1 y j + 1 1 x j + 2 y j + 2 / det 1 x j y j 1 x j + 1 y j + 1 1 x j + 2 y j + 2 .
Hence, we obtain
ϕ j ( x , y ) = 1 K y j + 1 y j + 2 x j + 2 x j + 1 .
Here, the indices are to be understood modulo 3, and  K is the area of triangle K. Thus, using (11), the entries of the stiffness matrix can be computed as
A j k = K ϕ j ( ϕ k ) T d x = 1 K ( y j + 1 y j + 2 , x j + 2 x j + 1 ) y k + 1 y k + 2 x k + 2 x k + 1 ,
with indices modulo 3. This can be written as
A = G G T , G : = 1 1 1 x 1 x 2 x 3 y 1 y 2 y 3 1 0 0 1 0 0 1 .
The pseudocode given in Algorithm 1 computes the local stiffness matrix contributions, based on Equations (17)–(21).
Algorithm 1 Computation of local stiffness matrix contributions.
1:
procedurestima( c 4 n )
2:
     d NCOL ( c 4 n )
3:
     M 1 [ ONES ( 1 , d + 1 ) ; c 4 n T ]
4:
     M 2 [ ZEROS ( 1 , d ) ; I d ]
5:
     G INV ( M 1 ) M 2
6:
     P 1 [ ONES ( 1 , d + 1 ) ; c 4 n T ]
7:
     S DET ( P 1 ) G G T j = 1 d j
8:
    return S
9:
end procedure
Using the local contributions, one can compute the global contributions using the pseudocode given in Algorithm 2.
Algorithm 2 Computation of the global contributions.
1:
procedureStiffAssemb( n 4 e , c 4 n )
2:
     r NROW ( c 4 n )
3:
     A SPARSE ( r , r )
4:
    for j 1 to r, do
5:
         A ( n 4 e ( j , : ) , n 4 e ( j , : ) ) A ( n 4 e ( j , : ) , n 4 e ( j , : ) ) + STIMA ( c 4 n ( n 4 e ( j , : ) , : ) )
6:
    end for
7:
    return A
8:
end procedure

5.2. Assembling the Mass Matrix

The entries of the mass matrix M can be computed as
M j k = K ϕ j ϕ k d x .
For triangular, piecewise affine elements, we obtain
K ϕ j ϕ k d x = 1 24 det x 2 x 1 x 3 x 1 y 2 y 1 y 3 y 1 2 1 1 1 2 1 1 1 2 ;
the pseudocode for M, based on Equations (22) and (23), is given in Algorithm 3.
Algorithm 3 Assembling the mass matrix.
1:
procedureMassAssemb( n 4 e , c 4 n )
2:
     r NROW ( c 4 n )
3:
     M SPARSE ( r , r )
4:
    for j 1 to r do
5:
         X 1 [ [ 1 1 1 ] ; ( c 4 n ( n 4 e ( j , : ) , : ) ) T ]
6:
         X 2 [ [ 2 1 1 ] ; [ 1 2 1 ] ; [ 1 1 2 ] ]
7:
         M ( n 4 e ( j , : ) , n 4 e ( j , : ) ) M ( n 4 e ( j , : ) , n 4 e ( j , : ) ) + ( 1 24 DET ( X 1 ) X 2 )
8:
    end for
9:
    return M
10:
end procedure

5.3. Assembling the Load Vector

The volume forces, which are calculated using Algorithm 4, are used for assembling the load vector. Using the value of f at the center of gravity ( x S , y S ) of K, the integral K f ϕ j d x is approximated by
K f ϕ j d x 1 6 det x 2 x 1 x 3 x 1 y 2 y 1 y 3 y 1 f ( x S , y S ) .
In addition, the load vector contains a contribution from the integral terms containing the kernel B; this is given in Algorithm 5.
Algorithm 4 Source function.
1:
proceduref( x , t )
2:
     V o l u m e F o r c e ( 1 2 t ) . π 2 . exp ( π 2 t ) . sin ( π . x ( : , 1 ) ) . sin ( π . x ( : , 2 ) )
3:
    return V o l u m e F o r c e
4:
end procedure
Algorithm 5 Coefficient function in the kernel.
1:
procedureintgral( t , s )
2:
     B T S exp ( π 2 ( t s ) )
3:
    return B T S
4:
end procedure

5.4. Boundary and Initial Conditions

The sets of pseudocode for the boundary and initial conditions given by Equations (2) and (3), respectively, are given in Algorithms 6 and 7, respectively.
Algorithm 6 Boundary conditions.
1:
procedureUd( x , t )
2:
     D B V ( x ( : , 1 ) = = 1 ) 0
3:
     D B V ( x ( : , 1 ) = = 0 ) 0
4:
     D B V ( x ( : , 1 ) = = 1 ) 1
5:
     D B V ( x ( : , 2 ) = = 1 ) 0
6:
     D B V ( x ( : , 2 ) = = 0 ) 0
7:
     D B V ( x ( : , 2 ) = = 1 ) 0
8:
    return D B V
9:
end procedure
Algorithm 7 Initial conditions.
1:
procedureU0( c 4 n )
2:
     x c 4 n ( : , 1 )
3:
     y c 4 n ( : , 2 )
4:
     u 0 sin ( π x ) sin ( π y )
5:
    return u 0
6:
end procedure

6. Improved Assembly

To improve the implementation, we present in this section an optimization of the algorithm that switches away from a looping approach towards the utilization of vector tools, available in software such as MATLAB. A brief description of these improvements follows. Similar approaches can be found in [40,43], and the sets of code supplied are modified versions of those given in [52]; they are included for completeness. The sets of pseudocode which make use of the subroutines presented in this section are given in Appendix B.

6.1. Assembling the Stiffness Matrix

The vectorization of the code for the stiffness matrix is done by using the commands SPARSE and RESHAPE, which allow us to store in the vectors I and J the indices related to the contributions of each node of each element for building the stiffness matrix A. This provides the possibility to evaluate the stiffness matrix A in one line, i.e., without a loop, as shown in Algorithm 8.
Algorithm 8 Assembling the stiffness matrix with vectorization.
1:
procedureStiffAssemb( n 4 e , n C , a r e a 4 , d 21 , d 31 , n E )
2:
     I RESHAPE ( n 4 e ( : , [ 1 2 3 1 2 3 1 2 3 ] ) T , 9 n E , 1 )
3:
     J RESHAPE ( n 4 e ( : , [ 1 1 1 2 2 2 3 3 3 ] ) T , 9 n E , 1 )
4:
     a ( SUM ( d 21 . d 31 , 2 ) . / a r e a 4 ) T
5:
     b ( SUM ( d 31 . d 31 , 2 ) . / a r e a 4 ) T
6:
     c ( SUM ( d 21 . d 21 , 2 ) . / a r e a 4 ) T
7:
     A [ 2 a + b + c ; a b ; a c ; a b ; b ; a ; a c ; a ; c ]
8:
     A SPARSE ( I , J , A ( : ) , n C , n C )
9:
    return A
10:
end procedure

6.2. Assembling the Mass Matrix

Similarly to the previous paragraph, we can build the mass matrix M by using the SPARSE command. We remark that, in this case, the evaluation of the matrix is reduced to the calculation of only two vectors, as shown in Algorithm 9.
Algorithm 9 Assembling the mass matrix with vectorization.
1:
procedureMassAssemb( n C , n 4 e , a r e a )
2:
     I n 4 e ( [ 1 2 3 1 2 3 1 2 3 ] , : )
3:
     J n 4 e ( [ 1 1 1 2 2 2 3 3 3 ] , : )
4:
     A 6 1 6 a r e a T
5:
     A 12 1 12 a r e a T
6:
     K g [ A 6 ; A 12 ; A 12 ; A 12 ; A 6 ; A 12 ; A 12 ; A 12 ; A 6 ]
7:
     M SPARSE ( I ( : ) , J ( : ) , K g ( : ) , n C , n C )
8:
    return M
9:
end procedure

6.3. Assembling the Load Vector

In order to assemble the right-hand side, we refer to what we have done in Section 5.3 considering the volume forces and the center of gravity. Here, however, the improvement consists of neglecting the loop by inserting the MATLAB command ACCUMARRAY, which creates an array of given size, where the values are collected through the REPMAT command, which in this case returns a 3 × 1 array containing copies of the corresponding evaluation of the element.

6.4. Boundary and Initial Conditions

For the vectorized version also, the sets of pseudocode for the boundary and initial conditions are given in Algorithms 6 and 7, respectively.

7. Overview of an Implementation in Matlab

A minimal MATLAB implementation of the presented algorithm is available from Supplementary Materials. There are six zipfiles which contain the necessary MATLAB files therein:
  • BE_LRR_unvectorized.zip (backward-Euler, left rectangular rule, unvectorized);
  • BE_LRR_vectorized.zip (backward-Euler, left rectangular rule, vectorized);
  • BE_RRR_unvectorized.zip (backward-Euler, right rectangular rule, unvectorized);
  • BE_RRR_vectorized.zip (backward-Euler, right rectangular rule, vectorized);
  • CN_unvectorized.zip (Crank–Nicolson, unvectorized);
  • CN_vectorized.zip (Crank–Nicolson, vectorized).
To run the demo program, uncompress the desired zip file and run the Main.m file; this:
  • Specifies the geometry;
  • Computes the solution;
  • Plots the solution.
In particular, the computation of the solution is carried out by SCHEME_NAME_PIDE.m, which sets the initial conditions via U0.m, and assembles the stiffness matrix and the mass matrix via StiffAssemb.m and MassAssemb.m, respectively; thereafter, solve_SCHEME_NAME.mupdates the boundary conditions via Ud.m, assembles the load vector via f.m and obtains the solution at the current time step. Furthermore, note that whilst most of the subroutines are the same in both the vectorized and unvectorized versions of the code, those for StiffAssemb.m and MassAssemb.m are necessarily slightly different, in line with the discussion in Section 5 and Section 6.

8. Numerical Results

In this section, we study a numerical example and compare the results obtained using different versions of the MATLAB-based sets of code; in addition, solutions were obtained using COMSOL Multiphysics. For the example, we consider the L-shaped domain Ω = [ 1 , 1 ] 2 [ 1 , 0 ] × [ 0 , 1 ] mentioned earlier; take
f ( x , y , t ) = ( 1 2 t ) π 2 u ( x , y , t )
and
B ( t , s ) = exp ( π 2 ( t s ) ) ,
which is a kernel that occurs in different settings in many of the references given earlier, and others [2,3,4,7,14,53,54]; this leads to the following exact solution for u:
u ( x , y , t ) = exp ( π 2 t ) sin ( π x ) sin ( π y ) .
Figure 2a shows the exact solution to the problem, whereas Figure 2b corresponds to the backward-Euler approximation, where the left rectangular rule is applied to treat the Volterra integral term. Figure 2c,d show the solutions obtained using the backward-Euler approximation with the right rectangular rule and the Crank–Nicolson approximation with the trapezoidal rule, respectively, to treat the Volterra integral term. In addition, Figure 3 shows a comparison of the analytical solution with the solution computed by COMSOL Multiphysics with 66142 P1 elements for t = T , y = 0.5 , where T = 0.1 ; as expected, the agreement is very good.
To illustrate the advantage of the vectorized code for each numerical scheme over the unvectorized one, which uses for loops for the assembly process, we have presented a comparison of the runtimes with respect to the number of elements, N. This is given in Table 3, which also shows the runtimes for COMSOL Multiphysics. Note that all sets of code were run on an Intel Core i7 Notebook with a 1.7 GHz processor and 8 GB of RAM. We can note from Table 3 that vectorized versions of the MATLAB sets of code presented in this article on the finest mesh get close to COMSOL’s performance. Nevertheless, there are several factors behind the results. On the one hand, in the developed MATLAB sets of code, we discretize the Volterra integral term; as a result, one has to store the memory term values at all of the time discretization points. On the other hand, because of the particular form of the kernel in (26), and as explained in Appendix C, COMSOL Multiphysics does not need to evaluate the integral at all; even so, the difference in computational time is not decisive. 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.
In addition, we define an efficiency factor, C e f f , given by C e f f = t u n v e c / t v e c , where t u n v e c is the runtime of the unvectorized code and t v e c 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 e f f . 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/LucaMeacci/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.

Funding

This research was funded by FAPESP (Fundação de Amparo à Pesquisa do Estado de São Paulo) grant numbers 2016/19648-9, 2017/11428-2 and 2018/07643-8 and the Programa de Excelência Académica (Proex)—Coordenação de Aperfeiçoamento de Pessoal de Nível Superior—Brazil (CAPES)—Finance Code PROEX-9740044/D. The APC was funded by KTH Royal Institute of Technology.

Acknowledgments

The sixth author acknowledges the award of a visiting researcher grant from the University of São Paulo.

Conflicts of Interest

The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses or interpretation of data; in the writing of the manuscript, or in the decision to publish the results.

Appendix A. Unvectorized Pseudocode

In this section, the unvectorized sets of pseudocode are presented.
  • Pseudo-code for Algorithms A1–A6 the backward-Euler scheme with the left rectangular rule, corresponding to Equation (9) and employing (7):
Algorithm A1 Backward-Euler scheme with left rectangular rule.
Main function
1:
procedureBELRFEMPIDE( c 4 n , n 4 e , d i r , N , d t )
2:
     r NROW ( c 4 n )
3:
     U ZEROS ( r , N + 1 )
4:
     F N UNIQUE ( [ 1 2 r ] ) UNIQUE ( d i r )
5:
     A STIFFASSEMB ( n 4 e , c 4 n )
6:
     B MASSASSEMB ( n 4 e , c 4 n )
7:
     U ( : , 1 ) U 0 ( c 4 n )
8:
    for n 2 to ( N + 1 ) , do
9:
         U ( : , n ) SOLVEBELRR ( c 4 n , n 4 e , d i r , d t , F N , A , B . n , U )
10:
    end for
11:
    return U
12:
end procedure
Auxiliary function
13:
proceduresolveBELRR( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U )
14:
     r NROW ( c 4 n )
15:
     b SPARSE ( r , 1 )
16:
    for j 1 to NROW ( n 4 e ) , do
17:
         M 1 [ [ 1 1 1 ] ; c 4 n ( n 4 e ( j , : ) , : ) T ]
18:
         S S U M ( c 4 n ( n 4 e ( j , : ) , : ) )
19:
         b ( n 4 e ( j , : ) ) b ( n 4 e ( j , : ) ) + DET ( M 1 ) d t 1 6 f ( S 3 , ( n 1 ) d t )
20:
    end for
21:
     I n t d t 2 A U ( : , 1 ) INTGRAL ( ( n 1 ) d t , 0 )
22:
    if n > 2 , then
23:
        for k 2 to ( n 1 ) , do
24:
            I n t I n t + d t 2 A U ( : , k ) INTGRAL ( ( n 1 ) d t , ( k 1 ) d t )
25:
        end for
26:
    end if
27:
    b b + ( B U ( : , n 1 ) ) + I n t
28:
     u SPARSE ( r , 1 )
29:
     u d UNIQUE ( d i r )
30:
     u ( u d ) U D ( c 4 n ( u d , : ) , ( n 1 ) d t )
31:
     b b ( d t A + B ) u
32:
     u ( F N ) INV ( d t A ( F N , F N ) + B ( F N , F N ) ) b ( F N )
33:
     s o l B E L R u
34:
    return s o l B E L R
35:
end procedure
  • Code for the backward-Euler scheme with the right rectangular rule, corresponding to Equation (9) and employing (8):
Algorithm A2 Backward-Euler scheme with right rectangular rule.
Main function
1:
procedureBERRFEMPIDE( c 4 n , n 4 e , d i r , N , d t )
2:
     r NROW ( c 4 n )
3:
     U ZEROS ( r , N + 1 )
4:
     F N UNIQUE ( [ 1 2 r ] ) UNIQUE ( d i r )
5:
     A STIFFASSEMB ( n 4 e , c 4 n )
6:
     B MASSASSEMB ( n 4 e , c 4 n )
7:
     U ( : , 1 ) U 0 ( c 4 n )
8:
    for n 2 to ( N + 1 ) , do
9:
         U ( : , n ) SOLVEBERRR ( c 4 n , n 4 e , d i r , d t , F N , A , B . n , U )
10:
    end for
11:
    return U
12:
end procedure
Auxiliary function
13:
procedureSOLVEBERRR( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U )
14:
     r NROW ( c 4 n )
15:
     b SPARSE ( r , 1 )
16:
    for j 1 to NROW ( n 4 e ) , do
17:
         M 1 [ [ 1 1 1 ] ; c 4 n ( n 4 e ( j , : ) , : ) T ]
18:
         S SUM ( c 4 n ( n 4 e ( j , : ) , : ) )
19:
         b ( n 4 e ( j , : ) ) b ( n 4 e ( j , : ) ) + DET ( M 1 ) d t 1 6 f ( S 3 , ( n 1 ) d t )
20:
    end for
21:
     I n t 0
22:
    if n > 2 , then
23:
         I n t d t 2 A U ( : , 1 ) INTGRAL ( ( n 1 ) d t , d t )
24:
        for k 2 to ( n 2 ) , do
25:
            I n t I n t + d t 2 A U ( : , k ) INTGRAL ( ( n 1 ) d t , k d t )
26:
        end for
27:
    end if
28:
     b b + ( B U ( : , n 1 ) ) + I n t
29:
     u SPARSE ( r , 1 )
30:
     u d UNIQUE ( d i r )
31:
     u ( U D ) U D ( c 4 n ( u d , : ) , ( n 1 ) d t )
32:
     b b ( d t A + B + d t 2 A INTGRAL ( ( n 1 ) d t , ( n 1 ) d t ) ) u
33:
     M 1 d t A ( F N , F N ) + B ( F N , F N ) + d t 2 A ( F N , F N ) INTGRAL ( ( n 1 ) d t , ( n 1 ) d t )
34:
     u ( F N ) INV ( M 1 ) b ( F N )
35:
     s o l B E R R u
36:
    return s o l B E R R
37:
end procedure
  • Code for Crank–Nicolson scheme with trapezoidal rule, corresponding to Equation (14):
Algorithm A3 Crank–Nicolson scheme with the trapezoidal rule.
Main function
1:
procedureCNFEMPIDE( c 4 n , n 4 e , d i r , N , d t )
2:
     r NROW ( c 4 n )
3:
     U ZEROS ( r , N + 1 )
4:
     F N UNIQUE ( [ 1 2 r ] ) UNIQUE ( d i r )
5:
     A STIFFASSEMB ( n 4 e , c 4 n )
6:
     B MASSASSEMB ( n 4 e , c 4 n )
7:
     U ( : , 1 ) U 0 ( c 4 n )
8:
    for j 2 to ( N + 1 ) , do
9:
         U ( : , j ) SOLVECN ( c 4 n , n 4 e , d i r , d t , F N , n , U , A , B )
10:
    end for
11:
    return U
12:
end procedure
Auxiliary function
13:
procedureSOLVECN( c 4 n , n 4 e , d i r , d t , F N , n , U , A , B )
14:
     r NROW ( c 4 n )
15:
     b SPARSE ( r , 1 )
16:
    for j 1 to NROW ( n 4 e ) , do
17:
         X 1 DET ( [ [ 1 1 1 ] ; c 4 n ( n 4 e ( j , : ) , : ) T ] )
18:
         X 2 SUM ( c 4 n ( n 4 e ( j , : ) , : ) )
19:
         X 3 SUM ( c 4 n ( n 4 e ( j , : ) , : ) )
20:
         b ( n 4 e ( j , : ) ) b ( n 4 e ( j , : ) ) + X 1 d t 1 12 ( f ( X 2 / 3 , ( n 1 ) d t ) + f ( X 3 / 3 , ( n 2 ) d t ) )
21:
    end for
22:
     I n t 1 8 . d t 2 A U ( : , 1 ) ( 2 INTGRAL ( ( n 1.5 ) d t , 0 ) + INTGRAL ( ( n 1.5 ) d t , ( n 1.5 ) d t ) )
23:
    if n > 2 , then
24:
         I n t 1 2 d t 2 A U ( : , 1 ) INTGRAL ( ( n 1.5 ) d t , 0 )
24:
                   + 1 8 d t 2 A U ( : , n 1 ) ( INTGRAL ( ( n 1.5 ) d t , ( n 1.5 ) d t )
24:
                                              + 6 INTGRAL ( ( n 1.5 ) d t , ( n 2 ) d t ) )
25:
        for k 2 to ( n 2 ) , do
26:
            I n t I n t + d t 2 A U ( : , k ) INTGRAL ( ( n 1.5 ) d t , ( k 1 ) d t )
27:
        end for
28:
    end if
29:
    b b + ( B d t 2 A ) U ( : , n 1 ) + I n t
30:
     u SPARSE ( r , 1 )
31:
     u d UNIQUE ( d i r )
32:
     u ( u d ) U D ( c 4 n ( u d , : ) , ( n 1 ) d t )
33:
     b b d t 2 d t 2 8 INTGRAL ( ( n 1.5 ) d t , ( n 1 ) d t ) A + B u
34:
     M 1 d t 2 d t 2 8 INTGRAL ( ( n 1.5 ) d t , ( n 1 ) d t ) A ( F N , F N ) + B ( F N , F N )
35:
     u ( F N ) INV ( M 1 ) b ( F N )
36:
     s o l C N u
37:
    return s o l C N
38:
end procedure

Appendix B. Vectorized Pseudocode

In this section, the vectorized sets of pseudocode are presented.
  • Code for the backward-Euler scheme with the left rectangular rule, corresponding to Equation (9) and employing (7):
Algorithm A4 Vectorized version of backward-Euler scheme with the left rectangular rule.
Main function
1:
procedureBELRFEMPIDE( c 4 n , n 4 e , d i r , N , d t )
2:
     n E NROW ( n 4 e )
3:
     n C NROW ( c 4 n )
4:
     U ZEROS ( n C , N + 1 )
5:
     F N UNIQUE ( [ 1 2 n C ] ) UNIQUE ( d i r )
6:
     c 1 c 4 n ( n 4 e ( : , 1 ) , : )
7:
     d 21 c 4 n ( n 4 e ( : , 2 ) , : ) c 1
8:
     d 31 c 4 n ( n 4 e ( : , 3 ) , : ) c 1
9:
     a r e a 4 2 ( d 21 ( : , 1 ) . d 31 ( : , 2 ) d 21 ( : , 2 ) . d 31 ( : , 1 ) )
10:
     A STIFFASSEMB ( n 4 e , n C , a r e a 4 , d 21 , d 31 , n E )
11:
     B STIFFASSEMB ( n C , n 4 e T , 1 4 a r e a 4 )
12:
     U ( : , 1 ) U 0 ( c 4 n )
13:
    for j 2 to ( N + 1 ) , do
14:
         U ( : , j ) SOLVEBELRR ( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U , c 1 , d 21 , d 31 , a r e a 4 )
15:
    end for
16:
    return U
17:
end procedure
Auxiliary function
18:
proceduresolveBELRR( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U , c 1 , d 21 , d 31 , a r e a 4 )
19:
     r NROW ( c 4 n )
20:
     f s T F ( c 1 + d 21 + d 31 3 , ( n 1 ) d t )
21:
     L REPMAT ( d t . a r e a 4 . f s T . 1 12 , 3 , 1 )
22:
     b ACCUMARRAY ( n 4 e ( : ) , L , [ r 1 ] )
23:
     I n t d t 2 A U ( : , 1 ) INTGRAL ( ( n 1 ) d t , 0 )
24:
    if n > 2 , then
25:
        for k 2 to ( n 1 ) , do
26:
            I n t I n t + d t 2 A U ( : , k ) INTGRAL ( ( n 1 ) d t , ( k 1 ) d t )
27:
        end for
28:
    end if
29:
    b b + B U ( : , n 1 ) + I n t
30:
     u SPARSE ( r , 1 )
31:
     u d UNIQUE ( d i r )
32:
     u ( u d ) U D ( c 4 n ( u d , : ) , ( n 1 ) d t )
33:
     b b ( d t A + B ) u
34:
     M 1 d t A ( F N , F N ) + B ( F N , F N )
35:
     u ( F N ) INV ( M 1 ) b ( F N )
36:
     s o l B E L R u
37:
    return s o l B E L R
38:
end procedure
  • Code for the backward-Euler scheme with the right rectangular rule, corresponding to Equation (9) and employing (8):
Algorithm A5 Vectorized version of backward-Euler scheme with the left rectangular rule.
Main function
1:
procedureBERRFEMPIDE( c 4 n , n 4 e , d i r , N , d t )
2:
     n E NROW ( n 4 e )
3:
     n C NROW ( c 4 n )
4:
     U ZEROS ( n C , N + 1 )
5:
     F N UNIQUE ( [ 1 2 n C ] ) UNIQUE ( d i r )
6:
     c 1 c 4 n ( n 4 e ( : , 1 ) , : )
7:
     d 21 c 4 n ( n 4 e ( : , 2 ) , : ) c 1
8:
     d 31 c 4 n ( n 4 e ( : , 3 ) , : ) c 1
9:
     a r e a 4 2 ( d 21 ( : , 1 ) . d 31 ( : , 2 ) d 21 ( : , 2 ) . d 31 ( : , 1 ) )
10:
     A STIFFASSEMB ( n 4 e , n C , a r e a 4 , d 21 , d 31 , n E )
11:
     B MASSASSEMB ( n C , n 4 e T , 1 4 a r e a 4 )
12:
     U ( : , 1 ) U 0 ( c 4 n )
13:
    for j 2 to ( N + 1 ) , do
14:
         U ( : , j ) SOLVEBERRR ( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U , c 1 , d 21 , d 31 , a r e a 4 )
15:
    end for
16:
    return U
17:
end procedure
Auxiliary function
18:
proceduresolveBERRR( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U , c 1 , d 21 , d 31 , a r e a 4 )
19:
     r NROW ( c 4 n )
20:
     f s T F ( c 1 + d 21 + d 31 3 , ( n 1 ) d t )
21:
     L REPMAT ( d t . a r e a 4 . f s T . 1 12 , 3 , 1 )
22:
     b ACCUMARRAY ( n 4 e ( : ) , L , [ r 1 ] )
23:
     I n t 0
24:
    if n > 2 , then
25:
         I n t d t 2 A U ( : , 1 ) INTGRAL ( ( n 1 ) d t , d t )
26:
        for k 2 to ( n 2 ) , do
27:
            I n t I n t + d t 2 A U ( : , k ) INTGRAL ( ( n 1 ) d t , k d t )
28:
        end for
29:
    end if
30:
    b b + B U ( : , n 1 ) + I n t
31:
     u SPARSE ( r , 1 )
32:
     u d UNIQUE ( d i r )
33:
     u ( u d ) U D ( c 4 n ( u d , : ) , ( n 1 ) d t )
34:
     b b ( d t A + B + d t 2 A INTGRAL ( ( n 1 ) d t , ( n 1 ) d t ) ) u
35:
     M 1 d t A ( F N , F N ) + B ( F N , F N ) + d t 2 A ( F N , F N ) INTGRAL ( ( n 1 ) d t , ( n 1 ) d t )
36:
     u ( F N ) INV ( M 1 ) b ( F N )
37:
     s o l B E R R u
38:
    return s o l B E R R
39:
end procedure
  • Code for Crank–Nicolson scheme with trapezoidal rule, corresponding to Equation (14):
Algorithm A6 Crank–Nicolson scheme with the trapezoidal rule.
Main function
1:
procedureCNFEMPIDE( c 4 n , n 4 e , d i r , N , d t )
2:
     n E NROW ( n 4 e )
3:
     n C NROW ( c 4 n )
4:
     U ZEROS ( n C , N + 1 )
5:
     F N UNIQUE ( [ 1 2 n C ] ) UNIQUE ( d i r )
6:
     c 1 c 4 n ( n 4 e ( : , 1 ) , : )
7:
     d 21 c 4 n ( n 4 e ( : , 2 ) , : ) c 1
8:
     d 31 c 4 n ( n 4 e ( : , 3 ) , : ) c 1
9:
     a r e a 4 2 ( d 21 ( : , 1 ) . d 31 ( : , 2 ) d 21 ( : , 2 ) . d 31 ( : , 1 ) )
10:
     A STIFFASSEMB ( n 4 e , n C , a r e a 4 , d 21 , d 31 , n E )
11:
     B MASSASSEMB ( n C , n 4 e T , 1 4 a r e a 4 )
12:
     U ( : , 1 ) U 0 ( c 4 n )
13:
    for j 2 to ( N + 1 ) , do
14:
         U ( : , j ) SOLVECN ( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U , c 1 , d 21 , d 31 , a r e a 4 )
15:
    end for
16:
    return U
17:
end procedure
Auxiliary function
18:
procedureSOLVECN( c 4 n , n 4 e , d i r , d t , F N , A , B , n , U , c 1 , d 21 , d 31 , a r e a 4 )
19:
     r NROW ( c 4 n )
20:
     f s T 1 F ( c 1 + d 21 + d 31 3 , ( n 1 ) d t )
21:
     f s T 2 F ( c 1 + d 21 + d 31 3 , ( n 2 ) d t )
22:
     f s T m i d 0.5 ( f s T 1 + f s T 2 )
23:
     L REPMAT ( d t . a r e a 4 . f s T m i d . 1 12 , 3 , 1 )
24:
     b ACCUMARRAY ( n 4 e ( : ) , L , [ r 1 ] )
25:
     I n t 1 8 d t 2 A U ( : , 1 ) ( 2 INTGRAL ( ( n 1.5 ) d t , 0 )
25:
                                              + INTGRAL ( ( n 1.5 ) d t , ( n 1.5 ) d t ) )
26:
    if n > 2 , then
27:
         I n t 1 2 d t 2 A U ( : , 1 ) INTGRAL ( ( n 1.5 ) d t , 0 )
27:
                   + 1 8 d t 2 A U ( : , n 1 ) ( INTGRAL ( ( n 1.5 ) d t , ( n 1.5 ) d t )
27:
                                     6 INTGRAL ( ( n 1.5 ) d t , ( n 2 ) d t ) )
28:
        for j 2 to ( n 2 ) , do
29:
            I n t I n t + d t 2 A U ( : , j ) INTGRAL ( ( n 1.5 ) d t , ( j 1 ) d t )
30:
        end for
31:
    end if
32:
    b b + ( B d t 2 A ) U ( : , n 1 ) + I n t
33:
     u SPARSE ( r , 1 )
34:
     u d UNIQUE ( d i r )
35:
     u ( u d ) U D ( c 4 n ( u d , : ) , ( n 1 ) d t )
36:
     b b d t 2 d t 2 8 INTGRAL ( ( n 1.5 ) d t , ( n 1 ) d t ) A + B u
37:
     M 1 d t 2 d t 2 8 INTGRAL ( ( n 1.5 ) d t , ( n 1 ) d t ) A ( F N , F N ) + B ( F N , F N )
38:
     u ( F N ) INV ( M 1 ) b ( F N )
39:
     s o l C N u
40:
    return s o l C N
41:
end procedure

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 t , s = B 0 t B 1 s , Equation (1) becomes
u t = 2 u x 2 + 2 u y 2 B 0 t ϕ + f ,
where
ϕ = 0 t B 1 s 2 u x 2 + 2 u y 2 d s ,
which differentiates with respect to t and using (A1) gives
ϕ t = B 1 t u t + B 0 t ϕ f .
Thus, the system to solve is (A1) and (A3), subject to
u ( x , t ) = g ( x ) , ( x , t ) Ω × [ 0 , T ] ,
u ( x , 0 ) = u 0 ( x ) , x Ω ,
ϕ ( x , 0 ) = 0 , x Ω .
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 (A1) and (A3), 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- α method [56,57].
On the other hand, if B t , s is not separable, e.g., B ( t , s ) = exp ( π 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

  1. Gurtin, M.E.; Pipkin, A.C. A general theory of heat conduction with finite wave speeds. Arch. Ration. Mech. Anal. 1968, 31, 113–126. [Google Scholar] [CrossRef]
  2. Joseph, D.D.; Preziosi, L. Heat waves. Rev. Mod. Phys. 1989, 61, 41–73. [Google Scholar] [CrossRef]
  3. Araújo, A.; Ferreira, J.A.; Oliveira, P. The effect of memory terms in diffusion phenomena. J. Comput. Math. 2006, 24, 91–102. [Google Scholar]
  4. Habetler, G.J.; Schiffman, R.L. A finite difference method for analyzing the compression of poro-viscoelastic media. Computing 1970, 6, 342–348. [Google Scholar] [CrossRef]
  5. Pao, C.V. Solution of a nonlinear integrodifferential system arising in nuclear reactor dynamics. J. Math. Anal. Appl. 1974, 48, 470–492. [Google Scholar] [CrossRef] [Green Version]
  6. Capasso, V. Asymptotic stability for an integro-differential reaction-diffusion system. J. Math. Anal. Appl. 1984, 103, 575–588. [Google Scholar] [CrossRef] [Green Version]
  7. Barbeiro, S.; Ferreira, J.A. Integro-differential models for percutaneous drug absorption. Int. J. Comput. Maths 2007, 84, 451–467. [Google Scholar] [CrossRef] [Green Version]
  8. Barbeiro, S.; Ferreira, J.A. Coupled vehicle-skin models for drug release. Comput. Methods Appl. Mech. Eng. 2009, 198, 2078–2086. [Google Scholar] [CrossRef] [Green Version]
  9. Chuanmiao, C.; Tsimin, S. Finite Element Methods for Integrodifferential Equations; World Scientific Publishing Co. Inc.: River Edge, NJ, USA, 1998. [Google Scholar]
  10. Yanik, E.G.; Fairweather, G. Finite element methods for parabolic and hyperbolic partial integro-differential equations. Nonlinear Anal. 1988, 12, 785–809. [Google Scholar] [CrossRef]
  11. Engler, H. On some parabolic integro-differential equations—Existence and asymptotics of solutions. Lect. Notes Math. 1983, 1017, 161–167. [Google Scholar]
  12. Reddy, G.M.M.; Sinha, R.K.; Cuminato, J.A. A posteriori error analysis of the Crank-Nicolson finite element method for parabolic integro-differential equations. J. Sci. Comput. 2019, 79, 414–441. [Google Scholar] [CrossRef]
  13. Sameeh, M.; Elsaid, A. Chebyshev collocation method for parabolic partial integrodifferential equations. Adv. Math. Phys. 2016, 2016, 7854806. [Google Scholar] [CrossRef] [Green Version]
  14. Filiz, A. Numerical solution of parabolic Volterra integro-differential equations via backward-Euler scheme. J. Comput. Appl. Math. 2013, 3, 277–282. [Google Scholar]
  15. Soliman, A.F.; El-asyed, A.M.; El-Azab, M.S. On the numerical solution of partial integro-differential equations. Math. Sci. Lett. 2012, 1, 71–80. [Google Scholar] [CrossRef]
  16. Avazzadeh, Z.; Rizi, Z.B.; Ghaini, F.M.M.; Loghmani, G.B. A numerical solution of nonlinear parabolic-type Volterra partial integro-differential equations using radial basis functions. Eng. Anal. Bound. Elem. 2012, 36, 881–893. [Google Scholar] [CrossRef]
  17. Ma, J. Finite element methods for partial Volterra integro-differential equations on two-dimensional unbounded spatial domains. Appl. Math. Comput. 2007, 186, 598–609. [Google Scholar] [CrossRef]
  18. Fakhar-Izadi, F.; Dehghan, M. The spectral methods for parabolic Volterra integro-differential equations. J. Comput. Appl. Math. 2011, 235, 4032–4046. [Google Scholar] [CrossRef] [Green Version]
  19. Kauthen, J.P. The method of lines for parabolic partial integro-differential equations. J. Integr. Equa. Appl. 1992, 4, 69–81. [Google Scholar] [CrossRef]
  20. Larsson, S.; Thomee, V.; Wahlbin, L.B. Numerical solution of parabolic integro-differential equations by the discontinuous Galerkin method. Math. Comput. 1998, 67, 45–71. [Google Scholar] [CrossRef] [Green Version]
  21. Greenwell-Yanik, C.E.; Fairweather, G. Analyses of spline collocation methods for parabolic and hyperbolic problems in 2 space variables. SIAM J. Numer. Anal. 1986, 23, 282–296. [Google Scholar] [CrossRef]
  22. Lin, Y.P.; Thomée, V.; Wahlbin, L.B. Ritz-Volterra projections to finite-element spaces and applications to integrodifferential and related equations. SIAM J. Numer. Anal. 1991, 28, 1047–1070. [Google Scholar] [CrossRef]
  23. Pani, A.K.; Sinha, R.K. Error estimates for semidiscrete Galerkin approximation to a time dependent parabolic integro-differential equation with nonsmooth data. Calcolo 2000, 37, 181–205. [Google Scholar] [CrossRef]
  24. Reddy, G.M.M.; Sinha, R.K. Ritz-Volterra reconstructions and A Posteriori Error Anal. Finite Elem. Method Parabol. Integro-Differ. Equations. IMA J. Numer. Anal. 2015, 35, 341–371. [Google Scholar] [CrossRef]
  25. Reddy, G.M.M.; Sinha, R.K. On the Crank-Nicolson anisotropic a posteriori error analysis for parabolic integro-differential equations. Math. Comp. 2016, 85, 2365–2390. [Google Scholar] [CrossRef]
  26. Reddy, G.M.M.; Sinha, R.K. The backward Euler anisotropic a posteriori error analysis for parabolic integro-differential equations. Numer. Methods Partial. Differ. Equ. 2016, 32, 1309–1330. [Google Scholar] [CrossRef]
  27. Shaw, S.; Whiteman, J.R. Numerical solution of linear quasistatic hereditary viscoelasticity problems. SIAM J. Numer. Anal. 2000, 38, 80–97. [Google Scholar] [CrossRef] [Green Version]
  28. Thomée, V.; Zhang, N.Y. Error estimates for semidiscrete finite element methods for parabolic integro-differential equations. Math. Comput. 1989, 53, 121–139. [Google Scholar] [CrossRef]
  29. Hecht, F. New development in freefem++. J. Numer. Math. 2012, 20, 251–265. [Google Scholar] [CrossRef]
  30. deal.II—An Open Source Finite Element Library. Available online: https://www.dealii.org/ (accessed on 21 September 2020).
  31. iFEM—Mathematical Software. Available online: http://swmath.org/software/7766 (accessed on 21 September 2020).
  32. FEniCS Project. Available online: https://fenicsproject.org/ (accessed on 21 September 2020).
  33. DUNE Numerics. Available online: https://www.dune-project.org/ (accessed on 21 September 2020).
  34. Physics Simulation Made Easy. Available online: https://www.featool.com/ (accessed on 21 September 2020).
  35. MathWorks. Available online: http://www.mathworks.com (accessed on 21 September 2020).
  36. COMSOL. Available online: http://www.comsol.com (accessed on 21 September 2020).
  37. Acosta, G.; Bersetche, F.M.; Borthagaray, J.P. A short FE implementation for a 2d homogeneous Dirichlet problem of a fractional Laplacian. Comput. Math. Appl. 2017, 74, 784–816. [Google Scholar] [CrossRef] [Green Version]
  38. Alberty, J.; Carstensen, C.; Funken, S.A.; Klose, R. Matlab implementation of the finite element method in elasticity. Computing 2002, 69, 239–263. [Google Scholar] [CrossRef]
  39. Abdulle, A.; Nonnenmacher, A. A short and versatile finite element multiscale code for homogenization problems. Comput. Methods Appl. Mech. Eng. 2009, 198, 2839–2859. [Google Scholar] [CrossRef]
  40. Alberty, J.; Carstensen, C.; Funken, S.A. Remarks around 50 lines of Matlab: Short finite element implementation. Numer. Algorithms 1999, 20, 117–137. [Google Scholar] [CrossRef]
  41. Bahriawati, C.; Carstensen, C. Three MATLAB implementations of the lowest-order Raviart-Thomas MFEM with a posteriori error control. Comput. Methods Appl. Math. 2005, 5, 333–361. [Google Scholar] [CrossRef]
  42. Carstensen, C.; Klose, R. Elastoviscoplastic finite element analysis in 100 lines of Matlab. J. Numer. Math. 2002, 10, 157–192. [Google Scholar] [CrossRef]
  43. Cuvelier, F.; Japhet, C.; Scarella, G. An efficient way to assemble finite element matrices in vector languages. BIT Numer. Math. 2016, 56, 833–864. [Google Scholar] [CrossRef] [Green Version]
  44. Funken, S.; Praetorius, D.; Wissgott, P. Efficient implementation of adaptive P1-FEM in Matlab. Comput. Methods Appl. Math. 2011, 11, 460–490. [Google Scholar] [CrossRef]
  45. Korzec, M.; Ahnert, T. Time-stepping methods for the simulation of the self-assembly of nano-crystals in Matlab on a GPU. J. Comput. Phys. 2013, 251, 396–413. [Google Scholar] [CrossRef]
  46. Sutton, O.J. The virtual element method in 50 lines of MATLAB. Numer. Algorithms 2017, 75, 1141–1159. [Google Scholar] [CrossRef] [Green Version]
  47. Wang, H.; Tian, H. A fast Galerkin method with efficient matrix assembly and storage for a peridynamic model. J. Comput. Phys. 2012, 231, 7730–7738. [Google Scholar] [CrossRef]
  48. Rahman, T.; Valdman, J. Fast MATLAB assembly of FEM matrices in 2D and 3D: Nodal elements. Appl. Math. Comput. 2013, 219, 7151–7158. [Google Scholar] [CrossRef]
  49. Frank, F.; Reuter, B.; Aizinger, V.; Knabner, P. FESTUNG: A MATLAB/GNU Octave toolbox for the discontinuous Galerkin method, Part I: Diffusion operator. Comput. Math. Appl. 2015, 70, 11–46. [Google Scholar] [CrossRef]
  50. Kim, S.; Lee, H.C. Finite element method to control the domain singularities of poisson equation using the stress intensity factor: Mixed boundary condition. Int. J. Numer. Anal. Model. 2017, 14, 500–510. [Google Scholar]
  51. Schiff, B. Finite-element eigenvalues for the Laplacian over an L-shaped domain. J. Comput. Phys. 1988, 76, 233–242. [Google Scholar] [CrossRef]
  52. Cuvelier, F.; Japhet, C.; Scarella, G. An Efficient Way to Perform the Assembly of Finite Element Matrices in Matlab and Octave; Technical Report; INRIA: Rocquencourt, France, 2013. [Google Scholar]
  53. Araújo, A.; Branco, J.R.; Ferreira, J.A. On the stability of a class of splitting methods for integro-differential equations. Appl. Numer. Math. 2009, 59, 436–453. [Google Scholar] [CrossRef] [Green Version]
  54. Khuri, S.A.; Sayfy, A. A numerical approach for solving an extended Fisher-Kolomogrov-Petrovskii-Piskunov equation. J. Comp. Appl. Math. 2010, 233, 2081–2089. [Google Scholar] [CrossRef] [Green Version]
  55. Chu, K.T. A direct matrix method for computing analytical Jacobians of discretized nonlinear integro-differential equations. J. Comput. Phys. 2009, 228, 5526–5538. [Google Scholar] [CrossRef] [Green Version]
  56. Chung, J.; Hulbert, G.M. A time integration algorithm for structural dynamics with improved numerical dissipation—The generalized-α method. J. Appl. Mech.—Trans. ASME 1993, 60, 371–375. [Google Scholar] [CrossRef]
  57. Jansen, K.E.; Whiting, C.H.; Hulbert, G.M. A generalized-alpha method for integrating the filtered Navier-Stokes equations with a stabilized finite element method. Comput. Methods Appl. Mech. Eng. 2000, 190, 305–319. [Google Scholar] [CrossRef]
Figure 1. Domain representation.
Figure 1. Domain representation.
Algorithms 13 00242 g001
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 τ = 0.00125 and h = 0.05 .
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 τ = 0.00125 and h = 0.05 .
Algorithms 13 00242 g002
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 3. Comparison of the analytical solution with the solution computed by COMSOL Multiphysics with 66,142 elements for T = 0.1 , y = 0.5 .
Algorithms 13 00242 g003
Table 1. Arrays c4n, n4e and dir.
Table 1. Arrays c4n, n4e and dir.
c4n
1-1.0-1.0
20.0-1.0
31.0-1.0
4-0.5-0.5
50.5-0.5
6-1.00.0
70.00.0
81.00.0
90.50.5
100.01.0
111.01.0
n4e
1124
2235
3385
4875
5725
6742
7476
8614
9679
109711
1191110
129106
dir
112
223
338
4811
51110
6107
776
861
Table 2. Some common functions and operations.
Table 2. Some common functions and operations.
A ( : ) All the elements of A, treated as a single column
A ( : , j ) j-th column of A
A ( i , : ) i-th row of A
A = = k Indices ( i , j ) where A ( i , j ) = k
A T Transpose of A
A ( α , β ) Entry of A at position ( α , β )
a b Assignment
A B Matrix multiplication
A . B Element-wise multiplication
A . / B Element-wise division
A B Return, without repeating, elements of A which are not in B
ACCUMARRAY ( x , y , s ) Return an array with size s (vector containing the dimensions of the output).
The values in the output are sums of the values in y having identical subscripts in x
DET ( A ) Determinant of A
I d d × d identity matrix
NCOL ( A ) Number of columns in A
INV ( A ) Inverse of A
NROW ( A ) Number of rows in A
ONES ( m , n ) m × n matrix with all entries equal to ones
REPMAT ( A , m , n ) Returns m × n block matrix with each block equal to A
RESHAPE ( A , m , n ) Reshape A into m × n matrix provided m n = NCOL(A)*NROW ( A )
SPARSE ( m , n ) m × n sparse matrix of zeros
SUM ( A , k ) Sum of elements of A along the index k
UNIQUE ( A ) Return entries of A without repeating
ZEROS ( m , n ) m × n matrix with all entries equal to zero
[ , ] Horizontal concatenation
[ ; ] Vertical concatenation
Table 3. Quantitative information on the runtimes of the unvectorized and vectorized MATLAB sets of code with different numerical schemes, and the same for code from COMSOL Multiphysics, when solving the PIDE. Abbreviations: BELR, backward-Euler scheme with left rectangular rule; BERR, backward-Euler scheme with right rectangular rule; CN, Crank–Nicolson scheme with trapezoidal rule; N, number of elements; t u n v e c S C H E M E , runtime of the unvectorized code in seconds involving loops in the assembly process, using a particular method S C H E M E (= BELR, BERR or CN); t v e c S C H E M E , runtime of the vectorized code in seconds without loops in the assembly process, using a particular method S C H E M E ; t C , runtime for COMSOL Multiphysics.
Table 3. Quantitative information on the runtimes of the unvectorized and vectorized MATLAB sets of code with different numerical schemes, and the same for code from COMSOL Multiphysics, when solving the PIDE. Abbreviations: BELR, backward-Euler scheme with left rectangular rule; BERR, backward-Euler scheme with right rectangular rule; CN, Crank–Nicolson scheme with trapezoidal rule; N, number of elements; t u n v e c S C H E M E , runtime of the unvectorized code in seconds involving loops in the assembly process, using a particular method S C H E M E (= BELR, BERR or CN); t v e c S C H E M E , runtime of the vectorized code in seconds without loops in the assembly process, using a particular method S C H E M E ; t C , runtime for COMSOL Multiphysics.
hN t unvec BELR s t vec BELR s t unvec BERR s t vec BERR s t unvec CN s t vec CN s t C s
0.22580.810.770.820.770.830.770.31
0.19780.980.811.000.811.040.820.55
0.0540862.061.081.961.082.131.081.73
0.02516,40610.264.3610.514.4010.934.416.93
0.012566,142114.4038.04112.8638.24114.4238.3634.13
Table 4. The efficiency factor, C e f f , for different MATLAB-based sets of code and different space meshes with a fixed time step ( τ = 0.00125 ) .
Table 4. The efficiency factor, C e f f , for different MATLAB-based sets of code and different space meshes with a fixed time step ( τ = 0.00125 ) .
hN C eff BELR C eff BERR C eff CN
0.22581.061.061.07
0.19781.221.231.27
0.0540861.911.821.97
0.02516,4062.352.392.48
0.012566,1423.012.952.98

Share and Cite

MDPI and ACS Style

Reddy, G.M.M.; Seitenfuss, A.B.; Medeiros, D.d.O.; Meacci, L.; Assunção, M.; Vynnycky, M. A Compact FEM Implementation for Parabolic Integro-Differential Equations in 2D. Algorithms 2020, 13, 242. https://doi.org/10.3390/a13100242

AMA Style

Reddy GMM, Seitenfuss AB, Medeiros DdO, Meacci L, Assunção M, Vynnycky M. A Compact FEM Implementation for Parabolic Integro-Differential Equations in 2D. Algorithms. 2020; 13(10):242. https://doi.org/10.3390/a13100242

Chicago/Turabian Style

Reddy, Gujji Murali Mohan, Alan B. Seitenfuss, Débora de Oliveira Medeiros, Luca Meacci, Milton Assunção, and Michael Vynnycky. 2020. "A Compact FEM Implementation for Parabolic Integro-Differential Equations in 2D" Algorithms 13, no. 10: 242. https://doi.org/10.3390/a13100242

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop