1 

2 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3 
% 
4 
% Copyright (c) 20032010 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/osl3.0.php 
11 
% 
12 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
13 

14 

15 
\section{Example 2: One Dimensional Heat Diffusion in an Iron Rod} 
16 
\sslist{example02.py} 
17 

18 
\label{Sec:1DHDv0} 
19 
\begin{figure}[ht] 
20 
\centerline{\includegraphics[width=4.in]{figures/onedheatdiff002}} 
21 
\caption{Example 2: One dimensional model of an Iron bar.} 
22 
\label{fig:onedhdmodel} 
23 
\end{figure} 
24 

25 
Our second example is of a cold iron bar at a constant temperature of $T\hackscore{ref}=20^{\circ} C$, see \reffig{fig:onedhdmodel}. The bar is perfectly insulated on all sides with a heating element at one end keeping the the temperature at a constant level $T\hackscore0=100^{\circ} C$. As heat is applied; energy will disperse along the bar via conduction. With time the bar will reach a constant temperature equivalent to that of the heat source. 
26 

27 
This problem is very similar to the example of temperature diffusion in granite blocks presented in the previous section~\ref{Sec:1DHDv00}. Thus, it is possible to modify the script we have already developed for the granite blocks to suit the iron bar problem. 
28 
The obvious difference between the two problems are the dimensions of the domain and different materials involved. This will change the time scale of the model from years to hours. 
29 
The new settings are; 
30 
\begin{python} 
31 
#Domain related. 
32 
mx = 1*m #meters  model length 
33 
my = .1*m #meters  model width 
34 
ndx = 100 # mesh steps in x direction 
35 
ndy = 1 # mesh steps in y direction  one dimension means one element 
36 
#PDE related 
37 
rho = 7874. *kg/m**3 #kg/m^{3} density of iron 
38 
cp = 449.*J/(kg*K) # J/Kg.K thermal capacity 
39 
rhocp = rho*cp 
40 
kappa = 80.*W/m/K # watts/m.Kthermal conductivity 
41 
qH = 0 * J/(sec*m**3) # J/(sec.m^{3}) no heat source 
42 
Tref = 20 * Celsius # base temperature of the rod 
43 
T0 = 100 * Celsius # temperature at heating element 
44 
tend= 0.5 * day #  time to end simulation 
45 
\end{python} 
46 
We also need to alter the initial value for the temperature. Now we need to set the 
47 
temperature to $T\hackscore{0}$ at the left end of the rod where we have $x\hackscore{0}=0$ and 
48 
$T\hackscore{ref}$ elsewhere. Instead of \verbwhereNegative function we use now the 
49 
\verbwhereZero which returns the value one for those sample points where 
50 
the argument (almost) equals zero and the value zero elsewhere. The initial 
51 
temperature is set to; 
52 
\begin{python} 
53 
# ... set initial temperature .... 
54 
T= T0*whereZero(x[0])+Tref*(1whereZero(x[0])) 
55 
\end{python} 
56 

57 
\subsection{Dirichlet Boundary Conditions} 
58 
In the iron rod model we want to keep the initial temperature $T\hackscore0$ on the left side of the domain constant with time. 
59 
This implies that when we solve the PDE~\refEq{eqn:hddisc}, the solution must have the value $T\hackscore0$ on the left hand 
60 
side of the domain. As mentioned already in Section~\ref{SEC BOUNDARY COND} where we discussed 
61 
boundary conditions, this kind of scenario can be expressed using a \textbf{Dirichlet boundary condition}. Some people also 
62 
use the term \textbf{constraint} for the PDE. 
63 

