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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3981 - (show annotations)
Fri Sep 21 02:47:54 2012 UTC (5 years, 10 months ago) by jfenwick
File MIME type: text/x-python
File size: 4984 byte(s)
First pass of updating copyright notices
1
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2012 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-2012 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 # example05a.py
29 # Create either a 2D syncline or anticline model using pycad meshing
30 # tools. Then model steady state heat solution.
31
32 #######################################################EXTERNAL MODULES
33 from esys.pycad import * #domain constructor
34 from esys.pycad.gmsh import Design #Finite Element meshing package
35 from esys.finley import MakeDomain #Converter for escript
36 import os #file path tool
37 from math import * # math package
38 from esys.escript import *
39 from esys.escript.unitsSI import *
40 from esys.escript.linearPDEs import LinearPDE
41 import matplotlib
42 matplotlib.use('agg') #It's just here for automated testing
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 #######################################################################
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 ...")

  ViewVC Help
Powered by ViewVC 1.1.26