{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example: Frame and bars" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example is from the CALFEM MATLAB manual (exs7.m)\n", "\n", "**Purpose:** \n", "\n", "Set up a frame, consisting of both beams and bars, and illustrate the calculations by\n", "use of graphics functions.\n", "\n", "**Description:** \n", "\n", "A frame consists of horizontal and vertical beams, and is stabilized with diagonal\n", "bars" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![frame and bars](../images/frame_and_bars.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As usual, import necessary modules." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import calfem.core as cfc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The frame with its coordinates and loading is shown in the left figure, and the finite\n", "element model in the right. \n", "The matrices of the global system i.e. the stiffness matrix K, the load vector f, the\n", "coordinate matrix Coord, and the corresponding degrees of freedom matrix Dof are\n", "defined by" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "K = np.zeros([18,18])\n", "f = np.zeros([18,1])\n", "f[12,0] = 1.0\n", "\n", "coord = np.array([\n", " [0.0, 0.0],\n", " [1.0, 0.0],\n", " [0.0, 1.0],\n", " [1.0, 1.0],\n", " [0.0, 2.0],\n", " [1.0, 2.0]\n", "])\n", "\n", "dof1 = np.array([\n", " [1, 2, 3],\n", " [4, 5, 6],\n", " [7, 8, 9],\n", " [10, 11, 12],\n", " [13, 14, 15],\n", " [16, 17, 18]\n", "])\n", "\n", "dof2 = np.array([\n", " [1, 2],\n", " [4, 5],\n", " [7, 8],\n", " [10, 11],\n", " [13, 14],\n", " [16, 17]\n", "])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The material properties, the topology, and the element coordinates for the beams\n", "and bars respectively, are defined by" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ep1 = [1.0, 1.0, 1.0]\n", "\n", "edof1 = np.array([\n", " [1, 2, 3, 7, 8, 9],\n", " [7, 8, 9, 13, 14, 15],\n", " [4, 5, 6, 10, 11, 12],\n", " [10, 11, 12, 16, 17, 18],\n", " [7, 8, 9, 10, 11, 12],\n", " [13, 14, 15, 16, 17, 18]\n", "])\n", "\n", "ex1, ey1 = cfc.coordxtr(edof1, coord, dof1);\n", "\n", "ep2 = [1.0, 1.0]\n", "\n", "edof2 = np.array([\n", " [1, 2, 10, 11],\n", " [7, 8, 16, 17],\n", " [7, 8, 4, 5],\n", " [13, 14, 10, 11]\n", "])\n", "\n", "ex2, ey2 = cfc.coordxtr(edof2, coord, dof2);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create and assemble element matrices" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "for elx, ely, eltopo in zip(ex1, ey1, edof1):\n", " Ke = cfc.beam2e(elx, ely, ep1)\n", " cfc.assem(eltopo, K, Ke)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "for elx, ely, eltopo in zip(ex2, ey2, edof2):\n", " Ke = cfc.bar2e(elx, ely, ep2)\n", " cfc.assem(eltopo,K,Ke)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Solve equation system" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "bc_prescr = np.array([1, 2, 3, 4, 5, 6])\n", "a, r = cfc.solveq(K, f, bc_prescr)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0. ]\n", " [ 0.37905924]\n", " [ 0.30451926]\n", " [-0.65956297]\n", " [ 0.3041448 ]\n", " [-0.28495132]\n", " [-0.54570174]\n", " [ 1.19791809]\n", " [ 0.44655174]\n", " [-0.85908643]\n", " [ 0.96969909]\n", " [-0.34780417]\n", " [-0.74373562]]\n" ] } ], "source": [ "print(a)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.6.10 64-bit", "language": "python", "name": "python361064bit3b840f9918f246278fc4b65bf6247be2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.13" } }, "nbformat": 4, "nbformat_minor": 4 }