next up previous contents
Next: Global Projection Operator Up: Elemental Spatial Operators Previous: Differentiation

Implementation and Programming

 So far we have outlined specifications for each element type. Each description includes three coordinate systems, a set of basis functions, a set of operators and a set of surface panels. By carefully defining each element type this way we can implement each type using a unified methodology. We used an object oriented programming approach. The first task is to define a ``generic'' element that has a sufficiently flexible data structure. The computer language C++ allowed us to define a base Element class. The class was given storage for the following:

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:

\begin{displaymath}
element-\gt Gradient(field, \frac{\partial field}{\partial x...
 ...\partial field}{\partial y}, \frac{\partial field}{\partial z})\end{displaymath}

would take the spatial derivatives of field and place the x,y and z derivatives in the arrays named $ \frac{\partial field}{\partial x}, \frac{\partial field}{\partial y}$ and $\frac{\partial field}{\partial z}$.

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.


  
Figure 4.1: A piece of code demonstrating how a list of elements can be constructed.
\begin{figure}
\begin{center}
\begin{tabular}
{\vert l\vert}\hline
\ // Make an...
 ...e\_vector, quad\_coordinates);\ \  \hline\end{tabular}\end{center}\end{figure}


  
Figure 4.2: A piece of code demonstrating how operations can be made on a list of elements.
\begin{figure}
\begin{center}
\begin{tabular}
{\vert l\vert} \hline
\ // Set th...
 ..., ``PI*cos(PI*x)*cos(PI*y)'');\ \  \hline\end{tabular}\end{center}\end{figure}

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.


next up previous contents
Next: Global Projection Operator Up: Elemental Spatial Operators Previous: Differentiation
T. Warburton
10/24/1998