/[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 2648 - (show annotations)
Mon Sep 7 00:06:15 2009 UTC (11 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 5449 byte(s)
ecording some changes related to Anthony's cookbook.
These tests still do not run.

test_heatref.py is the current problem.
Current problems include:
undefined symbols
a dependence on X somehow.

I've already addressed the matplotlib X thing somewhere else.
Find and apply.


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, needdirs
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 needdirs([save_path])
85 ########## note this folder path must exist to work ###################
86
87 ################################################ESTABLISHING PARAMETERS
88 #generate domain using rectangle
89 model = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
90 #extract finite points - the solution points
91 x=model.getX()
92 #create the PDE
93 mypde=LinearPDE(model) #assigns a domain to our PDE
94 mypde.setSymmetryOn() #set the fast solver on for symmetry
95 #establish location of boundary between two materials
96 bound = length(x-ic)-r #where the boundary will be located
97 A = (kappai)*whereNegative(bound)+(kappac)*wherePositive(bound)
98 D = (rhocpi/h)*whereNegative(bound)+(rhocpc/h)*wherePositive(bound)
99 #define our PDE coeffs
100 mypde.setValue(A=A*kronecker(model),D=D,d=eta,y=eta*Tc)
101 #set initial temperature
102 T= Ti*whereNegative(bound)+Tc*wherePositive(bound)
103
104 # rearrage mymesh to suit solution function space for contouring
105 oldspacecoords=model.getX()
106 coords=Data(oldspacecoords, T.getFunctionSpace())
107 #coords = np.array(coords.toListOfTuples())
108 coordX, coordY = toXYTuple(coords)
109 # create regular grid
110 xi = np.linspace(0.0,mx,100)
111 yi = np.linspace(0.0,my,100)
112
113 #... start iteration:
114 while t<=tend:
115 i+=1 #counter
116 t+=h #curretn time
117 Y = T*D #
118 mypde.setValue(Y=Y)
119 T=mypde.getSolution()
120 tempT = T.toListOfTuples(scalarastuple=False)
121 # grid the data.
122 zi = pl.matplotlib.mlab.griddata(coordX,coordY,tempT,xi,yi)
123 # contour the gridded data, plotting dots at the randomly spaced data points.
124 pl.matplotlib.pyplot.autumn()
125 pl.contourf(xi,yi,zi,10)
126 CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k')
127 pl.clabel(CS, inline=1, fontsize=8)
128 pl.axis([0,600,0,600])
129 pl.title("Heat diffusion from an intrusion.")
130 pl.xlabel("Horizontal Displacement (m)")
131 pl.ylabel("Depth (m)")
132 pl.savefig(os.path.join(save_path,"heatrefraction%03d.png") %i)
133 pl.clf()
134
135 # compile the *.png files to create an *.avi video that shows T change
136 # with time. This opperation uses linux mencoder.
137 os.system("mencoder mf://"+save_path+"/*.png -mf type=png:\
138 w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o \
139 twodheatdiff001tempT.avi")

  ViewVC Help
Powered by ViewVC 1.1.26