/[escript]/trunk/doc/examples/cookbook/twodheatdiff001.py
ViewVC logotype

Contents of /trunk/doc/examples/cookbook/twodheatdiff001.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 4 months ago) by jfenwick
File MIME type: text/x-python
File size: 5925 byte(s)
Don't panic.
Updating copyright stamps

1
2 ########################################################
3 #
4 # Copyright (c) 2009-2010 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) 2009-2010 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 #For interactive use, you can comment out the next two lines
44 import matplotlib
45 matplotlib.use('agg') #It's just here for automated testing
46 import pylab as pl #Plotting package.
47 import numpy as np #Array package.
48 import os #This package is necessary to handle saving our data.
49 from cblib2 import toXYTuple
50 from cblib1 import needdirs
51
52 ########################################################MPI WORLD CHECK
53 if getMPISizeWorld() > 1:
54 import sys
55 print "This example will not run in an MPI world."
56 sys.exit(0)
57
58 #################################################ESTABLISHING VARIABLES
59 #PDE related
60 mx = 600*m #meters - model length
61 my = 600*m #meters - model width
62 ndx = 100 #mesh steps in x direction
63 ndy = 100 #mesh steps in y direction
64 r = 200*m #meters - radius of intrusion
65 ic = [300, 0] #centre of intrusion (meters)
66 q=0.*Celsius #our heat source temperature is now zero
67
68 ## Intrusion Variables - Granite
69 Ti=2273.*Celsius # Kelvin -the starting temperature of our RHS Block
70 rhoi = 2750*kg/m**3 #kg/m^{3} density of granite
71 cpi = 790.*J/(kg*K) #j/Kg.K thermal capacity
72 rhocpi = rhoi*cpi #DENSITY * SPECIFIC HEAT
73 eta=0. # RADIATION CONDITION
74 kappai=2.2*W/m/K #watts/m.K thermal conductivity
75 ## Country Rock Variables - Sandstone
76 Tc = 473*Celsius # Kelvin #the starting temperature of our country rock
77 rhoc = 2000*kg/m**3 #kg/m^{3} density
78 cpc = 920.*J/(kg*K) #j/kg.k specific heat
79 rhocpc = rhoc*cpc #DENSITY * SPECIFIC HEAT
80 kappac = 1.9*W/m/K #watts/m.K thermal conductivity
81
82 #Script/Iteration Related
83 t=0. #our start time, usually zero
84 tday=100*365. #the time we want to end the simulation in days
85 tend=tday*24*60*60
86 outputs = 200 # number of time steps required.
87 h=(tend-t)/outputs #size of time step
88 #user warning
89 print "Expected Number of Output Files is: ", outputs
90 print "Step size is: ", h/(24.*60*60), "days"
91 i=0 #loop counter
92 #the folder to put our outputs in, leave blank "" for script path
93 save_path= os.path.join("data","twodheatdiff")
94 needdirs([save_path])
95 ########## note this folder path must exist to work ###################
96
97 ################################################ESTABLISHING PARAMETERS
98 #generate domain using rectangle
99 model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
100 #extract finite points - the solution points
101 x=model.getX()
102 #create the PDE
103 mypde=LinearPDE(model) #assigns a domain to our PDE
104 mypde.setSymmetryOn() #set the fast solver on for symmetry
105 #establish location of boundary between two materials
106 bound = length(x-ic)-r #where the boundary will be located
107 A = (kappai)*whereNegative(bound)+(kappac)*wherePositive(bound)
108 D = (rhocpi/h)*whereNegative(bound)+(rhocpc/h)*wherePositive(bound)
109 #define our PDE coeffs
110 mypde.setValue(A=A*kronecker(model),D=D,d=eta,y=eta*Tc)
111 #set initial temperature
112 T= Ti*whereNegative(bound)+Tc*wherePositive(bound)
113
114 # rearrage mymesh to suit solution function space for contouring
115 oldspacecoords=model.getX()
116 coords=Data(oldspacecoords, T.getFunctionSpace())
117 #coords = np.array(coords.toListOfTuples())
118 coordX, coordY = toXYTuple(coords)
119 # create regular grid
120 xi = np.linspace(0.0,mx,100)
121 yi = np.linspace(0.0,my,100)
122
123 ########################################################START ITERATION
124 while t<=tend:
125 i+=1 #counter
126 t+=h #curretn time
127 Y = T*D #
128 mypde.setValue(Y=Y)
129 T=mypde.getSolution()
130 tempT = T.toListOfTuples(scalarastuple=False)
131 # grid the data.
132 zi = pl.matplotlib.mlab.griddata(coordX,coordY,tempT,xi,yi)
133 # contour the gridded data, plotting dots at the
134 # randomly spaced data points.
135 pl.matplotlib.pyplot.autumn()
136 pl.contourf(xi,yi,zi,10)
137 CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k')
138 pl.clabel(CS, inline=1, fontsize=8)
139 pl.axis([0,600,0,600])
140 pl.title("Heat diffusion from an intrusion.")
141 pl.xlabel("Horizontal Displacement (m)")
142 pl.ylabel("Depth (m)")
143 if getMPIRankWorld() == 0:
144 pl.savefig(os.path.join(save_path,\
145 "heatrefraction%03d.png"%i))
146 pl.clf()
147
148 # compile the *.png files to create an *.avi video that shows T change
149 # with time. This opperation uses linux mencoder.
150 os.system("mencoder mf://"+save_path+"/*.png -mf type=png:\
151 w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o \
152 twodheatdiff001tempT.avi")

  ViewVC Help
Powered by ViewVC 1.1.26