64 
To define a Dirichlet boundary condition we need to identify where to apply the condition and determine what value the 
65 
solution should have at these locations. In \esc we use $q$ and $r$ to define the Dirichlet boundary conditions 
66 
for a PDE. The solution $u$ of the PDE is set to $r$ for all sample points where $q$ has a positive value. 
67 
Mathematically this is expressed in the form; 
68 
\begin{equation} 
69 
u(x) = r(x) \mbox{ for any } x \mbox{ with } q(x) > 0 
70 
\end{equation} 
71 
In the case of the iron rod 
72 
we can set; 
73 
\begin{python} 
74 
q=whereZero(x[0]) 
75 
r=T0 
76 
\end{python} 
77 
to prescribe the value $T\hackscore{0}$ for the temperature at the left end of the rod where $x\hackscore{0}=0$. 
78 
Here we use the \verbwhereZero function again which we have already used to set the initial value. 
79 
Notice that $r$ is set to the constant value $T\hackscore{0}$ for all sample points. In fact, 
80 
values of $r$ are used only where $q$ is positive. Where $q$ is nonpositive, 
81 
$r$ may have any value as these values are not used by the PDE solver. 
82 

83 
To set the Dirichlet boundary conditions for the PDE to be solved in each time step we need 
84 
to add some statements; 
85 
\begin{python} 
86 
mypde=LinearPDE(rod) 
87 
A=zeros((2,2))) 
88 
A[0,0]=kappa 
89 
q=whereZero(x[0]) 
90 
mypde.setValue(A=A, D=rhocp/h, q=q, r=T0) 
91 
\end{python} 
92 
It is important to remark here that the Dirichlet condition \textbf{overwrites} any Neuman boundary 
93 
condition \esc sets by default (or those defined by the user). 
94 

95 
\begin{figure} 
96 
\begin{center} 
97 
\includegraphics[width=4in]{figures/ttrodpyplot150} 
98 
\caption{Example 2: Total Energy in the Iron Rod over Time (in seconds).} 
99 
\label{fig:onedheatout1 002} 
100 
\end{center} 
101 
\end{figure} 
102 

103 
\begin{figure} 
104 
\begin{center} 
105 
\includegraphics[width=4in]{figures/rodpyplot001} 
106 
\includegraphics[width=4in]{figures/rodpyplot050} 
107 
\includegraphics[width=4in]{figures/rodpyplot200} 
108 
\caption{Example 2: Temperature ($T$) distribution in the iron rod at time steps $1$, $50$ and $200$.} 
109 
\label{fig:onedheatout 002} 
110 
\end{center} 
111 
\end{figure} 
112 

113 
Besides some cosmetic modification this all we need to change. The total energy over time is shown in \reffig{fig:onedheatout1 002}. As heat 
114 
is transfered into the rod by the heater the total energy is growing over time but reaches a plateau 
115 
when the temperature is constant is the rod, see \reffig{fig:onedheatout 002}. 
116 
You will notice that the time scale of this model is several order of magnitudes faster than 
117 
for the granite rock problem due to the different length scale and material parameters. 
118 
In practice it can take a few models run before the right time scale has been chosen\footnote{An estimate of the 
119 
time scale for a diffusion problem is given by the formula $\frac{\rho c\hackscore{p} L\hackscore{0}^2}{4 \kappa}$, see 
120 
\url{http://en.wikipedia.org/wiki/Fick\%27s_laws_of_diffusion}}. 
121 

122 

123 

124 

125 

126 

127 
\section{For the Reader} 
128 
\begin{enumerate} 
129 
\item Move the boundary line between the two granite blocks to another part of the domain. 
130 
\item Split the domain into multiple granite blocks with varying temperatures. 
131 
\item Vary the mesh step size. Do you see a difference in the answers? What does happen with the compute time? 
132 
\item Insert an internal heat source (Hint: The internal heat source is given by $q\hackscore{H}$.) 
133 
\item Change the boundary condition for iron rod example such that the temperature 
134 
at the right end is kept at a constant level $T\hackscore{ref}$, which corresponds to the installation of a cooling element (Hint: Modify $q$ and $r$). 
135 
\end{enumerate} 
136 
