ViewVC logotype

Contents of /trunk/doc/cookbook/TEXT/onedheatdiff.tex

Parent Directory Parent Directory | Revision Log Revision Log

Revision 2392 - (show annotations)
Thu Apr 16 01:53:23 2009 UTC (12 years ago) by ahallam
File MIME type: application/x-tex
File size: 8149 byte(s)
Initial Commital of CookBook to SVN
Has 2.5 Weeks work and semi completed first heat diffusion tutorial
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % Copyright (c) 2003-2009 by University of Queensland
5 % Earth Systems Science Computational Center (ESSCC)
6 % http://www.uq.edu.au/esscc
7 %
8 % Primary Business: Queensland, Australia
9 % Licensed under the Open Software License version 3.0
10 % http://www.opensource.org/licenses/osl-3.0.php
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 \documentclass{manual}
15 \title{One Dimensional Heat Equation}
17 \begin{document}
18 We will start by examining a simple one dimensional heat diffusion example. While this exact problem is not strictly relevant to earth sciences; it will provide a good launch pad to build our knowledge of escript and how to solve simple PDEs.
20 Start by imagining we have a simple cold iron bar at a constant temperature of zero which is perfectly insulated on either side. At one end we will apply a heating element of some description. Intuition tells us that as heat is applied, that energy will disperse through the bar with time. Essentially the heat will spread along the bar until the bar reaches the same temperature as the heat source. At this point the temperature in the bar will be constant and the same as the heat source.
22 We can model this problem using the one dimensional heat diffusion equation. It is defined as:
23 \begin{equation}
24 \rho c\hackscore p \frac{\partial T}{\partial t} - \kappa \frac{\partial^{2} T}{\partial x^{2}} = q\hackscore H
25 \label{DIFFUSION TEMP EQ 1}
26 \end{equation}
27 where $\rho c\hackscore p$ and $\kappa$ are given material constants and $q\hackscore H$ is our heat source. Equation \eqn{DIFFUSION TEMP EQ 1} contains two partial derivatives. $\frac{\partial T}{\partial t}$ describes the change in temperature with time while $\frac{\partial T}{\partial x}$ describes the spatial change to temperature. Because we only have a single dimension, our problem is thus only dependent on time and our position along the iron bar $x$ .
29 To solve this equation we will write a simple python script. The first step is to import the necessary libraries.
30 \begin{verbatim}
31 from esys.escript import *
32 from esys.escript.linearPDEs import LinearPDE
33 from esys.finley import Rectangle
34 import os
35 \end{verbatim}
36 It is generally a good idea to import all of escript, although if you know the packages you need you can specify them individually. The function \verb|LinearPDE| has been imported individually for ease of use later in the script. \verb|Rectangle| is going to be our type of domain. The \verb|os| package is needed to handle file outputs once our PDE has been solved.
38 Once our libraries have been imported we will assign values to our problem specific variables. In general the number of variables needed will vary between problems. These variables belong to two categories. They are either directly related to the PDE and can be used as inputs into the escript solver, or they are script variables used to control internal functions and iterations in our problem.
39 For this PDE there are a number of constants which will need values. They are:
40 \begin{verbatim}
41 q #our heat souce temperature
42 Tref #the starting temperature of our ironbar
43 rho
44 eta
45 kappa
46 T #The current temperature - this is our solutions.
47 \end{verbatim}
48 To control our script we will have to specify:
49 \begin{verbatim}
50 t #our start time, usually zero
51 tend #the time we want to end the simulation
52 h #size of the time step
54 i #our loop counter
55 save_path #the folder to put our outputs in, leave blank "" for script path
57 \end{verbatim}
58 The next step is to create a domain upon which we wish to solve our problem. There are many different types of domains in escript. We will use many variations in later tutorials but for our Iron rod we will simply use a rectangular domain. This can be thought of as the lengthways cross section of our rod. We do not need to model the volume of the rod because a cylinder is symmetrical about its center. There are four arguments we must consider when we decide to create a rectangular domain. These arguments are:
59 \begin{verbatim}
60 lenbr # length of the bar
61 widbr # the width/diameter of the bar
62 xstep # the number of discrete spatial steps along x direction
63 ystep # the number of discrete spatial steps along y direction
64 \end{verbatim}
65 When defining the size of our problem it will help us determine appropriate values for our domain arguments. If we make our dimensions large but our step sizes very small we will to a point, increase the accuracy of our solution. Unfortunately we also increase the number of calculations that must be calculated per time step. This means more computational time is required to produce a solution.
66 In our \textit{1D} problem we will define our bar as being 1 metre long. An appropriate \verb|xstep| would be 1 to 10\% of the length. Our \verb|ystep| need only be 1. This is because our problem stipulates no partial derivatives in the y direction. This means our temperature does not vary in the y direction.
67 Now that we know our inputs we will define our domain as:
68 \begin{verbatim}
69 rod = Rectangle(l0=lenbr,l1=widbr,n0=xstep,n1=ystep)
70 \end{verbatim}
71 Escript offers an easy way to extract our finite points from the domain \verb|rod| this is the property \verb|getX()| . If we let \verb|x| be these finite points, then:
72 \begin{verbatim}
73 x = rod.getX()
74 \end{verbatim}
75 With a domain and all our required variables established, it is now possible to set up our PDE so that it can be solved by escript. The first step is define the type of PDE that we are trying to solve. In this example it is a Linear PDE and we can define it by:
76 \begin{verbatim}
77 mypde=LinearPDE(rod)
78 \end{verbatim}
79 Because we have a symmetrical problem we will also need to set the symmetry on by:
80 \begin{verbatim}
81 myPDE.setSymmetryOn()
82 \end{verbatim}
83 The final step is to apply our PDE to the general form of a linear PDE as described in the escript manual. The general form equation is:
84 \begin{equation}\label{LINEARPDE.SINGLE.1}
85 -(A\hackscore{jl} u\hackscore{,l})\hackscore{,j}-(B\hackscore{j} u)\hackscore{,j}+C\hackscore{l} u\hackscore{,l}+D u =-X\hackscore{j,j}+Y \; .
86 \end{equation}
90 We now need to specify Our boundary conditions and initial values. The initial values required to solve this PDE are temperatures for each discrete point in our domain that we wish to solve for. We will set our bar to:
91 \begin{verbatim}
92 T = Tref
93 \end{verbatim}
94 Boundary conditions are a little more difficult. Fortunately the escript solver will handle our insulated boundary conditions. However, we will need to apply our heat source $q_{H}$ to the end of the bar at $x=0$ . escript makes this easy by letting us define areas in our domain. To retrieve all the finite points in our domain we will use
98 The final stage to our problem is exporting the data we have generated and turn our data and visualisation. It is best to export the calculated solutions at each time increment. escript has the inbuilt function \verb|saveVTK()| which makes this step very easy. saveVTK takes two arguments, the path and the filename. We are goind to use the \verb|os.path.join| command to join a subdirectory which must already exist with a file name. The string opperator \verb|%| allows us to increment our file names with the value \verb|i|. In substring \verb %03d does a number of things;
99 \begin{itemize}
100 \item \verb 0 becomes the padding number;
101 \item \verb 3 tells us the number of padding numbers that are required; and
102 \item \verb d indicates the end of the \verb % operator.
103 \end{itemize}
104 To increment a \verb %i is required directly after the operation the string is involed in. The second arugment of the \verb saveVTK function is the \verb sol=T where \verb T is the solution of our PDE for a given time steo. Thus the export command becomes:
105 \begin{verbatim}
106 saveVTK(os.path.join(save_path,"data%03d.xml") %i,sol=T)
107 \end{verbatim}
108 Visualisation is then implemented through \verb mayavi which provides a command line of gui interface to develop plots to suit our output data. For this example a surface plot is appropriate.
109 \end{document}

  ViewVC Help
Powered by ViewVC 1.1.26