Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Algorithm for Coding as applied to 1-D Variational and Galerkin FEM

A typical Finite Element (FE) code consists of three parts:

(i) Pre-processor,

(ii) Processor, and

(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,

▪ Data about Geometric and Material Properties and Other Parameters,

▪ 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

N P number of points of rod

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 

Their sizes are Nu  2 and N P  2 respectively.

Example:- A pre-processor algorithm for Rod Extension Problem

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,

m: number of nodes per element,

nn : number of global nodes,

 C  : connectivity matrix,
 X  : global coordinate vector;
Data about Geometric and Material Properties and Other Parameters:

A: area of cross-section of the rod,


 A : global vector containing (global) nodal values of A,
E: Young’s modulus of the rod material,

 E : global vector containing (global) nodal values of E,


p: distributed axial force acting on the rod,

 p : global vector containing (global) nodal values of p;


Boundary Data:

Nu : number of nodes at which u is specified,

 Bu  : matrix containing the data about the specified values of u,

N P : number of nodes at which P is specified,

 BP  : matrix containing the data about the specified values of P.

Now, the pre-processor algorithm can be expressed as follows:

Read ne and m

Calculate nn = ne  ( m − 1) + 1

Read Cij , i = 1, ….., ne , j = 1, ….., m (elements of the connectivity matrix)

Read X j , j = 1, ….., nn (coordinates of global nodes)

Read A j , j = 1, ….., nn (nodal value of A)

Read E j , j = 1, ….., nn (nodal value of E)

Read p j , j = 1, ….., nn (nodal value of p)

Read Nu and N P

Read ( Bu )ij , i = 1, ….., Nu , j = 1, 2

Read ( BP )ij , i = 1, ….., N P , j = 1, 2


2. 1-D Processor

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:

Step 1: Calculation of Element Quantities

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

element matrix  m or  k  f


e e e
instead of which has to be generated. For carrying out the

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

N  B  = d  N  / d (in terms of the natural


e e e
shape function vector and the vector

coordinate  ) also need to be coded in the processor. Better to do it using subroutines.

Step 2: Global Assembly of Element Quantities

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

vector of global dof U  . The coding operation of these reductions in sizes of  K  ,  F 

and U  also becomes cumbersome.

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:

 K11 K12 − − K1i − −  U1   F1 


K K 22 − − K 2i − −     
 21 U 2   F2 
− − − − − − −  −  − 
    
− − − − − − −  −  = −  . (3)
 K i1 Ki 2 − − K ii − −  U i   Fi 
    
− − − − − − −  −  − 
−    
 − − − − − −   −   − 

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:

Kij = 0 , for j  i ; Kii = 1 ; Fi =  . (5)

Then, the set (3) gets modified as follows:

 K11 K12 − − K1i − −  U1   F1 


K K 22 − − K 2i − −     
 21 U 2   F2 
− − − − − − −  −  − 
    
− − − − − − −  −  = −  . (6)
0 0 0 0 1 0 0  U i    
    
− − − − − − −  −  − 
−    
 − − − − − −   −   − 

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)

Then, the set (6) gets modified as follows:

 K11 K12 − − 0 − −  U1   F1 − K1i  


K − − 0 − −     
 21 K 22 U 2   F2 − K 2i  
− − − − 0 − −  −  − 
    
− − − − 0 − −  −  = − . (8)
0 0 0 0 1 0 0  U i    
    
− − − − 0 − −  −  − 
−     
 − − − 0 − −  −  − 

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.

Step 4: Solving FE Equations to Find Vector of Global DOF

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 commercial FE package offers the following choices in the processor:

▪ Solid Mechanics, Fluid Mechanics and Heat Transfer Problems,

▪ Static, Steady, Vibration, Time-Periodic, Transient and Stability Analyses,

▪ 1-D, 2-D, Axisymmetric and 3-D Cases.

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

the element quantities  k  and f


e e
using the Gauss-Legendre numerical integration scheme.

Simple Processor Algorithm for Rod Extension Problem

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

Processor Algorithm for generation of element level quantities:

The symbols used in the algorithm are as follows:

n1 , nm : global node numbers of the local nodes 1 and m,


e: element number,

x1e , xme : coordinates of the local nodes 1 and m,

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,

i: typical local node number,

j: global node number of the local node i,

nG : number of Gauss points,

k: index of the Gauss point,

 k : coordinate of k-th Gauss point ( 1  k  nG ),

wk : weight corresponding to  k ( 1  k  nG ),

 k e : element coefficient matrix,

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

Loop over i from 1 to m

j = Cei

Aie = Aj , Eie = E j , pie = p j

Loop over i ends.

3. Define nG ;  k , k = 1, ….., nG ; wk , k = 1, .…., nG .

4. Initialize  k  and f


e e
.

5. Integration of  k  and f


e e
using Gauss-Legendre integration:

Integration loop over k from 1 to nG

Calculate  N  at  =  k from the coded expressions


e

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

Take the transpose to find  B  at  =  k using a standard transpose subroutine.


e T

 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 

Integration loop ends.

Processor Algorithm for Assembly:

The symbols used in the algorithm are as follows.

 K  : global coefficient matrix,


 F  : global right side vector,
p, q: typical local node numbers,

r, s: global numbers of the local nodes p and q,

i: index for the number of nodes at which the axial point force is specified,

i p : global node number corresponding to the index i,

Pi : specified axial point force at the global node number i p .

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

assembly relations except the addition of  P :


*

Assembly loop over e from 1 to ne

Calculate  k  and f


e e
using the subroutine corresponding to the 1st part of the

processor

Loop over p from 1 to m

r = Cep

Fr = Fr + f pe

Loop over q from 1 to m


s = Ceq

Krs = Krs + k pq
e

Loop over q ends

Loop over p ends

Assembly loop (loop over e) ends.

3. Global assembly of  F  continues: Addition of  P :


*

Loop over index i from 1 to N P

( )
i p = Bp
i1

( )
Pi = B p
i2

Fip = Fi p + Pi

Loop over i ends.

Processor Algorithm for Application of Essential BC:

The symbols used in the algorithm are as follows.

i: index for the number of nodes at which the axial displacement is specified,

iu : global node number corresponding to the index i,

ui* : specified axial displacement at the global node number iu ,

j: typical global node number.

Now, the processor algorithm for the third step can be expressed as follows:

Incorporation of the essential BC and the specification of primary variable at interior


nodes using equations (5) and (7). In these equations, the index i is to be replaced by iu

and the quantity  is to be replaced by ui* :

Loop over the index i from 1 to Nu


iu = ( Bu ) i1

ui* = ( Bu )i 2

Loop over j from 1 to nn

K iu j = 0 , Fj = Fj − K jiu ui* , K jiu = 0

Loop over j ends

K iu iu = 1 , Fiu = ui*

Loop over i ends.

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:

uie = U j where j = Cei , i = 1, ….., m. (10)

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

function of  . Using the chain rule, the x-derivative becomes

du du d
= , (12)
dx d dx

where the derivative du / d of the expression (11) for u is given by:

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

Using the above expression, the derivative d / dx becomes

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.

You might also like