1 |
|
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 |
######################################################## |
13 |
|
14 |
__copyright__="""Copyright (c) 2003-2009 by University of Queensland |
15 |
Earth Systems Science Computational Center (ESSCC) |
16 |
http://www.uq.edu.au/esscc |
17 |
Primary Business: Queensland, Australia""" |
18 |
__license__="""Licensed under the Open Software License version 3.0 |
19 |
http://www.opensource.org/licenses/osl-3.0.php""" |
20 |
__url__="https://launchpad.net/escript-finley" |
21 |
|
22 |
""" |
23 |
Author: Antony Hallam antony.hallam@uqconnect.edu.au |
24 |
""" |
25 |
|
26 |
############################################################FILE HEADER |
27 |
# twodheatdiff002.py |
28 |
# Model temperature diffusion between a granite intrusion and sandstone |
29 |
# country rock. This is a two dimensional problem with the granite as a |
30 |
# heat source. |
31 |
|
32 |
#######################################################EXTERNAL MODULES |
33 |
#To solve the problem it is necessary to import the modules we require. |
34 |
#This imports everything from the escript library |
35 |
from esys.escript import * |
36 |
# This defines the LinearPDE module as LinearPDE |
37 |
from esys.escript.linearPDEs import LinearPDE |
38 |
# This imports the rectangle domain function from finley. |
39 |
from esys.finley import Rectangle |
40 |
# A useful unit handling package which will make sure all our units |
41 |
# match up in the equations under SI. |
42 |
from esys.escript.unitsSI import * |
43 |
import pylab as pl #Plotting package. |
44 |
import numpy as np #Array package. |
45 |
import os #This package is necessary to handle saving our data. |
46 |
from cblib import toXYTuple |
47 |
|
48 |
#################################################ESTABLISHING VARIABLES |
49 |
#PDE related |
50 |
mx = 600*m #meters - model length |
51 |
my = 600*m #meters - model width |
52 |
ndx = 100 #mesh steps in x direction |
53 |
ndy = 100 #mesh steps in y direction |
54 |
r = 200*m #meters - radius of intrusion |
55 |
ic = [300, 0] #centre of intrusion (meters) |
56 |
q=0.*Celsius #our heat source temperature is now zero |
57 |
|
58 |
## Intrusion Variables - Granite |
59 |
Ti=2273.*Celsius # Kelvin -the starting temperature of our RHS Block |
60 |
rhoi = 2750*kg/m**3 #kg/m^{3} density of granite |
61 |
cpi = 790.*J/(kg*K) #j/Kg.K thermal capacity |
62 |
rhocpi = rhoi*cpi #DENSITY * SPECIFIC HEAT |
63 |
eta=0. # RADIATION CONDITION |
64 |
kappai=2.2*W/m/K #watts/m.K thermal conductivity |
65 |
## Country Rock Variables - Sandstone |
66 |
Tc = 473*Celsius # Kelvin #the starting temperature of our country rock |
67 |
rhoc = 2000*kg/m**3 #kg/m^{3} density |
68 |
cpc = 920.*J/(kg*K) #j/kg.k specific heat |
69 |
rhocpc = rhoc*cpc #DENSITY * SPECIFIC HEAT |
70 |
kappac = 1.9*W/m/K #watts/m.K thermal conductivity |
71 |
|
72 |
#Script/Iteration Related |
73 |
t=0. #our start time, usually zero |
74 |
tday=100*365. #the time we want to end the simulation in days |
75 |
tend=tday*24*60*60 |
76 |
outputs = 200 # number of time steps required. |
77 |
h=(tend-t)/outputs #size of time step |
78 |
#user warning |
79 |
print "Expected Number of Output Files is: ", outputs |
80 |
print "Step size is: ", h/(24.*60*60), "days" |
81 |
i=0 #loop counter |
82 |
#the folder to put our outputs in, leave blank "" for script path |
83 |
save_path="data/twodheatdiff" |
84 |
########## note this folder path must exist to work ################### |
85 |
|
86 |
################################################ESTABLISHING PARAMETERS |
87 |
#generate domain using rectangle |
88 |
model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) |
89 |
#extract finite points - the solution points |
90 |
x=model.getX() |
91 |
#create the PDE |
92 |
mypde=LinearPDE(model) #assigns a domain to our PDE |
93 |
mypde.setSymmetryOn() #set the fast solver on for symmetry |
94 |
#establish location of boundary between two materials |
95 |
bound = length(x-ic)-r #where the boundary will be located |
96 |
A = (kappai)*whereNegative(bound)+(kappac)*wherePositive(bound) |
97 |
D = (rhocpi/h)*whereNegative(bound)+(rhocpc/h)*wherePositive(bound) |
98 |
#define our PDE coeffs |
99 |
mypde.setValue(A=A*kronecker(model),D=D,d=eta,y=eta*Tc) |
100 |
#set initial temperature |
101 |
T= Ti*whereNegative(bound)+Tc*wherePositive(bound) |
102 |
|
103 |
# rearrage mymesh to suit solution function space for contouring |
104 |
oldspacecoords=model.getX() |
105 |
coords=Data(oldspacecoords, T.getFunctionSpace()) |
106 |
#coords = np.array(coords.toListOfTuples()) |
107 |
coordX, coordY = toXYTuple(coords) |
108 |
# create regular grid |
109 |
xi = np.linspace(0.0,mx,100) |
110 |
yi = np.linspace(0.0,my,100) |
111 |
|
112 |
#... start iteration: |
113 |
while t<=tend: |
114 |
i+=1 #counter |
115 |
t+=h #curretn time |
116 |
Y = T*D # |
117 |
mypde.setValue(Y=Y) |
118 |
T=mypde.getSolution() |
119 |
tempT = T.toListOfTuples(scalarastuple=False) |
120 |
# grid the data. |
121 |
zi = pl.matplotlib.mlab.griddata(coordX,coordY,tempT,xi,yi) |
122 |
# contour the gridded data, plotting dots at the randomly spaced data points. |
123 |
pl.matplotlib.pyplot.autumn() |
124 |
pl.contourf(xi,yi,zi,10) |
125 |
CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k') |
126 |
pl.clabel(CS, inline=1, fontsize=8) |
127 |
pl.axis([0,600,0,600]) |
128 |
pl.title("Heat diffusion from an intrusion.") |
129 |
pl.xlabel("Horizontal Displacement (m)") |
130 |
pl.ylabel("Depth (m)") |
131 |
pl.savefig(os.path.join(save_path,"heatrefraction%03d.png") %i) |
132 |
pl.clf() |
133 |
|
134 |
# compile the *.png files to create an *.avi video that shows T change |
135 |
# with time. This opperation uses linux mencoder. |
136 |
os.system("mencoder mf://"+save_path+"/*.png -mf type=png:\ |
137 |
w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o \ |
138 |
twodheatdiff001tempT.avi") |