{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example: One-dimensional heat flow " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example is from the CALFEM manual (exs2.py).\n", "\n", "**Purpose:**\n", "\n", "Analysis of one-dimensional heat flow.\n", "\n", "**Description:**\n", "\n", "Consider a wall built up of concrete and thermal insulation. The outdoor\n", "temperature is −17 ◦C and the temperature inside is 20 ◦C. At the inside of\n", "the thermal insulation there is a heat source yielding $10 ~W/m^2$.\n", "\n", "![](../images/exs2.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The wall is subdivided into five elements and the one-dimensional spring\n", "(analogy) element `spring1e` is used. Equivalent spring stiffnesses are\n", "$k_i = λ A/L$ for thermal conductivity and $k_i = A/R$ for thermal\n", "surface resistance. Corresponding spring stiffnesses per $m^2$ of the wall\n", "are:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\\begin{align}\n", "k_1 &= 1/0.04 = 25.0 ~W/K \\\\\n", "k_2 &= 1.7/0.070 = 24.3 ~W/K \\\\\n", "k_3 &= 0.040/0.100 = 0.4 ~W/K \\\\\n", "k_4 &= 1.7/0.100 = 17.0 ~W/K \\\\\n", "k_5 &= 1/0.13 = 7.7 ~W/K \n", "\\end{align}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A global system matrix K and a heat flow vector f are defined. The heat source\n", "inside the wall is considered by setting $f_4 = 10$. The element matrices\n", "`Ke` are computed using `spring1e`, and the function `assem` assembles the\n", "global stiffness matrix.\n", "\n", "The system of equations is solved using `solveq` with considerations to the\n", "boundary conditions in `bc` and `bcVal`. The prescribed temperatures are \n", "$T_1 = −17 ~^{\\circ}C$ and $T_2 = 20~^{\\circ}C$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Necessary modules are first imported." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import calfem.core as cfc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, the element topology is defined" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "Edof = np.array([\n", " [1,2],\n", " [2,3],\n", " [3,4],\n", " [4,5],\n", " [5,6]\n", "])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create stiffness matrix K and load vector f" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "K = np.mat(np.zeros((6,6)))\n", "f = np.mat(np.zeros((6,1)))\n", "f[3] = 10.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define element properties (ep) and create element matrices for the different material layers." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "ep1 = 25.0\n", "ep2 = 24.3\n", "ep3 = 0.4\n", "ep4 = 17.0\n", "ep5 = 7.7" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Element stiffness matrices" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "Ke1 = cfc.spring1e(ep1)\n", "Ke2 = cfc.spring1e(ep2)\n", "Ke3 = cfc.spring1e(ep3)\n", "Ke4 = cfc.spring1e(ep4)\n", "Ke5 = cfc.spring1e(ep5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Assemble all element matrices into the global stiffness matrix" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Stiffness matrix K:\n", "[[ 25. -25. 0. 0. 0. 0. ]\n", " [-25. 49.3 -24.3 0. 0. 0. ]\n", " [ 0. -24.3 24.7 -0.4 0. 0. ]\n", " [ 0. 0. -0.4 17.4 -17. 0. ]\n", " [ 0. 0. 0. -17. 24.7 -7.7]\n", " [ 0. 0. 0. 0. -7.7 7.7]]\n" ] } ], "source": [ "cfc.assem(Edof[0,:], K, Ke1)\n", "cfc.assem(Edof[1,:], K, Ke2) \n", "cfc.assem(Edof[2,:], K, Ke3)\n", "cfc.assem(Edof[3,:], K, Ke4)\n", "cfc.assem(Edof[4,:], K, Ke5)\n", "\n", "print(\"Stiffness matrix K:\")\n", "print(K)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the boundary conditions and solve the system of equations" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Displacements a:\n", "[[-17. ]\n", " [-16.43842455]\n", " [-15.86067203]\n", " [ 19.23779344]\n", " [ 19.47540439]\n", " [ 20. ]]\n", "Reaction forces r:\n", "[[-1.40393862e+01]\n", " [ 0.00000000e+00]\n", " [ 0.00000000e+00]\n", " [ 0.00000000e+00]\n", " [ 5.68434189e-14]\n", " [ 4.03938619e+00]]\n" ] } ], "source": [ "bc = np.array([1,6])\n", "bc_val = np.array([-17.0, 20.0])\n", "a,r = cfc.solveq(K, f, bc, bc_val)\n", "\n", "print(\"Displacements a:\")\n", "print(a)\n", "\n", "print(\"Reaction forces r:\")\n", "print(r)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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": 2 }