13 


14 
\section{One Dimensional Heat Diffusion in an Iron Rod} 
\section{One Dimensional Heat Diffusion in an Iron Rod} 
15 
%\label{Sec:1DHDv0} 
%\label{Sec:1DHDv0} 
16 
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 partial differential equations (PDEs) \footnote{In case you wonder what a 
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 partial differential equations (PDEs) 
17 
\textit{partial differential equation} wikipedia provides a 
\footnote{Wikipedia provides an excellent and comprehensive introduction to \textit{Partial Differential Equations} \url{http://en.wikipedia.org/wiki/Partial_differential_equation}, however their relevance to \ESCRIPT and implementation should become a clearer as we develop our understanding further into the cookbook.} 

comprehensive introducton at 


\url{http://en.wikipedia.org/wiki/Partial_differential_equation}, 


but things should become a bit clearer when you read further in the cookbook.} 

18 


19 

The first model consists of a simple cold iron bar at a constant temperature of zero Figure \ref{fig:onedhdmodel}. The bar is perfectly insulated on all sides with a heating element of some description at one end. Intuition tells us that as heat is applied; energy will disperse along the bar via convection. With time the bar will reach a constant temperature equivalent to the heat source. 
20 

\begin{figure}[h!] 
21 
Start by imagining we have a simple cold iron bar at a constant temperature of zero. 
\centerline{\includegraphics[width=4.in]{figures/onedheatdiff}} 
22 
\TODO{Add a diagram to explain the setup.} 
\caption{One dimensional model of an Iron bar.} 
23 
The bar is perfectly insulated on all sides and 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 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. 
\label{fig:onedhdmodel} 
24 

\end{figure} 
25 
We can model this problem using the one dimensional heat diffusion equation. A detailed discussion on how the heat diffusion equation is derived can be found at 

26 
\url{http://online.redwoods.edu/instruct/darnold/DEProj/sp02/AbeRichards/paper.pdf} 
We can model the heat distribution of this problem in time using the one dimensional heat diffusion equation 
27 
Heat diffusion equation is defined as: 
\footnote{A detailed discussion on how the heat diffusion equation is derived can be found at \url{http://online.redwoods.edu/instruct/darnold/DEProj/sp02/AbeRichards/paper.pdf}}; 
28 

which is defined as: 
29 
\begin{equation} 
\begin{equation} 
30 
\rho c\hackscore p \frac{\partial T}{\partial t}  \kappa \frac{\partial^{2} T}{\partial x^{2}} = q\hackscore H 
\rho c\hackscore p \frac{\partial T}{\partial t}  \kappa \frac{\partial^{2} T}{\partial x^{2}} = q\hackscore H 
31 
\label{eqn:hd} 
\label{eqn:hd} 
32 
\end{equation} 
\end{equation} 
33 
where $\rho$ is the material density, $c\hackscore p$ is the specific heat and $\kappa$ is the temperature diffusion constant. All of these values are readily available for most materials or can be established through predefined experimentation techniques. \TODO{Give some numbers for eg. granite}. 
where $\rho$ is the material density, $c\hackscore p$ is the specific heat and $\kappa$ is the thermal conductivity constant for a given material 
34 
The heatsource is on the right hand side of \eqref{eqn:hd} as $q_{H}$, this could be a constant or defined by an expression \TODO{Give an example}. There are also two partial derivatives in \eqref{eqn:hd}, $\frac{\partial T}{\partial t}$ describes the change in temperature with time while $\frac{\partial T}{\partial x}$ describes the spatial change to temperature. There is only a single spatial dimension to our problem, and so our temperature solution $T$ is only dependent on the time $t$ and our position along the iron bar $x$. 
\footnote{A list of some common thermal conductivities is available from Wikipedia \url{http://en.wikipedia.org/wiki/List_of_thermal_conductivities}}. 
35 

The heatsource is defined by the right hand side of \eqref{eqn:hd} as $q\hackscore{H}$, this could be a constant or a function of time. For example $q\hackscore{H} = Te^{\gamma t}$ where we have the output of our heatsource decaying with time. There are also two partial derivatives in \eqref{eqn:hd}; $\frac{\partial T}{\partial t}$ describes the change in temperature with time while $\frac{\partial ^2 T}{\partial x^2}$ is the spatial change of temperature. As there is only a single spatial dimension to our problem, our temperature solution $T$ is only dependent on the time $t$ and our position along the iron bar $x$. 
36 


37 
\TODO{Explain the concept of time discritzation} 
When solving a PDE analytically we are finding an exact solution to our equation, however it is not always possible to solve a problem this way. Computers can be used in these cases when a large number of sums or visualisation is required. Computers require a numerical approach to solving problems  \ESCRIPT is one example  and it becomes necessary to discretize the equation so that we are left with a finite number of equations for a finite number of spatial and time steps in the model. While this is of course an approximation and introduces a degree of error, we find that a sufficiently sampled model is generally accurate enough for the requirements of the modeller. 
38 


39 
To solve this equation we will write a simple python script which uses \ESCRIPT and 
To solve this equation we will write a simple python script which uses \ESCRIPT and \FINLEY of the \ESYS module. At this point we assume that you have some basic understanding of the python programming language. If not there are some pointers and links available in Section \ref{sec:escpybas} . 
40 
\FINLEY of the \ESYS module. At this point we assume that you have some basic 

41 
understanding of the python programming language. There are in fact a large number of 
In the following section we will develop a script for \ESCRIPT to solve the heat equation stepbystep. Firstly it is necessary to import all the libraries 
42 
python tutorial available online, for instance 
\footnote{The libraries contain predefined scripts that are required to solve certain problems, these can be simple like sin and cos functions or more complicated like those from our \ESCRIPT library.} 
43 
\begin{itemize} 
that we will require. 

\item This is a very crisp introduction \url{http://hetland.org/writing/instantpython.html}. It covers everthing you need to get started with \ESCRIPT. 


\item A nice and easy to follow introduction: \url{http://www.sthurlow.com/python/} 


\item An other crip tutorial \url{http://www.zetcode.com/tutorials/pythontutorial/}. 


\item A very comprehensive tutorial from the python authors: \url{http://www.python.org/doc/2.5.2/tut/tut.html}. It covers much more than what you will ever need for \ESCRIPT. 


\item an other comprehensive tutorial: \url{http://www.tutorialspoint.com/python/index.htm} 


\end{itemize} 


In the following we will develop the script to solve the heat equation stepbystep. 


The first step is to import the necessary libraries. 

44 
\begin{verbatim} 
\begin{verbatim} 
45 
from esys.escript import * 
from esys.escript import * 
46 
from esys.escript.linearPDEs import SingleLinearPDE 
from esys.escript.linearPDEs import SingleLinearPDE 
47 
from esys.finley import Rectangle 
from esys.finley import Rectangle 
48 

from esys.escript.unitsSI import * 
49 
import os 
import os 
50 
\end{verbatim} 
\end{verbatim} 
51 
It is generally a good idea to import all of \verb escript , although if you know the packages you need you can specify them individually. The function \verbLinearPDE has been imported individually for ease of use later in the script. \verbRectangle is going to be our type of domain and the \verbos package is needed to handle file outputs once our PDE has been solved. 
It is generally a good idea to import all of the \verb escript library, although if you know the packages you need you can specify them individually. The function \verbLinearPDE has been imported for ease of use later in the script. \verbRectangle is going to be our type of domain. The package \verb unitsSI is a module of \esc that provides support for units definitions with our variables; and the \verbos package is needed to handle file outputs once our PDE has been solved. 
52 


53 
Once our libraries dependancies have been established, defining the problem specific variables is the next step. 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. For this PDE there are a number of constants which will need values. Firstly, the domain upon which we wish to solve our problem needs to be defined. There are many different types of domains in escript. We will demonstrate a few in later tutorials but for our iron rod we will simply use a rectangular domain. 
Once our libraries dependancies have been established, defining the problem specific variables is the next step. 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. For this PDE there are a number of constants which will need values. Firstly, the domain upon which we wish to solve our problem needs to be defined. There are many different types of domains in escript. We will demonstrate a few in later tutorials but for our iron rod we will simply use a rectangular domain. 
54 


55 
Using a rectangular domain simplifies a \textit{3D} object into a single dimension. The iron rod will have a lengthways cross section that looks like a rectangle. As a result 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, the model length, width and step size in each direction. 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 solved per time step. This means more computational time is required to produce a solution. In our \textit{1D} problem we will define our bar as being 1 metre long. An appropriate \verbndx would be 1 to 10\% of the length. Our \verbndy need only be 1, uhis is because our problem stipulates no partial derivatives in the $y$ direction. This means the temperature does not vary with $y$. Thus the domain perameters can be defined as follows: 
Using a rectangular domain simplifies a \textit{3D} object into a single dimension. The iron rod will have a lengthways cross section that looks like a rectangle. As a result 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, the model length, width and step size in each direction. 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 solved per time step. This means more computational time is required to produce a solution. In our \textit{1D} problem we will define our bar as being 1 metre long. An appropriate \verbndx would be 1 to 10\% of the length. Our \verbndy need only be 1, This is because our problem stipulates no partial derivatives in the $y$ direction so the temperature does not vary with $y$. Thus the domain perameters can be defined as follows; note we have used the \verb unitsSI convention to make sure all our input units are converted to SI. 

\TODO{Use the Unit module!} 

56 
\begin{verbatim} 
\begin{verbatim} 
57 
#Domain related. 
#Domain related. 
58 
mx = 1 #meters  model lenght 
mx = 1*m #meters  model lenght 
59 
my = .1 #meters  model width 
my = .1*m #meters  model width 
60 
ndx = 100 # steps in x direction 
ndx = 100 # steps in x direction 
61 
ndy = 1 # steps in y direction 
ndy = 1 # steps in y direction 
62 
\end{verbatim} 
\end{verbatim} 
63 
The material constants and the temperature variables must also be defined. For the iron rod in the model they are defined as: 
The material constants and the temperature variables must also be defined. For the iron rod in the model they are defined as: 
64 
\begin{verbatim} 
\begin{verbatim} 
65 
#PDE related 
#PDE related 
66 
q=473. #Kelvin  our heat source temperature 
q=200. * Celsius #Kelvin  our heat source temperature 
67 
Tref = 273. # Kelvin  starting temp of iron bar 
Tref = 0. * Celsius # Kelvin  starting temp of iron bar 
68 
rho = 7874. #kg/m^{3} density of iron 
rho = 7874. *kg/m**3 #kg/m^{3} density of iron 
69 
cp = 449. #j/Kg.K 
cp = 449.*J/(kg*K) #jules/Kg.K thermal capacity 
70 
rhocp = rho*cp 
rhocp = rho*cp 
71 
eta = 0 #radiation condition 
kappa = 80.*W/m/K #watts/m.K thermal conductivity 

kappa = 68. #temperature diffusion constant 

72 
\end{verbatim} 
\end{verbatim} 

\TODO{remove radiation condition and if required introduce in a second example} 

73 
Finally, to control our script we will have to specify our timing controls and where we would like to save the output from the solver. This is simple enough: 
Finally, to control our script we will have to specify our timing controls and where we would like to save the output from the solver. This is simple enough: 
74 
\begin{verbatim} 
\begin{verbatim} 
75 
#Script/Iteration Related 
#Script/Iteration Related 
82 
#note this folder path must exist to work 
#note this folder path must exist to work 
83 
save_path = "data/onedheatdiff001" 
save_path = "data/onedheatdiff001" 
84 
\end{verbatim} 
\end{verbatim} 
85 
Now that we know our inputs we will build a domain using the \verb Rectangle() function from \verb Finley . The four arguments allow us to define our domain \verb rod as: 
Now that we know our inputs we will build a domain using the \verb Rectangle() function from \verb Finley . The four arguments allow us to define our domain \verb rod as: 
86 
\begin{verbatim} 
\begin{verbatim} 
87 
rod = Rectangle(l0=mx,l1=my,n0=ndx,n1=ndy) 
rod = Rectangle(l0=mx,l1=my,n0=ndx,n1=ndy) 
88 
\end{verbatim} 
\end{verbatim} 
89 
In this form \verb rod does not represent any discrete points, but rather an area of \verb ndx*ndy cells that fit into a rectangular space with opposing vertices at the origin and the point \verb [mx,my] . The reason for this is so that the discrete points used in the solution can be specified by the user. That is, are discrete points used at the corners of each cell, the middle point of a cell or halfway along each side of the cell etc. Fortunately \verb escript offers an easy way to extract finite points from the domain \verbrod using the domain property function \verbgetX() . This function uses the vertices of each cell as finite points to solve in the solution. If we let \verbx be these finite points, then: 
In this form \verb rod does not represent any discrete points, but rather an area of \verb ndx*ndy cells that fit into a rectangular space with opposing vertices at the origin and the point \verb [mx,my] . Our domain is contructed this way to allow the user to determine where the discrete points of each model will be located. Discretisation may be at the corners of each cell, the middle point of a cell or halfway along each side of the cell etc. Depending on the PDE or the model there may be advantages and disadvantages for each case. Fortunately \verb escript offers an easy way to extract finite points from the domain \verbrod using the domain property function \verbgetX() . This function sets the vertices of each cell as finite points to solve in the solution. If we let \verbx be these finite points, then; 
90 
\begin{verbatim} 
\begin{verbatim} 
91 
x = rod.getX() 
x = rod.getX() 
92 
\end{verbatim} 
\end{verbatim} 
93 
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 to define the type of PDE that we are trying to solve in each time step. In this example it is a single linear PDE (in comparison to a system of PDEs which will discussed later) 
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 to define the type of PDE that we are trying to solve in each time step. In this example it is a single linear PDE 
94 
we can define it by: 
\footnote{in comparison to a system of PDEs which will be discussed later.} 
95 

we can define by: 
96 
\begin{verbatim} 
\begin{verbatim} 
97 
mypde=LinearSinglePDE(rod) 
mypde=LinearSinglePDE(rod) 
98 
\end{verbatim} 
\end{verbatim} 
99 
In the next step we need to define the coefficients of the PDE. The linear 
In the next step we need to define the coefficients of the PDE. The linear 
100 
PDEs in \ESCRIPT provide a general interface to do this. Here we will only discuss a simplified form that suits our heat diffusion problem and refer to the \ESCRIPT user's guide for the general case. This simpler form 
PDEs in \ESCRIPT provide a general interface to do this. Here we will only discuss a simplified form that suits our heat diffusion problem and refer to the \ESCRIPT user's guide for the general case. This simpler form 
101 
\footnote{In the form of the \ESCRIPT users guide which uses the Einstein convention 
\footnote{In the form of the \ESCRIPT users guide which using the Einstein convention is written as 

this equation is written as 

102 
$(A\hackscore{jl} u\hackscore{,l})\hackscore{,j}+D u =Y$} 
$(A\hackscore{jl} u\hackscore{,l})\hackscore{,j}+D u =Y$} 
103 
is described by 
is described by; 
104 
\begin{equation}\label{eqn:commonform nabla} 
\begin{equation}\label{eqn:commonform nabla} 
105 
\nabla.(A.\nabla u) + Du = f 
\nabla.(A.\nabla u) + Du = f 
106 
\end{equation} 
\end{equation} 
107 
where $A$, $D$ and $f$ are known values. 
where $A$, $D$ and $f$ are known values. The symbol $\nabla$ which is called the \textit{Nabla operator} or \textit{del operator} represents 
108 
The symbol $\nabla$ which is called the \textit{Nabla operator} or \textit{del operator} represents 
the spatial derivative of its subject  in this case $u$. Lets assume for a moment that we deal with a onedimensional problem then 

the spatial derivative of what ever stands next to the right from it. Lets assume for a moment that we deal with a onedimensional problem then 

109 
\begin{equation} 
\begin{equation} 
110 
\nabla = \frac{\partial}{\partial x} 
\nabla = \frac{\partial}{\partial x} 
111 
\end{equation} 
\end{equation} 
113 
\begin{equation}\label{eqn:commonform} 
\begin{equation}\label{eqn:commonform} 
114 
A\frac{\partial^{2}u}{\partial x^{2}} + Du = f 
A\frac{\partial^{2}u}{\partial x^{2}} + Du = f 
115 
\end{equation} 
\end{equation} 
116 
if $A$ is constant. This is exactly the equation we need to solve 
if $A$ is constant then equation \ref{eqn:commonform} is consistent with our heat diffusion problem in Equation \ref{eqn:hd}  except for $u$. When comparing equations \eqref{eqn:hd} and \eqref{eqn:commonform} we see that; 
117 
in each time step as described in equation~\ref{XXXXX}. When comparing equations \eqref{eqn:hd} and \eqref{eqn:commonform} we see that; 
\begin{equation} 
118 

A = \kappa; D = \rho c \hackscore{p}; f = q \hackscore{H} 
119 

\end{equation} 
120 


121 

We can write the partial $\frac{\partial T}{\partial t}$ in terms of $u$ by discretising the time of our solution. Many methods could be used here but we have decided on the Backwards Euler approximation which states; 
122 

\begin{equation} 
123 

f'(x) \approx \frac{f(x+h)f(x)}{h} 
124 

\label{eqn:beuler} 
125 

\end{equation} 
126 

where h is the the discrete step size $\Delta x$. 
127 

Now let $f(x) = T(t)$ and from equation \ref{eqn:beuler} we see that; 
128 

\begin{equation} 
129 

T'(t) \approx \frac{T(t+h)  T(t)}{h} 
130 

\end{equation} 
131 

which can also be written as; 
132 

\begin{equation} 
133 

T\hackscore{,t}^{(n)} \approx \frac{T^{(n)}  T^{(n1)}}{h} 
134 

\label{eqn:Tbeuler} 
135 

\end{equation} 
136 

where $n$ denotes the n\textsuperscript{th} time step. Substituting equation \ref{eqn:Tbeuler} into equation \ref{eqn:hd} we get; 
137 

\begin{equation} 
138 

\frac{\rho c\hackscore p}{h} (T^{(n)}  T^{(n1)})  \kappa \frac{\partial^{2} T}{\partial x^{2}} = q\hackscore H 
139 

\label{eqn:hddisc} 
140 

\end{equation} 
141 

To fit our simplified general form we can rearrange so that; 
142 

\begin{equation} 
143 

\frac{\rho c\hackscore p}{h} T^{(n)}  (\kappa T^{(n)}\hackscore{,i})\hackscore{,i} = q\hackscore H + \frac{\rho c\hackscore p}{h} T^{(n1)} 
144 

\label{eqn:hdgenf} 
145 

\end{equation} 
146 

This is the form required for escript to solve our PDE across the domain for successive time nodes $t^{(n)}$ where 
147 

$t^{(0)}=0$ and $t^{(n)}=t^{(n1)}+h$ where $h>0$ is the step size which is assumed to be constant. 
148 

In the following the upper index ${(n)}$ refers to a value at time $t^{(n)}$. When comparing equation \ref{eqn:hdgenf} with equation \ref{eqn:commonform} we see that; 
149 
\begin{equation} 
\begin{equation} 
150 
A = \kappa; D = \frac{\rho c \hackscore{p}}{h}; f = q \hackscore{H} 
A = \kappa; D = \frac{\rho c \hackscore{p}}{h}; f = q \hackscore{H} + \frac{\rho c\hackscore p}{h} T^{(n1)} 
151 
\end{equation} 
\end{equation} 
152 


153 
We need to revisit the general PDE~\ref{eqn:commonform nabla} under the light of a 
\TODO{DISCUSS BOUNDARY CONDITIONS} 
154 
two dimensional domain. As pointed out earlier \ESCRIPT is not designed 
It is pointed out that the initial conditions satisfy the boundary condition defined by 
155 
to solve onedimensional problems so the general PDE~\ref{eqn:commonform nabla} 

156 
needs to be read as a higher dimensional problem. In the case of 
Together with the natural boundary condition 
157 
two spatial dimensions the Nable operator has in fact 
\begin{equation} 
158 
two components $\nabla = (\frac{\partial}{\partial x} 
\kappa T\hackscore{,i}^{(n)} n\hackscore i = \eta (T\hackscore{ref}T^{(n)}) 
159 
\frac{\partial}{\partial y})$. If we spell out the general PDE~\ref{eqn:commonform nabla} and assume a constant coefficient $A$ it then takes the form 
\label{DIFFUSION TEMP EQ 2222} 
160 

\end{equation} 
161 

taken from 
162 

this forms a boundary value problem that has to be solved for each time step. 
163 

As a first step to implement a solver for the temperature diffusion problem we will 
164 

first implement a solver for the boundary value problem that has to be solved at each time step. 
165 


166 

We need to revisit the general PDE equation ~\ref{eqn:commonform nabla} under the light of a two dimensional domain. \ESCRIPT is inherently designed to solve problems that are greater than one dimension and so \ref{eqn:commonform nabla} needs to be read as a higher dimensional problem. In the case of two spatial dimensions the Nabla operator has in fact two components $\nabla = (\frac{\partial}{\partial x}, \frac{\partial}{\partial y})$. In full the general equation ~\ref{eqn:commonform nabla} assuming a constant coefficient $A$ takes the form; 
167 
\begin{equation}\label{eqn:commonform2D} 
\begin{equation}\label{eqn:commonform2D} 
168 
A\hackscore{00}\frac{\partial^{2}u}{\partial x^{2}} 
A\hackscore{00}\frac{\partial^{2}u}{\partial x^{2}} 
169 
A\hackscore{01}\frac{\partial^{2}u}{\partial x\partial y} 
A\hackscore{01}\frac{\partial^{2}u}{\partial x\partial y} 
173 
\end{equation} 
\end{equation} 
174 
We notice that for the higher dimensional case $A$ becomes a matrix. It is also 
We notice that for the higher dimensional case $A$ becomes a matrix. It is also 
175 
important to notice that the usage of the Nable operator creates 
important to notice that the usage of the Nable operator creates 
176 
a compact formulation which is also independend from the spatial dimension. 
a compact formulation which is also independant from the spatial dimension. 
177 
So to make the general PDE~\ref{eqn:commonform2D} one dimensional as 
So to make the general PDE~\ref{eqn:commonform2D} one dimensional as 
178 
shown in~\ref{eqn:commonform} we need to set 
shown in~\ref{eqn:commonform} we need to set 
179 
\begin{equation}\label{eqn:commonform2D} 
\begin{equation}\label{eqn:commonform2D} 
180 
A\hackscore{00}=A; A\hackscore{01}=A\hackscore{10}=A\hackscore{11} 
A\hackscore{00}=A; A\hackscore{01}=A\hackscore{10}=A\hackscore{11}=0 
181 
\end{equation} 
\end{equation} 
182 


183 

Now that we have established the general form we will submit to escript it is necessary to establish the state of our system at time zero or $T^{(n=0)}$. This is due to the time derivative approximation we have used. We have chosen the starting temperature of our iron bar to be 0$\deg C$ . The temperature becomes; 
184 
BLABLA 
\begin{equation} 
185 
\TODO{explain boundray condition; ignore radiation} 
T(x,0) = T\hackscore{ref} = 0 
186 

\end{equation} 
187 

for all $x$ in the domain. 






188 


189 
Because we have a symmetrical problem we will also need to set the symmetry on by: 
Because we have a symmetrical problem we will also need to set the symmetry on by: 
190 
\begin{verbatim} 
\begin{verbatim} 
191 
myPDE.setSymmetryOn() 
myPDE.setSymmetryOn() 
192 
\end{verbatim} 
\end{verbatim} 

To input the PDE into \esc it must be compared with the general form\footnote{Available in section ?? of the users guide to \esc }. For most simple PDEs however, the general form is over complicated and confusing. Thus for this example, we will use a simplified version 










193 


194 
Additionally we must also consider the boundary conditions of our PDE. They take the form: 
Additionally we must also consider the boundary conditions of our PDE. They take the form: 
195 
\begin{equation} 
\begin{equation} 
216 
\TODO{explain how to use matlibplot to visualize T} 
\TODO{explain how to use matlibplot to visualize T} 
217 


218 



\TODO{Move this to the 2D section as an advanced topic} 


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 \verbsaveVTK() which makes this step very easy. saveVTK takes two arguments, the path and the filename. We are goind to use the \verbos.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 \verbi. In substring \verb %03d does a number of things; 


\begin{itemize} 


\item \verb 0 becomes the padding number; 


\item \verb 3 tells us the number of padding numbers that are required; and 


\item \verb d indicates the end of the \verb % operator. 


\end{itemize} 


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: 


\begin{verbatim} 


saveVTK(os.path.join(save_path,"data%03d.xml") %i,sol=T) 


\end{verbatim} 


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. 
