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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 9 months ago) by jfenwick
File MIME type: text/x-python
File size: 6430 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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 # example05b.py
28 # Create either a 2D syncline or anticline model using pycad meshing
29 # tools. Then model steady state heat solution. Look at some line profiles.
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","example05")
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 ################################################CREATE MESH FOR ESCRIPT
116 # Create a Design which can make the mesh
117 d=Design(dim=2, element_size=200)
118 # Add the subdomains and flux boundaries.
119 d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
120 PropertySet("linebottom",l12))
121 # Create the geometry, mesh and Escript domain
122 d.setScriptFileName(os.path.join(save_path,"example05.geo"))
123 d.setMeshFileName(os.path.join(save_path,"example05.msh"))
124 domain=MakeDomain(d, optimizeLabeling=True)
125 print("Domain has been generated ...")
126 ##############################################################SOLVE PDE
127 mypde=LinearPDE(domain)
128 mypde.getSolverOptions().setVerbosityOn()
129 mypde.setSymmetryOn()
130 kappa=Scalar(0,Function(domain))
131 kappa.setTaggedValue("top",2.0*W/m/K)
132 kappa.setTaggedValue("bottom",4.0*W/m/K)
133 mypde.setValue(A=kappa*kronecker(domain))
134 x=Solution(domain).getX()
135 mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
136 qS=Scalar(0,FunctionOnBoundary(domain))
137 qS.setTaggedValue("linebottom",qin)
138 mypde.setValue(y=qS)
139 print("PDE has been generated ...")
140 ###########################################################GET SOLUTION
141 T=mypde.getSolution()
142 print("PDE has been solved ...")
143
144 ##################################################REGRIDDING & PLOTTING
145 xi, yi, zi = toRegGrid(T, nx=50, ny=50)
146 pl.matplotlib.pyplot.autumn()
147 pl.contourf(xi,yi,zi,10)
148 pl.xlabel("Horizontal Displacement (m)")
149 pl.ylabel("Depth (m)")
150 pl.savefig(os.path.join(save_path,"Tcontour.png"))
151 print("Solution has been plotted ...")
152 ##########################################################VISUALISATION
153 # calculate gradient of solution for quiver plot
154 #Projector is used to smooth the data.
155 proj=Projector(domain)
156 #move data to a regular grid for plotting
157 xi,yi,zi = toRegGrid(T,200,200)
158 cut=int(len(xi)/2)
159 pl.clf()
160 pl.plot(zi[:,cut],yi)
161 pl.title("Temperature Depth Profile")
162 pl.xlabel("Temperature (K)")
163 pl.ylabel("Depth (m)")
164 pl.savefig(os.path.join(save_path,"tdp.png"))
165 pl.clf()
166
167 # Heat flow depth profile.
168 # grid the data.
169 qu=proj(-kappa*grad(T))
170 xiq,yiq,ziq = toRegGrid(qu[1],50,50)
171 cut=int(len(xiq)/2)
172 pl.plot(ziq[:,cut]*1000.,yiq)
173 pl.title("Vertical Heat Flow Depth Profile")
174 pl.xlabel("Heat Flow (mW/m^2)")
175 pl.ylabel("Depth (m)")
176 pl.savefig(os.path.join(save_path,"hf.png"))
177 pl.clf()
178
179 # Temperature Gradient Depth Profile at x[50]
180 zT=proj(-grad(T))
181 xt,yt,zt=toRegGrid(zT[1],200,200)
182 cut=int(len(xt)/2)
183 pl.plot(zt[:,cut]*1000.,yt)
184 pl.title("Vertical Temperature Gradient \n Depth Profile")
185 pl.xlabel("Temperature gradient (K/Km)")
186 pl.ylabel("Depth (m)")
187 pl.savefig(os.path.join(save_path,"tgdp.png"))
188 pl.clf()
189
190 # Thermal Conditions Depth Profile
191 xk,yk,zk = toRegGrid(proj(kappa),200,200)
192 cut=int(len(xk)/2)
193 pl.plot(zk[:,cut],yk)
194 pl.title("Thermal Conductivity Depth Profile")
195 pl.xlabel("Conductivity (W/K/m)")
196 pl.ylabel("Depth (m)")
197 pl.axis([1,5,-6000,0])
198 pl.savefig(os.path.join(save_path,"tcdp.png"))
199 pl.clf()
200 print("vertical profiles created ...")

  ViewVC Help
Powered by ViewVC 1.1.26