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

Contents of /release/4.1/doc/examples/cookbook/example05a.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26