Coding Algorithm
Coding Algorithm
(i) Pre-processor,
(iii) Post-processor.
The pre-processor reads and generates the data to be supplied to the processor.
In the processor, the FE equations are generated and solved to find the (global) nodal values
of the primary variable (i.e., the global dof).
The post-processor calculates the secondary variables (like the axial strain, axial stress and
axial point force in the rod extension problem) from the global dof (found by the processor)
using the shape function derivatives.
1 Pre-Processor
The pre-processor partially reads and partially generates the data needed by the processor. The
main data which a 1-D FE processor needs is the following:
▪ Mesh Data,
▪ Boundary Data.
Mesh Data: The mesh data consists of the number of elements, number of nodes per element,
number and type of dof per node, connectivity matrix and global coordinate vector. Commercial
FE packages include a library of the elements and a mesh generation routine. Therefore, they
require only the domain size (and shape for 2-D/3-D domains) and the element choice (i.e., the
number of nodes per element and number and type of dof per node) as the input data. Using the
mesh generation routine, they create the data about the number of elements, connectivity matrix
and global coordinate vector.
Data about Geometric and Material Properties and Other Parameters:
As stated earlier, one way to supply this data is to provide the values of the geometric properties,
material properties and other parameters nodewise at all the global nodes. Then, their functional
forms over a typical element are approximated (in the processor) by interpolation using the
Lagrangian shape functions.
For the rod extension problem, the geometric property is A (i.e., the area of the rod cross-
section), the material property is E (i.e., the Young’s modulus) and the other parameter is p (i.e.,
the distributed axial force acting on the rod).
Boundary Data: The data about these specifications of the primary and secondary variables at
both the boundary and interior nodes is called the boundary data. This data is usually supplied
through the following two 2-coulmn matrices for problem governed by second order differential
equations:
▪ The first matrix contains the data about the specified values of the primary variable at the
boundary and interior nodes. The first column contains the global node number and the
second column contains the specified value at that node.
▪ The second matrix contains the data about the specified values of the secondary variable
at the boundary and interior nodes. The first column contains the global node number and
the second column contains the specified value at that node.
The problems of beam bending, stability and vibration which are governed by a fourth
order ODE, besides the primary variable, its 1st derivative is also specified as the essential BC.
Further, two secondary variables, namely the transverse point force along y-axis and point
moment about z-axis are specified as the natural BCs for the beam bending problem.
In this case, the data can be supplied dof-wise. In this case, the two boundary data
matrices consist of 2 columns. The 1st column contains the global dof number and the 2nd column
contains the specified dof. In the odd row, the specified dof is the primary variable (for the 1st
matrix) and the transverse force along y-axis (for the 2nd matrix). In the even row, the specified
dof is the 1st derivative (for the 1st matrix) and the point moment about z-axis (for the 2nd matrix).
For the rod extension problem, the primary variable is the axial displacement (denoted by
u) and the secondary variable is the axial point force (denoted by P). Therefore, these matrices
can be denoted as Bu and BP .
Figure 1. Specifications of axial displacements at Nu number of points and axial point forces at
To illustrate the procedure of constructing the matrices Bu and BP , consider the rod
of Fig. 1. Here, the axial displacements are specified at Nu number of nodes including the first
global node at the left boundary ( x = 0 ) and the axial point force are specified at N P number of
nodes including the last global node at the right boundary ( x = ) . The specified value u at the
first global node is u* (i.e., the value appearing in the essential BC), at iu -th global node is ui*
and at the last specified global node is u*Nu . The specified value of P at the first specified global
node is P1 , at iP -th global node is Pi and at the last global node is P* (i.e., the value appearing
in the natural BC). Let nn be the number of global nodes. Then, the matrices Bu and BP
become
1 u* − P1
−
− − −
− − − −
Bu = iu u*i , BP = iP Pi . (1)
− − − −
− − −
− u*Nu n *
n P
To give more flexibility, one option would be to specify the choice of element and then proceed
accordingly. However, we will only consider Lagrangian elements here which have only 1 dof
(i.e., the primary variable) per node, the number and type of dof per node is not required as the
input data. For a Lagrangian element, the number of global nodes nn is given by the following
formula:
nn = ne ( m − 1) + 1 , (2)
where ne is the number of elements and m is the number of nodes per element.
Notation used:
Mesh Data:
ne : number of elements,
C : connectivity matrix,
X : global coordinate vector;
Data about Geometric and Material Properties and Other Parameters:
Read ne and m
Calculate nn = ne ( m − 1) + 1
Read Nu and N P
As stated earlier, the processor generates the FE equations and solves them to find the global
nodal values of the primary variables (i.e., the global dof). This is done in the following 4 steps:
In this step, the element coefficient matrix k and right side vector f
e e
are evaluated using
the Gauss-Legendre numerical integration scheme. This is usually coded using a do loop with the
Gauss point number as the index. For the problems of vibration /stability, there is another
integration in the expressions for k , f or the other element matrices like m or k ,
e e e e
the data about the number of Gauss points nG , the Gauss point coordinates k and the
corresponding weights wk need to be provided to the processor. Further, the expressions for the
In this step, the element coefficient matrix k and right side vector f
e e
are combined
to obtain the global coefficient matrix K and right side vector F using the simplified global
assembly relations. The assembly of k is usually coded using a triple do loop. The outermost
e
do loop has the element number as the index. The two inner do loops have the local node
f
e
numbers as the indices. For the assembly of , only one inner do loop is needed. However,
an additional do loop is needed to incorporate the specified secondary variable at the interior and
boundary nodes. The connectivity matrix C is needed in carrying out the assembly of K and
F .
Step 3: Incorporation of Essential BC and Specification of Primary Variable at Interior Nodes
For the rod extension problem, two methods of applying the essential BC have been described in
class. In the first method, one equation is dropped so as to modify the FE equations. This method
has the following two drawbacks as far as its coding is concerned.
▪ In this method, the equation corresponding to the specified global dof (in the essential
BC) is removed from the set of FE equations. Coding wise, this operation involves
renumbering of the remaining equations. Usually, besides the essential BC, the primary
variable could also be specified at some interior nodes. Then, the equations
corresponding to the global dof of these nodes also need to be removed and this makes
the coding very cumbersome.
▪ Removal of certain equations from the set of FE equations (4.47) results in the reduction
in the size of the global coefficient matrix K , the global right side vector F and the
An alternate or 2nd method which does not require the renumbering of equations and the
consequent reduction in size of K , F and U exists. This method is used in commercial
FE packages and also recommended. The set of algebraic equations can be expressed as:
Suppose the primary variable is specified at i-th global node. It means the i-th global dof is
specified. Let the specified value be . Then, the i-th global dof is known and is given by
Ui = . (4)
As explained earlier, if the i-th global dof is known, it means the i-th equation of the set (3)
becomes meaningless. In the 2nd method, to avoid reducing the sizes of K , F and U , the
meaningless i-th equation is replaced instead of removing it. The replacement is done using
equation (4). This involves the following operations:
This destroys the symmetry of K matrix. The symmetry can be restored by transposing the i-th
term of each equation (except the i-th equation) to the right side. This involves the following
operations:
K ji = 0 , Fj = Fj − K ji , for j i ; (7)
This step is usually coded using a do loop over the number of nodes at which the primary
variable is specified.
The application of these two methods for the incorporation of the essential BC and
specifications of the primary variable at the interior nodes is similar to the other 1-D problems
where the Lagrangian elements are used except the problems of rod and shaft vibration. There is
an additional global matrix M besides K . As a result, while applying any one of the above
methods, the same operations need to be carried out on the matrix M that are done on the
matrix K . Since the FE equations for these two problems are the eigenvalue problems, if the
2nd method is used for these two problems, the rigid body modes (i.e., the axial rigid translation
for the rod vibration and axial rigid rotation for the shaft vibration) appear as the eigenvectors in
the solution. (These eigenvectors correspond to the eigenvalues having the magnitude zero).
Therefore, the 1st method is recommended for the vibration/stability problems to avoid the
appearance of the rigid body modes in the solution.
For the 1-D problems of beam bending, stability and vibration, the Hermitian elements
need to be used which have 2 dof per node: the primary variable and its 1st derivative. The two
methods need to be extended to the case of 2 dof per node before applying to the beam bending,
stability and vibration problems for the incorporation of the essential BCs and specifications of
the primary variable (and its 1st derivative) at the interior nodes.
This step is usually carried out using a standard solver subroutine. In most cases, the FE
equations are such that the global coefficient matrix becomes banded and symmetric. Therefore,
the solver subroutine for the banded and symmetric case should be used to reduce the memory
requirement and the solution time. In the vibration and stability problems, the FE equations
represent an eigenvalue problem. In this case, a subroutine for finding the eigenvalues and
eigenvectors should be used.
A simple processor algorithm of the rod extension problem is presented next for the first
three steps. This processor differs from the commercial FE packages in the following aspects:
▪ In the processor algorithm presented, only one set of the Gauss point data is coded
depending on the chosen value of m (i.e., the number of nodes per element). A library of Gauss
points similar to commercial FE package can be provided.
▪ Commercial FE packages contain a library of the shape functions (and their derivatives)
of the elements of various types and various orders. In the presented algorithm, the shape
function expressions (and their 1st derivative) of only one Lagrangian element are coded
depending on the chosen value of m (i.e., the number of nodes per element).
▪ Commercial FE packages assume the geometric and material properties and other
parameters to be constant over each element. In the presented algorithm, the data about the
geometric and material properties and other parameters is provided nodewise (and not
elementwise) in the pre-processor and their functional forms are generated in the processor using
the Lagrangian shape functions. From these functional forms, values of the geometric and
material properties and other parameters are calculated at the Gauss points for the evaluation of
As stated earlier, this processor uses only the m-noded Lagrangian element, shown in Fig. 2.
Figure 2. Typical m-noded Lagrangian element. Local nodes are marked by ' ' and Gauss
points by ' ' . Aie , Eie and pie are values of A, E and p at local node i
e
: element length,
A
e
: element vector containing (local) nodal values of A,
E
e
: element vector containing (local) nodal values of E,
p
e
: element vector containing (local) nodal values of p,
wk : weight corresponding to k ( 1 k nG ),
f
e
: element right side vector,
N
e
: shape function vector of m-noded Lagrangian element,
B : - derivative of N
e e
,
B : transpose of B .
e T e
Now, the processor algorithm for the first step can be expressed as follows:
e
1. Calculation of :
n1 = Ce1 , nm = Cem
x1e = X n1 , xme = X nm
e
= xme − x1e .
2. Calculation of A , E and p :
e e e
Initialize A , E and p ;
e e e
j = Cei
m m m
Calculate A = N ie Aie , E = N ie Eie , p = N ie pie at = k
i =1 i =1 i =1
Calculate B =
d
N at = k from the coded expressions
e e
d
B B at = k using a standard
e e T
Carry out the multiplication to find
multiplication subroutine
2 AE e T
k e = k e + wk B B
e
e
p e e
f = f + wk N
e e
2
i: index for the number of nodes at which the axial point force is specified,
Now, the processor algorithm for the second step can be expressed as follows:
1. Initialize K and F .
2. Global assembly of K and partial global assembly of F using the simplified global
processor
r = Cep
Fr = Fr + f pe
Krs = Krs + k pq
e
( )
i p = Bp
i1
( )
Pi = B p
i2
Fip = Fi p + Pi
i: index for the number of nodes at which the axial displacement is specified,
Now, the processor algorithm for the third step can be expressed as follows:
ui* = ( Bu )i 2
K iu iu = 1 , Fiu = ui*
3. 1-D Post-Processor
As stated earlier, the post-processor calculates the secondary variables (like the axial strain, axial
stress and axial point force in the rod extension problem) from the global dof (i.e., the global
nodal values of the primary variable) found by the processor using the shape function
derivatives.
For the Lagrangian elements, the 1st derivative (i.e., the x-derivative) of the
approximation for the primary variable becomes discontinuous at the inter-element boundaries.
As a result, a good expression for the x-derivative over the whole domain cannot simply be
obtained by combining its elementwise approximations. To obtain a good expression for the x-
derivative, the following numerical observation is used: values of the x-derivative of the
approximation (for the primary variable) are most accurate at the Gauss points. As a result,
values of the x-derivative are evaluated at all the Gauss points of all the elements. Then, the
expression for the x-derivative over the whole domain is obtained by linear interpolation between
the successive Gauss points. (Near the inter-element boundaries, the interpolation is done
between the last Gauss point of the element and the first Gauss point of the successive
neighbouring element).
For the problems of rod and shaft vibration, the secondary variables are not required.
Only the natural frequencies (i.e., the square-root of the eigenvalues) and the corresponding
amplitudes of either the axial displacement u0 for the rod vibration (i.e., the corresponding
eigenvectors) or the cross-sectional rotation 0 for the shaft vibration (i.e., the corresponding
eigenvectors) are required. They are determined by solving the FE equations which are the
eigenvalue problems for these two cases.
For the rod extension problem, the primary variable is the axial displacement u, and the
1st secondary variable is the axial strain xx . Since this problem is governed by a second order
ODE, as stated earlier, the 1st secondary variable at cross-section x is the x-derivative of the
primary variable. Thus, the axial strain xx is given by
du
xx = . (9)
dx
u
e
For this problem, the vector of element dof is the element displacement vector
which can be extracted from the global displacement vector U using the connectivity matrix
C as follows:
Here, j is the global number of the local node i. The approximation for the primary variable u
over e is given by the interpolation relation:
m
u = N ieuie . (11)
i =1
Here, uie are the element dof and N ie are the shape functions of the m-noded Lagrangian
element. Since N ie are functions of the natural coordinate , the expression (11) for u is also a
du du d
= , (12)
dx d dx
du m
dN ie e
= ui . (13)
d i =1 d
To find the derivative d / dx , the linear transformation is used:
xme + x1e e
x= + , (14)
2 2
d 2
= . (15)
dx e
(For a non-linear transformation between x and , the derivative d / dx does not become a
constant). Substituting the expressions (15) and (17) in equation (14), we get the following
expression for the x-derivative of the approximation (13) for u:
du 2 m dN ie e
= ui . (16)
dx e i =1 d
Note that du / dx is a function of . Substitution of the expression (16) for the x-derivative of u
in equation (9) leads to the following expressions for the 1st secondary variable xx as a function
of :
du 2 m dN ie e
xx = ui , (17)
dx e i =1 d
For the rod extension problem, the 2nd secondary variable is the axial stress xx which is
given by
xx = E xx . (18)
Substitution of the expression (17) for xx in equation (18) leads to the following expressions for
xx as a function of :
2 m dN i e
e
xx E xx = E e ui , (19)
i =1 d
For this problem, the 3rd secondary variable is the axial point force P which is
P = A xx . (20)
Substitution of the expression (19) for xx in equation (20) leads to the following expressions for
P as a function of :
2 m dN e
e
P A xx = AE e i ui . (21)
i =1 d
As stated earlier, first, the values of xx , xx and P are found at all the Gauss points of all
the elements using the above expressions. Then, from these values, their expressions over the
whole domain are generated using linear interpolation functions.