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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2948 - (hide annotations)
Thu Feb 25 04:54:30 2010 UTC (8 years, 3 months ago) by gross
Original Path: trunk/doc/examples/cookbook/heatrefraction_solver001.py
File MIME type: text/x-python
File size: 5068 byte(s)
a new almost completed version of the cookbook
1 gross 2948
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     # heatrefraction_mesher001.py
28     # Create either a 2D syncline or anticline model using pycad meshing
29     # tools.
30    
31     #######################################################EXTERNAL MODULES
32     from esys.pycad import * #domain constructor
33     from esys.pycad.gmsh import Design #Finite Element meshing package
34     from esys.finley import MakeDomain #Converter for escript
35     import os #file path tool
36     from math import * # math package
37     from esys.escript import *
38     from esys.escript.unitsSI import *
39     from esys.escript.linearPDEs import LinearPDE
40     import matplotlib
41     matplotlib.use('agg') #It's just here for automated testing
42     from cblib import toRegGrid
43     import pylab as pl #Plotting package
44    
45     ########################################################MPI WORLD CHECK
46     if getMPISizeWorld() > 1:
47     import sys
48     print "This example will not run in an MPI world."
49     sys.exit(0)
50    
51     #################################################ESTABLISHING VARIABLES
52     #set modal to 1 for a syncline or -1 for an anticline structural
53     #configuration
54     modal=-1
55    
56     # the folder to put our outputs in, leave blank "" for script path -
57     # note this folder path must exist to work
58     save_path= os.path.join("data","heatrefrac")
59     mkDir(save_path)
60    
61     ################################################ESTABLISHING PARAMETERS
62     #Model Parameters
63     width=5000.0*m #width of model
64     depth=-6000.0*m #depth of model
65     Ttop=20*K # top temperature
66     qin=70*Milli*W/(m*m) # bottom heat influx
67    
68     sspl=51 #number of discrete points in spline
69     dsp=width/(sspl-1) #dx of spline steps for width
70     dep_sp=2500.0*m #avg depth of spline
71     h_sp=1500.0*m #heigh of spline
72     orit=-1.0 #orientation of spline 1.0=>up -1.0=>down
73    
74     ####################################################DOMAIN CONSTRUCTION
75     # Domain Corners
76     p0=Point(0.0, 0.0, 0.0)
77     p1=Point(0.0, depth, 0.0)
78     p2=Point(width, depth, 0.0)
79     p3=Point(width, 0.0, 0.0)
80    
81     # Generate Material Boundary
82     x=[ Point(i*dsp\
83     ,-dep_sp+modal*orit*h_sp*cos(pi*i*dsp/dep_sp+pi))\
84     for i in range(0,sspl)\
85     ]
86     mysp = Spline(*tuple(x))
87     # Start and end of material boundary.
88     x1=mysp.getStartPoint()
89     x2=mysp.getEndPoint()
90    
91     # Create TOP BLOCK
92     # lines
93     tbl1=Line(p0,x1)
94     tbl2=mysp
95     tbl3=Line(x2,p3)
96     l30=Line(p3, p0)
97     # curve
98     tblockloop = CurveLoop(tbl1,tbl2,tbl3,l30)
99     # surface
100     tblock = PlaneSurface(tblockloop)
101    
102    
103     # Create BOTTOM BLOCK
104     # lines
105     bbl1=Line(x1,p1)
106     bbl3=Line(p2,x2)
107     bbl4=-mysp
108     l12=Line(p1, p2)
109     # curve
110     bblockloop = CurveLoop(bbl1,l12,bbl3,bbl4)
111     # surface
112     bblock = PlaneSurface(bblockloop)
113    
114     #clockwise check as splines must be set as polygons in the point order
115     #they were created. Otherwise get a line across plot.
116     bblockloop2=CurveLoop(mysp,Line(x2,p2),Line(p2,p1),Line(p1,x1))
117    
118     #############################################CREATE MESH FOR ESCRIPT
119     # Create a Design which can make the mesh
120     d=Design(dim=2, element_size=200)
121     # Add the subdomains and flux boundaries.
122     d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
123     PropertySet("linebottom",l12))
124     # Create the geometry, mesh and Escript domain
125     d.setScriptFileName(os.path.join(save_path,"heatrefraction.geo"))
126     d.setMeshFileName(os.path.join(save_path,"heatrefraction.msh"))
127     domain=MakeDomain(d, optimizeLabeling=True)
128     print "Domain has been generated ..."
129     ############################################# solve PDE
130     mypde=LinearPDE(domain)
131     mypde.getSolverOptions().setVerbosityOn()
132     mypde.setSymmetryOn()
133     kappa=Scalar(0,Function(domain))
134     kappa.setTaggedValue("top",2.0*W/m/K)
135     kappa.setTaggedValue("bottom",4.0*W/m/K)
136     mypde.setValue(A=kappa*kronecker(domain))
137     x=Solution(domain).getX()
138     mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
139     qS=Scalar(0,FunctionOnBoundary(domain))
140     qS.setTaggedValue("linebottom",qin)
141     mypde.setValue(y=qS)
142     print "PDE has been generated ..."
143     ###########################################################GET SOLUTION
144     T=mypde.getSolution()
145     print "PDE has been solved ..."
146    
147     ###########################################################
148     xi, yi, zi = toRegGrid(T, nx=50, ny=50)
149     pl.matplotlib.pyplot.autumn()
150     pl.contourf(xi,yi,zi,10)
151     pl.xlabel("Horizontal Displacement (m)")
152     pl.ylabel("Depth (m)")
153     pl.savefig(os.path.join(save_path,"heatrefraction.png"))
154     print "Solution has been plotted ..."

  ViewVC Help
Powered by ViewVC 1.1.26