1994-IEEETransactionsOnMagneticsObjectOriented

download 1994-IEEETransactionsOnMagneticsObjectOriented

of 4

Transcript of 1994-IEEETransactionsOnMagneticsObjectOriented

  • 8/10/2019 1994-IEEETransactionsOnMagneticsObjectOriented

    1/4

    3618 IEEE TRANSACTIONSON MAGNETICS, OL. 30. NO. 5, SEPTEMBER1994

    An Object-Oriented Finite-Element Program forElectromagnetic Field Computation

    E. J. Silva, R. C. Mesquita, R. R. Saldanha an d P. F.M. PalmeiraDepartamento de EngenhariaElCtrica - Universidade Federal de Minas Gerais

    AV. do Contomo842, Centro, Belo Horizonte,MG 301 10, Brazil

    bstrud The purpose of this paper i s to illustrate how theconcepts of object-oriented programming can be applied to thefinite element method, and to illustrate the advantages of thisapproach. The basic concepts of the object-orientedprogramming method are also presented. A 3 D magnetostaticprogram that uses nodal elements and edge elements has beendeveloped and implemented using the C language.

    INTRODUCTION

    When it is necessary to change finite element programsto implement a new formulation, a lot of adaptations mustbedone. Even in well structured programs this task is not easilypeIfOtTIled.

    Normally, it is necessary to change routines included inlarge libraries, adap tdata structures, etc. Some changes don ein some modules propagate through all the programinvolving rewriting thousandsof lines of code.

    A new programming paradigm called object-orientedprogramming (OOP) has been developed to modify thissituation. Its main purpose is to achieve portability,reusability, reliability and easeof maintenance of complexprograms.

    This paper describes the basic concepts on which theobject-oriented modelis built. These concepts are applied todevelop a 3D magnetostatic finite element program. Theconcept of the reusability is applied.

    Nowadays several programming languages support theobject-oriented methodology, such a s Smalltalk, that was thefirst object-oriented program ming language, C+ +, ObjectPascal and Eiffel. Each programming language is mostadapted to an area of application. For the finite elementanalysis we choose theC++ language because it is an object-oriented extension of the C languagethat offers resources fornumerical analysis.

    BASIC CONCEPTSOF OBJECT-ORIENTEDROGRAMMING

    The OOP has received a lot of attention in the last fewyears [1],[2],[3],[4]. It is based in the concepts of objects,classes, methods, inheritance and polymorp hism. Theconcepts of class, object and method are presented in

    this section. Inheritance an d polymorphism are presented inthe next section that shows their importance in the finiteelement program based in the object-oriented paradigm.

    Objects are self-contained structures. They containattributes (data) and procedures (methods). This unionofdata and methods which manipulate that data is calledencapsulation. The objects communicate with each other bymessages. When an object receivesa message it interpretsthat m essage and executes an action based on its nature.

    A Class is a type defined by the program mer. Ea ch objectis an instance of class. It is characterized by its name, itsattributes and the set of methods it implements. A graphicalrepresentation of a class is shown inFig. 1 [5]. Class-&-Objects is a n expression that means a class and the objectsthat belong to it,Fig. 1 (a). A class like the one inFig. 1 @represents a special kind of class called abstract class. Theabstract classdoes not have objects.

    A class in C++ can be understood asan extension of thestructure conceptof the C language. This extension supportsthe use of member functions in classes. The layout of thestructures in C a ndC++ is identical. So, such structures canbe freely used in the Same program.

    The details of representation of data and methods canbehidden using classes in such a way that only membersofclass can have access to them. Th e keywords private ,protected and public do this control inC++.

    A class can have links with other classes,Fig. 2. Thislink is applied to represent the co ncept ofthe inheritance. In

    this case, the classesB and C are descendants of classA.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 torepresent the fact that an object canbe part of the other. Forexample, in the finite element method node is a part ofelement.

    Attributes

    Methods

    Attribute

    Methods

    h)

    Fig. 1. Graphicalrepresentation of Class- -objects and Class.Manuscript received November 1 1993.

    0018-9464/94 4.00 1994 EEE

    Authorized licensed use limited to: UNIVERSIDADE FEDERAL DE MINAS GERAIS. Downloaded on August 19, 2009 at 11:41 from IEEE Xplore. Restrictions apply.

  • 8/10/2019 1994-IEEETransactionsOnMagneticsObjectOriented

    2/4

    3619

    F i g 2. Relationship between classes

    Fig. 3. Relationship between objects

    In C++ Methods are called member functions. Thedefinition of a member function is done in the body of itsclass. These methods operate on the values of instancevariables stored with the object. The methods are activatedby a message. Given a message, a class searches its protocolfor the corresponding function.

    INHERITANCEAND POLYMORPHISM

    Inheritance is a mechanism that permits to express thecommon characteristics among classes. This simplifies thedefinition of classes that are similar to other existent ones.The descendant inherits automatically all thedata andmethods of its ancestor. Inheritance is one of the mostimportant formsof the reusability of codes in OOP.

    Polymorphism is the ability of using the name of afunctionto represent different implementationsof it. In C++virtual functions implement this concept.

    These two concepts will be illustrated in this sectionusing an element class that will belong to a finite elementprogram.

    All kinds of element of a mesh have in its definition anarray of nodes and one material that fulfills it. Then anyt yp of element can inherit these data. lso every elementmust have a method that computes its local matrix. For eachtyp of element the code that implements this computationwill be different. This is a typical application for the conceptof virtual functionsas will be seen in the sequence. The classElement is definedas:

    class Element{ / / A n abstract classprotected:

    //Attributesint material;int num-nodes;int num-edges;IntVector nodes;IntVector edges;char *potential;

    //Constructor

    Elemenqintnnod, nt nedg):edges(nedg),nodes(nnod) {

    public:

    num-nodes=nnod;num-edges=nedg;pote ncia hew char[I];}

    //member functionsvirtu al Matrix calc-k-local(Nadetree *pnt)=O;

    1

    In fact, th i s class is an abstract class because ithas a purevirtual function, that is, function without body.So there areno objects of this class. At first sight, it seems thatthis classhas no use. However we can define its descendants(subclasses) from it, an dso it becomesa basic class.

    The first specializations for Elem entare the Element-3dand the Element-2d classes. The only specialization shownhere i s the Element-3d.

    class Element-3d:public E lement{public:

    //ConstructorElement_3d(intnnod, nt nedg):Element(nnod,nedg){}//member functionsvirtual M atrix calc-k-local( . PO;Matrix get-elem-xyz(Nodetree 'pnt);

    Element-3d still is a generic form of an elemen t. Newspecializationsc n be derived. For exam ple, hexahedral andtetrahedral finite elements are widely used in 3-D. They arethe simplest shapeof a 3-D elements

    //Hexahedral elementclass Element-3d-hex-Nod:public Element-3d{public:

    //construeorElement-3d-hex-Nod():Element-3d(8,12) {1//member functions/ i

    Matrix calc-k-local( . );

    //Tetrahedral elementclassElement-3d-tet-Nod:public Element-3d{public:

    //constructorElement-3d-tet-Nod():Element-3d(4,6) {

    //member unction//..Matrix calc-k-local( . );

    Authorized licensed use limited to: UNIVERSIDADE FEDERAL DE MINAS GERAIS. Downloaded on August 19, 2009 at 11:41 from IEEE Xplore. Restrictions apply.

  • 8/10/2019 1994-IEEETransactionsOnMagneticsObjectOriented

    3/4

    3620

    These new classes are descendants of Element-3d andtherefore inherit thedata and methods from their ancestors(Element and Element-3d). Fig. 4 shows the hierarchy ofelements implemented in the program.

    Element

    Elem 3

    Fig. 4 Structure for a hierarchy of the elements.

    The concept of polymorphism guarantees that the rightmethod will be invoked for each kind of element whencomputing its local m atrix.

    OBJECT-ORIENTEDINITE LEMENTROGRAM

    The project of an object-oriented software systembasically consists in the division of the program into classesand the establishmentof an appropriate hierarchy of classes.The modular characteristic of the finite element methodpermits the easy iden tification of these classes.

    Initially the node seems to be just one of the varyousattributes of the element. However in the object-orientedphilosophy it is interesting to define a class for nodes.Thisclass has as data a set of coordinates, the boundaryconditions and the nu mber of degree of freedom.

    The member functions of this class must include

    functions for reading and writing the attributes of the nodein data file. Other functions are needed to attribute theequation number associated to each degree of freedom.

    In the previous section the implementation of the elementclass was described. The implementation of the classesElement-3d-hex-Nod and cd-k-local() method are nowpresented. In these examples8 noded brick elements areused to solve a 3-D magnetic vector potential magnetostaticproblem [6].

    classElement-3d-hex-Nod:public Element-3d{public:

    //constructorElement-3d-hex-Nod():Element-3d(8,12) {}

    //member functionsVector calc-func-n(double r, double s; double t),Matrix calc-dv-n(double r; doubles; double t);Matrix jacobian(doub1er, double s; double t; Matrix xe);

    Matrix calc-rot-n(doub1e r, double s double t; M atrix &jb);Vector calc-div-n(double r; doubles double t; Matrix &jb);Matrix calc-k-local(Ncdtree *pn t)

    1

    // computeslocal matrixMatrixElement~3d~hex~Nod::calc~k~local(Nodetree pn){Matrix ke( 24,2 4,0.); //initialize a matrixwith zeroMatrix b; //create a matrixwth default dimension (3x3)Matrix xe(8,3),Matrix bw ( 3,24);Vector bb(24);doubler,s,tfloat nu, wijk;int ij,k;nu=material;//coordinates matrix of the elementxe = get-elem-xyz(pn);

    //loop for Gauss integrationfor (i=O; ipoint( );jb==acobian(r,s,t,xe);dj=talc-det.j b );wijk=pgauss->weight(i)*pgauss->weightCj )*pgauss->weight( ),bw=calc-rot-n( r,s,tjb);bb=calc-div-n(r,s.tj b)ke t= ((bw.trans( )*bw) +bb*bb.trans( ))*nu*wijk*dj;

    return (ke);1

    The pgauss is a pointer to the objects of the class QGaussthat have the points and weights ofthe Gauss-Legendrequadrature. This method involves manipulation of matrices.A few classes to handle the basic matrix algebra weredeveloped . Metho ds for multiplication, addition, scaling andtransposition are supported by classes Vector and Matrix.These methods include vector by vector, matrix by vectorand matrix by matrix operations.

    The assembly of the global matrix isa method of theclass Sp-Matrix defined asa descendant of the matrix class.The skyline storage schemeis used. To solve the systemofequations the Cholesky method is applied.

    The management of the objects and the establishment ofthe relationship between them are necessary toturn theprogram functional. In this work, the organizationof objectsin arrays was adopted. The management by array requires

    the creation of a generic class that manipulates arrays ofobjects [ l] . In our case the class tree was defined. Methodsto initialize, to add, to remove and to find objects mustbecreated. 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.

  • 8/10/2019 1994-IEEETransactionsOnMagneticsObjectOriented

    4/4