10-Introducing The Finite Element Method in Electromagnetics To Undergraduates Using MATLAB PDF
10-Introducing The Finite Element Method in Electromagnetics To Undergraduates Using MATLAB PDF
Abstract This paper shows how electrical engineering undergraduates can acquire a working
knowledge of the finite element method (FEM) within a short period of time using MATLAB. For
simplicity, only first-order triangular elements are considered. The scalar wave equation for
homogeneous isotropic waveguides is used for introducing the FEM. Simple waveguide problems,
including a design problem, are discussed as examples. It is shown how the knowledge acquired can
be extended to other electromagnetic problems.
Keywords electromagnetic field computation; finite element method; first order triangular element;
MATLAB
The availability of immense and cheap computing power on desktop or laptop com-
puters has made the numerical solution of electromagnetic problems viable, even
for undergraduate students. Many educators have taken two approaches: use com-
mercially available software1 (which may be an expensive option), or design user
interfaces and simulation code2,3 based on existing programmable mathematical
packages. Neither of these constitutes the object of this paper. The aim of this paper
is similar to that reported in Ref. 4, which introduces the method of moments through
MATLAB.5 MATLAB has received worldwide acceptance in the teaching of many
engineering courses in, for example, signal processing and control engineering. It
will not be unreasonable for teachers in electromagnetics to expect students to have
a working knowledge of and access to MATLAB.
The Finite Element Method (FEM) is a well-established technique in electro-
magnetics and still generates considerable research. Several excellent texts and
monographs6–9 are available. They are suitable for researchers or for a complete
course on finite elements. Moreover, these texts often emphasise the rigorous
mathematical basis of various FEM formulations. Some also provide program
code.6,9 A practical approach to the derivation of the FEM and its implementation is
provided in Ref. 8. The object of this paper is to provide a brief hands-on under-
standing of FEM through MATLAB, as MATLAB provides powerful support for
matrix operations and dynamic memory allocation.
The material in this paper can be covered in a two-hour lecture. Students may be
given two weeks to absorb the material and carry out assignments similar to the
examples given in this paper.
It is noted that at least one commercial FEM software package, namely Femlab
3 from Comsol Inc.,10 has a version that runs as an add-on to MATLAB. It is not
suitable for teaching FEM programming. However, as illustrated in Ref. 11, students
can use this software to test variational formulations derived by them as the soft-
ware accepts variational formulations as input. Thus, Ref. 11 and this paper are com-
plementary if Femlab 3 is available.
FEM formulation
Introduction
For initiating students to the FEM through MATLAB, the scalar wave equation for
a homogeneous isotropic medium is chosen. The equation is written as:
∇ 2f + k 2f = 0 (1)
2
where k is the eigenvalue.
The scalar wave equation has many applications. In the context of electromag-
netics, the scalar wave equation can be used to analyse problems such as the
propagation of plane waves, TE and TM modes in waveguides,12 weakly guiding
optical fibers,13 etc. Moreover, by setting k = 0 in the FEM formulation of eqn (1),
one can also illustrate the FEM solution of electrostatic problems.
The FEM solves eqn (1) by minimisation of a corresponding functional given by:
1 ∂f ∂f
2 2
F(f ) = ∫∫ + − k 2f 2 ds (2)
2 s ∂ x ∂ y
where S represents the cross-sectional area of the waveguide, k2 = erk20 − kz2,
k0 = 2p/l0, l0 is the free space wavelength, er is the relative permittivity of
the medium and the field variation along the direction of propagation, z is taken as
e−jkzz. Students can be referred to Ref. 7 for methods for obtaining FEM functionals.
F(f ) = ∑ ∫∫ + − k 2f e2 ds (3)
e =1 Ae 2 ∂ x ∂ y
where e represents the element (triangle) number, Ne represents the total number of
elements and Ae represents the area of the element e over which the functions are
integrated.
The function fe at a point P(x,y) inside the triangle may be approximated as
f e = a + bx + cy + dx 2 + fy 2 + gxy + . . . .
For simplicity, we consider only linear terms:
f e = a + bx + cy (4)
φe1
(x 1, y 1)
1 y
x
Element e
P(x, y)
2
(x2, y 2) 3
φe2 (x 3, y 3)
φ e3
Triangles with fe expressed as linear functions are called first-order triangular ele-
ments. Fig. 1 shows a triangle where the values of coordinates and fe at the vertices
are shown.
Using the linear approximation in eqn (4), we can write
f e1 = a + bx1 + cy1 f e 2 = a + bx 2 + cy2 f e 3 = a + bx3 + cy3 .
Solution of these equations gives
3 3 3
a = ∑ aif ei b = ∑ bif ei c = ∑ cif ei
i =1 i =1 i =1
where the terms ui = ai + bix + ciy are also known as barycentric or area coordinates.
It may be noted that
3 3
∂f e ∂f e
= ∑ bif ei and = ∑ cif ei .
∂x i =1 ∂y i =1
Using row vectors fe = [fe1 fe2 fe3], u = [u1 u2 u3], b = [b1 b2 b3] and c = [c1 c2 c3],
(3) can be written as
1 Ne (bf et ) bf et + (cf et )
t t
where,
Pe = Ae{b t b + c tc} (6)
and
2 1 1
Ae
Qe = 1 2 1 . (7)
12
1 1 2
To obtain the matrix Qe, one uses the result provided in Ref. 8:
l! m! n! 2! Ae
∫∫ u u u ds =
l m n
1 2 3
(l + m + n + 2)!
.
Ae
Matrices with subscript e, obtained for triangle number e, are called local
matrices.
Coordinates of nodes
A file coord.txt which has two columns containing x coordinate in the first column
and y coordinate in the second, with rows arranged to correspond to node numbers
in ascending order.
where f = [f1 f2 . . . fNn], and P eg and Qeg are Nn × Nn square matrices, such that if p,
q and r are node numbers (1), (2) and (3) of triangle e, only nine matrix elements
of Peg and Qeg are nonzero: pp, pq, pr, qp, qq, qr, rp, rq and rr.
Equation (8) can be written as:
1
F(f ) =
2
[f P gf t − k 2f Q gf t ] (9)
Ne Ne
where P g = ∑ P eg and Q g = ∑ Qeg .
e =1 e =1
Pg and Qg are called global matrices. The global matrices are thus obtained
by adding the local matrices written as Nn × Nn square matrices. This operation is
easily carried out by the following MATLAB program (explained by comments
following %).
for e=1:ne;
% Get the three node numbers of triangle number e
node=[element(e,:)];
% Get the coordinates of each node and form row vectors
x=[coord(node(1),1),coord(node(2),1),coord(node(3),
1)];
y=[coord(node(1),2),coord(node(2),2),coord(node(3),
2)];
% Calculate the local matrix for triangle number e
[pe,qe]=triangle(x,y);
% Add each element of the local matrix to
% the appropriate element of the global matrix
for k=1:3;for m=1:3;
pg(node(k),node(m))=pg(node(k),node(m))+pe(k,m);
qg(node(k),node(m))=qg(node(k),node(m))+qe(k,m);
% Close the three for loops
end;end;end;
The finite element solution is obtained by minimising the functional in (10) with
respect to the nodal values, i.e., by setting
∂ F(f )
= 0 for k = 1, 2, . . . Nn .
∂f k
Thus
1 Nn g 1 Nn
∑
2 i =1
( Pik + Pkig )f i − k 2 ∑ (Q ikg + Q gki )fi = 0.
2 i =1
Since the matrices are symmetrical, this becomes
Nn Nn
∑ Pikgfi − k 2 ∑ Qikgfi = 0
i =1 i =1
or in matrix form,
P gf t − k 2 Q gf t = 0. (11)
Now one has to implement boundary conditions. Only perfectly conducting bound-
aries are considered here. The number of boundary nodes is denoted as Nb.
As before, the eigenvalue equation is solved, but this time with the reduced
matrices obtained with the above procedure.
TABLE 1 Values of k2 (in cm−2) for TEmn modes (analytical values in brackets)
n
m 0 1 2
TABLE 2 Values of k2 (in cm−2) for TMmn modes (analytical values in brackets)
n
m 1 2 3
TABLE 3 Values of k2 (in cm−2) for TEmn modes (analytical values in brackets)
n
m 0 1 2
TABLE 4 Values of k2 (in cm−2) for TEmn modes (analytical values in brackets)
n
m 1 2 3
Fig. 2 Single ridge waveguide TE10 mode cut-off wavelength a = 2.286 cm and b/a = 0.45.
Dots represent values calculated by FEM.
Fig. 3 Single ridge waveguide TE30 mode cut-off wavelength a = 2.286 cm and b/a = 0.45.
Dots represent values calculated by FEM.
Electrostatic problems
The functional for Laplace’s equation is:
1 ∂f 2 ∂f 2
F(f ) =
2 ∫∫
e 0 r
e + ds
S ∂ x ∂ y
where f represents the electric potential. e0 is the permittivity of free space and er
is the dielectric constant.
For homogeneous isotropic media, it is easy to see that the FEM equation is
Pgf t = 0, the matrix P g being the same as that in Section II.D.
Two boundaries are considered here. The mesh data should have two sets of
boundary nodes. We can take f = 0 at one boundary. For nodes on this boundary,
the corresponding rows and columns of P g are deleted. For the other boundary,
f = V, a numerical value. The rows of P g corresponding to nodes on this boundary
are deleted as before. However the column corresponding to each node is multiplied
by −V and put as a separate matrix. The matrices are added together to form the
matrix R. Next the columns are deleted from P g to get the reduced matrix P.
The FEM equation is now of the form Pf t = R which can be solved for f t using
Matlab.
e =1
l 0
and
Ne
Q g = − ∑ Q eg .
e =1
Conclusion
It is shown how the FEM can be introduced to electrical engineering undergradu-
ates using only a few lines of MATLAB code. The MATLAB codes relate directly
to the FEM operations. Four waveguide examples are given. These examples can be
run on a standard PC. A design example illustrated the advantage of FEM compared
to an analytical method. It was also shown how the concepts acquired can be readily
extended to other problems. The demonstrated problems are 2D in nature. However,
similar programming techniques can be employed for more complex problems, such
as 3D problems presented, for example, by Silvester and Ferrari.6 Institutions with
inadequate financial resources may benefit from the proposed methodology, as only
MATLAB is needed, no add-ons (not even a mesh generator). The material presented
in this paper may also be useful to beginning research students who are uninitiated
in the FEM.
Acknowledgement
The author thanks Mr Duen Hong Ong, an undergraduate, for the results given in
Section III.
References
1 J. Lu and D. V. Thiel, ‘Computational and visual electromagnetics using an integrated program-
ming language for undergraduate engineering students’, IEEE Trans. Magnetics, 36 (2000),
1000–1003.
2 S. Selleri, ‘A Matlab experimental framework for electromagnetic education’, IEEE Antennas and
Propagat. Mag., 45 (2003), 85–90.
3 S. Selleri, ‘A Matlab application programmer interface for educational electromagnetics’ in
Antennas and Propagat. Soc. Symp, 22–27 June, 2003.
4 S. Makarov, ‘MoM antenna simulations with Matlab RWG basis functions’, IEEE Antennas and
Propagat. Mag., 43 (2001), 100–107.
5 MATLAB, The Math Works Inc., http://www.mathworks.com
6 P. P. Silvester and R. L. Ferrari, Finite Elements for Electrical Engineers (Cambridge University
Press, Cambridge, 1990).
7 J. Jin, The Finite Element Method in Electromagnetics (John Wiley and Sons, New York, 1993).
8 S. R. H. Hoole, Computer-Aided Design of Electromagnetic Devices (Elsevier, New York,
1989).
9 T. Itoh, G. Pelosi and P. P. Silvester, Finite Element Software for Microwave Engineering (John
Wiley and Sons, New York, 1996).
10 K. Foster, ‘Retaking the field – an old computational favourite is overhauled’, IEEE Spectrum, July
(2004), 54–55.
11 L. Y. Tio, A. A. P. Gibson, B. M. Dillon and L. E. Davis, ‘Weak form finite element formulation for
Helmholtz equation’, Int. J. Elect. Enging. Educ., 41 (2004), 1–9.
12 S. Ramo, J. R. Whinnery and T. Van Duzer, Fields and Waves in Communication Electronics (John
Wiley, New York, 1994).