### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# Python class book note presentation MAE 6286

GWU

GPA 3.9

### View Full Document

## 179

## 2

1 review

## Popular in python

## Popular in General Engineering

This 14 page Class Notes was uploaded by Sidhu Anuragh on Tuesday February 10, 2015. The Class Notes belongs to MAE 6286 at George Washington University taught by Lorena A. Barba in Fall. Since its upload, it has received 179 views. For similar materials see python in General Engineering at George Washington University.

## Similar to MAE 6286 at GWU

## Popular in General Engineering

## Reviews for Python class book note presentation

If Sidhu isn't already a tutor, they should be. Haven't had any of this stuff explained to me as clearly as this was. I appreciate the help!

-*Mrs. Brett Schultz*

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 02/10/15

21015 423 PM 6286 githubsiddarth4076286treemaster Final Projectsiddarthjeripotulaipynbgithubsiddarth4076286treemasterFinal Projectsiddarthjeripotulaipynb Content Under Creative Commons Attribute Licence CCby 49 code under MIT license c2814 by Siddarth jeripotula 2D heat diffusion equation with robin boundary condition In Module 4 httpnbvieweripvthonorglgithubnumerical moocnumerical moocblobmasterlessonsO4 SpreadoutO4 Heat Equation 2D Implicitipvnb we solved a two dimentional heat diffusion equation which included Dirichlet and Neumann boundary conditions using an implicit scheme Now we will solve a similar problem using robin bounday condition Robin boundry condition Robin boundary conditions are a weighted combination of Dirichlet boundary condition and Neumann boundary conditions This contrasts to the mixed boundary condition httpenwikipediaorgwikiMixed boundary condition which are boundary conditions of different types speci ed on different subsets of the boundary Robin boundary condition are also called impipedance boundary conditions from their applications in electromagnetic problems or convective boundary conditions from their applications in heat transfer problems 1 0T k hT hToo 1 at Lets define our problem we are using the same grid defined in notebook on 2D Implicit httpnbvieweripvthonorglgMnumerical moocnumerical moocblobmasterlessonsO4 SpreadoutO4 Heat Equation 2D Implicitipvnb subject to dirichlet boundary condition on the three sides and robin boundary condition on one side In this note book we will see how the temperature is varied if we cool the silicon chip on one side with air To refreash lets rewrite the problem statement with this conditions We will consider the chip as a 2D plate of size 1cm x 1cm made of silicon K 159WmCCp 0712 103JkgC p 2329kgm3 and diffusivity a 10 4m2rmsust to demonstratea numerical solution Lets say that the one of the sides of the chip is cooled by air which is has heat transfer coefflcent of h 32Wm2k and the velocity of air is v 10m3The other three edges are touching other components that have a constant temperature of of T 393K when the machine is operatingThe room temperature is Tcgt0 293K Now lets see how the temperature varies across the chip as it is cooled from one side httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotua20ipynb Page 1 of 14 In 65 displayImagefilenamequot62862dchip 2jpgquot y T 393 K M Robin boundary p condition m T 293 K ll 4 n 4 T 393 K 1 cm lets begin39 limpliicit Schemes in 2D In Note book on 2D EXplicit httpnbvieweripvthonorggithubnumerical moocnumerical moocblobmasterlessonsspreadout 4 Heat aquation2Dlmplicitipym we have looked at the heat conduction equation Lets rewrite the equation again in 0T 02T 02T 2 0t a lt 0x2 032 this note book The implicit scheme for 2D heat equation with central difference in space is written as 1 1 1 1 1 2 1 Ti Ti Ti jrtJ 2T3r T1111 T311 2T n 11J T551 At sz A312 3 Rearrange the equation such that all the unknown terms are on the left side and all the known terms are on the right side And also lets assume that the mesh spacing is equal in both the directions ieAX AY 6 62 62 n1 n1 n1 n1 n1 n you can review notebook on 2D Implicit httpnbvieweripvthonorggithubnumerical moocnumerical moocblobmasterlessonsO4 SpreadoutO4 Heat Equation 2D mplicitipynb to understand how to form the grid and how to form the matrix Since we have learned them in that module we will directly jump to solving the boundary conditions and substituting them in our 2D heat equation Boundary conditions In our problem the top left and bottom boundaries have Dirichlet boundary condition and rignt boundary has robin boundary condition Now let39s looks at each case httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotua20ipynb 21015 423 PM Page 2 of 14 21015 423 PM Bottom boundary condition The equation forj 1 interior point adjacent to the bottom boundary uses values fromj 0 which are known Let39s put that on the right hand side of the equation We get this quation for all points across the x axis that are adjacent to teh bottom boundary 62 62 1 1 1 1 1 41111 2111 E 4 Tiff T5311 am T571 Till 5 Left boundary condition similar to bottom boundary condition the equation for i 1 interior points adjacent to the left boundary uses known values from i 0 and we will put that on the right hand side 52 52 1 1 1 1 39 1 T2n f f tTn1 J Right boundary condition The boundary condition for the right is Robin boundary condition 0T k hT hToo 0t Its nite difference approximation is Tn1 n1 nx IJ nx 2j T hTIZCtllJ hToo 7 Rearranging the terms we have 6hToo k n1 n1 T 8 quotHal k 6h k 6h quotx421 forthe sake ofsimplicitylets takeAl 5hT andB L k5h k5h Finite difference equation fori nx 2 62 n1 n1 n1 n1 Tnx 3J Tm 4 B Tnx 2j Tnx ZJ l Tnx 2J1 62 TAITMX 2j A1 9 Top boundary conditions Top boundary condition in our case is Dirichlet boundary condition Therefore the equation forj my 2we have 62 62 1 1 1 1 T 2 4 Tag 2 fl39i73 Tn tTnl my 2 z1ny zny 1 W 10 z lny 2 Bottom Left corner At T14 there is Dirichlet boundary condition ati 0 andj 0 The equation for this boundary is as follows 52 52 1 1 1 1 1 42quot E 4gtTfif T1quot Em on 173 11 Top Left Corner At top left corner we have Dirichlet boundary condition at i 0 andj my 1 Therefore the equation at point T1ny2 is httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotua20ipynb Page 3 of 14 x A1 float constant in Robin boundary condition deltahroutdeltahk B float constant in Robin boundary conditions kdeltahk httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotua20ipynb 21015 423 PM Page 4 of 14 Return A2D array of floats Matrix of implicit 2D heat equation A numpyzerosnx 2ny 2nx 2ny 2 rownumber 0 row counter for j in range lny l for i in range lnx l corners if i1 and j1 Bottom left corner Dirichlet down and left Arownumberrownumber lsigma4 set diagnal Arownumberrownumberl l fetch il Arownumberrownumbernx 2 l fetch j1 elif inx 2 and j Bottom right corner Dirichlet downRobi n right Arownumberrownumber lsigma4 B set diagnal Arownumberrownumber l l fetch i l Arownumberrownumbernx 2 l fetch j1 elif i1 and jny 2 Top Left corner Dirichlet up and left Arownumberrownumber lsigma4 set diagnal Arownumberrownumberl l fetch il Arownumberrownumber nx 2 l fetch j l elif inx 2 and jny 2 Top right corner Dirichlet upRobin right Arownumberrownumber lsigma4 B set diagnal Arownumberrownumber l l fetch i l Arownumberrownumber nx 2 l fetch j l Sides elif i Left boundary Dirichlet Arownumberrownumber lsigma 4 set diagonal Arownumberrownumberl l fetch il Arownumberrownumbernx 2 l fetch j1 Arownumberrownumber nx 2 l fetch j l elif inx 2 Right boundary Robin Arownumberrownumber lsigma 4 B set diagonal Arownumberrownumber l l fetch i l Arownumberrownumbernx 2 l fetch j1 Arownumberrownumber nx 2 l fetch j l elif j Bottom boundary Dirichlet Arownumberrownumber lsigma 4 set diagonal Arownumberrownumberl l fetch il Arownumberrownumber l l fetch i l Arownumberrownumbernx 2 l fetch j1 elif jny 2 Top boundary Dirichlet Arownumberrownumber lsigma 4 set diagonal Arownumberrownumberl l fetch il Arownumberrownumber l l fetch i l Arownumberrownumber nx 2 l fetch j l interior points else Arownumberrownumber lsigma 4 set diagonal Arownumberrownumberl l fetch il Arownumberrownumber l l fetch i l l fetch j1 l fetch j l Arownumberrownumbernx 2 Arownumberrownumber nx 2 rownumber 1 ump to next row of the matrix return A In 44 def generateRHSnx ny sigma T Tbc Al B quot Generates right hand side for 2D implicit heat equation with Dirichl et in Top Left and bottom and Robin in the right Assume dxdy parameters httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotula20ipynb 21015 423 PM Page 5 of 14 x T array of float Temperature in current time step TLbc float Temperature in Dirichlet boundary condition A1 float constant in Robin boundary condition deltahToutdeltahk B float constant in Robin boundary conditions kdeltahk Return RHS array of float Right hand side of the 2D implicit heat eqation II II II RHS numpyzerosnx 2ny 2 rownumber 0 row counter for j in rangelny l for i in rangelnx l corners if i1 and j1 Bottom left corner Dirichlet down and left RHSrownumber Tjilsigma 2Tbc elif inx 2 and j1 Bottom right corner Dirichlet downRob in right RHSrownumber Tjilsigma Tbc Al elif i1 and jny 2 Top left corner Dirichlet up and left RHSrownumber Tjilsigma 2Tbc elif inx 2 and jny 2 Top right corner Dirichlet up and R obin right RHSrownumber Tjilsigma Tbc Al Sides elif i1 Left boundary Dirichlet RHSrownumber Tjilsigma Tbc elif inx 2 Right boundary Robin RHSrownumber Tjilsigma Al elif j1 Bottom boundary Dirichlet RHSrownumber Tjilsigma Tbc elif jny 2 Top boundary Dirichlet RHSrownumber Tjilsigma Tbc Interior point else RHSrownumber Tjilsigma rownumber 1 ump to next row return RHS In 45 def maplDt02Dnx ny TlD Tbc quotquotquotTakes temperatures of solution of linear system stored in 1D and puts them in a 2D array with the BCs valid for constant Dirichlet bottom left and bottom and Robin in the ri ght parameters nX int number of nodes in X direction ny int number of nides in y direction TL1D ARRAY 0F FLOATS SOLUTION 0F LINEAR SYSTEM TLbc float Dirichlet BC Return T2D array of float Temperature stored in 2D array with BCs httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotula20ipynb 21015 423 PM Page 6 of 14 X 2 TLbc float Dirichlet BC temperature nx int number of nodes in X direction ny int number of nides in y direction dt float Time step size A1 float constant in Robin boundary condition deltahToutdeltahk B float constant in Robin boundary conditions kdeltahk Return 2D array of floats temperture profile after nt time steps jmid numpyshapeT02 imid numpyshapeTl2 counter0 errorl err whi1eerrorgt0001 Tn Tcopy b generateRHSnx ny sigma T Tbc Al B use numpylinalgsolve Tinterior solveAb T maplDt02Dnx ny Tinterior Tbc errornumpysqrtT Tn 2mean errappenderror counterl return Terrorcounternumpyasarrayerr Lets run the code To do that we have to give the input conditions In 47 Inputs to the current problem alpha 110 4 L 11o 2 H 11o 2 httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotula20ipynb 21015 423 PM Page 7 of 14 21015 423 PM nx 21 ny 21 nt 300 dx Lnx l dy Hny l x numpylinspace0Lnx y numpylinspace0Lny Tbc 373 Ti numpyonesnynx293 delta llO 2 Tout 293 ambient temperature k 150 h 32 B kdeltahk constants in Robin boundary condition A1 deltahToutdeltahk constants in Robin boundary condition In 48 sigma 025 A constructMatrixnx ny sigma Al B In 49 T Ticopy dt sigma mindx dy2 alpha Terrorcountererr btcs2DT A nt sigma Tbc nx ny dt Al B Lets plot the error for each iteration In 50 print error plotxnumpylinspacelcountercounter matplot1ib inline pltfigure pltplotplotxerr pltylim010 pltxlabel39Iterations39 pltylabel39RMS error39 plttitle39Error vs Iterations39 pltshow print counter 000099249606801 1 Error VS Iterations U 4 r RMS error lJ 0 i A A 0 100 200 300 400 500 600 700 8130 Iterations In 51 print counterdt 0498125 Lets plot and see the temperature pro lel In 52 import matplotlibpyplot as plt matplot1ib inline from matplotlib import rcParams rcParams39fontfamily39 39serif39 rcParams39fontsize39 16 httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotula20ipynb Page 8 of 14 x Al float constant in Robin boundary condition deltahroutdeltahk httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projeotsiddarth20jeripotua20ipynb Page 9 of 14 B float constant in Robin boundary conditions kdeltahk Return A2D array of floats Matrix of implicit 2D heat equation A numpyzerosnx 2ny 2nx 2ny 2 rownumber 0 row counter for j in range lny l for i in range lnx l corners if i1 and j1 Bottom left corner Robin down and left Arownumberrownumber lsigma4 2B set diagnal Arownumberrownumberl l fetch il Arownumberrownumbernx 2 l fetch j1 elif inx 2 and j Bottom right corner Robin downRobin ri ght Arownumberrownumber lsigma4 2B set diagnal Arownumberrownumber l l fetch i l Arownumberrownumbernx 2 l fetch j1 elif i1 and jny 2 Top Left corner Robin up and left Arownumberrownumber lsigma4 2B set diagnal Arownumberrownumberl l fetch il Arownumberrownumber nx 2 l fetch j l elif inx 2 and jny 2 Top right corner Robin upRobin righ 11 Arownumberrownumber lsigma4 2B set diagnal Arownumberrownumber l l fetch i l Arownumberrownumber nx 2 l fetch j l Sides elif i Left boundary Robin Arownumberrownumber lsigma 4 B set diagonal Arownumberrownumberl l fetch il Arownumberrownumbernx 2 l fetch j1 Arownumberrownumber nx 2 l fetch j l elif inx 2 Right boundary Robin Arownumberrownumber lsigma 4 B set diagonal Arownumberrownumber l l fetch i l Arownumberrownumbernx 2 l fetch j1 Arownumberrownumber nx 2 l fetch j l elif j Bottom boundary Robin Arownumberrownumber lsigma 4 B set diagonal Arownumberrownumberl l fetch il Arownumberrownumber l l fetch i l Arownumberrownumbernx 2 l fetch j1 elif jny 2 Top boundary Robin Arownumberrownumber lsigma 4 B set diagonal Arownumberrownumberl l fetch il Arownumberrownumber l l fetch i l Arownumberrownumber nx 2 l fetch j l interior points else Arownumberrownumber lsigma 4 set diagonal Arownumberrownumberl l fetch il Arownumberrownumber l l fetch i l l fetch j1 l fetch j l Arownumberrownumbernx 2 Arownumberrownumber nx 2 rownumber 1 ump to next row of the matrix return A Again we have to de ne the function for Right hand side of the matrix as our boundaycondhkn1changed httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotula20ipynb 21015 423 PM Page100f14 x T array of float Temperature in current time step TLbc float Temperature in Dirichlet boundary condition A1 float constant in Robin boundary condition deltahToutdeltahk B float constant in Robin boundary conditions kdeltahk Return RHS array of float Right hand side of the 2D implicit heat eqation II II II RHS numpyzerosnx 2ny 2 rownumber 0 row counter for j in rangelny l for i in rangelnx l corners if i1 and j Bottom left corner Robin down and left RHSrownumber Tjilsigma 2Al elif inx 2 and j1 Bottom right corner Robin downRobin r ight RHSrownumber Tjilsigma 2Al elif i1 and jny 2 Top left corner Robin up and left RHSrownumber Tjilsigma 2Al elif inx 2 and jny 2 Top right corner Robin up and Robin right RHSrownumber Tjilsigma 2 Al Sides elif i Left boundary Robin RHSrownumber Tjilsigma Al elif inx 2 Right boundary Robin RHSrownumber Tjilsigma Al elif j1 Bottom boundary Robin RHSrownumber Tjilsigma Al elif jny 2 Top boundary Robin RHSrownumber Tjilsigma Al Interior point else RHSrownumber Tjilsigma rownumber 1 ump to next row return RHS In 56 def maplDt02D2nx ny TlD Tbc quotquotquotTakes temperatures of solution of linear system stored in 1D and puts them in a 2D array with the BCs valid for Robin boundary condition on all sides parameters nx int number of nodes in X direction ny int number of nides in y direction TL1D ARRAY 0F FLOATS httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotuIa20ipynb Page 11 of 14 X 2 TLbc float Dirichlet BC temperature nx int number of nodes in X direction ny int number of nides in y direction dt float Time step size A1 float constant in Robin boundary condition deltahToutdeltahk B float constant in Robin boundary conditions kdeltahk Return 2D array of floats temperture profile after nt time steps jmid numpyshapeT02 imid numpyshapeTl2 Ti numpyonesnynx293 counter0 errorl err whi1eerrorgt0001 Tn Tcopy b generateRHS2nx ny sigma T Tbc Al B use numpylinalgsolve Tinterior solveAb T maplDt02D2nx ny Tinterior Tbc errornumpysqrtT Ti 2mean errappenderror counterl return Terrorcounternumpyasarrayerr In 58 nt 600 A constructMatrix2nx ny sigma Al B dt sigma mindx dy2 alpha httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotuIa20ipynb Page 12 of 14 Terrorcountererr btcs2D2T A nt sigma Tbc nx ny dt Al B In 59 print error plotxnumpylinspacelcountercounter matplotlib inline pltfigure pltplotplotxerr pltylim0100 pltxlabel39Iterations39 pltylabel39RMS error39 plttitle39Error vs Iterations39 pltshow print counter 0000999974099244 100 ErroersItera ons RMS error 0 20000 40000 60000 80000 100000 120000 Iterations In 60 print counterdt Time taken for temperature to reach 20 degrees celcius In 61 my mx numpymeshgridyx pltfigurefigsize77 pltcontourfmymxT20 pltcolorbar pltxlabel39X39 pltylabel39Y39 plttitle39Temperature Distribution39 Out6l ltmatplotlibtextText at 0x10297eed0gt Temperature Distribution 0010 290939 00000255 0008 00000225 00000195 0005 gt 00000165 0004 00000135 00000105 0002 00000075 0000 00000045 0000 0002 0004 0005 0008 0010 In 62 print T273 httpnbvieweripythonorggithubsiddarth4076286blobmasterFinal20Projectsiddarth20jeripotula20ipynb 21015 423 PM Page13of14 21015 423 PM my mx numpymeshgridyx pltfigurefigsize77 pltcontourfmymxT Ti20 pltcolorbar pltxlabel39X39 pltylabel39Y39 plttitle39Error39 Out62 ltmatplotlibtextText at 0x10a3daa10gt Error 0010 00010095 00010065 0008 00010035 00010005 0006 00009975 0004 00009945 00009915 0002 00009885 0000 0000 0002 0004 0006 0008 0010 00009855 Isn39t it cool Ifyou want to get clear idea you can always print the value ofT and see what happened to the Temperature in our experiment You must have noticed by now that we have incuded a condition in our code that makes this code run as long as error is greater than 0001 Which means that in our experiment as soon as the heat source is removed we are allowing the chip to cool till the temperature reaches close to the atmospheric temperature under free convection The result show us how the Temperature varies across the chip References 1 Custafson K 1998 Domain Decomposition Operator Trignometry Robin Condition Contemporary Mathematics 218 432 437 2 Barba Lorena A et al quotMEA 6286 Practical Numerical Methods with Pythonquot CW Open edX The George Washington University 2014 Elyopenedxseasgwueducourses MAE6286m4J about httpopenedxseasgwueducoursesGWMAE62862014 fallabout In 63 from IPythoncoredisp1ay import HTML cssfile 396286numericalmoocstylecss39 HTMLopencssfile quotrquotread Out63 httpnbvieweripythonorggithubsiddarth4076286bl0bmasterFinal20Pr0jectsiddarth20jerip0tua20ipynb Page 14 0f 14

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

#### "When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the material...plus I made $280 on my first study guide!"

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.