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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2672 - (show annotations)
Fri Sep 18 01:46:47 2009 UTC (12 years, 1 month ago) by ahallam
File MIME type: text/x-python
File size: 6573 byte(s)
Heat refraction updates : alex's downhole profiles
1
2 ########################################################
3 #
4 # Copyright (c) 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) 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 # heatrefraction001.py
28 # Model steady state temperature distribution in two block model, mesh
29 # from heatrefraction_mesher001.py
30
31 #######################################################EXTERNAL MODULES
32 # To solve the problem it is necessary to import the modules we
33 # require.
34
35
36
37 # This imports everything from the escript library
38 from esys.escript import *
39 # This defines LinearPDE as LinearPDE
40 from esys.escript.linearPDEs import LinearPDE, Poisson
41 from esys.escript.pdetools import Projector
42 # This imports the rectangle domain function from finley
43 from esys.finley import Rectangle, ReadMesh, Domain
44 # This package is necessary to handle saving our data.
45 import os
46 # A useful unit handling package which will make sure all our units
47 # match up in the equations.
48 from esys.escript.unitsSI import *
49 # numpy for array handling
50 import numpy as np
51
52 import matplotlib
53 #For interactive use, you can comment out the next line
54 matplotlib.use('agg') #It's just here for automated testing
55
56 # pylab for matplotlib and plotting
57 import pylab as pl
58 # cblib functions
59 from cblib import toQuivLocs, toXYTuple, needdirs, toRegGrid, gradtoRegGrid
60
61 ########################################################MPI WORLD CHECK
62 if getMPISizeWorld() > 1:
63 import sys
64 print "This example will not run in an MPI world."
65 sys.exit(0)
66
67 #################################################ESTABLISHING VARIABLES
68 qin=70*Milli*W/(m*m) #our heat source temperature is now zero
69 Ti=290.15*K # Kelvin #the starting temperature of our iron bar
70 width=5000.0*m
71 depth=-6000.0*m
72
73 # the folder to gett our outputs from, leave blank "" for script path -
74 # note these depen. are generated from heatrefraction_mesher001.py
75 saved_path = save_path= os.path.join("data","heatrefrac001" )
76 needdirs([saved_path])
77
78 ################################################ESTABLISHING PARAMETERS
79 ## DOMAIN
80 mymesh=ReadMesh(os.path.join(saved_path,"heatrefraction_mesh001.fly"))
81 tpg = np.loadtxt(os.path.join(saved_path,"toppg"))
82 tpgx = tpg[:,0]
83 tpgy = tpg[:,1]
84 bpg = np.loadtxt(os.path.join(saved_path,"botpg"))
85 bpgx = bpg[:,0]
86 bpgy = bpg[:,1]
87
88 # set up kappa (thermal conductivity across domain) using tags
89 kappa=Scalar(0,Function(mymesh))
90 kappa.setTaggedValue("top",2.0)
91 kappa.setTaggedValue("bottom",4.0)
92
93 #... generate functionspace...
94 #... open PDE ...
95 mypde=LinearPDE(mymesh)
96 #define first coefficient
97 mypde.setValue(A=kappa*kronecker(mymesh))
98
99 # ... set initial temperature ....
100 x=mymesh.getX()
101
102 qH=Scalar(0,FunctionOnBoundary(mymesh))
103 qH.setTaggedValue("linebottom",qin)
104 mypde.setValue(q=whereZero(x[1]),r=Ti)
105 mypde.setValue(y=qH)
106
107 ###########################################################GET SOLUTION
108 T=mypde.getSolution()
109
110 ##########################################################VISUALISATION
111 # calculate gradient of solution for quiver plot
112 qu=-kappa*grad(T)
113 quT=qu.toListOfTuples()
114
115 #Projector is used to smooth the data.
116 proj=Projector(mymesh)
117 smthT=proj(T)
118
119 quivshape = [20,20] #quivers x and quivers y
120 # function to calculate quiver locations
121 qu,qulocs = toQuivLocs(quivshape,width,depth,qu)
122
123 #move data to a regular grid for plotting
124 xi,yi,zi = toRegGrid(smthT,mymesh,200,200,width,depth)
125
126 # contour the gridded data,
127 # plotting dots at the randomly spaced data points.
128
129 # select colour
130 pl.matplotlib.pyplot.autumn()
131 # plot polygons for boundaries
132 CKL = pl.fill(tpgx,tpgy,'brown',label='2 W/m/k',zorder=-1000)
133 CKM = pl.fill(bpgx,bpgy,'red',label='4 W/m/k',zorder=-1000)
134 # contour temperature
135 CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k')
136 # labels and formatting
137 pl.clabel(CS, inline=1, fontsize=8)
138 pl.title("Heat Refraction across a clinal structure.")
139 pl.xlabel("Horizontal Displacement (m)")
140 pl.ylabel("Depth (m)")
141 pl.legend()
142 if getMPIRankWorld() == 0: #check for MPI processing
143 pl.savefig(os.path.join(saved_path,"heatrefraction001_cont.png"))
144
145 #Quiver Plot qulocs -> tail location, qu -> quiver length/direction
146 QUIV=pl.quiver(qulocs[:,0],qulocs[:,1],qu[:,0],qu[:,1],\
147 angles='xy',color="white")
148 pl.title("Heat Refraction across a clinal structure\n with\
149 gradient quivers.")
150 if getMPIRankWorld() == 0: #check for MPI processing
151 pl.savefig(os.path.join(saved_path,"heatrefraction001_contqu.png"))
152
153 #Temperature Depth Profile along x[50]
154 cut=int(len(xi)/2)
155 pl.clf()
156 pl.plot(zi[:,cut],yi)
157 pl.title("Heat Refraction Temperature Depth Profile")
158 pl.xlabel("Temperature (K)")
159 pl.ylabel("Depth (m)")
160 if getMPIRankWorld() == 0: #check for MPI processing
161 pl.savefig(os.path.join(saved_path,"heatrefraction001_tdp.png"))
162
163 #Temperature Gradient Profile along x[50]
164
165
166
167 pl.clf()
168 # grid the data.
169 qu=proj(-kappa*grad(T))
170 xiq,yiq,ziq = gradtoRegGrid(qu,mymesh,200,200,width,depth,1)
171 cut=int(len(xiq)/2)
172 pl.plot(ziq[:,cut]*1000.,yiq)
173 pl.title("Heat Flow Depth Profile")
174 pl.xlabel("Heat Flow (mW/m^2)")
175 pl.ylabel("Depth (m)")
176 if getMPIRankWorld() == 0: #check for MPI processing
177 pl.savefig(os.path.join(saved_path,"heatrefraction001_hf.png"))
178
179 pl.clf()
180 zT=proj(-grad(T))
181
182 xt,yt,zt=gradtoRegGrid(zT,mymesh,200,200,width,depth,1)
183 cut=int(len(xt)/2)
184 pl.plot(zt[:,cut]*1000.,yt)
185 pl.title("Heat Refraction Temperature Gradient \n Depth Profile")
186 pl.xlabel("Temperature (K/Km)")
187 pl.ylabel("Depth (m)")
188 if getMPIRankWorld() == 0: #check for MPI processing
189 pl.savefig(os.path.join(saved_path,"heatrefraction001_tgdp.png"))
190
191 pl.clf()
192 xk,yk,zk = toRegGrid(kappa,mymesh,200,200,width,depth)
193 cut=int(len(xk)/2)
194 pl.plot(zk[:,cut],yk)
195 pl.title("Heat Refraction Thermal Conductivity Depth Profile")
196 pl.xlabel("Conductivity (W/K/m)")
197 pl.ylabel("Depth (m)")
198 pl.axis([1,5,-6000,0])
199 if getMPIRankWorld() == 0: #check for MPI processing
200 pl.savefig(os.path.join(saved_path,"heatrefraction001_tcdp.png"))
201

  ViewVC Help
Powered by ViewVC 1.1.26