{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import theme\n", "theme.load_style()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Lesson 3: Direct Methods\n", "## 1D Spring Elements\n", "\n", "\n", "\n", "\"Creative\n", "\n", "This lecture by Tim Fuller is licensed under the\n", "Creative Commons Attribution 4.0 International License. All code examples are also licensed under the [MIT license](http://opensource.org/licenses/MIT)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Topics\n", "\n", "- [Introduction to FEA](#intro_to_fea)\n", "- [Direct Stiffness Method](#dir_stiff_methd)\n", " - [Example 1: Tapered Bar](#tapered_bar)\n", " - [Example 2: Parallel Spring Network](#multi_spring)\n", " - [Example 3: Prescribed Displacements](#presc_disp)\n", " - [Example 4: Self Weight](#ex_self_weight)\n", "- [Computational Implementation](#comp_impl)\n", " - [Pre Processing](#preproc)\n", " - [Solution Phase](#solphase)\n", " - [Example Linear Finite Element Code](#one_d_code)\n", "- [Exercises](#exercises)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " \n", "# Introduction to FEA[](#top)\n", "\n", "The general steps in solving a problem using FEM:\n", "\n", "**Preprocessing Phase**\n", "\n", "1. Discretize the problem domain and choose element type\n", "2. Assume solution that approximates the element behavior\n", "3. Define the Strain/Displacement and Stress/Strain Relationships\n", "4. Derive the element stiffness matrix and equations\n", "5. Assemble element equations into global equations\n", "6. Introduce boundary conditions\n", "\n", "**Solution Phase**\n", "\n", "1. Solve for the unknown degrees of freedom\n", "2. Compute reactions\n", "\n", "**Postprocessing Phase**\n", "\n", "1. Find element strains and stresses and other important information.\n", "2. Interpret results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# The Direct Stiffness Method[](#top)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We first demonstrate the discretization process and other steps of the FEM through the direct stiffness method. In future lectures we will discuss other discretization methods. We now demonstrate the direct stiffness method through a number of examples familiar to students of mechanical engineering.\n", "\n", "## Example 1: Tapered Bar\n", "\n", "Consider the problem of finding the displacement $\\delta$ at the free end of the tapered bar, caused by the axial force $F$.\n", "\n", "\n", "\n", "For a small taper angle we can obtain a reasonable approximation for the displacement by\n", "\n", "\n", "$$\n", " \\delta_{\\scriptscriptstyle\\mathrm{approx}} = \\frac{PL}{A'E}\n", "$$\n", "\n", "\n", "where $A'=A_0/2$. Suppose that the angle of the taper is not negligible and that $E$ is not constant but varies along the length of the beam. Let's use the finite element method to find the approximate displacement to this more difficult problem. We will follow the general steps of the FEM already outlined.\n", "\n", "### Preprocessing Phase\n", "\n", "#### Step 1: Discretize and Select Element Type\n", "\n", "Discretization is accomplished by subdividing the problem domain into *finite elements* connected by *nodes*, as shown below. The original tapered beam is divided into 4 finite elements with 5 nodes. Each element has a length $l$ and uniform cross-sectional area $A$ represented by the average area of the cross sections at the nodes. We choose for our element type a spring. The spring element is chosen for its simplicity in understanding and implementing. As the semester progresses we will use other more sophisticated elements. However, for now, the spring element is sufficient in helping us understand the general steps of the FEM.\n", "\n", "\n", "\n", "We concentrate now on the chosen spring element. Let us isolate one element from the global $x$ coordinates shown and put it in its own local coordinate system $\\hat{x}$ and study its properties there.\n", "\n", "\n", "\n", "Take note of the new syntax. Hatted quantities ($\\hat{f}$, $\\hat{u}$) are reckoned with respect to the local coordinate $x$. That is, $\\hat{x}_1=0$ and $\\hat{x}_2=L$, where $L$ is the element length. Another, alternative notation is also shown - that of explicitly labeling the element number as a superscript to the property.\n", "\n", "
\n", " Properties of the Spring Element
\n", "\n", "\n", "
\n", "\n", "
\n", "Remark
\n", "We distinguish between degrees of the system, degrees of freedom of the element, and degrees of freedom of the node. In general, a node has $n_{\\text{dof}}^{\\text{n}}$ degrees of freedom; an element has $n_{\\text{dof}}^{\\text{e}} = n \\times n_{\\text{dof}}^{\\text{n}}$ degrees of freedom, where $n$ is the number of nodes defining the element element; and the system has $n_{\\text{dof}}^{\\text{sys}} = N \\times n_{\\text{dof}}^{\\text{n}}$ degrees of freedom, where $N$ is the total number of nodes. We'll come back to the significance of these statements when discussing computational implementation.\n", "
\n", "\n", "For the following steps we will consider only one of the four elements in our discretized problem domain. Later we will take into account the other elements. Let's choose element two\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Step 2: Select a Displacement Function\n", "\n", "In the direct stiffness method that we cover today the selection of a the displacement function is not necessary. Thus, we will skip this step and save it for a later lecture." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Step 3: Define the Strain/Displacement and Stress/Strain Relationship\n", "\n", "Recall from elementary physics that the force stretch relationship for an ideal spring, assuming small displacements, is given by $F=k\\delta$\n", "\n", "where $k$ is the spring constant and $\\delta$ is the displacement.\n", "Observing the stretched spring, the displacement $\\delta$ is\n", "\n", "$$\n", "\\delta = u_2^{(2)} - u_1^{(2)}\n", "$$\n", "\n", "and \n", "\n", "$$\n", "f = k_2\\left(u_2^{(2)} - u_1^{(2)}\\right)\n", "$$\n", "\n", "where $k_{2}$ is the spring constant for element 2.\n", "\n", "
\n", " Recall
\n", "The equivalent spring stiffness of a bar is given by k=AE/L\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Step 4: Derive Element Stiffness Matrix and Equations\n", "\n", "We now derive the stiffness matrix for the spring element. The nodal forces are\n", "\n", "$$\n", "f_1^{(2)} = -k_2\\left(u_2^{(2)} - u_1^{(2)}\\right)\n", "$$\n", "\n", "$$\n", "f_2^{(2)} = k_2\\left(u_2^{(2)} - u_1^{(2)}\\right)\n", "$$\n", "\n", "combining and putting in matrix form gives\n", "\n", "$$\n", " \\begin{Bmatrix} f_1^{(2)} \\\\ f_2^{(2)} \\end{Bmatrix} \n", "= \\begin{bmatrix} k_2 & -k_2 \\\\ -k_2 & k_2 \\end{bmatrix}\n", " \\begin{Bmatrix} u_1^{(2)} \\\\ u_2^{(2)} \\end{Bmatrix}\n", "$$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Step 5: Assemble Element Equations into Global Equations\n", "\n", "The preceding analysis applied only to element two of our example problem. The exact same analysis can be performed on the remaining elements and the conclusions would be the same, namely, for elements 1, 3, and 4\n", "\n", "$$\n", " \\begin{Bmatrix} f_1^{(1)} \\\\ f_2^{(1)} \\end{Bmatrix} \n", "= \\begin{bmatrix} k_1 & -k_1 \\\\ -k_1 & k_1 \\end{bmatrix}\n", " \\begin{Bmatrix} u_1^{(1)} \\\\ u_2^{(1)} \\end{Bmatrix}\n", "$$\n", "\n", "$$\n", " \\begin{Bmatrix} f_1^{(3)} \\\\ f_2^{(3)} \\end{Bmatrix} \n", "= \\begin{bmatrix} k_3 & -k_3 \\\\ -k_3 & k_3 \\end{bmatrix}\n", " \\begin{Bmatrix} u_1^{(3)} \\\\ u_2^{(3)} \\end{Bmatrix}\n", "$$\n", "\n", "$$\n", " \\begin{Bmatrix} f_1^{(4)} \\\\ f_2^{(4)} \\end{Bmatrix} \n", "= \\begin{bmatrix} k_4 & -k_4 \\\\ -k_4 & k_4 \\end{bmatrix}\n", " \\begin{Bmatrix} u_1^{(4)} \\\\ u_2^{(4)} \\end{Bmatrix}\n", "$$\n", "\n", "Now that we have developed stiffnesses for individual elements it is our goal to develop a global stiffness for the structure. Before we look at the global stiffness, however, let's look the nodal displacements. Note that elements 1, 2 3, and 4 must remain connected at common nodes 2, 3, and 4. This is called *continuity* or the *compatibility requirement*. This compatibility yields the following relationships:\n", "\n", "$$\n", " \\begin{split}\n", " u_{2}^{(1)} &= u_{1}^{(2)} = u_{2}\\\\\n", " u_{2}^{(2)} &= u_{1}^{(3)} = u_{3}\\\\\n", " u_{2}^{(3)} &= u_{1}^{(4)} = u_{4}\\\\\n", " \\end{split}\n", "$$\n", "\n", "\n", "also, since nodes 1 and 5 are only connected to one element each\n", "\n", "\n", "$$\n", " \\begin{split}\n", " u_{1}^{(1)} &= u_{1}\\\\\n", " u_{2}^{(4)} &= u_{5}\n", " \\end{split}\n", "$$\n", "\n", "\n", "From the free-body diagrams of each node and the fact that external forces must equal the internal forces at each node, we can write the nodal equilibrium equations for nodes 1, 2, 3, 4, and 5 as\n", "\n", "\n", "$$\n", " \\begin{split}\n", " f_{1} = f_{1}^{(1)} &= R \\\\\n", " f_{2} = f_{2}^{(1)} + f_{1}^{(2)} &= 0 \\\\\n", " f_{3} = f_{2}^{(2)} + f_{1}^{(3)} &= 0 \\\\\n", " f_{4} = f_{2}^{(3)} + f_{1}^{(4)} &= 0 \\\\\n", " f_{5} = f_{2}^{(4)} &= F \\\\\n", " \\end{split}\n", "$$\n", "\n", "Making substitutions we find\n", "\n", "\n", "$$\n", " \\begin{split}\n", " R &= k_{1}u_{1} - k_{1}u_{2} \\\\\n", " 0 &= -k_{1}u_{1} + k_{1}u_{2} + k_{2}u_{2}-k_{2}u_{3} \\\\\n", " 0 &= -k_{2}u_{2} + k_{2}u_{3} + k_{3}u_{3} - k_{3}u_{4} \\\\\n", " 0 &= -k_{3}u_{3} + k_{3}u_{4} + k_{4}u_{4} - k_{4}u_{5} \\\\\n", " F &= -k_{4}u_{4} + k_{4}u_{5}\\\\\n", " \\end{split}\n", "$$\n", "\n", "\n", "In matrix form\n", "\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " R \\\\ 0 \\\\ 0 \\\\ 0 \\\\ F\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " k_{1} & -k_{1} & 0 & 0 & 0\\\\\n", " -k_{1} & k_{1} + k_{2} & -k_{2} & 0 & 0\\\\\n", " 0 & -k_{2} & k_{2} + k_{3} & -k_{3} & 0 \\\\\n", " 0 & 0 & -k_{3} & k_{3} + k_{4} & -k_{4} \\\\\n", " 0 & 0 & 0 & -k_{4} & k_{4}\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " u_{1} \\\\ u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Note: There is more than one way to assemble the global system of equations. Another method is using superposition, as shown below\n", "
\n", "\n", "These global equations can also be obtained using the superposition. Let's write the local force/displacement equation for element 1 in the following expanded form\n", "\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " f_{1} \\\\ f_{2} \\\\ f_{3} \\\\ f_{4} \\\\ f_{5}\n", " \\end{Bmatrix}\n", " =\n", " \\begin{Bmatrix}\n", " R \\\\ 0 \\\\ 0 \\\\0 \\\\ 0\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " k_{1} & -k_{1} & 0 & 0 & 0 \\\\\n", " -k_{1} & k_{1} & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " u_{1} \\\\ u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "\n", "Similarly,\n", "\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " f_{1} \\\\ f_{2} \\\\ f_{3} \\\\ f_{4} \\\\ f_{5}\n", " \\end{Bmatrix}\n", " =\n", " \\begin{Bmatrix}\n", " 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & k_{2} & -k_{2} & 0 & 0 \\\\\n", " 0 & -k_{2} & k_{2} & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " u_{1} \\\\ u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " f_{1} \\\\ f_{2} \\\\ f_{3} \\\\ f_{4} \\\\ f_{5}\n", " \\end{Bmatrix}\n", " =\n", " \\begin{Bmatrix}\n", " 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & k_{3} & -k_{3} & 0 \\\\\n", " 0 & 0 & -k_{3} & k_{3} & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " u_{1} \\\\ u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "and\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " f_{1} \\\\ f_{2} \\\\ f_{3} \\\\ f_{4} \\\\ f_{5}\n", " \\end{Bmatrix}\n", " =\n", " \\begin{Bmatrix}\n", " 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ F\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & 0 & 0 \\\\\n", " 0 & 0 & 0 & k_{4} & -k_{4} \\\\\n", " 0 & 0 & 0 & -k_{4} & k_{4}\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " u_{1} \\\\ u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "This process can be generalized and the global displacement/force equations written\n", "\n", "\n", "$$\n", " \\{F\\}= [K] \\{u\\}\n", "$$\n", "\n", "\n", "Where\n", "\n", "\n", "$$\n", " [K] = \\sum_{e=1}^N [k]^{(e)}\n", " \\quad \\mathrm{and} \\quad\n", " \\{F\\} = \\sum_{e=1}^N \\{f\\}^{(e)}\n", "$$\n", "\n", "\n", "where $[k]^{(e)}$ and $\\{f\\}^{(e)}$ are the expanded element stiffness and force, respectively." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Degree of Freedom Mapping\n", "\n", "This assembly procedure defines a mapping from local degrees of freedom to global degrees of freedom. Mathematically, the mapping from local to global degrees of freedom is given by\n", "\n", "$$\n", "n_{\\text{dof}}^{\\text{sys}} = n \\times n_{\\text{dof}}^{\\text{d}} + d\n", "$$ \n", "\n", "where $n$ is the global node number and the local degree of freedom $d$ takes values $0, 1, 2$ for the $x, y, z$ degree of freedom, respectively.\n", "\n", "Graphically, the mapping looks like\n", "\n", "\n", "\n", "
\n", "This mapping is true only for node numbering staring at 0!\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Step 6: Apply Boundary Conditions\n", "\n", "It can be shown that $\\det{[K]}=0$, or, $[K]$ is non-invertible. Meaning that, **as is, the system is not stable** and has either no solutions or infinite solutions. Boundary conditions must be supplied to make the system non-singular. This makes sense intuitively, before boundary conditions are specified the structure is free to move without constraint, meaning that there are infinite solutions for the displacement at each node.\n", "\n", "For our tapered bar problem, consider the condition that the origin is fixed. Boundary conditions of this type are called *homogeneous*. In our example, this means that $u_{1}=0$ and \n", "\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " R \\\\ 0 \\\\ 0 \\\\ 0 \\\\ F \\\\\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " k_{1} & -k_{1} & 0 & 0 & \\\\\n", " -k_{1} & k_{1} + k_{2} & -k_{2} & 0 & 0 \\\\\n", " 0 & -k_{2} & k_{2} + k_{3} & -k_{3} & 0 \\\\\n", " 0 & 0 & -k_{3} & k_{3} + k_{4} & -k_{4} \\\\\n", " 0 & 0 & 0 & -k_{4} & k_{4}\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " 0 \\\\ u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "\n", "note that the displacements $u_{2}, u_{3},$ and $u_{4}$ do not explicitly depend on the reaction force $f_{1}$, this motivates us to write the following partitions:\n", "\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " R \\\\ \\hline 0 \\\\ 0 \\\\ 0 \\\\ F \\\\\n", " \\end{Bmatrix}\n", " =\n", " \\left[\n", " \\begin{array}{c|ccc}\n", " k_{1} & -k_{1} & 0 & 0 & 0\\\\\n", " \\hline -k_{1} & k_{1}+k_{2} & -k_{2} & 0 & 0 \\\\\n", " 0 & -k_{2} & k_{2} + k_{3} & -k_{3} & 0 \\\\\n", " 0 & 0 & -k_{3} & k_{3} + k_{4} & -k_{4} \\\\\n", " 0 & 0 & 0 & -k_{4} & k_{4}\n", " \\end{array}\n", " \\right]\n", " \\begin{Bmatrix}\n", " 0 \\\\ \\hline u_{2} \\\\ u_{3} \\\\ u_{4} \\\\ u_{5}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "\n", "or,\n", "\n", "\n", "$$\n", " \\begin{Bmatrix}\n", " \\{F^1\\} \\\\ \\{F^2\\}\n", " \\end{Bmatrix}\n", " =\n", " \\begin{bmatrix}\n", " \\left[K^{11}\\right] & \\left[K^{12}\\right] \\\\\n", " \\left[K^{21}\\right] & \\left[K^{22}\\right]\n", " \\end{bmatrix}\n", " \\begin{Bmatrix}\n", " \\{u^1\\} \\\\ \\{u^2\\}\n", " \\end{Bmatrix}\n", "$$\n", "\n", "\n", "where\n", "\n", "\n", "$$\n", " \\{F^1\\}=[R]^T, \\quad \\{F^2\\}=[0, \\ 0, \\ 0, \\ F]^T\n", "$$\n", "\n", "\n", "\n", "\n", "$$\n", " \\left[K^{11}\\right] = \\left[ k_{1} \\right],\n", " \\ldots,\n", " \\left[K^{22}\\right] =\n", " \\begin{bmatrix}\n", " k_{1}+k_{2} & -k_{2} & 0 & 0 \\\\\n", " -k_{2} & k_{2}+k_{3} & -k_{3} & 0 \\\\\n", " 0 & -k_{3} & k_{3} + k_{4} & -k_{4} \\\\\n", " 0 & 0 & -k_{4} & k_{4}\n", " \\end{bmatrix}\n", "$$\n", "\n", "\n", "and\n", "\n", "\n", "$$\n", " \\{u^1\\} = [0]^T,\n", " \\quad\n", " \\{u^2\\} = \\left[u_{2}, \\ u_{3}, \\ u_{4}, \\ u_{5} \\right]^T\n", "$$\n", "\n", "\n", "In expanded form,\n", "\n", "\n", "$$\n", " \\{F^1\\}=\\left[ K^{11}\\right]\\{u^1 \\} + \\left[ K^{12} \\right] \\{u^2\\}\n", "$$\n", "\n", "$$\n", " \\{F^2\\} = \\left[K^{21}\\right]\\{u^1 \\} + \\left[K^{22}\\right]\\{u^2\\}\n", "$$\n", "\n", "
\n", "The above method of applying boundary conditions is referred to as a partitioning method. If combined with re-ordering of the global equations, it is a great way of decreasing the size of the system being solved. However, it is more difficult to implement computationally.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Solution Phase\n", "\n", "#### Step 1: Solve for the Nodal Displacements\n", "\n", "Solve for displacements that satisfy\n", "\n", "$$\n", "[K]^*\\{u\\} = \\{F\\}^*\n", "$$\n", "\n", "where $[K]^*$ and $\\{F\\}^*$ are the boundary condition modified stiffness and force.\n", "\n", "Upon solving for $\\{u\\}$ we find\n", "\n", "$$\n", " \\begin{Bmatrix} u_1 \\\\ u_2 \\\\ u_3 \\\\ u_4 \\end{Bmatrix}\n", " =\n", " F \\begin{Bmatrix} 0 \\\\\n", " \\frac{1}{k_1} \\\\\n", " \\frac{1}{k_1} + \\frac{1}{k_2} \\\\\n", " \\frac{1}{k_1} + \\frac{1}{k_2} + \\frac{1}{k_3} \\\\\n", " \\frac{1}{k_1} + \\frac{1}{k_2} + \\frac{1}{k_3} + \\frac{1}{k_4}\n", " \\end{Bmatrix}\n", "$$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Step 2: Compute Reactions\n", "\n", "Finally, the reaction force at the fixed boundary can be found from\n", "\n", "$$\n", "\\{r\\} = [K]\\{u\\} - \\{f\\}\n", "$$\n", "\n", "which, for this example, reduces to\n", "\n", "$$\n", " f_{1}\n", " = -k_{1}u_{2} = -F\n", "$$\n", "\n", "\n", "which is not a surprising result." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Post Processing Phase\n", "\n", "#### Step 1: Find element strains and stresses and other important information.\n", "\n", "##### General Spring Element\n", "\n", "For spring elements, post processing involves computing resultant element elongation and forces\n", "\n", "\n", "\n", "\n", "\n", "
Element ElongationElement Forces
\n", "$$\\begin{pmatrix}\n", "\\Delta L^{(1)} \\\\\n", "\\Delta L^{(2)} \\\\\n", "\\Delta L^{(3)} \\\\\n", "\\end{pmatrix} = \n", "\\begin{pmatrix}\n", "u_2 - u_1 \\\\\n", "u_3 - u_2 \\\\\n", "u_4 - u_3\n", "\\end{pmatrix} $$$$\\begin{pmatrix}\n", "f^{(1)} \\\\\n", "f^{(2)} \\\\\n", "f^{(3)}\n", "\\end{pmatrix} = \n", "\\begin{pmatrix}\n", "k^{(1)}\\Delta L^{(1)} \\\\\n", "k^{(1)}\\Delta L^{(2)} \\\\\n", "k^{(1)}\\Delta L^{(3)}\n", "\\end{pmatrix} $$\n", "
\n", "\n", "##### Bar Element\n", "\n", "For bar elements, post processing involves computing resulant strains, stresses, and forces.\n", "\n", "\n", "\n", "\n", "\n", "
Element ElongationElement Strains
$$\\begin{pmatrix}\n", "\\Delta L^{(1)} \\\\\n", "\\Delta L^{(2)} \\\\\n", "\\Delta L^{(3)}\n", "\\end{pmatrix} = \n", "\\begin{pmatrix}\n", "u_2 - u_1 \\\\\n", "u_3 - u_2 \\\\\n", "u_4 - u_3\n", "\\end{pmatrix} $$$$\\begin{pmatrix}\n", "\\epsilon^{(1)} \\\\\n", "\\epsilon^{(2)} \\\\\n", "\\epsilon^{(3)}\n", "\\end{pmatrix} = \n", "\\begin{pmatrix}\n", "\\Delta L^{(1)} / L^{(1)} \\\\\n", "\\Delta L^{(2)} / L^{(2)} \\\\\n", "\\Delta L^{(3)} / L^{(3)}\n", "\\end{pmatrix}$$
\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Element StressesElement Forces
$$ \\begin{pmatrix}\n", "\\sigma^{(1)} \\\\\n", "\\sigma^{(2)} \\\\\n", "\\sigma^{(3)}\n", "\\end{pmatrix} =\n", "\\begin{pmatrix}\n", "E^{(1)}\\epsilon^{(1)} \\\\\n", "E^{(2)}\\epsilon^{(2)} \\\\\n", "E^{(3)}\\epsilon^{(3)}\n", "\\end{pmatrix}$$ $$ \\begin{pmatrix}\n", "f^{(1)} \\\\\n", "f^{(2)} \\\\\n", "f^{(3)}\n", "\\end{pmatrix} = \n", "\\begin{pmatrix}\n", "A^{(1)}\\sigma^{(1)} \\\\\n", "A^{(2)}\\sigma^{(2)} \\\\\n", "A^{(3)}\\sigma^{(3)}\n", "\\end{pmatrix}$$
." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 2: Parallel Spring Network\n", "\n", "Consider the following network of springs\n", "\n", "\n", "\n", "\n", "\n", "With the left and right edges of the plate is fixed as shown, what is the displacement of the rigid bar due to the force $P$?\n", "\n", "We solve the problem using the same steps as above. However, we solve the problem entirely using sympy.\n", "\n", "#### Preprocessing Phase\n", "\n", "Individual element stiffnesses take the same form as in previous examples. However, when inserting the element stiffnesses in to the appropriate locations in the global stiffness, we must account for the fact that 3 elements have node 2 in common. Note that\n", "\n", "$$\n", " \\begin{split}\n", " u_{1}^{(1)} &= u_{1} = 0 \\\\\n", " u_{2}^{(1)} = u_{1}^{(2)} = u_{1}^{(3)} &= u_{2} \\\\\n", " u_{2}^{(3)} &= u_{3} = 0 \\\\\n", " u_{2}^{(4)} &= u_{4} = 0 \\\\\n", " \\end{split}\n", "$$\n", "\n", "Expansion of element stiffness for insertion in to the global stiffness is demonstrated below." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sympy as sp\n", "import numpy as np\n", "from sympy import Matrix, symbols, Symbol, zeros as spzeros, init_printing, N\n", "init_printing()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "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dKm6VGIFxMA+q7pUYgXEwD6rulRiBcRAMKuAeyhOD4GNLFNX\nU8W9wAdIBdxDqEDF4ApvE1dRcod8eKmQe4h5ykf13iauoeUO+fBSIfcQExWPrvA2cQ0ld8yHlwq5\nh5ioeHSFt4lrKLljPqxU0D3ERMWjem8Tl9Byx3xYqaAlhplKR0NvM1jNKQ3ncUruBT7vlMp7m2Q1\nJy+BdEQpVYEPKxV0D6WcCQ5YpmQ1JwlSHSi5e681y4eVyiD3UNVAEuS9TTckXz+aJEpO6LgX+PBS\nIfcw4aY5Qb1Nv5pTkyuKUXEv8eGlQu5hxEx36Eo/LNNwNacuG4lScS/x4aX6YcvUr+YkTSsPgPPJ\nZqRea8oHSAXcQ7ZczQDxNoPVnDU5OKyGe4kPkIqj8frzdDXn6/PXZszz+Qip6GrO2sYa4Mnq0kf+\nz5CKrOZ8UHvjY5bPZ0j1RlXkpbtUYq26VJVS9b86iQV7/tXJyf1NxXF8/Ic/OOpXji5/dXIczf+5\nOWO6syLbKQAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left[\\begin{matrix}k_{1} & - k_{1} & 0 & 0\\\\- k_{1} & k_{1} + k_{2} + k_{3} & - k_{2} & - k_{3}\\\\0 & - k_{2} & k_{2} & 0\\\\0 & - k_{3} & 0 & k_{3}\\end{matrix}\\right]$$" ], "text/plain": [ "⎡k₁ -k₁ 0 0 ⎤\n", "⎢ ⎥\n", "⎢-k₁ k₁ + k₂ + k₃ -k₂ -k₃⎥\n", "⎢ ⎥\n", "⎢ 0 -k₂ k₂ 0 ⎥\n", "⎢ ⎥\n", "⎣ 0 -k₃ 0 k₃ ⎦" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Expand element stiffnesses to have same shape as global stiffness\n", "# by inserting appropriate columns and rows of zeros.\n", "k1, k2, k3 = symbols('k1 k2 k3')\n", "K1 = Matrix(4, 4, lambda i,j: 0)\n", "K1[0:2, 0:2] = Matrix(2, 2, lambda i,j: k1 if i==j else -k1)\n", "K2 = Matrix(4, 4, lambda i,j: 0)\n", "K2[1:3, 1:3] = Matrix(2, 2, lambda i,j: k2 if i==j else -k2)\n", "K3 = Matrix(4, 4, lambda i,j: 0)\n", "K3[1, :] = Matrix(1,4,[0,k3, 0, -k3])\n", "K3[3, :] = Matrix(1,4,[0,-k3, 0, k3])\n", "Kg = K1 + K2 + K3\n", "Kg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Apply Boundary Conditions\n", "\n", "In this example, we apply boundary conditions using the \"penalty method\". The penalty method is easily explained by example. Consider the global system of equations\n", "\n", "$$\n", "\\begin{bmatrix} \n", "k_1 & -k_1 & 0 & 0\\\\\n", "-k_1 & k_1+k_2+k_3 & -k_2 & -k_3 \\\\\n", "0 & -k_2 & k_2 & 0 \\\\\n", "0 & -k_3 & 0 & k_3 \n", "\\end{bmatrix}\n", "\\begin{Bmatrix} \n", "u_1 \\\\\n", "u_2 \\\\\n", "u_3 \\\\\n", "u_4\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix} \n", "R_1 \\\\\n", "P \\\\\n", "R_3 \\\\\n", "R_4\n", "\\end{Bmatrix}\n", "$$\n", "\n", "We substitute for the unknown reactions the known boundary conditions times a large number $X$. In the stiffness matrix, we substitute the appropriate components with $X$, as shown:\n", "\n", "$$\n", "\\begin{bmatrix} \n", "X & -k_1 & 0 & 0\\\\\n", "-k_1 & k_1+k_2+k_3 & -k_2 & -k_3 \\\\\n", "0 & -k_2 & X & 0 \\\\\n", "0 & -k_3 & 0 & X\n", "\\end{bmatrix}\n", "\\begin{Bmatrix} \n", "u_1 \\\\\n", "u_2 \\\\\n", "u_3 \\\\\n", "u_4\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix} \n", "X u^*_1 \\\\\n", "P \\\\\n", "X u^*_3 \\\\\n", "X u^*_4\n", "\\end{Bmatrix}\n", "$$\n", "\n", "Inspecting row 1, we see\n", "\n", "$$Xu_1 - k_1 u_2 = X u_1^*$$\n", "\n", "where $u_1^*$ is the known boundary condition ($u_1^*=0$ in this case). On dividing by $X$ we get\n", "\n", "$$u_1 - \\frac{k_1 u_2}{X} = u_1^*$$\n", "\n", "if $X$ is chosen large enough $\\frac{k_1 u_2}{X} \\approx 0$ and\n", "\n", "$$u_1 \\approx u_1^*$$\n", "\n", "Generally, the penalty method follows as\n", "\n", "For a known displacement $\\delta_m$ applied at node $m$ and $X>>\\text{any} \\ K_{ij}$\n", "\n", "$$\\begin{align} K_{mm} &= X \\\\ F_{m} &= X\\delta_m \\end{align}$$\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG0AAABlCAMAAABwdZ0JAAAAP1BMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADFBd4eAAAAFHRS\nTlMAMquZdlQQQO0wRM3viSJmu918bCLsZyAAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAQgSURBVGgF\n7Vprl5wgDEVh2O34bvn/v7UkvIOoVOb0nFY+rIghVy6BvYZh7BNlElMvtWOhK4n/TmHpk8abN3xh\njK+MLRrqBZ43A8JYp7jQ5XUTIOnONcqiNEinm5Ue5AIQvW7pFDS1L3xgUs3a7+gGAvgBbRCSdfzt\ngSWfBC+9ygDTwljRRo6ddg1Gm6YVS4o2ArnCPtKXQb+U3OD1sjKv6KhoI8WgHVk05zJFG6ZeRL6X\nEUCmIYNicuW9QSvbQJR0hsl9NBKWK96/7CAIpjDNwea1umIo1lAviSGh3NykYyNoCu/fyk1ygmfR\n9m1gztisFrYBkH9dgrYsUVRIxcH/O57JAGjQSjYw2csomdAucL1hxxRt1RzMftyzwl2gM5eAY2oG\nrWTTwV4CITDxiVtmzQoMKwD9rJt1nHnyvcDgGM26IJd0bPiQYxzpqjSD8kxKFUenYxLH722Ie3Kb\noPXobfJUmnl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{matrix}\\right]$$" ], "text/plain": [ "⎡5.0e-30⎤\n", "⎢ ⎥\n", "⎢ 0.5 ⎥\n", "⎢ ⎥\n", "⎢2.5e-30⎥\n", "⎢ ⎥\n", "⎣2.5e-30⎦" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Apply boundary conditions by setting appropriate components of K\n", "# to 0 or 1. We form K by making a copy of Kg so that we can retain\n", "# the original stiffness.\n", "K = Matrix(Kg)\n", "X = 1.E+30\n", "K[0,0] = X\n", "K[2,2] = X\n", "K[3,3] = X\n", "\n", "# Form the force array F. Note that f1 and f3 are the unknown reaction\n", "# forces\n", "P = symbols('P')\n", "F = Matrix(4, 1, [0, P, 0, 0])\n", "\n", "# Solve for displacements.\n", "u = K.LUsolve(F)\n", "\n", "# At this point, the solution will be messy. \n", "# Let's substitute some actual numbers\n", "subs ={k1: 10, k2: 5, k3: 5, P: 10}\n", "N(u.subs(subs))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH0AAABkCAMAAACch89EAAAAP1BMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADFBd4eAAAAFHRS\nTlMAMquZdlQQQO0wRM3d74kiZrt8bEuug40AAAAJcEhZcwAADsQAAA7EAZUrDhsAAAOUSURBVGgF\n7Zvr0qMgDIZRkH7rAXSX+7/WJQFRmXJaWjudhT+KUJ8SQsirLekUlp7cWWYDJaRTlOky3AknKyB7\nBfTuVvABW+voE+Oko6O7H6eC0fyxVNIXmD3m4GTS08dneVyIn1XSJ9GzE2tdgCamOPNoraR762TD\n+qD4AYievZaukD6q3OVTS1/Xk5dxRWGo49kT3jn2TdtYqt3npRIA68whyjWNlWPHm2yzBb2ZzqfZ\nlckta6qs23Mz6Lss3+PaEs70Zt6Hm7xuQTp1K2zeYA5WV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$$" ], "text/plain": [ "⎡ -5.0 ⎤\n", "⎢ ⎥\n", "⎢-5.0e-29⎥\n", "⎢ ⎥\n", "⎢ -2.5 ⎥\n", "⎢ ⎥\n", "⎣ -2.5 ⎦" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Solve for reactions by back substituting u in to the global equations\n", "react = Kg * u - F\n", "react.subs(subs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Which is exactly as expected.\n", "\n", "
\n", "The penalty method is less accurate as the number of nodes & elements increases, but it is algorithmically simple and leads to a general formulation for boundary conditions.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 3: Prescribed Displacement\n", "\n", "Suppose now, that instead of there being an applied force to the end of our tapered beam we force the displacement at the end of the beam to be some prescribed amount $\\delta$.\n", "\n", "\n", "\n", "The solution technique is similar the previous problem. Namely, find element stiffnesses, derive the global stiffness, apply boundary conditions, solve for displacements, and find element forces.\n", "\n", "We'll solve this problem again using sympy.\n", "\n", "#### Preprocessing Phase" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Stiffness and force symbols\n", "k1, k2, d = symbols('k_1 k_2 delta')\n", "\n", "# Global stiffness matrix\n", "Kg = Matrix([[ k1, -k1, 0], \n", " [-k1, k1 + k2, -k2], \n", " [ 0, -k2, k2]])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Apply Boundary Conditions\n", "\n", "We've looked at partitioning the system of equations and the penalty method as ways of applying boundary conditions. In this example we use a substitution method whereby the unknown reactions are substituted with the known boundary conditions and 1s and 0s are substituted in the appropriate locations in the global stiffness. This is perhaps best shown with an example, consider the global system for this problem\n", "\n", "$$\n", "\\begin{bmatrix}\n", "k_1 & -k_1 & 0 \\\\ \n", "-k_1 & k_1 + k_2 & -k2 \\\\ \n", "0 & -k2 & k2\n", "\\end{bmatrix}\n", "\\begin{Bmatrix}\n", "u_1 \\\\ \n", "u_2 \\\\ \n", "u_3\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix}\n", "R_1 \\\\ \n", "0 \\\\ \n", "R_3\n", "\\end{Bmatrix} \\Longrightarrow\n", "\\begin{bmatrix}\n", "1 & 0 & 0 \\\\ \n", "-k_1 & k_1 + k_2 & -k2 \\\\ \n", "0 & 0 & 1\n", "\\end{bmatrix}\n", "\\begin{Bmatrix}\n", "u_1 \\\\ \n", "u_2 \\\\ \n", "u_3\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix}\n", "0 \\\\ \n", "0 \\\\ \n", "\\delta\n", "\\end{Bmatrix}\n", "$$\n", "\n", "It's easy to see that this system of equations satisfies the boundary conditions.\n", "\n", "
\n", "Note: The substitution method as shown is simple to implement, but has the (severe) disadvantange that the resulting system of equations is not symmetric. We will later see how to make the system symmetric\n", "
" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEMAAABLCAMAAAAcR8osAAAAPFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo1xBWAAAAE3RSTlMA\nMquZdlQQQOkwRInN3SJm77tsdo1uFAAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAqdJREFUWAntmNnS\nnSAMgIMg/SsqUt7/XZuAC0gAT+10Op1ycRZjPmPIpiB8WAN8vpaoCiC8VLjGzxFgSXHwxBAtdS2N\nkq0zbJ8xo4F6WeuX6TPsRtpmfsNwwdej11VI3w4fGJOvu7zL0F6SAZNXv27H6g0pi/jFcrp2/A6G\njga8uheI/hjf+BQWR06wr/ZWhRiTr2IMFor1rZEw3X1BfYOp2UDgfXbzlo2J9OB/RuoNip2/36dC\nLjOWUbWF7M/tT/+17gVVJzp3CZ+pVv67xVA2nKsb6RZOaDF07DvTkl+2+Ndi2DloGwlCtRppg+Em\n7eluZjviLw3CGMd2qjrDoEsd1XS/N0qsRfxt1RkerymxIYhNudBbsArx7q0yNAYwzLiryiEGYv0Y\nWfdWGbBoWKkAOgVigRBmmkKuXHXGKpWhHkt6gyI79MD33DqjuJ6Wq2aj/gMGzU0f+qOwo3qA7Pj2\n9X2Xxwnt8eeu9eMrr0HtROelhT+4RL9yn5MWtZCNxNBxyXBWWjDYjDgZrLRgsIl+MlhpwTgSfXd5\n/DoZrLRgHImO8X0F9sk4pHkpue3LmeiT2UJ+DTOujT6wHJ1ShCauuTGSRE+m68OOU5qXkhsjSXSG\nkUghKSU3xpXowDASaVpKboxkOxjGJc1KySNGmLYvAMZrVkpqDKG8rE/5eSmpMdKr9n7/OcakbGO4\nfGQHNkvXeG58xKCGfWVP4Z5HDBMHkUJ5P/CIMVHvra9HDIiDSI3yhLEa2XiaezSfCky1maaA2urb\noTdsDbaxtUUtLK8VnqCarxX6dmy0saI1X3YZccC0bMPfje4yIHjCtaKszzA4101HVS7dhUf6DMBH\nwqKQZawHjOx87s+/xwgTWOvRgHMDHTvfsWl6UabUNTHVNMrj4R2bUvATHQglfphjd+QAAAAASUVO\nRK5CYII=\n", "text/latex": [ "$$\\left[\\begin{matrix}0\\\\\\frac{\\delta k_{2}}{k_{1} + k_{2}}\\\\\\delta\\end{matrix}\\right]$$" ], "text/plain": [ "⎡ 0 ⎤\n", "⎢ ⎥\n", "⎢ δ⋅k₂ ⎥\n", "⎢───────⎥\n", "⎢k₁ + k₂⎥\n", "⎢ ⎥\n", "⎣ δ ⎦" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Apply boundary conditions to a copy of the global stiffness. We\n", "# set appropriate components to the first and last row of K to 0 or 1\n", "# to strictly enforce the known displacement\n", "K = Matrix(Kg)\n", "K[2,1], K[2,2] = 0, 1\n", "\n", "# Form the force array - inserting known boundary conditions in to\n", "# the appropriate locations\n", "f1 = symbols('f1')\n", "F = Matrix([[f1], \n", " [0], \n", " [d]])\n", "\n", "u2, u3 = symbols('u2 u3')\n", "u = Matrix(3, 1, [0, u2, u3])\n", "u[1:, :] = K[1:, 1:].LUsolve(F[1:, :])\n", "u" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Solve for reactions" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIsAAABXCAMAAAADO0aZAAAAP1BMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADFBd4eAAAAFHRS\nTlMAMquZdlQQQO0wRM3dIolmu+98bPScZGcAAAAJcEhZcwAADsQAAA7EAZUrDhsAAATmSURBVGgF\n7ZrptqQoDICxRO5tF9Ru3/9ZJ2ErttJY4fbUmTP8sJSo+SpECATRHaY8xBul6+dpEULuOn24qEjF\n+dVsEYTojl5CGfIbKNeAMOJ9szlGTxQVkaw8XRHgcSBLV0qJNXI1N6pDpQ8UFam4erUyWZT9H+Oc\nvb2oyOS1Sy7LOhkK3YtOxg5XVNSUZ3VMlm1UB7bStA5whu30sI3lKzqtN/BtUuGxaHDdrQdFR29d\nbtS71ewrNvDtvP1egfFYDlDcS/D+XW7uM5wNS6iYhCC7MYtFgeOLCb5muQGOMKaxLFGFGP6OXWYl\nFvjnYpOim4Xp7ixLVKGwLyQVll3E0kuNvorqHjKyy7NCOWcm0PBYKgqsXYJA9YvKhocgy08as3Ty\n6JOxBAea5v6ipjmUCVvDjmbkY26EynVju1Q00Ks4LOdxwbm0RshhKQMF0PCMHe5FDfAoh6XaoUKn\nb0tV6oXVXw5LdaAJLFVplcFXcliqcUFgqUq92uovh8XHBSFQQA2BxUvpUQOHxccFIVBIWLwU4IjN\nxWAJcQFE3mb4e0xQdjxAeBWk9KiBwRLFBdEg5NsoklKjBgZLFBdUWCIpNWpgsDzjAtdG5uPwdnlK\nyVEDg8WotoeKXYKUHjW0YEkCBYzEk0KPGlqwJKoZF/+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UVORK5CYII=\n", "text/latex": [ "$$\\left[\\begin{matrix}- \\frac{\\delta k_{1} k_{2}}{k_{1} + k_{2}}\\\\0\\\\- \\frac{\\delta k_{2}^{2}}{k_{1} + k_{2}} + \\delta k_{2}\\end{matrix}\\right]$$" ], "text/plain": [ "⎡ -δ⋅k₁⋅k₂ ⎤\n", "⎢ ───────── ⎥\n", "⎢ k₁ + k₂ ⎥\n", "⎢ ⎥\n", "⎢ 0 ⎥\n", "⎢ ⎥\n", "⎢ 2 ⎥\n", "⎢ δ⋅k₂ ⎥\n", "⎢- ─────── + δ⋅k₂⎥\n", "⎣ k₁ + k₂ ⎦" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Solve for reactions by back substitution\n", "react = Kg * u\n", "react" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 4: Self-Weight\n", "\n", "#### Load Types\n", "\n", "In previous examples, forces were applied directly to the model nodes. There are situations, however, that loads act on a body or a surface. Body loads have units of force per unit mass and scale with element volume. Surface tractions have units of force per unit area and scale with element surface area or cross section. \n", "\n", "#### Element Body Forces\n", "\n", "A *distributed body force* has units of force/length in 1D. In structural problems, body forces are often the result of gravity. Body forces can also result from acceleration, e.g., a centripetal force in a centrifuge.\n", "\n", "Element force due to a general body load is given by\n", "\n", "$$\n", "b^{(e)} = \\left(\\frac{\\text{force}}{\\text{mass}}\\right)\\rho^{(e)} V^{(e)}\n", "$$\n", "\n", "The element force due to self-weighted bar:\n", "\n", "$$\n", "w^{(e)}=g\\rho^{(e)}A^{(e)}L^{(e)}\n", "$$\n", "\n", "and the distributed body load is\n", "\n", "$$\n", "b(x) = \\frac{w^{(e)}}{L^{(e)}} = \\frac{m^{(e)}g}{L^{(e)}} \n", "= \\rho^{(e)}A^{(e)}g\n", "$$\n", "\n", "#### Nodal Forces\n", "\n", "Body loads are defined over the element domain, but our FE method admits only forces applied at nodes. So, body loads and surface tractions (􏰀point loads)􏰁 are partitioned to neighboring nodes as shown for element 1.\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Implementing the Direct Stiffness Method Computationally[](#top)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The steps necessary for implementing a 1D linear finite program computationally are shown in the figure below\n", "\n", "\n", "\n", "The computational implementation requires (minimally)\n", "\n", "- specification of mesh, loads and constrains, and material properties\n", "- assembly of element stiffnesses and forces in to the global stiffness and force\n", "- solution of $[K]\\{F\\}=\\{u\\}$ for unkown displacements\n", "- post processing results\n", "\n", "In the following sections, we walk through the actual machinery to implement the finite elemenet method computationally with the following example.\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pre Processing\n", "\n", "### Mesh Specification\n", "\n", "The mesh consists of vertices defining nodal coordinates and element connectivity tables specifiying how vertices are connected.\n", "\n", "#### Connectivity Tables\n", "\n", "For complex systems, especially in higher dimensions, manually assembling the global stiffness matrix would be tedious and error‐prone. To avoid errors in a FEM code we use a connectivity table, a lookup table that contains the nodes associated with each element.\n", "\n", "The element connectivity for our example is\n", "\n", "| Element Number | Node i | Node j |\n", "| :-------------: |:------:| :-----:|\n", "| 1 | 1 | 3 | \n", "| 2 | 3 | 4 |\n", "| 3 | 4 | 2 |\n", "\n", "#### Vertices\n", "\n", "Nodal coordinates (vertices) are given as an array of nodal coordinates. For our example we have\n", "\n", "In general, for a 3D mesh we have\n", "\n", "|Node|Coordinate|\n", "|:--:|:--------:|\n", "| 1 |$0.$|\n", "| 2 |$3.$|\n", "| 3 |$1.$|\n", "| 4 |$2.$|\n", "\n", "Node labels in the first column must correspond to the appropriate node labels in the connectivity table. But, they need not be given in ascending node order as shown. Alternatively, we could order the nodal coordinates as \n", "\n", "|Node|Coordinate|\n", "|:--:|:--------:|\n", "| 1 |$0.$|\n", "| 3 |$1.$|\n", "| 4 |$2.$|\n", "| 2 |$3.$|\n", "\n", "so long as there is a way for mapping the node label to the appropriate index of the vertices array. The mechanisim with which this accomplished the use of a node map that maps node labels to the appropriate index in the array of nodal vertices. For example nodal coordinates in the right column of the above table could be passed and the left column could be passed as the node map. The finite element program would then use the node map to look up the location of a node's vertices.\n", "\n", "### Constraints and Loads\n", "\n", "Constraints and loads are specified in such a way that the program can apply the appropriate contraint or load to the correct the node, local degree of freedom, and with the right magnitude. Several ways exist to pass this information to a program, one way is with an array of the following form\n", "\n", " a = [(node label of constraint/load 1, 'x' 'y' or 'z', magnitude 1),\n", " (node label of constraint/load 2, 'x' 'y' or 'z', magnitude 2),\n", " .\n", " .\n", " .\n", " (node label of constraint/load n, 'x' 'y' or 'z', magnitude n)]\n", " \n", "Each row contains the necessary information for applying a constraint or load to an appropriate node. Note, in our 1D examples, the local degree of freedom is restricted to be only '`x`'. This restriction is relaxed when we move on to more than one dimension." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution Phase\n", "\n", "### Assemble Global Equations\n", "\n", "Individual element stiffnesses must be \"assembled\" or mapped in to the global stiffness in the appropriate locations. We can use the information in the system's connectivity table to to generate the appropriate mapping. First consider the following question\n", "\n", "
\n", "Q: How can we tell by inspection if the stiffness matrix is correct?
\n", "\n", "A: Look at the ith row and jth column of K
\n", "\n", "\n", "
\n", "\n", "With that in mind, the algorithm for generating the stiffness matrix is:\n", "\n", " K = 0\n", " k = [k1, k2, k3, ..., kn]\n", " for all elements\n", " determine global index I of node i of element\n", " determine global index J of node j of element\n", " K[I, I] = K[I, I] + k[el]\n", " K[J, J] = K[J, J] + k[el]\n", " K[I, J] = K[I, J] - k[el]\n", " K[J, I] = K[J, I] - k[el]\n", " \n", "Incidentally, the algorithm shown is extremely inefficient and can be optimized, but optimization is the job of computer scientists. As engineers, we seek the right answer as a learning exercise. In this algorithm, the `i` and `j` global index are determined by the node mapping, previously discussed.\n", "\n", "The global force is assembled in a similar fashion.\n", "\n", "### Apply Boundary Conditions\n", "\n", "Below we implement concepts learned in to a concise code for determining nodal displacements. Let us first revisit the question of imposing boundary conditions. In the substitution method we saw that the resulting global stiffness was not symmetric. For large systems this becomes problematic because solving non-symmetric equations is much more expensive than symmetric. But, the substitution method is easy to implement and there is not a loss of accuracy as in the penalty method. Let's modify substitution method so that the system of equations remains symmetric. We look at Example 3. We had:\n", "\n", "$$\n", "\\begin{bmatrix}\n", "k_1 & -k_1 & 0 \\\\ \n", "-k_1 & k_1 + k_2 & -k2 \\\\ \n", "0 & -k2 & k2\n", "\\end{bmatrix}\n", "\\begin{Bmatrix}\n", "u_1 \\\\ \n", "u_2 \\\\ \n", "u_3\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix}\n", "R_1 \\\\ \n", "0 \\\\ \n", "R_3\n", "\\end{Bmatrix} \\Longrightarrow\n", "\\begin{bmatrix}\n", "1 & 0 & 0 \\\\ \n", "-k_1 & k_1 + k_2 & -k2 \\\\ \n", "0 & 0 & 1\n", "\\end{bmatrix}\n", "\\begin{Bmatrix}\n", "u_1 \\\\ \n", "u_2 \\\\ \n", "u_3\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix}\n", "\\delta_1 \\\\ \n", "0 \\\\ \n", "\\delta_3\n", "\\end{Bmatrix}\n", "$$\n", "\n", "where $\\delta_1$ and $\\delta_3$ are the known displacements. \n", "\n", "But, we would like the final system to be symmetric. We obtain the goal by setting each entry in the first and third columns (apart from the diagonal) to zero, so that the stiffness is symmetric. Recall that we can add and subtract equations in the system from one another without affecting the solution. Therefore, to symmetrize the stiffness matrix in our example, we can subtract appropriate multiples of the first and third rows so as to set each entry in the first and thrid columns to zero.\n", "\n", "$$\n", "\\begin{bmatrix}\n", "1 & 0 & 0 \\\\ \n", "0 & k_1 + k_2 & 0 \\\\ \n", "0 & 0 & 1\n", "\\end{bmatrix}\n", "\\begin{Bmatrix}\n", "u_1 \\\\ \n", "u_2 \\\\ \n", "u_3\n", "\\end{Bmatrix}\n", "=\n", "\\begin{Bmatrix}\n", "0 \\\\ \n", "k_1 \\delta_1 + k_2\\delta_3 \\\\ \n", "\\delta\n", "\\end{Bmatrix}\n", "$$\n", "\n", "Compare equations to convince yourself that this is correct.\n", "\n", "Generally, symmetric substitution follows as\n", "\n", "For a known displacement $\\delta_m$ applied at node $m$\n", "\n", "$$\n", "\\begin{align}\n", "F_i &= F_i − \\sum_{i=1, i\\neq m}^N K_{im}\\delta_m \\\\\n", "F_m &= \\delta_m \\\\\n", "K_{mj} &= 0, \\quad j=1\\ldots{}N \\\\\n", "K_{im} &= 0, \\quad i=1\\ldots{}N \\\\\n", "K_{mm} &= 1\n", "\\end{align}\n", "$$\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Linear Finite Element Code\n", "\n", "See `femlib.ifem.solve_system` for the code." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#%load femlib/ifem.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "Check out the new function 'enumerate' introduced in the code above. enumerate(thing), where thing is a sequence, returns a iterator that will return (0, thing[0]), (1, thing[1]), (2, thing[2]), and so forth.

\n", "\n", "A common idiom to change every element of a list looks like this:

\n", "\n", "for i in range(len(L)):
\n", "   item = L[i]
\n", "   # ... compute some result based on item ...
\n", "   L[i] = result
\n", "

\n", "This can be rewritten using enumerate() as:
\n", "

\n", "for i, item in enumerate(L):
\n", "   # ... compute some result based on item ...
\n", "   L[i] = result
\n", "

\n", "see the enumerate documentation\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The Example, Completed" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Recall our example problem\n", "\n", "\n", "\n", "Using `femlib.ifem.solve_system`, the solution for the unknown displacements and reactions is given by" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "u = [ 0. 0.90909091 1.36363636 0. ]\n", "r = [ -9.09090909e+02 0.00000000e+00 -1.81898940e-12 -4.09090909e+03]\n" ] } ], "source": [ "# Solution of the example problem\n", "from femlib.ifem import solve_system\n", "vertices = np.array([0., 1., 2., 3.])\n", "node_map = [1, 3, 4, 2]\n", "connect = np.array([[1, 1, 3],\n", " [2, 3, 4],\n", " [3, 4, 2]])\n", "k = [1000, 2000, 3000]\n", "F4x = 5000\n", "cfs = [(4, 'x', F4x)]\n", "bcs = [(1, 'x', 0), (2, 'x', 0)]\n", "\n", "u, r = solve_system(vertices, connect, k, bcs, cfs, node_map)\n", "print 'u =', u\n", "print 'r =', r" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.0\n" ] } ], "source": [ "# sum of reactions and force should be 0\n", "print round(np.sum(r) + F4x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A Uniform Bar Code\n", "\n", "An important part of computational mechanics is using existing libraries/code. Doing so saves time/resources and allows us to concentrate on more specific parts of our own codes. Let us use the previous code example to write a special purpose 1D uniform bar code. See `apps/uniformbar.py` for the implementation.\n", "\n", "Re-using the existing code allowed us to write a new application with only 5 or so lines of code." ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }