You are on page 1of 4

3618 IEEE TRANSACTIONS ON MAGNETICS, VOL. 30. NO.

5, SEPTEMBER 1994
An Object-Oriented Finite-Element Program for
Electromagnetic Field Computation
E. J. Silva, R. C. Mesquita, R. R. Saldanha and P. F. M. Palmeira
Departamento deEngenhariaElCtrica - UniversidadeFederal deMinas Gerais
AV. do Contomo 842, Centro, Belo Horizonte, MG, 301 10, Brazil
Abstrud - The purpose of this paper i s to illustrate how the
concepts of object-oriented programming can be applied to the
finite element method, and to illustrate the advantages of this
approach. The basic concepts of the object-oriented
programming method are also presented. A 3-D magnetostatic
program that uses nodal elements and edge elements has been
developed and implemented using the C++ language.
INTRODUCTION
When it is necessary to change finite element programs
to implement a new formulation, a lot of adaptations must be
done. Even in well structured programs this task is not easily
peIfOtTIled.
Normally, it is necessary to change routines included in
large libraries, adapt data structures, etc. Some changes done
in some modules propagate through all the program
involving rewriting thousands of lines of code.
A new programming paradigm called object-oriented
programming (OOP) has been developed to modify this
situation. Its main purpose is to achieve portability,
reusability, reliability and ease of maintenance of complex
programs.
This paper describes the basic concepts on which the
object-oriented model is built. These concepts are applied to
develop a 3D magnetostatic finite element program. The
concept of the reusability is applied.
Nowadays several programming languages support the
object-oriented methodology, such as Smalltalk, that was the
first object-oriented programming language, C++, Object
Pascal and Eiffel. Each programming language is most
adapted to an area of application. For the finite element
analysis we choose the C++language because it is an object-
oriented extension of the C language that offers resources for
numerical analysis.
BASIC CONCEPTS OF OBJ ECT-ORIENTED PROGRAMMING
The OOP has received a lot of attention in the last few
years [1],[2],[3],[4]. It is based in the concepts of objects,
classes, methods, inheritance and polymorphism. The
concepts of class, object and method are presented in
this section. Inheritance and polymorphism are presented in
the next section that shows their importance in the finite
element program based in the object-oriented paradigm.
Objects are self-contained structures. They contain
attributes (data) and procedures (methods). This union of
data and methods which manipulate that data is called
encapsulation. The objects communicate with each other by
messages. When an object receives a message it interprets
that message and executes an action based on its nature.
A Class is a type defined by the programmer. Each object
is an instance of class. It is characterized by its name, its
attributes and the set of methods it implements. A graphical
representation of a class is shown in Fig. 1 [5]. Class-&-
Objects is an expression that means a class and the objects
that belong to it, Fig. 1 (a). A class like the one in Fig. 1 @)
represents a special kind of class called abstract class. The
abstract class does not have objects.
A class in C++can be understood as an extension of the
structure concept of the C language. This extension supports
the use of member functions in classes. The layout of the
structures in C and C++is identical. So, such structures can
befreely used in the Same program.
The details of representation of data and methods can be
hidden using classes in such a way that only members of
class can have access to them. The keywords "private",
"protected" and "public" do this control in C++.
A class can have links with other classes, Fig. 2. This
link is applied to represent the concept of the inheritance. In
this case, the classes B and C are descendants of class A.
Note that the lines link the internal rectangle (the class).
Relationships between objects can also be shown
graphically as in Fig. 3. The purpose of this link is to
represent the fact that an object can bepart of the other. For
example, in the finite element method node is a part of
element.
Attributes
Methods
Attributea
Methods
(h)
Fig. 1. Graphical representation of Class-%-objects and Class.
Manuscript received November 1, 1993.
0018-9464/94$4.00 Q 1994 IEEE
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DE MINAS GERAIS. Downloaded on August 19, 2009 at 11:41 from IEEE Xplore. Restrictions apply.
3619
Fi g 2. Relationship between classes
4
Fig. 3. Relationship between objects
In C++ Methods are called member functions. The
definition of a member function is done in the body of its
class. These methods operate on the values of instance
variables stored with the object. The methods are activated
by a message. Given a message, a class searches its protocol
for the corresponding function.
INHERITANCE AND POLYMORPHISM
Inheritance is a mechanism that permits to express the
common characteristics among classes. This simplifies the
definition of classes that are similar to other existent ones.
The descendant inherits automatically all the data and
methods of its ancestor. Inheritance is one of the most
important forms of the reusability of codes in OOP.
Polymorphism is the ability of using the name of a
function to represent different implementations of it. In C++
virtual functions implement this concept.
These two concepts will be illustrated in this section
using an element class that will belong to a finite element
program.
All kinds of element of a mesh have in its definition an
array of nodes and one material that fulfills it. Then any
type of element can inherit these data. Also every element
must have a method that computes its local matrix. For each
type of element the code that implements this computation
will be different. This is a typical application for the concept
of virtual functions as will be seen in the sequence. The class
Element is defined as:
class Element
{ //An abstract class
protected:
//Attributes
int material;
int num-nodes;
int num-edges;
IntVector nodes;
IntVector edges;
char *potential;
//Constructor
Elemenqint nnod, int nedg):edges(nedg),nodes(nnod) {
public:
num-nodes=nnod;
num-edges=nedg ;
potenciahew char[ I];}
//member functions
virtual Matrix calc-k-local(Nadetree *pnt)=O;
1
In fact, t hi s class is an abstract class because it has a pure
virtual function, that is, function without body. So there are
no objects of this class. At first sight, it seems that this class
has no use. However we can define its descendants
(subclasses) from it, and so it becomes a basic class.
The first specializations for Element are the Element-3d
and the Element-2d classes. The only specialization shown
here is the Element-3d.
class Element-3d:public Element
{
public:
//Constructor
Element_3d(int nnod, int nedg):Element(nnod,nedg){}
//member functions
virtual Matrix calc-k-local( . PO;
Matrix get-elem-xyz(Nodetree 'pnt);
1
Element-3d still is a generic form of an element. New
specializations can be derived. For example, hexahedral and
tetrahedral finite elements are widely used in 3-D. They are
the simplest shape of a 3-D elements
//Hexahedral element
class Element-3d-hex-Nod:public Element-3d
{
public:
//construe tor
Element-3d-hex-Nod():Element-3d(8,12) {1
//member functions
/i .. .
Matrix calc-k-local( . );
1
//Tetrahedral element
class Element-3d-tet-Nod:public Element-3d
{
public:
//constructor
Element-3d-tet-Nod():Element-3d(4,6) {}
//member function
//.. .
Matrix calc-k-local( . );
1
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DE MINAS GERAIS. Downloaded on August 19, 2009 at 11:41 from IEEE Xplore. Restrictions apply.
3620
These new classes are descendants of Element-3d and
therefore inherit the data and methods from their ancestors
(Element and Element-3d). Fig. 4 shows the hierarchy of
elements implemented in the program.
Element
e
Elem 3
9
Fig. 4 - Structure for a hierarchy of the elements.
The concept of polymorphism guarantees that the right
method will be invoked for each kind of element when
computing its local matrix.
OBJ ECT-ORIENTED FINITE ELEMENT PROGRAM
The project of an object-oriented software system
basically consists in the division of the program into classes
and the establishment of an appropriate hierarchy of classes.
The modular characteristic of the finite element method
permits the easy identification of these classes.
Initially the node seems to be just one of the varyous
attributes of the element. However in the object-oriented
philosophy it is interesting to define a class for nodes. This
class has as data a set of coordinates, the boundary
conditions and the number of degree of freedom.
The member functions of this class must include
functions for reading and writing the attributes of the node
in data file. Other functions are needed to attribute the
equation number associated to each degree of freedom.
In the previous section the implementation of the element
class was described. The implementation of the classes
Element-3d-hex-Nod and cd-k-local() method are now
presented. In these examples 8 noded brick elements are
used to solve a 3-D magnetic vector potential magnetostatic
problem [6].
class Element-3d-hex-Nod:public Element-3d
{
public:
//constructor
Element-3d-hex-Nod():Element-3d(8,12) {}
//member functions
Vector calc-func-n(double r, double s; double t),
Matrix calc-dv-n(double r; double s; double t);
Matrix jacobian(doub1er, double s; double t; Matrix & xe);
Matrix calc-rot-n(doub1e r, double s; double t; Matrix &jb);
Vector calc-div-n(double r; double s, double t; Matrix &jb);
Matrix calc-k-local(Ncdtree *pnt)
1
// computes local matrix
Matrix Element~3d~hex~Nod::calc~k~local(Nodetree *pn)
{
Matrix ke ( 24,24,0.); //initialize a matrix with zero
Matrix jb; //create a matrix wi thdefault dimension (3x3)
Matrix xe(8,3),
Matrix bw ( 3,24);
Vector bb(24);
double r,s,t
float nu, wijk;
int ij,k;
nu=material;
//coordinates matrix of the element
xe =get-elem-xyz(pn);
//loop for Gauss integration
for (i=O; i<npg; i++)
for 04; j<npg; j++)
for (k=O; k<npg; k++)
{
?gauss->point(i);
s=pgauss->pointCj);
t=pgauss->point( k);
jb==acobian(r,s,t,xe);
dj =talc-det.j b();
wijk=pgauss->weight(i)*
pgauss->weightCj )*pgauss->weight( k),
bw=calc-rot-n( r,s,tjb);
bb=calc-div-n(r,s.tj b)
ket=((bw.trans( )*bw ) +bb*bb.trans( ))*nu*wijk*dj;
1
return (ke);
1
The pgauss is a pointer to the objects of the class QGauss
that have the points and weights of the Gauss-Legendre
quadrature. This method involves manipulation of matrices.
A few classes to handle the basic matrix algebra were
developed. Methods for multiplication, addition, scaling and
transposition are supported by classes Vector and Matrix.
These methods include vector by vector, matrix by vector
and matrix by matrix operations.
The assembly of the global matrix is a method of the
class Sp-Matrix defined as a descendant of the matrix class.
The skyline storage scheme is used. To solve the systemof
equations the Cholesky method is applied.
The management of theobjects and the establishment of
the relationship between them are necessary to turn the
program functional. In this work, the organization of objects
in arrays was adopted. The management by array requires
the creation of a generic class that manipulates arrays of
objects [l]. In our case the class tree was defined. Methods
to initialize, to add, to remove and to find objects must be
created. So when a set of nodes is created it is stored in the
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DE MINAS GERAIS. Downloaded on August 19, 2009 at 11:41 from IEEE Xplore. Restrictions apply.
362 1
list node. Fig. 5 shows the graphic representation of the data
management. -
Fig. 5. Datamanagement
REUSABILITY - EXTENDING THE CODE FOR EDGE ELEMENTS
Rarely the reusability of a software is done efficiently in
procedural programs. The object-oriented programming can
offer considerable facilities for this purpose. In this section it
is described how the hexahedral edge elements [7] are
included in the program based in nodal elements.
In OOP the reusability can bedone in three main forms:
adding a specific method to an existent class, creating a new
class or creating a subclass.
The inclusion of edge element can be considered as a
modification of the functions of the class
Element-3d-hex-Nod. In this way it is reasonable to use the
concept of inheritance to create a subclass
Element-3d-hex-Edg derived from Element-3d-hex-Nod.
The new element can be defined as:
//hexahedral edgeelement
class Element-3d-hex-Edgpublic Element-3d-hex-Nod
public:
//constructor
Element_3dhex_Edg() : Element-3d-hex-Nod() {}
//member functions
IntVector assignLm(Edgetree *pd)
Vector assi@c(Edgtree *pd)
Matrix calc-func-wn(doub1e r; double s; double t;
Matrix &jb);
Matrix calc-rot-wn(double r, double s; double t;
Matrix &jb);
Matrix calc-k-local(Nodetree *pnt),
1
Suppose that el tqtr is a pointer loaded with
Element-3d-hex-Nod. When the instruction el tgtr-
>calc-K-local() is found it will execute the function
Element-3d-hex-Nod: :calc-k-local because el tqtr points to
Element-3d-hex-Nod. If in the next step the pointer is
loaded with Element-3d-hex-Edg, when the same
instruction is found the program will use
Element-3d-hex-Edg::calc-k-local(). What guarantees that
the correct function is used is the polymorphism discussed
previously. This decision is only made at run time and it is
called dynamic binding.
It should beemphasized that no line of the original code
was changed. Moreover, there is no necessity to know how
the codes of the basic class Elem_3d_hex_Nod, used by the
new class, were implemented.
CONCLUSIONS
The object-oriented programming was applied to design a
3D magnetostatic finite element program. Some details of
implementation, using C++, have been presented.
The concepts of inheritance and polymorphism were
illustrated using an element class applied to a finite element
analysis program.
Classes-&-objects and their relationship in the finite
element program were described.
The reusability of the software can be done efficiently. As
an example of this, the program based in nodal elements was
extended to include edge elements using inheritance.
Data encapsulation by objects prevents modifications in
specific points to afFect the rest of the program. Also during
program verification it is only necessary to validate the
methods of an object. This advantage favors the development
speed.
The general conclusion is that OOP can be used to
significantly improve finite element analysis programs
REFERENCES
[ l ] R. S. Weimer, L. J. Pinson, "An Introduction to Object-Oriented
programming and C++", New York: Addison-Wesley, 1988.
121 B. W. R. Fords, R. 0. Foschi and S. F. Steimer, "Object-oriented finite
element analysis", Compur. & Struct., Vol. 34, No. 3, pp. 355-374, 1990.
[3] T. Zimmemann, Y. D. Pblerin and P. Bomme,"Object-oriented finite
element programming: I Governing principles", Comput. Methods in Appl.
andMech. Engrg.. Vol98, No. 2, pp.291-303, 1992.
[4] Y. D. Pklerin, T. Zimmermann and P. Bomme,"Object-oriented f~te
element programming: I1 A prototype program in Smaltalk", Comput.
Methods in Appl. andMech.Engrg., Vol. 98, No. 3, pp. 361-397, 1992.
[SI C. Peter, E. Yourdon, "Object-Oriented analysis", Prentice Hall, 1992.
[6] S. R. H. Hoole, "Computer Aided Analysis and Design of
[7] k Bossavit, "A rationale for edge-elements in 3-D fields computations",
Elecfromagnetics Devices", New York: Elsevier, 1989.
IEEE Trans. Magn., Vol. 24, No.1, pp. 74-79, 1988.
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DE MINAS GERAIS. Downloaded on August 19, 2009 at 11:41 from IEEE Xplore. Restrictions apply.

You might also like