w04-g02-matrix-assembly
Matrix Assembly
The Direct Stiffness Method is the simplest finite-element method. It is used in structural analysis to compute the reactions of a load or force acting on a structure based on the material stiffness properties of all its constitutive elements.
In the end, it only consists in solving a linear system of the form
\boldsymbol{K} . \boldsymbol{d} = \boldsymbol{f}
, where
\boldsymbol{d}
is a vector containing the displacements of all
degrees of freedom involved, \boldsymbol{f}
is the loading vector
and \boldsymbol{K}
the global stiffness matrix of the structure.
The goal of this exercise is to construct the global stiffness matrix
for a simple truss system of dimension dim
and consisting of
nb_elements
elements. An example of such a truss system is
illustrated below:
The structural configuration (number of elements, number of nodes, coordinates of each node and connectivities of each elements) are hard-coded in the starting point file (see below).
Assembly
For the assembly of the global stiffness matrix we need to:
- Compute the local stiffness matrix of every element
\boldsymbol{K}_e
in its local coordinates (x_e,y_e
).
\boldsymbol{K}_e = \left(\begin{array}{cc}k_e & 0 & -k_e & 0 \\ 0 & 0 & 0 & 0 \\ -k_e & 0 & k_e & 0 \\ 0 & 0 & 0 & 0\end{array}\right)
where k_e=\dfrac{A_eE_e}{L_e}
is the stiffness for element e
based on its cross-section area, elastic modulus and length.
- Transform
\boldsymbol{K}_e
to global coordinates (x,y) through a rotation\boldsymbol{R}
. The transformed local stiffness matrix is thus\boldsymbol{K}_e (x,y) = \boldsymbol{R}^T. \boldsymbol{K}_e. \boldsymbol{R}
.
\boldsymbol{R} = \left(\begin{array}{cc}\sin \theta & \cos\theta & 0 & 0 \\ -\cos\theta & \sin\theta & 0 & 0 \\ 0 & 0 &\sin\theta & \cos\theta \\ 0 & 0 & -\cos\theta & \sin\theta \end{array}\right)
where \sin\theta=\dfrac{dx_e}{L_e}
and \cos\theta=\dfrac{dy_e}{L_e}
- Construct a global indicies, a 2D array of size (
nb_elements
,nb_nodes_per_element
xdim
) that maps local rows and columns of the local stiffness matrix of an element to the global rows and columns of the global stiffness matrix. For example, local stiffness matrix of element 1 (connected to node 1 and 3 with 2 degrees of freedom (x, y
) per node) will be mapped to the (0, 1, 4, 5) rows and (0, 1, 4, 5) columns of the global stiffness matrix.
\boldsymbol{K} = \boldsymbol{K} + \left(\begin{array}{cc}K_1(0, 0) & K_1(0, 1) & 0 & 0 & K_1(0, 2) & K_1(0, 3) \\ K_1(1, 0) & K_1(1, 1) & 0 & 0 & K_1(1, 2) & K_1(1, 3)\\ 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 \\ K_1(2, 0) & K_1(2, 1) & 0 & 0 & K_1(2, 2) & K_1(2, 3) \\ K_1(3, 0) & K_1(3, 1) & 0 & 0 & K_1(3, 2) & K_1(3, 3) \end{array}\right)
- Assemble local matrices of local size (
nb_nodes_per_element
xdim
,nb_nodes_per_element
xdim
) into the global matrix of global size (nb_nodes
xdim
) by replacing local indicies with global indicies.
Implementation
-
Follow the comments given in the file and implement the missing part of the code as instructed.
-
Use the file named
matrix_assembly.cpp
as a starting point which is provided in thetehpc/basics/
directory. -
Make sure that your code is well structured and commented.
Notes:
Compile and run your code by:
- going into the
tehpc/build/
folder - compile with the following command:
g++ -Werror -Wpedantic -g -o matrix_assembly ../basics/matrix_assembly.cpp
- run code with
./matrix_assembly