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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (4 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 5687 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
1
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2009-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 """
24 Author: Antony Hallam antony.hallam@uqconnect.edu.au
25 """
26
27 ############################################################FILE HEADER
28 # example05c.py
29 # Create either a 2D syncline or anticline model using pycad meshing
30 # tools. The model steady state heat solution. How to create arrow or
31 # quiver plots.
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 from esys.finley import MakeDomain #Converter for escript
39 import os #file path tool
40 from math import * # math package
41 from esys.escript import *
42 from esys.escript.unitsSI import *
43 from esys.escript.linearPDEs import LinearPDE
44 from esys.escript.pdetools import Projector
45 from cblib import toRegGrid, subsample
46 import pylab as pl #Plotting package
47 import numpy as np
48
49 ########################################################MPI WORLD CHECK
50 if getMPISizeWorld() > 1:
51 import sys
52 print("This example will not run in an MPI world.")
53 sys.exit(0)
54
55 #################################################ESTABLISHING VARIABLES
56 #set modal to 1 for a syncline or -1 for an anticline structural
57 #configuration
58 modal=-1
59
60 # the folder to put our outputs in, leave blank "" for script path -
61 # note this folder path must exist to work
62 save_path= os.path.join("data","example05")
63 mkDir(save_path)
64
65 ################################################ESTABLISHING PARAMETERS
66 #Model Parameters
67 width=5000.0*m #width of model
68 depth=-6000.0*m #depth of model
69 Ttop=20*K # top temperature
70 qin=70*Milli*W/(m*m) # bottom heat influx
71
72 sspl=51 #number of discrete points in spline
73 dsp=width/(sspl-1) #dx of spline steps for width
74 dep_sp=2500.0*m #avg depth of spline
75 h_sp=1500.0*m #heigh of spline
76 orit=-1.0 #orientation of spline 1.0=>up -1.0=>down
77
78 ####################################################DOMAIN CONSTRUCTION
79 # Domain Corners
80 p0=Point(0.0, 0.0, 0.0)
81 p1=Point(0.0, depth, 0.0)
82 p2=Point(width, depth, 0.0)
83 p3=Point(width, 0.0, 0.0)
84
85 # Generate Material Boundary
86 x=[ Point(i*dsp\
87 ,-dep_sp+modal*orit*h_sp*cos(pi*i*dsp/dep_sp+pi))\
88 for i in range(0,sspl)\
89 ]
90 mysp = Spline(*tuple(x))
91 # Start and end of material boundary.
92 x1=mysp.getStartPoint()
93 x2=mysp.getEndPoint()
94
95 # Create TOP BLOCK
96 # lines
97 tbl1=Line(p0,x1)
98 tbl2=mysp
99 tbl3=Line(x2,p3)
100 l30=Line(p3, p0)
101 # curve
102 tblockloop = CurveLoop(tbl1,tbl2,tbl3,l30)
103 # surface
104 tblock = PlaneSurface(tblockloop)
105 # Create BOTTOM BLOCK
106 # lines
107 bbl1=Line(x1,p1)
108 bbl3=Line(p2,x2)
109 bbl4=-mysp
110 l12=Line(p1, p2)
111 # curve
112 bblockloop = CurveLoop(bbl1,l12,bbl3,bbl4)
113
114 # surface
115 bblock = PlaneSurface(bblockloop)
116
117 ################################################CREATE MESH FOR ESCRIPT
118 # Create a Design which can make the mesh
119 d=Design(dim=2, element_size=200)
120 # Add the subdomains and flux boundaries.
121 d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
122 PropertySet("linebottom",l12))
123 # Create the geometry, mesh and Escript domain
124 d.setScriptFileName(os.path.join(save_path,"example05.geo"))
125 d.setMeshFileName(os.path.join(save_path,"example05.msh"))
126 domain=MakeDomain(d, optimizeLabeling=True)
127 print("Domain has been generated ...")
128 ##############################################################SOLVE PDE
129 mypde=LinearPDE(domain)
130 mypde.getSolverOptions().setVerbosityOn()
131 mypde.setSymmetryOn()
132 kappa=Scalar(0,Function(domain))
133 kappa.setTaggedValue("top",2.0*W/m/K)
134 kappa.setTaggedValue("bottom",4.0*W/m/K)
135 mypde.setValue(A=kappa*kronecker(domain))
136 x=Solution(domain).getX()
137 mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
138 qS=Scalar(0,FunctionOnBoundary(domain))
139 qS.setTaggedValue("linebottom",qin)
140 mypde.setValue(y=qS)
141 print("PDE has been generated ...")
142 ###########################################################GET SOLUTION
143 T=mypde.getSolution()
144 print("PDE has been solved ...")
145 ###############################################################PLOTTING
146 # show temperature:
147 xi, yi, zi = toRegGrid(T, nx=50, ny=50)
148 CS = pl.contour(xi,yi,zi,5,linewidths=0.5,colors='k')
149 pl.clabel(CS, inline=1, fontsize=8)
150 # show sub domains:
151 tpg=np.array([p.getCoordinates() for p in tblockloop.getPolygon() ])
152 pl.fill(tpg[:,0],tpg[:,1],'brown',label='2 W/m/k',zorder=-1000)
153 bpg=np.array([p.getCoordinates() for p in bblockloop.getPolygon() ])
154 pl.fill(bpg[:,0],bpg[:,1],'red',label='4 W/m/k',zorder=-1000)
155 # show flux:
156 xflux, flux=subsample(-kappa*grad(T), nx=20, ny=20)
157 pl.quiver(xflux[:,0],xflux[:,1],flux[:,0],flux[:,1], angles='xy',color="white")
158 # create plot
159 pl.title("Heat Refraction across a clinal structure\n with heat flux.")
160 pl.xlabel("Horizontal Displacement (m)")
161 pl.ylabel("Depth (m)")
162 pl.legend()
163 pl.savefig(os.path.join(save_path,"flux.png"))
164 print("Flux has been plotted ...")

  ViewVC Help
Powered by ViewVC 1.1.26