Introducing The Boundary Element Method With MATLAB
Introducing The Boundary Element Method With MATLAB
To cite this article: Keng-Cheng Ang (2008) Introducing the boundary element method with
MATLAB, International Journal of Mathematical Education in Science and Technology, 39:4, 505-519,
DOI: 10.1080/00207390701722676
Taylor & Francis makes every effort to ensure the accuracy of all the information (the
“Content”) contained in the publications on our platform. However, Taylor & Francis,
our agents, and our licensors make no representations or warranties whatsoever as to
the accuracy, completeness, or suitability for any purpose of the Content. Any opinions
and views expressed in this publication are the opinions and views of the authors,
and are not the views of or endorsed by Taylor & Francis. The accuracy of the Content
should not be relied upon and should be independently verified with primary sources
of information. Taylor and Francis shall not be liable for any losses, actions, claims,
proceedings, demands, costs, expenses, damages, and other liabilities whatsoever or
howsoever caused arising directly or indirectly in connection with, in relation to or arising
out of the use of the Content.
This article may be used for research, teaching, and private study purposes. Any
substantial or systematic reproduction, redistribution, reselling, loan, sub-licensing,
systematic supply, or distribution in any form to anyone is expressly forbidden. Terms &
Conditions of access and use can be found at http://www.tandfonline.com/page/terms-
and-conditions
International Journal of Mathematical Education in
Science and Technology, Vol. 39, No. 4, 15 June 2008, 505–519
CLASSROOM NOTES
Introducing the boundary element method with MATLAB
Keng-Cheng Ang*
The boundary element method provides an excellent platform for learning and
Downloaded by [Marshall University] at 00:51 02 November 2013
1. Introduction
In many universities all over the world, the mathematical software MATLAB is being
introduced to first year undergraduates pursuing engineering, science or mathematics
courses. In fact, successful integration of MATLAB into mathematics or engineering
mathematics courses have been frequently reported. For example, Dunn and Harman
exploited the Graphics User Interface (GUI) features of MATLAB in designing programs
to help students learn calculus [1]. Colgan reported the successful use of MATLAB in the
teaching of core mathematics to first year engineering students [2]. More recently,
Tonkes et al. managed to overcome several inherent difficulties involved in using
MATLAB for numerical analysis to develop an innovative learning model for
computational mathematics for their first year students [3].
Regarded as the language for technical computing, MATLAB has also been widely
used by researchers in industrial and applied mathematics, as well as engineers, scientists
and economists. One main reason for its popularity appears to be its efficiency in dealing
with matrices and matrix algebra. In addition, the availability of special purpose toolboxes
(such as Signal Processing, Optimization and Financial Toolboxes) has made it easier for
researchers to use MATLAB in their work.
The boundary element method (or BEM) is a computational tool that has been used in
many areas of applied science and engineering. For example, the BEM has been applied to
*Email: [email protected]
solve problems involving the Schrödinger equation [4] and diffusion equation [5]. The
BEM, however, is not introduced in undergraduate courses as frequently as other
numerical methods such as finite difference or finite element methods. The main reason for
this seems to be the fact that the BEM appears to be more complex to implement on the
computer.
Davies and Crann [6] have proposed using a spreadsheet such as Excel to introduce the
BEM to undergraduates, and have developed a reasonably sound but fairly complex
method of implementing it on Excel. While it is true that the spreadsheet may be a popular
tool for teaching numerical methods, it also has its limitations. For instance, construction
and manipulation of matrices are not the strengths of a typical spreadsheet software.
Moreover, changes in values of parameters (such as number of boundary elements and
hence sizes of the matrices and vectors) are not well handled by a spreadsheet nor are they
convenient to make. Of course, one could use the Visual Basic Application (VBA) features
Downloaded by [Marshall University] at 00:51 02 November 2013
provided in Excel to overcome these difficulties, but this would require a fairly
sophisticated level of programming skill and defeats the purpose of using the spreadsheet
in the first place.
In contrast, a tool such as MATLAB provides the perfect platform and environment
for a numerical method such as the BEM, which typically involves matrix computations.
The ‘trade-off ’ (if it may be deemed as such), is that one has to contend with
having to learn some programming. Nevertheless, as we shall demonstrate in this
article, the level of programming skills required will be no higher than that required if
VBA or FORTRAN were used. Moreover, MATLAB has user-friendly built-in
graphical output display features which can be very useful in the post-processing phase
of the BEM.
In this article, we shall illustrate the implementation of the BEM using MATLAB.
We shall restrict our discussion to the solution of the two-dimensional Laplace’s equation
with given Dirichlet or Neumann or mixed boundary conditions. For a more detailed
discussion on the origins and development of the method, the reader may wish to refer to
books listed in the references such as [7], [8] and [9]. We shall also assume that the reader
has a basic knowledge of MATLAB programming, although the reader may also wish to
consult a standard text on MATLAB such as [10].
2. Laplace’s equation
One of the most convenient ways to introduce the BEM is through studying the solution of
the two-dimensional Laplace’s equation
@2 u @2 u
r2 u ¼ þ ¼ 0, for ðx, yÞ 2 R, ð1Þ
@x2 @y2
@u
and q ¼ ¼ gðx, yÞ for ðx, yÞ 2 C , ð3Þ
@n
International Journal of Mathematical Education in Science and Technology 507
Cα
Cβ
n
P
R
n
Cε
where R is a two-dimensional region in the x–y plane bounded by a simply closed curve
C ¼ C [ C , as shown in Figure 1.
A fundamental solution of Laplace’s equation in two dimensions is given by [11]
1
u ¼ ln ðx Þ2 þ ðy Þ2 : ð4Þ
4
We note that u* satisfies Laplace’s equation (1) everywhere in the region R except at point
P(, ) where it has a singularity. However, if we consider a region R C", where C" is a
small circle containing and centred at P(, ), then u* is defined and r2 u ¼ 0 in this region
(Figure 2).
Applying Green’s second identity for R C", we obtain
Z Z Z
2 2
@u @u
ur u u r u d ¼ u u ds: ð5Þ
RC" CþC" @n @n
Clearly, the left hand side of the above equation is zero, and we thus have
Z
@u @u
u u ds ¼ 0, ð6Þ
CþC" @n @n
508 Classroom Notes
C ’ C1 [ C2 [ C3 [ [ CN
as illustrated in Figure 3. We construct these segments by choosing N points, say (x1, y1),
(x2, y2), . . . , (xN, yN) on the boundary, and we define (xNþ1, yNþ1) ¼ (x1, y1). Then, Ck is
the straight line joining (xk, yk) to (xkþ1, ykþ1). These straight line segments Ck for
k ¼ 1, 2, . . . , N are known as boundary elements.
International Journal of Mathematical Education in Science and Technology 509
CN
C1
C2
C3
Downloaded by [Marshall University] at 00:51 02 November 2013
For simplicity and convenience, we assume that values of u and @u=@n are constant over
each boundary element. More specifically, we take the values at the midpoints of each
element to be the values over the whole element. That is, for k ¼ 1, 2, . . . , N,
@u
u u k , and qk for ðx, yÞ 2 Ck ,
@n
where u k and q k are values of u and @u=@n at the midpoint ðx k , y k Þ of boundary element Ck.
Using this set-up for the boundary, we can write Equation (8) as an approximation
given by
X
N
uð, Þ ¼ ðu k Gk ð, Þ q k Fk ð, ÞÞ ð10Þ
k¼1
where
Z
Fk ð, Þ ¼ u ð, Þds ð11Þ
Ck
Z
@u ð, Þ
Gk ð, Þ ¼ ds ð12Þ
Ck @n
If we know u k and q k , then we can use Equation (10) to find the values of u(, ) for
ð, Þ 2 R. However, in a properly posed boundary value problem, either u k or q k (but not
both) is known on any given portion of the boundary.
We can, however, make use of Equation (10) to first find approximations to these
unknown boundary values, before using it again to approximate the values at the interior
points. To do so, we let (, ) be the midpoint of element Ck for k ¼ 1 to N, thus obtaining
N equations with N unknowns. Noting that when (, ) is on Ck, ¼ 1/2, we have
1 XN
u m ¼ ðu k Gk ðx m , y m Þ q k Fk ðx m , ym ÞÞ for m ¼ 1, 2, . . . , N, ð13Þ
2 k¼1
where um ¼ ð1=4Þ lnððx x m Þ2 þ ðy y m Þ2 Þ and ðx m , ym Þ is the midpoint of element Cm.
510 Classroom Notes
To solve for the unknowns, it is convenient to write the equations given in (13) as a
system of equations in the form of Az ¼ b. The unknowns are either u or q and are the
elements in z with associated coefficients stored in matrix A b is made up of all the known
values. What needs to be done is to construct the matrix A and the column vector b, and to
keep track of the type of boundary value in each of the elements of z. In other words, for
each m ¼ 1, 2, . . . , N, we need to construct
X
N X
N
Amk zk ¼ bmk ð14Þ
k¼1 k¼1
We construct A and b systematically by considering the two cases, namely (a) when u is
given, and (b) when q ¼ @u=@n is given over the boundary Ck, for each equation
(m ¼ 1, 2, . . . , N) in (13).
For each m (that is, each row in the matrix equation), we need to find the Amk entry,
Downloaded by [Marshall University] at 00:51 02 November 2013
and the contribution bmk to the element in b by running through each boundary element Ck.
If, over a boundary element Ck, u is known, then q is the unknown and the element in A is
given by Amk ¼ Fk ðx m , y m Þ. The contribution to the corresponding element in b is either
u k Gk ðx m , y m Þ if k 6¼ m, or u k Gk ðx m , y m Þ þ 1=2um if k ¼ m.
On the other hand, if q is known over a boundary element Ck, then the contribution
to b is q k Fk ðx m , ym Þ. The element in A is either Gk ðx m , y m Þ if k 6¼ m, or Gk ðx m , y m Þ 1=2
if k ¼ m.
In summary, we have the following ‘rules’ for the construction of matrix A and
vector b:
8
> Fk ðx m , y m Þ if u given over Ck
>
<
Amk ¼ Gk ðx m , ym Þ if q given over Ck and k 6¼ m ð15Þ
>
> 1
: Gk ðx m , ym Þ if q given over Ck and k ¼ m
2
8
< q k Fk ðx m , y m Þ
> if q given over Ck
bmk ¼ u k Gk ðx m , ym Þ if u given over Ck and k 6¼ m ð16Þ
>
: 1
u k Gk ðx m , y m Þ þ 2 if u given over Ck and k ¼ m
Once A and vector b are formed, we can solve for z, bearing in mind that zk ¼ qk if u is
given over Ck, and zk ¼ u k if q is given over Ck.
When all the values on the boundary are known, we can then use Equation (10) to
obtain values at any interior point in the domain R.
4. Matlab implementation
It is clear from the preceding discussion that a method such as the BEM would best be
implemented with a tool that can perform matrix computations efficiently, carry out
numerical integration conveniently, and produce graphical output if desired. MATLAB is
one such tool that can do all of these with a simple set of code. In this section, we outline
the implementation of the method using a MATLAB program.
It is useful to divide the MATLAB program into three distinct stages or phases, namely
Pre-processing, Processing and Post-processing. At each stage, some input is required and
the outcome is some information or output.
International Journal of Mathematical Education in Science and Technology 511
4.1. Pre-processing
During Pre-processing, the program reads in information on the boundary elements from
a text file. The file contains the coordinates of the node points of the boundary elements,
and the types and values of boundary conditions. At this stage, we also compute the
coordinates of all the midpoints and the lengths of each boundary element, as well
as the unit normal vectors to each element. These are the information needed for the next
two stages.
4.2. Processing
The Processing phase mainly consists of setting up the matrices required to find
approximations to the unknown boundary values. We follow the rules given by (15) and
(16). Once the matrix A and column vector b are constructed, we can solve for z and then
Downloaded by [Marshall University] at 00:51 02 November 2013
Since the integration will have to be performed again in the Processing phase, it is
convenient to write a simple function, which calls the quadl function. In the current
implementation, this function is given the name findfg, which simply evaluates the
integrals Fk and Gk when k 6¼ m.
4.3. Post-processing
In the Post-processing phase, we essentially use Equation (10) again to find values of u at
interior points. We can choose to accept choices of interior points (, ) from the user
interactively and respond with the approximate value of u(, ) using (10). We could also
choose a specific set of points in R and find u at these points.
With MATLAB, however, we can exploit the graphical output features and generate
a surface plot or contour plot of the approximate solution. This will give a better physical
interpretation for the solution of the problem. In the current implementation,
Downloaded by [Marshall University] at 00:51 02 November 2013
we have chosen this way of post-processing and the code given in the Appendix is fairly
self-explanatory.
5. Examples
In this section, we examine two examples to illustrate the use of the MATLAB program.
5.1. Example 1
Consider the following problem.
r2 u ¼ 0 for 0 < x < 1, 0 < y < 1,
subject to the boundary conditions
u¼0
on x ¼ 0, for 0 < y < 1,
u ¼ cosðyÞ
@u
q¼ ¼ 0 on y ¼ 0 and y ¼ 1 for 0 < x < 1:
@n
It can easily verified that the exact solution for this problem is
sinhðxÞ cosðyÞ
u¼ :
sinhðÞ
To use the MATLAB program, we need to provide the necessary input information,
stored in a file called ‘input. dat’. This input file has four columns; the first two
columns are the x and y coordinates of the boundary node points, and the third and fourth
columns contain the corresponding boundary condition type and boundary values
respectively.
In this example, the domain is a square. For simplicity, we shall choose equally spaced
out points along the sides. Suppose we have four boundary elements, each of length 0.25,
on each of the four sides. The boundary node points and their midpoints are shown in
Figure 4(b) below.
Note that when labelling boundary node points and elements, it is conventional to go
in a counterclockwise direction. In the figure above, the node point (0, 0) is labelled as ‘1’,
(0.25, 0) is labelled as 2 and so on. The first boundary element is from node point 1 to node
International Journal of Mathematical Education in Science and Technology 513
(a) (b) 1
13 12 11 10 9
0.00 0.00 1 0.0000
0.25 0.00 1 0.0000 0.9
0.50 0.00 1 0.0000
0.8
0.75 0.00 1 0.0000
1.00 0.00 0 0.9239 14 8
0.7
1.00 0.25 0 0.3827
1.00 0.50 0 -0.3827 0.6
1.00 0.75 0 -0.9239
1.00 1.00 1 0.0000 0.5 15 7
0.75 1.00 1 0.0000
0.50 1.00 1 0.0000 0.4
0.25 1.00 1 0.0000
0.00 1.00 0 0.0000 0.3
0.00 0.75 0 0.0000 0.2
16 6
0.00 0.50 0 0.0000
0.00 0.25 0 0.0000 0.1
0.00 0.00
Downloaded by [Marshall University] at 00:51 02 November 2013
0
1 2 3 4 5
0 0.2 0.4 0.6 0.8 1
Figure 4. Input data and plot of boundary nodes (o) and midpoints of boundary elements (x).
point 2. In this example, there are 16 node points. However, when setting up the input file,
we need to include the 17th node point, which coincides with node point 1. Hence there
are 17 pairs of coordinates in this case.
The next two columns contain the boundary condition type and values. We denote the
Dirichlet boundary condition (i.e. u given) by the value 0 and the Neumann boundary
condition (i.e. q given) by the value 1. This is followed by the actual boundary value at the
midpoint of the boundary element, beginning from element 1 to element 16.
Using the input file and running the program in the usual way on MATLAB, a surface
plot of the solution is obtained. This is shown in Figure 5 below.
Although the solution is presented here as a surface plot, it will not be difficult to
modify the Post-processing portion of the program to find approximate values at specified
points or along a chosen line within the domain. For instance, the values of u along the line
x ¼ 0.8 are found using the BEM and plotted with the exact solution in Figure 6 below.
5.2. Example 2
Consider the following problem where the domain is a quarter-circle.
u ¼ y on x ¼ 0, for 05y51,
u ¼ x þ y on x þ y2 ¼ 1, for x40 and y40,
2
@u
q¼ ¼ 1 on y ¼ 0 for 05x51:
@n
514 Classroom Notes
0.9
0.8
0.7
0.6
0.5
y
0.4
0.3
0.2
0.1
Downloaded by [Marshall University] at 00:51 02 November 2013
0
0 0.2 0.4 0.6 0.8 1
x
Figure 5. Surface plot of solution for example 1.
0.6
0.4
0.2
0
u
0.2
0.4
0.6
0.8
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
y
Figure 6. Approximate (o) and exact values (solid line) of u along x ¼ 0.8 for example 1.
y
0.862
0.4 14 0.4 0.68
0.3 7 0.3 0.498
0.2 15 0.2 0.316
0.1 0.1 0.135
0 0
1 2 3 4 5 6 0 0.2 0.4 0.6 0.8 1
0 0.2 0.4 0. 6 0.8 1
x
Downloaded by [Marshall University] at 00:51 02 November 2013
In this case, solution is presented as a contour plot shown in Figure 7(b). As can be
seen, the contour plot shows a series of (almost) straight lines of the form x þ y ¼ constant,
which essentially describes the exact solution.
6. Conclusion
The boundary element method is an important computational tool used by researchers in
many fields such as the physical and engineering sciences. The main advantage of the BEM
over other numerical methods for partial differential equations is the fact that only the
boundary of the domain needs to be discretized. If one were to use the finite difference or
finite element methods, the domain of the problem must be divided into computational
cells. In fact, in many applications of such methods, much time and computational effort
are spent on generating the computational grids. Sometimes, the choice of the number, type
and position of these grids or cells may have significant impact on the accuracy or efficiency
of the methods. Such a problem does not arise in the BEM as grid generation is not needed.
In this article, we have demonstrated a simple way of implementing the BEM using a
mathematical tool, MATLAB. Although other tools are possible, we have shown the ease
at which the BEM can be introduced to a newcomer to the field very quickly using the
program developed and described here.
The BEM is an interesting and useful numerical method. Students should not be put
off by it simply because they feel challenged by the daunting task of having to write
complicated programs to implement it. With MATLAB, the method can be presented in a
non-threatening way, along with results that can give a physical interpretation and
meaning to the problem.
References
[1] P. Dunn and C. Harman, Calculus demonstrations using Matlab, Int. J. Math. Edu. Sci. and
Technol. 33 (2002), pp. 584–596.
[2] L. Colgan, Matlab in first-year engineering mathematics, Int. J. Math. Edu. Sci. and Technol. 31
(2000), pp. 15–25.
516 Classroom Notes
[3] E. Tonkes, B. Loch, and A. Stac, An innovative learning model for computation in first year
mathematics, Int. J. Math. Edu. Sci. and Technol. 36 (2005), pp. 751–759.
[4] W.T. Ang and K.C. Ang, A dual-reciprocity boundary element solution of a generalized non-
linear Schrödinger equation, Numer. Methods Partial Differential Equations 20 (2004),
pp. 843–854.
[5] W.T. Ang, K.C. Ang, and M. Dehghan, The determination of a control parameter in a
two-dimensional diffusion equation using a dual-reciprocity boundary element method, Int. J.
Comp. Math. 78 (2003), pp. 65–74.
[6] A. Davies and D. Crann, The boundary element method on a spreadsheet, Int. J. Math. Edu. Sci.
and Technol. 29 (1998), pp. 851–865.
[7] C.A. Brebbia and J. Dominguez, Boundary Elements: An Introductory Course, 2nd ed.,
McGraw-Hill, Southampton, 1992.
[8] W.S. Hall, The Boundary Element Method, Kluwer, London, 1994.
[9] M.A. Jaswon and G.T. Symm, Integral Equation Methods in Potential Theory and Elastostatics,
Academic Press, London, 1997.
[10] A. Knight, Basics of MATLAB and Beyond, CRC Press, Boca Raton, 2000.
Downloaded by [Marshall University] at 00:51 02 November 2013
[11] P.K. Kythe, An Introduction to Boundary Element Methods, CRC Press, Boca Raton, 1995.
Main program:
%% Program to implement the Boundary Element Method for
%% the Laplace’s Equation with given boundary conditions
%% Author: Kengã Cheng Ang
%% ======================================================
Clear
% - - - - - Pre-processing - - - - -
% Read boundary coodinates, values and type of boundary condition
% from input file
Fid = fopen(’input.dat’,’r’);
Indat = fscanf (fid,’%g%g%d%g’, [4, inf]);
indat = indat’;
xb = indat (:,1);
yb = indat (:,2);
bt = indat (:,3);
bv = indat(:,4);
n = length (xb) 1;% n = number of elements
for i = 1:n
xm (i) = 0.5d0*(xb (i) + xb(i + 1));
ym (i) = 0.5d0*(yb(i) + yb(i + 1));
lm(i) = sqrt((xb(i + 1) xb(i))^2 d0 + (yb(i + 1) yb(i))^2 d0);
nx(i) = (yb(i + 1) yb(i))/lm (i);
ny(i) = (xb(i) xb (i + 1))/lm(i);
end
International Journal of Mathematical Education in Science and Technology 517
% - - - - - Processing - – - -
% Find approximations for unknown boundary values by
% – constructing matrix A and vector b
% – solving the system "Ax = b" for x
for m = 1:n
b(m) = 0d0;
for k = 1:n
if(k = = m)
G = 0.0;
F = lm(k)/(2.0*pi)*(log(1m(k)/2.0) 1.0);
del = 1.0;
Downloaded by [Marshall University] at 00:51 02 November 2013
else
[F, G] = findfg (xm(m), ym (m), xb (k), yb (k), nx (k), ny
(k), lm (k));
del = 0.0;
end
if (bt (k) = = 0)
A (m, k) = F;
b(m) = b(m) + bv(k)*( G + 0.5d0*del);
else
A(m, k) = G 0.5d0*del;
b(m) = b(m) + bv(k)*F;
end
end
end
z = A\b’;% solve system "Ax = b" and store in z
% Assign approximate boundary values accordingly
for m = 1:n
u (m) = (1 bt (m))*bv (m) + bt (m)*z(m);
q(m) = (1 bt (m))*z(m) + bt(m)*bv (m);
end
% - - - - - - Post-processing - - - - - -
% Find value(s) at required point (s)
for j = 1:99
y(j) = 0.01*j;
for i = 1:99
x(i) = 0.01*i;
s(j, i) = 0d0;
for k = 1:n
[F, G] = findfg (x (i), y (j), xb (k), yb (k), nx (k), ny (k),
lm (k));
s(j, i) = s(j, i) + u(k)*G q(k)*F;
end
end
end
figure(1)
518 Classroom Notes
% filename intf.m
function y = intf (t, xi, eta, xk, yk, nkx, nky, lk)
y = log ((xk t*lk*nky xi).^2 + (yk + t*lk*nkx eta).^2);
% filename intg.m
function y = intg(t, xi, eta, xk, yk, nkx, nky, lk)
y = (nkx*(xk t*lk*nky xi) + nky*(yk + t*lk*nkx eta)). . .
./((xk t*lk*nky xi).^2 + (yk + t*lk*nkx eta).^2);
International Journal of Mathematical Education in Science and Technology 519
1. Introduction
This paper first briefly describes the general process of formulating an inter disciplinary
project. The paper then discusses four main requirements of the project. Following the
description of each requirement is a detailed solution. The paper closes with a discussion
on the success of the project in the classroom.