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

Annotation of /trunk/doc/examples/cookbook/example05b.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2948 - (hide annotations)
Thu Feb 25 04:54:30 2010 UTC (9 years, 11 months ago) by gross
Original Path: trunk/doc/examples/cookbook/heatrefraction_solver002.py
File MIME type: text/x-python
File size: 6607 byte(s)
a new almost completed version of the cookbook
1 gross 2948
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     # heatrefraction_mesher001.py
28     # Create either a 2D syncline or anticline model using pycad meshing
29     # tools.
30    
31     #######################################################EXTERNAL MODULES
32     import matplotlib
33     matplotlib.use('agg') #It's just here for automated testing
34     from esys.pycad import * #domain constructor
35     from esys.pycad.gmsh import Design #Finite Element meshing package
36     from esys.finley import MakeDomain #Converter for escript
37     import os #file path tool
38     from math import * # math package
39     from esys.escript import *
40     from esys.escript.unitsSI import *
41     from esys.escript.linearPDEs import LinearPDE
42     from esys.escript.pdetools import Projector
43     from cblib import toRegGrid
44     import pylab as pl #Plotting package
45    
46     ########################################################MPI WORLD CHECK
47     if getMPISizeWorld() > 1:
48     import sys
49     print "This example will not run in an MPI world."
50     sys.exit(0)
51    
52     #################################################ESTABLISHING VARIABLES
53     #set modal to 1 for a syncline or -1 for an anticline structural
54     #configuration
55     modal=-1
56    
57     # the folder to put our outputs in, leave blank "" for script path -
58     # note this folder path must exist to work
59     save_path= os.path.join("data","heatrefrac")
60     mkDir(save_path)
61    
62     ################################################ESTABLISHING PARAMETERS
63     #Model Parameters
64     width=5000.0*m #width of model
65     depth=-6000.0*m #depth of model
66     Ttop=20*K # top temperature
67     qin=70*Milli*W/(m*m) # bottom heat influx
68    
69     sspl=51 #number of discrete points in spline
70     dsp=width/(sspl-1) #dx of spline steps for width
71     dep_sp=2500.0*m #avg depth of spline
72     h_sp=1500.0*m #heigh of spline
73     orit=-1.0 #orientation of spline 1.0=>up -1.0=>down
74    
75     ####################################################DOMAIN CONSTRUCTION
76     # Domain Corners
77     p0=Point(0.0, 0.0, 0.0)
78     p1=Point(0.0, depth, 0.0)
79     p2=Point(width, depth, 0.0)
80     p3=Point(width, 0.0, 0.0)
81    
82     # Generate Material Boundary
83     x=[ Point(i*dsp\
84     ,-dep_sp+modal*orit*h_sp*cos(pi*i*dsp/dep_sp+pi))\
85     for i in range(0,sspl)\
86     ]
87     mysp = Spline(*tuple(x))
88     # Start and end of material boundary.
89     x1=mysp.getStartPoint()
90     x2=mysp.getEndPoint()
91    
92     # Create TOP BLOCK
93     # lines
94     tbl1=Line(p0,x1)
95     tbl2=mysp
96     tbl3=Line(x2,p3)
97     l30=Line(p3, p0)
98     # curve
99     tblockloop = CurveLoop(tbl1,tbl2,tbl3,l30)
100     # surface
101     tblock = PlaneSurface(tblockloop)
102    
103    
104     # Create BOTTOM BLOCK
105     # lines
106     bbl1=Line(x1,p1)
107     bbl3=Line(p2,x2)
108     bbl4=-mysp
109     l12=Line(p1, p2)
110     # curve
111     bblockloop = CurveLoop(bbl1,l12,bbl3,bbl4)
112     # surface
113     bblock = PlaneSurface(bblockloop)
114    
115     #clockwise check as splines must be set as polygons in the point order
116     #they were created. Otherwise get a line across plot.
117     bblockloop2=CurveLoop(mysp,Line(x2,p2),Line(p2,p1),Line(p1,x1))
118    
119     #############################################CREATE MESH FOR ESCRIPT
120     # Create a Design which can make the mesh
121     d=Design(dim=2, element_size=200)
122     # Add the subdomains and flux boundaries.
123     d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
124     PropertySet("linebottom",l12))
125     # Create the geometry, mesh and Escript domain
126     d.setScriptFileName(os.path.join(save_path,"heatrefraction.geo"))
127     d.setMeshFileName(os.path.join(save_path,"heatrefraction.msh"))
128     domain=MakeDomain(d, optimizeLabeling=True)
129     print "Domain has been generated ..."
130     ############################################# solve PDE
131     mypde=LinearPDE(domain)
132     mypde.getSolverOptions().setVerbosityOn()
133     mypde.setSymmetryOn()
134     kappa=Scalar(0,Function(domain))
135     kappa.setTaggedValue("top",2.0*W/m/K)
136     kappa.setTaggedValue("bottom",4.0*W/m/K)
137     mypde.setValue(A=kappa*kronecker(domain))
138     x=Solution(domain).getX()
139     mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
140     qS=Scalar(0,FunctionOnBoundary(domain))
141     qS.setTaggedValue("linebottom",qin)
142     mypde.setValue(y=qS)
143     print "PDE has been generated ..."
144     ###########################################################GET SOLUTION
145     T=mypde.getSolution()
146     print "PDE has been solved ..."
147    
148     ###########################################################
149     xi, yi, zi = toRegGrid(T, nx=50, ny=50)
150     pl.matplotlib.pyplot.autumn()
151     pl.contourf(xi,yi,zi,10)
152     pl.xlabel("Horizontal Displacement (m)")
153     pl.ylabel("Depth (m)")
154     pl.savefig(os.path.join(save_path,"heatrefraction.png"))
155     print "Solution has been plotted ..."
156     ##########################################################VISUALISATION
157     # calculate gradient of solution for quiver plot
158     #Projector is used to smooth the data.
159     proj=Projector(domain)
160     #move data to a regular grid for plotting
161     xi,yi,zi = toRegGrid(T,200,200)
162     cut=int(len(xi)/2)
163     pl.clf()
164     pl.plot(zi[:,cut],yi)
165     pl.title("Temperature Depth Profile")
166     pl.xlabel("Temperature (K)")
167     pl.ylabel("Depth (m)")
168     pl.savefig(os.path.join(save_path,"heatrefraction_tdp.png"))
169     pl.clf()
170    
171     # Heat flow depth profile.
172     # grid the data.
173     qu=proj(-kappa*grad(T))
174     xiq,yiq,ziq = toRegGrid(qu[1],50,50)
175     cut=int(len(xiq)/2)
176     pl.plot(ziq[:,cut]*1000.,yiq)
177     pl.title("Vertical Heat Flow Depth Profile")
178     pl.xlabel("Heat Flow (mW/m^2)")
179     pl.ylabel("Depth (m)")
180     pl.savefig(os.path.join(save_path,"heatrefraction_hf.png"))
181     pl.clf()
182    
183     # Temperature Gradient Depth Profile at x[50]
184     zT=proj(-grad(T))
185     xt,yt,zt=toRegGrid(zT[1],200,200)
186     cut=int(len(xt)/2)
187     pl.plot(zt[:,cut]*1000.,yt)
188     pl.title("Vertical Temperature Gradient \n Depth Profile")
189     pl.xlabel("Temperature gradient (K/Km)")
190     pl.ylabel("Depth (m)")
191     pl.savefig(os.path.join(save_path,"heatrefraction_tgdp.png"))
192     pl.clf()
193    
194     # Thermal Conditions Depth Profile
195     xk,yk,zk = toRegGrid(proj(kappa),200,200)
196     cut=int(len(xk)/2)
197     pl.plot(zk[:,cut],yk)
198     pl.title("Thermal Conductivity Depth Profile")
199     pl.xlabel("Conductivity (W/K/m)")
200     pl.ylabel("Depth (m)")
201     pl.axis([1,5,-6000,0])
202     pl.savefig(os.path.join(save_path,"heatrefraction_tcdp.png"))
203     pl.clf()
204     print "vertical profiles created ..."

  ViewVC Help
Powered by ViewVC 1.1.26