{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 10 - Two-Dimensional Steady & Transient Heat Conduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa10.1 Page 195" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the values of T from 1st element to last is:\n", "\n", "47.142854591 \t91.2499974482 \t182.857141581 \t57.3214260196 \t114.999997448 \t220.178570153 \t47.1428558669 \t91.2499987241 \t182.857142219 \t" ] } ], "source": [ "from __future__ import division\n", "tnew=[]\n", "e=[]\n", "for i in range(1,10):\n", " tnew.append(101)\n", " e.append(1) #assumed values\n", "\n", "t=1e-6\n", "#since all the nodes are interior nodes so discretized eqn used is eqn 10.10\n", "while e[0]>t and e[1]>t and e[2]>t and e[3]>t and e[4]>t and e[5]>t and e[6]>t and e[7]>t and e[8]>t:\n", " told=[]\n", " for i in range(1,10):\n", " told.append(tnew[i-1])\n", " tnew[0]=(told[1]+40+told[3])/4 #on solving eqns for various nodes we get,\n", " tnew[1]=(tnew[0]+told[2]+told[4]+20)/4\n", " tnew[2]=(tnew[1]+told[5]+420)/4\n", " tnew[3]=(told[4]+tnew[0]+told[6]+20)/4\n", " tnew[4]=(tnew[1]+told[7]+told[5]+tnew[3])/4\n", " tnew[5]=(tnew[2]+tnew[4]+told[8]+400)/4\n", " tnew[6]=(tnew[3]+told[7]+40)/4\n", " tnew[7]=(tnew[4]+tnew[6]+told[8]+20)/4\n", " tnew[8]=(tnew[5]+420+tnew[7])/4\n", " e=[]\n", " for i in range(1,10):\n", " e.append(abs(tnew[i-1]-told[i-1]))\n", " \n", "\n", "print \"the values of T from 1st element to last is:\\n\"\n", "for i in range(1,10):\n", " print tnew[i-1],'\\t'," ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa10.2 Page 198" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the values of T from 1st element to last is:\n", "\n", "145.833332213 \t141.666666106 \t120.833333053 \t141.666666527 \t145.833333263 \t" ] } ], "source": [ "from __future__ import division\n", "tnew=[]\n", "e=[]\n", "for i in range(1,6):\n", " tnew.append(101)\n", " e.append(1)\n", "\n", "t=1e-6\n", "#since there is no source term so we get the following eqns.\n", "while e[0]>t and e[1]>t and e[2]>t and e[3]>t and e[4]>t:\n", " told=[]\n", " for i in range(1,6):\n", " told.append(tnew[i-1])\n", " \n", " tnew[0]=(told[1]*2+300)/4\n", " tnew[1]=(tnew[0]+told[2]+300)/4\n", " tnew[2]=(tnew[1]+told[3]+200)/4\n", " tnew[3]=(told[4]+tnew[2]+300)/4\n", " tnew[4]=(2*tnew[3]+300)/4\n", " \n", " for i in range(1,6):\n", " e[i-1]=(abs(tnew[0]-told[i-1]))\n", " \n", "\n", "print \"the values of T from 1st element to last is:\\n\"\n", "for i in range(1,6):\n", " print tnew[i-1],'\\t'," ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa10.3 Page 201" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the value of RED points respectively : 47.1429, 47.1429, 115.0000, 91.2500 & 47.1429\n", "the value of BLUE points respectively : 91.2500, 220.1786, 57.3214 & 91.2500\n" ] } ], "source": [ "from __future__ import division\n", "from numpy import zeros\n", "tn=zeros([5,5])\n", "for j in range(1,6):\n", " tn[j-1,0]=400 #defining conditions\n", "\n", "for j in range(2,5):\n", " tn[0,j-1]=20\n", " tn[4,j-1]=20\n", " tn[j-1,4]=20\n", "\n", "e=[] \n", "for i in range(1,10):\n", " e.append(1)\n", "\n", "for i in range(2,5):\n", " tn[i-1,1:4]=60\n", "\n", "\n", "t1=1e-6\n", "t=zeros([4,4])\n", "while e[0]>t1 and e[1]>t1 and e[2]>t1 and e[3]>t1 and e[4]>t1 and e[5]>t1 and e[6]>t1 and e[7]>t1 and e[8]>t1:\n", " for i in range(1,4):\n", " for j in range(1,4):\n", " t[i,j]=tn[i,j]\n", " \n", " #using red-black gauss-seidel method\n", " for i in range(1,4):\n", " for j in range(1,4):\n", " tn[i,j]=(tn[i+1,j]+tn[i-1,j]+tn[i,j+1]+tn[i,j-1])/4\n", " #now getting the absolute difference of the 9 variables\n", " e[0]=abs(t[1,1]-tn[1,1])\n", " e[1]=abs(t[1,2]-tn[1,2])\n", " e[2]=abs(t[1,3]-tn[1,3])\n", " e[3]=abs(t[2,1]-tn[2,1])\n", " e[4]=abs(t[2,2]-tn[2,2])\n", " e[5]=abs(t[2,3]-tn[2,3])\n", " e[6]=abs(t[3,1]-tn[3,1])\n", " e[7]=abs(t[3,2]-tn[3,2])\n", " e[8]=abs(t[3,3]-tn[3,3])\n", "\n", "#now defining positions of the various nodes according to red black combination\n", "R1=t[1,3]\n", "R2=t[3,3]\n", "R3=t[2,2]\n", "R4=t[1,2]\n", "R5=t[1,3]\n", "B1=t[3,2]\n", "B2=t[2,1]\n", "B3=t[2,3]\n", "B4=t[1,2]\n", "print \"the value of RED points respectively : %.4f, %.4f, %.4f, %.4f & %.4f\"%(R1,R2,R3,R4,R5)\n", "\n", "print \"the value of BLUE points respectively : %.4f, %.4f, %.4f & %.4f\"%(B1, B2, B3, B4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa10.8 Page 202" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the values of T from 1st element to last is\n", "157.831321254\n", "192.469876146\n", "280.72288988\n", "184.939753978\n", "231.325296989\n", "330.421684639\n", "175.903610664\n", "217.469876356\n", "309.638552636\n" ] } ], "source": [ "from __future__ import division\n", "from numpy import zeros\n", "tnew=[0];told=[0];e=[0];\n", "for i in range(1,10):\n", " tnew.append(101)\n", " told.append(0)\n", " e.append(1) #assumed values\n", "\n", "t=1e-6\n", "while e[(1)]>t and e[(2)]>t and e[(3)]>t and e[(4)]>t and e[(5)]>t and e[(6)]>t and e[(7)]>t and e[(8)]>t and e[(9)]>t:\n", " for i in range(1,10):\n", " told[i]=tnew[(i)]\n", " #using eqn 10.10 for the interior nodes and convective boundary conditions for corner nodes\n", " tnew[(1)]=(told[(2)]+50+.5*told[(4)]+100/3)*3/7\n", " tnew[(2)]=(tnew[(1)]+told[(3)]+told[(5)]+100)/4\n", " tnew[(3)]=(tnew[(2)]+told[(6)]+600)/4\n", " tnew[(4)]=(told[(5)]+.5*tnew[(1)]+.5*told[(7)]+100/3)*3/7\n", " tnew[(5)]=(tnew[(2)]+told[(8)]+told[(6)]+tnew[(4)])/4\n", " tnew[(6)]=(tnew[(3)]+tnew[(5)]+told[(9)]+500)/4\n", " tnew[(7)]=(.5*tnew[(4)]+.5*told[(8)]+100/3)*3/4\n", " tnew[(8)]=(tnew[(5)]+.5*tnew[(7)]+.5*told[(9)]+100/3)*3/7\n", " tnew[(9)]=(tnew[(6)]+100/3+.5*tnew[(8)]+250)*3/7\n", " for i in range(1,10):\n", " e[i]=abs(tnew[i]-told[i])\n", " \n", "\n", "print \"the values of T from 1st element to last is\"\n", "for i in range(1,10):\n", " print tnew[i]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa10.9 Page 211" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the values of T from 1st element to last is\n", "83.6250164077\n", "83.3426002934\n", "81.8505046198\n", "86.8385228347\n", "86.864496399\n", "86.0434332286\n", "86.7854379748\n", "87.2768602399\n", "88.5496879219\n" ] } ], "source": [ "from __future__ import division\n", "from numpy import zeros\n", "tnew=[0];told=[0];e=[0];\n", "for i in range(1,10):\n", " tnew.append(101)\n", " told.append(0)\n", " e.append(1) #assumed values\n", "\n", "t=1e-6\n", "while e[(1)]>t and e[(2)]>t and e[(3)]>t and e[(4)]>t and e[(5)]>t and e[(6)]>t and e[(7)]>t and e[(8)]>t and e[(9)]>t:\n", " for i in range(1,10):\n", " told[(i)]=tnew[(i)]\n", " #using the basic discretization eqn. for all the nodes since the boundary conditions vary for each point\n", " tnew[(1)]=(told[(2)]+1.25+told[(4)])/2.05\n", " tnew[(2)]=(.5*tnew[(1)]+.5*told[(3)]+told[(5)]+1.25)/2.05\n", " tnew[(3)]=(.5*tnew[(2)]+.5*told[(6)]+1.25)/1.05\n", " tnew[(4)]=(told[(5)]+.5*tnew[(1)]+45)/2\n", " tnew[(5)]=(tnew[(2)]+told[(8)]+90+tnew[(4)])/4\n", " tnew[(6)]=(.5*tnew[(3)]+tnew[(5)]+.5*told[(7)]+91.25)/3.05\n", " tnew[(7)]=(.5*tnew[(6)]+.5*told[(8)]+91.25)/2.05\n", " tnew[(8)]=(91.25+.5*tnew[(7)]+.5*told[(9)])/2.05\n", " tnew[(9)]=(47.125+.5*tnew[(8)])/1.025\n", " for i in range(1,10):\n", " e[i]=abs(tnew[i]-told[i])\n", " \n", "\n", "print \"the values of T from 1st element to last is\"\n", "for i in range(1,10):\n", " print told[i]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa10.10 Page 213" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the soln of eg 10.10-->Alternating Direction Implicit Method\n", "the soln by ADI method is\n", "20.0 20.0 20.0\n", "--------------\n", "20.0 20.0 20.0\n", "--------------\n", "48.1904761905 43.6666666667 105.0\n" ] } ], "source": [ "from __future__ import division\n", "from numpy import zeros\n", "print \"the soln of eg 10.10-->Alternating Direction Implicit Method\"\n", "nmax=25\n", "a=[0,1,1] #defining variables\n", "b=[-4,-4,-4]\n", "c=[1,1]\n", "t=zeros([6,6])\n", "tstar=zeros([6,6])\n", "t[1,2]=20 ; t[1,3]=20 ; t[1,4]=20; t[2,1]=20; t[3,1]=20 ; t[4,1]=20 ; t[5,2]=20 ; t[5,3]=20 ; t[5,4]=20 ; t[2,5]=400; t[3,5]=400; t[4,5]=400\n", "tstar[1,2]=20 ; tstar[1,3]=20; tstar[1,4]=20 ; tstar[2,1]=20 ; tstar[3,1]=20 ; tstar[4,1]=20 ; tstar[5,2]=20 ; tstar[5,3]=20 ; tstar[5,4]=20 ; tstar[2,5]=400 ; tstar[3,5]=400 ; tstar[4,5]=400\n", "for i in range(2,5):\n", " for j in range(2,5):\n", " t[i,j]=20\n", " \n", "\n", "#solving by TDMA Method\n", "d=zeros(4)\n", "for nn in range(1,nmax+1):\n", " for jj in range(2,5):\n", " d[(1)]=-t[1,jj]-t[2,jj+1]-tstar[2,jj-1]\n", " d[(2)]=-t[3,jj+1]-tstar[3,jj-1]\n", " d[(3)]=-t[5,jj]-t[4,jj+1]-tstar[4,jj-1]\n", " i=1 ; n=3\n", " Beta=[0,b[i]]\n", " Gamma=[0,d[i]/Beta[i]]\n", " i1=i+1\n", " for j in range(i1,n+1):\n", " Beta.append(b[(j-1)]-a[(j-1)]*c[(j-2)]/Beta[(j-1)])\n", " Gamma.append((d[(j)]-a[(j-1)]*Gamma[(j-1)])/Beta[(j)])\n", " #end \n", " x=zeros(n)\n", " x[-1]=Gamma[n-1]\n", " n1=n-i\n", " for k in range(1,n1+1):\n", " j=n-k\n", " x[j-1]=Gamma[(j)]-c[(j-1)]*x[j-1]/Beta[j]\n", " #end\n", " tstar[2,jj]=x[0]\n", " tstar[3,jj]=x[1]\n", " tstar[4,jj]=x[2]\n", "#end\n", " for ii in range(2,5):\n", " d[(1)]=-t[ii,1]-tstar[ii+1,2]-tstar[ii-1,2]\n", " d[(2)]=-tstar[ii+1,3]-tstar[ii-1,3]\n", " d[(3)]=-t[ii,5]-tstar[ii+1,4]-tstar[ii-1,4]\n", " i=1 ; n=3\n", " Beta[(i)]=b[i]\n", " Gamma[i]=d[(i)]/Beta[(i)]\n", " i1=i+1\n", " for j in range(i1,n+1):\n", " Beta[(j)]=b[(j-1)]-a[(j-1)]*c[j-2]/Beta[(j-1)]\n", " Gamma[(j)]=(d[(j)]-a[(j-1)]*Gamma[(j-1)])/Beta[(j)]\n", " #end \n", " \n", " x[-1]=Gamma[(n)]\n", " n1=n-i\n", " for k in range(1,n1+1):\n", " j=n-k\n", " x[j]=Gamma[(j)]-c[(j-1)]*x[(j)]/Beta[(j)]\n", " #end\n", " t[ii,2]=x[0]\n", " t[ii,3]=x[1]\n", " t[ii,4]=x[2]\n", "\n", "\n", "print \"the soln by ADI method is\"\n", "print t[2,4],t[2,3],t[2,2]\n", "print \"--------------\"\n", "print t[3,4],t[3,3],t[3,2]\n", "print \"--------------\"\n", "print t[4,4],t[4,3],t[4,2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exa 10.11 Page 215" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the soln by ADI is\n", "1.58563151796\n", "1.90275782155\n", "2.98098725376\n", "5.25161158747\n", "9.62288055617\n", "17.8433017473\n", "33.2010436374\n", "61.8392029825\n", "945.175268307\n", "-467.149084346\n" ] } ], "source": [ "from __future__ import division\n", "from numpy import arange,zeros\n", "a=[0,0];b=[0,0];c=[0,0]\n", "for k in range(2,11):\n", " a.append(-1)\n", " b.append(2.4)\n", " c.append(-1)\n", "\n", "alpha=1 ; delta_t=.05 ; delta_x=.1\n", "m=alpha*delta_t/delta_x**2\n", "b[1]=2.4\n", "c[1]=-2\n", "t=zeros([12,12])\n", "tstar=zeros([12,12])\n", "\n", "for k in range(1,12):\n", " t[11,k]=400 ; tstar[11,k]=400 ; t[k,11]=400 ; tstar[k,11]=400\n", "\n", "\n", "for i in range(1,11):\n", " for j in range(1,11):\n", " t[i,j]=0\n", " tstar[i,j]=0\n", " \n", "d=zeros(11)\n", "for tm in arange(.05,5+.05,.05):\n", " for jj in range(1,11):\n", " if jj==1:\n", " for ii in range(1,11):\n", " d[(ii)]=2*t[ii,2]-1.6*t[ii,1]\n", " d[(10)]=d[(10)]+400\n", " else:\n", " for ii in range(1,11):\n", " d[(ii)]=t[ii,jj+1]+t[ii,jj-1]-1.6*t[ii,jj]\n", " d[(10)]=d[(10)]+400\n", " i=1 ; n=10\n", " Beta=[0,b[i]]\n", " Gamma=[0,d[i]/Beta[i]]\n", " i1=i+1\n", " for j in range(i1,n+1):\n", " Beta.append(b[(j)]-a[(j)]*c[(j-1)]/Beta[(j-1)])\n", " Gamma.append((d[(j)]-a[(j)]*Gamma[(j-1)])/Beta[(j)])\n", " \n", " x=zeros(n+1)\n", " x[(n)]=Gamma[(n)] \n", " x[(j)]=Gamma[(j)]-c[(j)]*x[(j)]/Beta[(j)]\n", " for count in range(1,11):\n", " tstar[count,jj]=x[(count)]\n", " \n", " for ii in range(1,11):\n", " if ii==1:\n", " for jj in range(1,11):\n", " d[(jj)]=2*tstar[ii+1,1]-1.6*tstar[ii,1]\n", " d[(10)]=d[(10)]+400\n", " else:\n", " for jj in range(1,11):\n", " d[(jj)]=tstar[ii-1,jj]+tstar[ii+1,jj]-1.6*tstar[ii,jj]\n", " d[(10)]=d[(10)]+400\n", " \n", " i=1 ; n=10\n", " Beta[(i)]=b[i]\n", " Gamma[(i)]=d[(i)]/Beta[(i)]\n", " i1=i+1\n", " for j in range(i1,n+1):\n", " Beta[(j)]=b[(j)]-a[(j)]*c[(j-1)]/Beta[(j-1)]\n", " Gamma[(j)]=(d[(j)]-a[(j)]*Gamma[(j-1)])/Beta[(j)]\n", " \n", " x[(n)]=Gamma[(n)]\n", " n1=n-i\n", " for k in range(1,n1+1):\n", " j =n-k\n", " x[(j)]=Gamma[(j)]-c[(j)]*x[(j+1)]/Beta[(j)]\n", " \n", " for count in range(1,11):\n", " t[ii,count]=x[count]\n", " \n", "\n", "print \"the soln by ADI is\"\n", "for i in range(1,11):\n", " print t[i,i]\n" ] } ], "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.9" } }, "nbformat": 4, "nbformat_minor": 0 }