The last item is important for efficiency. If we were to create a class that did not know how to operate on its own data, then we would need a list of conditional ``if'' statements every time such an operation needed to be done in the code. Clearly this is not an efficient approach. The object oriented programming (OOP) approach replaces the set of if statements with a memory access that determines which operator should be used for the element in question. Also this method is efficient for programming purposes. Once an operator is defined for all the elements, any piece of code that requires this operator only has to call the one interface to the operator regardless of the element type. For instance, say we would like to differentiate a function held in an array of values at quadrature points (field) then in pseudo code:
![]()
would take the spatial derivatives of field and place the x,y and z derivatives in the arrays named
and
.
A more complicated example might be to create two elements, set the data values at the quadrature points of the elements, differentiate the fields and compare the differentiation errors on each element. The pseudo code to set up the elements is shown in figure 4.1. We would like to point out that the implementation of the element constructors is provided in the library routines of . In figure 4.2 we show the code for the next stage of applying the derivative operators to the list of elements we have created. Notice in this section that no explicit mention of the types of each element is made when we use the operator on them.
In the next section we consider the discretization of the projection, the convection, and the diffusion linear operators. They are formulated as discrete operators in each element and then globally assembled over the entire domain.