/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 7475 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 from __future__ import division, print_function
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Apache License, version 2.0
21 http://www.apache.org/licenses/LICENSE-2.0"""
22 __url__="https://launchpad.net/escript-finley"
23
24 """
25 Author: Antony Hallam antony.hallam@uqconnect.edu.au
26 """
27
28 ############################################################FILE HEADER
29 # example05b.py
30 # Create either a 2D syncline or anticline model using pycad meshing
31 # tools. Then model steady state heat solution. Look at some line profiles.
32
33 #######################################################EXTERNAL MODULES
34 import matplotlib
35 matplotlib.use('agg') #It's just here for automated testing
36 from esys.pycad import * #domain constructor
37 from esys.pycad.gmsh import Design #Finite Element meshing package
38 import os #file path tool
39 from math import * # math package
40 from esys.escript import *
41 from esys.escript.unitsSI import *
42 from esys.escript.linearPDEs import LinearPDE
43 from esys.escript.pdetools import Projector
44 from cblib import toRegGrid, HAVE_NATGRID
45 import pylab as pl #Plotting package
46
47 try:
48 # This imports the rectangle domain function
49 from esys.finley import MakeDomain#Converter for escript
50 HAVE_FINLEY = True
51 except ImportError:
52 print("Finley module not available")
53 HAVE_FINLEY = False
54 ########################################################MPI WORLD CHECK
55 if getMPISizeWorld() > 1:
56 import sys
57 print("This example will not run in an MPI world.")
58 sys.exit(0)
59
60 if not HAVE_NATGRID:
61 print("This example requires natgrid to be available to matplotlib")
62
63
64 if HAVE_FINLEY and HAVE_NATGRID:
65 #################################################ESTABLISHING VARIABLES
66 #set modal to 1 for a syncline or -1 for an anticline structural
67 #configuration
68 modal=-1
69
70 # the folder to put our outputs in, leave blank "" for script path -
71 # note this folder path must exist to work
72 save_path= os.path.join("data","example05")
73 mkDir(save_path)
74
75 ################################################ESTABLISHING PARAMETERS
76 #Model Parameters
77 width=5000.0*m #width of model
78 depth=-6000.0*m #depth of model
79 Ttop=20*K # top temperature
80 qin=70*Milli*W/(m*m) # bottom heat influx
81
82 sspl=51 #number of discrete points in spline
83 dsp=width/(sspl-1) #dx of spline steps for width
84 dep_sp=2500.0*m #avg depth of spline
85 h_sp=1500.0*m #heigh of spline
86 orit=-1.0 #orientation of spline 1.0=>up -1.0=>down
87
88 ####################################################DOMAIN CONSTRUCTION
89 # Domain Corners
90 p0=Point(0.0, 0.0, 0.0)
91 p1=Point(0.0, depth, 0.0)
92 p2=Point(width, depth, 0.0)
93 p3=Point(width, 0.0, 0.0)
94
95 # Generate Material Boundary
96 x=[ Point(i*dsp\
97 ,-dep_sp+modal*orit*h_sp*cos(pi*i*dsp/dep_sp+pi))\
98 for i in range(0,sspl)\
99 ]
100 mysp = Spline(*tuple(x))
101 # Start and end of material boundary.
102 x1=mysp.getStartPoint()
103 x2=mysp.getEndPoint()
104
105 # Create TOP BLOCK
106 # lines
107 tbl1=Line(p0,x1)
108 tbl2=mysp
109 tbl3=Line(x2,p3)
110 l30=Line(p3, p0)
111 # curve
112 tblockloop = CurveLoop(tbl1,tbl2,tbl3,l30)
113 # surface
114 tblock = PlaneSurface(tblockloop)
115
116
117 # Create BOTTOM BLOCK
118 # lines
119 bbl1=Line(x1,p1)
120 bbl3=Line(p2,x2)
121 bbl4=-mysp
122 l12=Line(p1, p2)
123 # curve
124 bblockloop = CurveLoop(bbl1,l12,bbl3,bbl4)
125 # surface
126 bblock = PlaneSurface(bblockloop)
127
128 ################################################CREATE MESH FOR ESCRIPT
129 # Create a Design which can make the mesh
130 d=Design(dim=2, element_size=200)
131 # Add the subdomains and flux boundaries.
132 d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
133 PropertySet("linebottom",l12))
134 # Create the geometry, mesh and Escript domain
135 d.setScriptFileName(os.path.join(save_path,"example05.geo"))
136 d.setMeshFileName(os.path.join(save_path,"example05.msh"))
137 domain=MakeDomain(d, optimizeLabeling=True)
138 print("Domain has been generated ...")
139 ##############################################################SOLVE PDE
140 mypde=LinearPDE(domain)
141 mypde.getSolverOptions().setVerbosityOn()
142 mypde.setSymmetryOn()
143 kappa=Scalar(0,Function(domain))
144 kappa.setTaggedValue("top",2.0*W/m/K)
145 kappa.setTaggedValue("bottom",4.0*W/m/K)
146 mypde.setValue(A=kappa*kronecker(domain))
147 x=Solution(domain).getX()
148 mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
149 qS=Scalar(0,FunctionOnBoundary(domain))
150 qS.setTaggedValue("linebottom",qin)
151 mypde.setValue(y=qS)
152 print("PDE has been generated ...")
153 ###########################################################GET SOLUTION
154 T=mypde.getSolution()
155 print("PDE has been solved ...")
156
157 ##################################################REGRIDDING & PLOTTING
158 xi, yi, zi = toRegGrid(T, nx=50, ny=50)
159 pl.matplotlib.pyplot.autumn()
160 pl.contourf(xi,yi,zi,10)
161 pl.xlabel("Horizontal Displacement (m)")
162 pl.ylabel("Depth (m)")
163 pl.savefig(os.path.join(save_path,"Tcontour.png"))
164 print("Solution has been plotted ...")
165 ##########################################################VISUALISATION
166 # calculate gradient of solution for quiver plot
167 #Projector is used to smooth the data.
168 proj=Projector(domain)
169 #move data to a regular grid for plotting
170 xi,yi,zi = toRegGrid(T,200,200)
171 cut=int(len(xi)//2)
172 pl.clf()
173 pl.plot(zi[:,cut],yi)
174 pl.title("Temperature Depth Profile")
175 pl.xlabel("Temperature (K)")
176 pl.ylabel("Depth (m)")
177 pl.savefig(os.path.join(save_path,"tdp.png"))
178 pl.clf()
179
180 # Heat flow depth profile.
181 # grid the data.
182 qu=proj(-kappa*grad(T))
183 xiq,yiq,ziq = toRegGrid(qu[1],50,50)
184 cut=int(len(xiq)//2)
185 pl.plot(ziq[:,cut]*1000.,yiq)
186 pl.title("Vertical Heat Flow Depth Profile")
187 pl.xlabel("Heat Flow (mW/m^2)")
188 pl.ylabel("Depth (m)")
189 pl.savefig(os.path.join(save_path,"hf.png"))
190 pl.clf()
191
192 # Temperature Gradient Depth Profile at x[50]
193 zT=proj(-grad(T))
194 xt,yt,zt=toRegGrid(zT[1],200,200)
195 cut=int(len(xt)//2)
196 pl.plot(zt[:,cut]*1000.,yt)
197 pl.title("Vertical Temperature Gradient \n Depth Profile")
198 pl.xlabel("Temperature gradient (K/Km)")
199 pl.ylabel("Depth (m)")
200 pl.savefig(os.path.join(save_path,"tgdp.png"))
201 pl.clf()
202
203 # Thermal Conditions Depth Profile
204 xk,yk,zk = toRegGrid(proj(kappa),200,200)
205 cut=int(len(xk)//2)
206 pl.plot(zk[:,cut],yk)
207 pl.title("Thermal Conductivity Depth Profile")
208 pl.xlabel("Conductivity (W/K/m)")
209 pl.ylabel("Depth (m)")
210 pl.axis([1,5,-6000,0])
211 pl.savefig(os.path.join(save_path,"tcdp.png"))
212 pl.clf()
213 print("vertical profiles created ...")

  ViewVC Help
Powered by ViewVC 1.1.26